From 7b82a482e20fce7b6def5213b85123c929ba06cd Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Wed, 13 Apr 2016 15:38:16 +0000 Subject: [PATCH] A combined patch from Adrian's, James Yong's and my work for "Add Support For Compound Screen Widget XML Files" - https://issues.apache.org/jira/browse/OFBIZ-4090 and "Add Example for Compound Screen Widget" - https://issues.apache.org/jira/browse/OFBIZ-6990 Adrian: This adds the ability to include screen widgets, form widgets, menu widgets, and simple methods in a single XML file. This approach could be used in situations where the widgets share a logical grouping - so they can be kept in one place. James: An example to test out Compound Screen Widget jlerouxc: here are the changes and tests globally # As James mentionned we no longer need *-v2.xsd files, I removed them from Adrian's patch # I created a compound-widgets.xsd based on Adrian's and James Yong's previous work. From Paul Foxworthy's comment in OFBIZ-4090, I decided to name the root compound-widgets (hence the file name). I arranged its elements in another way, see below with ExampleCompoundWidgets.xml # I slightly modified James Yong's ExampleCompoundScreenWidget.xml file and renamed it ExampleCompoundWidgets.xml. I added an "s" because there are several OFBiz widgets gathered in one place. For the modifications: I simply changed the names and arranged the elements in another way which I find better suited. I'm used to 1st create the query, then the menus, the screens and their forms. We rarely use widget-trees but it's there also. Finally the simple-method at end if any. The order is not enforced though, so everybody can use her/his own :) # I added a French label # I completed the widget-catalog.xml with this new entry and tested locally in Eclipse by reloading the XML catalog entries. I hope I did not miss nor mixed things, the local instance I used is a bit overcrowded with pending changes... git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1738958 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/ofbiz/minilang/SimpleMethod.java | 7 +- .../ofbiz/webapp/control/ConfigXMLReader.java | 3 + framework/widget/dtd/compound-widgets.xsd | 15 +++ framework/widget/dtd/widget-catalog.xml | 1 + .../org/ofbiz/widget/model/FormFactory.java | 9 +- .../org/ofbiz/widget/model/MenuFactory.java | 3 + .../org/ofbiz/widget/model/ScreenFactory.java | 3 + .../example/config/ExampleUiLabels.xml | 4 + .../webapp/example/WEB-INF/controller.xml | 1 + .../widget/example/ExampleCompoundWidgets.xml | 115 ++++++++++++++++++ .../example/widget/example/ExampleMenus.xml | 3 + 11 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 framework/widget/dtd/compound-widgets.xsd create mode 100644 specialpurpose/example/widget/example/ExampleCompoundWidgets.xml diff --git a/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java b/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java index 7fb39f752e..ad90a0096a 100644 --- a/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java +++ b/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java @@ -142,7 +142,12 @@ public final class SimpleMethod extends MiniLangElement { } catch (Exception e) { throw new MiniLangException("Could not read SimpleMethod XML document [" + xmlURL + "]: ", e); } - compileAllSimpleMethods(document.getDocumentElement(), simpleMethods, xmlURL.toString()); + Element rootElement = document.getDocumentElement(); + if (!"simple-methods".equalsIgnoreCase(rootElement.getTagName())) { + rootElement = UtilXml.firstChildElement(rootElement, "simple-methods"); + } + + compileAllSimpleMethods(rootElement, simpleMethods, xmlURL.toString()); if (MiniLangUtil.isDocumentAutoCorrected(document)) { MiniLangUtil.writeMiniLangDocument(xmlURL, document); } diff --git a/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java b/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java index aee8b16f96..922e840b2b 100644 --- a/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java +++ b/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java @@ -159,6 +159,9 @@ public class ConfigXMLReader { try { Document document = UtilXml.readXmlDocument(location, true); Element rootElement = document.getDocumentElement(); + if (!"site-conf".equalsIgnoreCase(rootElement.getTagName())) { + rootElement = UtilXml.firstChildElement(rootElement, "site-conf"); + } if (Debug.verboseOn()) Debug.logVerbose("Loaded XML Config - " + location, module); return rootElement; diff --git a/framework/widget/dtd/compound-widgets.xsd b/framework/widget/dtd/compound-widgets.xsd new file mode 100644 index 0000000000..43c9846782 --- /dev/null +++ b/framework/widget/dtd/compound-widgets.xsd @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/framework/widget/dtd/widget-catalog.xml b/framework/widget/dtd/widget-catalog.xml index b21babd482..c18da1da53 100644 --- a/framework/widget/dtd/widget-catalog.xml +++ b/framework/widget/dtd/widget-catalog.xml @@ -31,4 +31,5 @@ under the License. + diff --git a/framework/widget/src/org/ofbiz/widget/model/FormFactory.java b/framework/widget/src/org/ofbiz/widget/model/FormFactory.java index cdd034b7e9..f9f2edcbb1 100644 --- a/framework/widget/src/org/ofbiz/widget/model/FormFactory.java +++ b/framework/widget/src/org/ofbiz/widget/model/FormFactory.java @@ -103,6 +103,9 @@ public class FormFactory { if (formFileDoc != null) { // read document and construct ModelForm for each form element Element rootElement = formFileDoc.getDocumentElement(); + if (!"forms".equalsIgnoreCase(rootElement.getTagName())) { + rootElement = UtilXml.firstChildElement(rootElement, "forms"); + } List formElements = UtilXml.childElementList(rootElement, "form"); for (Element formElement : formElements) { String formName = formElement.getAttribute("name"); @@ -119,7 +122,11 @@ public class FormFactory { } public static ModelForm createModelForm(Document formFileDoc, ModelReader entityModelReader, DispatchContext dispatchContext, String formLocation, String formName) { - Element formElement = UtilXml.firstChildElement(formFileDoc.getDocumentElement(), "form", "name", formName); + Element rootElement = formFileDoc.getDocumentElement(); + if (!"forms".equalsIgnoreCase(rootElement.getTagName())) { + rootElement = UtilXml.firstChildElement(rootElement, "forms"); + } + Element formElement = UtilXml.firstChildElement(rootElement, "form", "name", formName); return createModelForm(formElement, entityModelReader, dispatchContext, formLocation, formName); } diff --git a/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java b/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java index 5a811c672a..d037ea3e10 100644 --- a/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java +++ b/framework/widget/src/org/ofbiz/widget/model/MenuFactory.java @@ -79,6 +79,9 @@ public class MenuFactory { if (menuFileDoc != null) { // read document and construct ModelMenu for each menu element Element rootElement = menuFileDoc.getDocumentElement(); + if (!"menus".equalsIgnoreCase(rootElement.getTagName())) { + rootElement = UtilXml.firstChildElement(rootElement, "menus"); + } for (Element menuElement: UtilXml.childElementList(rootElement, "menu")){ ModelMenu modelMenu = new ModelMenu(menuElement, menuLocation); modelMenuMap.put(modelMenu.getName(), modelMenu); diff --git a/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java b/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java index db9417f916..73e76fd2b9 100644 --- a/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java +++ b/framework/widget/src/org/ofbiz/widget/model/ScreenFactory.java @@ -166,6 +166,9 @@ public class ScreenFactory { if (screenFileDoc != null) { // read document and construct ModelScreen for each screen element Element rootElement = screenFileDoc.getDocumentElement(); + if (!"screens".equalsIgnoreCase(rootElement.getTagName())) { + rootElement = UtilXml.firstChildElement(rootElement, "screens"); + } List screenElements = UtilXml.childElementList(rootElement, "screen"); for (Element screenElement: screenElements) { ModelScreen modelScreen = new ModelScreen(screenElement, modelScreenMap, sourceLocation); diff --git a/specialpurpose/example/config/ExampleUiLabels.xml b/specialpurpose/example/config/ExampleUiLabels.xml index c1f5e22870..cc220283a9 100644 --- a/specialpurpose/example/config/ExampleUiLabels.xml +++ b/specialpurpose/example/config/ExampleUiLabels.xml @@ -137,6 +137,10 @@ Graphes 绘图样例 + + Compound Screen Widget + Screen Widget composé + Dashboard Personnalisation des pages diff --git a/specialpurpose/example/webapp/example/WEB-INF/controller.xml b/specialpurpose/example/webapp/example/WEB-INF/controller.xml index 18ee59a78d..40fb9aa59f 100644 --- a/specialpurpose/example/webapp/example/WEB-INF/controller.xml +++ b/specialpurpose/example/webapp/example/WEB-INF/controller.xml @@ -25,6 +25,7 @@ under the License. elements found in the common-controller.xml file. --> + Example Component Site Configuration File diff --git a/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml b/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml new file mode 100644 index 0000000000..3619c86aec --- /dev/null +++ b/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + +
+
+
+
+
+
+ + +
+ + + + + + + + + + +
+ + + + + +
+
+
+
+
+
+
+ + +
+ +
+ +
+ +
+
+ + + + + + + +
diff --git a/specialpurpose/example/widget/example/ExampleMenus.xml b/specialpurpose/example/widget/example/ExampleMenus.xml index 047f677fa6..7f5498b05b 100644 --- a/specialpurpose/example/widget/example/ExampleMenus.xml +++ b/specialpurpose/example/widget/example/ExampleMenus.xml @@ -48,6 +48,9 @@ under the License. + + +