From 710ac5b727017935ecf6405e7bfaa7415e5ec2f0 Mon Sep 17 00:00:00 2001 From: Ariel Backenroth Date: Wed, 13 Jun 2007 21:11:24 +0000 Subject: [PATCH] externalizing widget config for xforms to xml - adding a utility method to ConfigElement to get a list of child config elements by name - using JSONObject to generate js rendition of config - adding a build script to build json.jar since json.org only distributes source - adding a preview link for form instance data to create web content summary screen - doing the full jsp2.0 thing with summary screen for create website, i have a hunch it will fix a websphere issue git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5943 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .classpath | 1 + config/alfresco/web-client-config-wcm.xml | 75 ++++ .../alfresco/web/forms/xforms/XFormsBean.java | 4 +- .../web/forms/xforms/XFormsProcessor.java | 162 ++++++++- .../unit-tests/simple-test/textarea-test.xsd | 4 +- .../unit-tests/simple-test/textarea-test.xsl | 69 ++++ .../wcm/create-web-content-wizard/summary.jsp | 241 ++++++------ .../jsp/wcm/create-website-wizard/summary.jsp | 344 +++++++++--------- source/web/scripts/ajax/xforms.js | 89 +---- 9 files changed, 633 insertions(+), 356 deletions(-) create mode 100644 source/test-resources/xforms/unit-tests/simple-test/textarea-test.xsl diff --git a/.classpath b/.classpath index 23e0ed9aa8..382f25e040 100644 --- a/.classpath +++ b/.classpath @@ -17,5 +17,6 @@ + diff --git a/config/alfresco/web-client-config-wcm.xml b/config/alfresco/web-client-config-wcm.xml index 69c04eb082..6d341062bd 100644 --- a/config/alfresco/web-client-config-wcm.xml +++ b/config/alfresco/web-client-config-wcm.xml @@ -26,6 +26,81 @@ 30 + + + + + + + + bold,italic,underline,separator,forecolor,backcolor,separator,link,unlink,image + + + bold,italic,underline,strikethrough,separator,fontselect,fontsizeselect + link,unlink,image,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,undo,redo,separator,forecolor,backcolor + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java index 32aa3a38ed..2653d5e27e 100644 --- a/source/java/org/alfresco/web/forms/xforms/XFormsBean.java +++ b/source/java/org/alfresco/web/forms/xforms/XFormsBean.java @@ -50,8 +50,8 @@ import org.alfresco.web.app.servlet.ajax.InvokeCommand; import org.alfresco.web.bean.FileUploadBean; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.bean.wcm.AVMBrowseBean; -import org.alfresco.web.bean.wcm.AVMUtil; import org.alfresco.web.bean.wcm.AVMNode; +import org.alfresco.web.bean.wcm.AVMUtil; import org.alfresco.web.forms.*; import org.alfresco.web.ui.common.Utils; @@ -161,7 +161,7 @@ public class XFormsBean private Schema2XFormsProperties schema2XFormsProperties; private AVMBrowseBean avmBrowseBean; private AVMService avmService; - + public XFormsBean() { } diff --git a/source/java/org/alfresco/web/forms/xforms/XFormsProcessor.java b/source/java/org/alfresco/web/forms/xforms/XFormsProcessor.java index 3b5147afc9..13d47e8782 100644 --- a/source/java/org/alfresco/web/forms/xforms/XFormsProcessor.java +++ b/source/java/org/alfresco/web/forms/xforms/XFormsProcessor.java @@ -20,16 +20,20 @@ package org.alfresco.web.forms.xforms; import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.ResourceBundle; +import java.util.*; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletRequest; +import org.alfresco.config.ConfigElement; +import org.alfresco.config.ConfigService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.web.bean.wcm.AVMBrowseBean; import org.alfresco.web.bean.wcm.AVMUtil; import org.alfresco.web.forms.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.json.JSONException; +import org.json.JSONObject; import org.springframework.web.util.JavaScriptUtils; import org.w3c.dom.Document; @@ -92,8 +96,14 @@ public class XFormsProcessor "validation_provide_values_for_required_fields" }; + private static JSONObject widgetConfig = null; + public XFormsProcessor() { + if (XFormsProcessor.widgetConfig == null) + { + XFormsProcessor.widgetConfig = XFormsProcessor.loadConfig(); + } } public Session process(final Document instanceDataDocument, @@ -225,6 +235,19 @@ public class XFormsProcessor append(k.equals(BUNDLE_KEYS[BUNDLE_KEYS.length - 1]) ? "\n};" : ","). append("\n"); } + + try + { + js.append("alfresco.xforms.widgetConfig = \n"). + append(LOGGER.isDebugEnabled() + ? XFormsProcessor.widgetConfig.toString(0) + : XFormsProcessor.widgetConfig). + append("\n"); + } + catch (JSONException jsone) + { + LOGGER.error(jsone); + } e.appendChild(result.createTextNode(js.toString())); div.appendChild(e); @@ -241,4 +264,141 @@ public class XFormsProcessor XMLUtil.print(result, out); } + + private static JSONObject loadConfig() + { + final ConfigService cfgService = Application.getConfigService(FacesContext.getCurrentInstance()); + final ConfigElement xformsConfig = cfgService.getGlobalConfig().getConfigElement("wcm").getChild("xforms"); + final List widgetConfig = xformsConfig.getChildren("widget"); + + class WidgetConfigElement + implements Comparable + { + public final String xformsType; + public final String xmlSchemaType; + public final String appearance; + public final String javascriptClassName; + private List params; + + public WidgetConfigElement(final String xformsType, + final String xmlSchemaType, + final String appearance, + final String javascriptClassName) + { + if (xformsType == null) + { + throw new NullPointerException(); + } + this.xformsType = xformsType; + this.xmlSchemaType = xmlSchemaType; + this.appearance = appearance; + this.javascriptClassName = javascriptClassName; + } + + public void addParam(final String p) + { + if (this.params == null) + { + this.params = new LinkedList(); + } + this.params.add(p); + } + + public List getParams() + { + return (this.params == null + ? (List)Collections.EMPTY_LIST + : Collections.unmodifiableList(this.params)); + } + + public int compareTo(final WidgetConfigElement other) + { + int result = this.xformsType.compareTo(other.xformsType); + if (result != 0) + { + return result; + } + + result = this.compareAttribute(this.xmlSchemaType, other.xmlSchemaType); + if (result != 0) + { + return result; + } + result = this.compareAttribute(this.appearance, other.appearance); + if (result != 0) + { + return result; + } + throw new RuntimeException("widget definitions " + this + + " and " + other + " collide"); + } + + public String toString() + { + return (this.getClass().getName() + "{" + + "xformsType: "+ this.xformsType + + ", xmlSchemaType: " + this.xmlSchemaType + + ", appearance: " + this.appearance + + ", javascriptClassName: " + this.javascriptClassName + + ", numParams: " + this.getParams().size() + + "}"); + } + + private int compareAttribute(final String s1, final String s2) + { + return (s1 != null && s2 == null + ? 1 + : (s1 == null && s2 != null + ? -1 + : (s1 != null && s2 != null + ? s1.compareTo(s2) + : 0))); + } + } + + final TreeSet widgetConfigs = new TreeSet(); + for (final ConfigElement ce : widgetConfig) + { + final WidgetConfigElement wce = new WidgetConfigElement(ce.getAttribute("xforms-type"), + ce.getAttribute("xml-schema-type"), + ce.getAttribute("appearance"), + ce.getAttribute("javascript-class-name")); + + final List params = ce.getChildren("param"); + for (final ConfigElement p : params) + { + wce.addParam(p.getValue()); + } + widgetConfigs.add(wce); + } + try + { + final JSONObject result = new JSONObject(); + for (final WidgetConfigElement wce : widgetConfigs) + { + if (!result.has(wce.xformsType)) + { + result.put(wce.xformsType, new JSONObject()); + } + final JSONObject xformsTypeObject = result.getJSONObject(wce.xformsType); + String s = wce.xmlSchemaType == null ? "*" : wce.xmlSchemaType; + if (!xformsTypeObject.has(s)) + { + xformsTypeObject.put(s, new JSONObject()); + } + final JSONObject schemaTypeObject = xformsTypeObject.getJSONObject(s); + s = wce.appearance == null ? "*" : wce.appearance; + final JSONObject o = new JSONObject(); + schemaTypeObject.put(s, o); + o.put("className", wce.javascriptClassName); + o.put("params", wce.getParams()); + } + return result; + } + catch (JSONException jsone) + { + LOGGER.error(jsone, jsone); + return null; + } + } } diff --git a/source/test-resources/xforms/unit-tests/simple-test/textarea-test.xsd b/source/test-resources/xforms/unit-tests/simple-test/textarea-test.xsd index 373511fbd2..20733c5430 100644 --- a/source/test-resources/xforms/unit-tests/simple-test/textarea-test.xsd +++ b/source/test-resources/xforms/unit-tests/simple-test/textarea-test.xsd @@ -13,7 +13,7 @@ - + full @@ -29,7 +29,7 @@ - + full diff --git a/source/test-resources/xforms/unit-tests/simple-test/textarea-test.xsl b/source/test-resources/xforms/unit-tests/simple-test/textarea-test.xsl new file mode 100644 index 0000000000..a320800852 --- /dev/null +++ b/source/test-resources/xforms/unit-tests/simple-test/textarea-test.xsl @@ -0,0 +1,69 @@ + + + + + + + + + + + textarea test + + +
Generated by textarea-test.xsl
+ + + +
+ +
+ plain text: + +
+
+ +
+ rich text anyType: + +
+
+ +
+ rich text stringType: + +
+
+ +
+ rich text stringType attribute: + +
+
+ +
+ rich text stringType attribute: + +
+
+
diff --git a/source/web/jsp/wcm/create-web-content-wizard/summary.jsp b/source/web/jsp/wcm/create-web-content-wizard/summary.jsp index 530fc7efb8..13b8b76286 100644 --- a/source/web/jsp/wcm/create-web-content-wizard/summary.jsp +++ b/source/web/jsp/wcm/create-web-content-wizard/summary.jsp @@ -1,130 +1,155 @@ -<%-- - * Copyright (C) 2005-2007 Alfresco Software Limited. + + - - - + - - - - - - - - - - -
${msg.form}:${WizardManager.bean.form.title}
${msg.location}:${WizardManager.bean.formInstanceData.sandboxRelativePath}
-
-
-
-
+ + - - - + - - - - - + + + + + + + + ${WizardManager.bean.formInstanceData.name} + - + target="window_${WizardManager.bean.formInstanceData.name}"> /images/icons/preview_website.gif absmiddle border: 0px - ${rendition.name} + ${WizardManager.bean.formInstanceData.name} - ${rendition.description} - + + + + + + +
${msg.form}:${WizardManager.bean.form.title}
${msg.location}:${WizardManager.bean.formInstanceData.sandboxRelativePath}
+
-
-
-
+ + - - - + + + - - - - - + + + + + ${rendition.name} + + + + + + /images/icons/preview_website.gif + + absmiddle + border: 0px + ${rendition.name} + + + + ${rendition.description} + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + +
diff --git a/source/web/jsp/wcm/create-website-wizard/summary.jsp b/source/web/jsp/wcm/create-website-wizard/summary.jsp index d0c1f7e175..2c24e490ec 100644 --- a/source/web/jsp/wcm/create-website-wizard/summary.jsp +++ b/source/web/jsp/wcm/create-website-wizard/summary.jsp @@ -1,193 +1,203 @@ -<%-- - * Copyright (C) 2005-2007 Alfresco Software Limited. + + - + - - - + + - - - - - - - - - - - - - - -
${msg.website_dnsname}: ${WizardManager.bean.dnsName}
${msg.website_webapp}: ${WizardManager.bean.webapp}
${msg.title}: ${WizardManager.bean.title}
${msg.description}: - - - ${msg.description_not_set} - - ${WizardManager.bean.description} - -
-
-
-
-
+ - - - + + + - - - - - - + + + + ${WizardManager.bean.name} + - - - + + + - - - +
${msg.name}: ${r.name}
${msg.title}: ${r.title}
${msg.output_path_pattern}: ${r.outputPathPattern}
${msg.website_dnsname}: ${WizardManager.bean.dnsName}
${msg.website_webapp}: ${WizardManager.bean.webapp}
${msg.title}: ${WizardManager.bean.title}
${msg.description}: + ${msg.description_not_set} - ${r.description} + ${WizardManager.bean.description} -
${msg.workflow}: - - - ${msg.none} - - ${r.workflow.title} - -
-
+
-
-
-
+ + - - - + + + - - - - - - - - - - - - - - -
${msg.description}: - - - ${msg.description_not_set} - - ${r.description} - -
${msg.website_filename_pattern}: ${r.filenamePattern}
-
-
-
-
-
+ + + + + + ${r.name} + + + + + + + + + + + + + + +
${msg.name}: ${r.name}
${msg.title}: ${r.title}
${msg.output_path_pattern}: ${r.outputPathPattern}
${msg.description}: + + + ${msg.description_not_set} + + ${r.description} + +
${msg.workflow}: + + + ${msg.none} + + ${r.workflow.title} + +
+
+
+
+
+
- - - + + + - - - - - - - - - - -
${msg.roles}: ${r.role}
-
-
-
-
-
+ + + + + + ${r.title} + + + + + + + + + +
${msg.description}: + + + ${msg.description_not_set} + + ${r.description} + +
${msg.website_filename_pattern}: ${r.filenamePattern}
+
+
+
+
+
+ + + + + + + + + + ${r.name} + + + + + + +
${msg.roles}: ${r.role}
+
+
+
+
+
+
diff --git a/source/web/scripts/ajax/xforms.js b/source/web/scripts/ajax/xforms.js index 510851e679..4b0a2f599b 100644 --- a/source/web/scripts/ajax/xforms.js +++ b/source/web/scripts/ajax/xforms.js @@ -846,9 +846,9 @@ dojo.declare("alfresco.xforms.RichTextEditor", this.statics.currentInstance = this; - tinyMCE.settings.theme_advanced_buttons1 = this._tinyMCE_buttons[0]; - tinyMCE.settings.theme_advanced_buttons2 = this._tinyMCE_buttons[1]; - tinyMCE.settings.theme_advanced_buttons3 = this._tinyMCE_buttons[2]; + tinyMCE.settings.theme_advanced_buttons1 = this._tinyMCE_buttons[0] || ""; + tinyMCE.settings.theme_advanced_buttons2 = this._tinyMCE_buttons[1] || ""; + tinyMCE.settings.theme_advanced_buttons3 = this._tinyMCE_buttons[2] || ""; tinyMCE.addMCEControl(this.widget, this.id); var editorDocument = tinyMCE.getInstanceById(this.id).getDoc(); @@ -4006,11 +4006,19 @@ dojo.declare("alfresco.xforms.XForm", " schemaType " + schemaType + " appearance " + appearance); } - if (x == null) + if (x == null || typeof x.className == "undefined") { return null; } - var result = new x.className(this, xformsNode, x.params); + var cstr = eval(x.className); + if (!cstr) + { + throw new Error("unable to load constructor " + x.className + + " for xforms type " + xformsType + + " schemaType " + schemaType + + " appearance " + appearance); + } + var result = new cstr(this, xformsNode, x.params); if (result instanceof alfresco.xforms.Widget) { return result; @@ -4624,74 +4632,3 @@ tinyMCE.init({ theme_advanced_buttons3: "", urlconverter_callback: "alfresco_TinyMCE_urlconverter_callback" }); - -alfresco.xforms.widgetConfig = -{ - "xf:group": - { - "*": { "minimal": { className: alfresco.xforms.HGroup }, "*": { className: alfresco.xforms.VGroup }} - }, - "xf:repeat": - { - "*": { "*": { className: alfresco.xforms.Repeat } } - }, - "xf:textarea": - { - "*": - { - "minimal": { className: alfresco.xforms.PlainTextEditor }, - "*": { className: alfresco.xforms.RichTextEditor, params: [ "bold,italic,underline,separator,forecolor,backcolor,separator,link,unlink,image", "", "" ] }, - "full": { className: alfresco.xforms.RichTextEditor, params: ["bold,italic,underline,strikethrough,separator,fontselect,fontsizeselect", "link,unlink,image,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,undo,redo,separator,forecolor,backcolor", "" ] } - } - }, - "xf:upload": - { - "*": { "*": { className: alfresco.xforms.FilePicker } } - }, - "xf:range": - { - "*": { "*": { className: alfresco.xforms.NumericalRange } } - }, - "xf:input": - { - "date": { "*": { className: alfresco.xforms.DatePicker }}, - "time": { "*": { className: alfresco.xforms.TimePicker }}, - "gDay": { "*": { className: alfresco.xforms.DayPicker }}, - "gMonth": { "*": { className: alfresco.xforms.MonthPicker }}, - "gYear": { "*": { className: alfresco.xforms.YearPicker }}, - "gMonthDay": { "*": { className: alfresco.xforms.MonthDayPicker }}, - "gYearMonth": { "*": { className: alfresco.xforms.YearMonthPicker }}, - "dateTime": { "*": { className: alfresco.xforms.DateTimePicker }}, - "*": { "*": { className: alfresco.xforms.TextField }} - }, - "xf:select1": - { - "boolean": { "*": { className: alfresco.xforms.Checkbox }}, - "*": { "full": { className: alfresco.xforms.RadioSelect1}, - "*": { className: alfresco.xforms.ComboboxSelect1 }} - }, - "xf:select": - { - "*": { "full": { className: alfresco.xforms.CheckboxSelect}, - "*": { className: alfresco.xforms.ListSelect }} - }, - "xf:submit": - { - "*": { "*": { className: alfresco.xforms.Submit } } - }, - "xf:trigger": - { - "*": { "*": { className: alfresco.xforms.Trigger }} - }, - "xf:switch": - { - "*": { "*": { className: alfresco.xforms.SwitchGroup } } - }, - "xf:case": - { - "*": { "*": { className: alfresco.xforms.CaseGroup }} - }, - "chiba:data": { "*": { "*": null } }, - "xf:label": { "*": { "*": null } }, - "xf:alert": { "*": { "*": null } } -}