You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2016/05/31 16:48:09 UTC

svn commit: r1746302 [1/5] - in /ofbiz/trunk: framework/base/src/org/ofbiz/base/util/ framework/minilang/dtd/ framework/minilang/src/org/ofbiz/minilang/ framework/minilang/src/org/ofbiz/minilang/method/otherops/ framework/webapp/dtd/ framework/widget/d...

Author: jleroux
Date: Tue May 31 16:48:09 2016
New Revision: 1746302

URL: http://svn.apache.org/viewvc?rev=1746302&view=rev
Log:
A slightly modified patch from James Yong for "Autocompletion for Compound Widget" https://issues.apache.org/jira/browse/OFBIZ-7061

1. The following xsd are duplicated to use namespaces
  site-conf.xsd     ->  site-conf-ns.xsd
  widget-form.xsd   ->  widget-form-ns.xsd
  widget-screen.xsd ->  widget-screen-ns.xsd
  widget-menu.xsd   ->  widget-menu-ns.xsd
  simple-methods.xsd->  simple-methods-ns.xsd
For example, in site-conf-ns.xsd, we have the following document level attribute
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns="http://ofbiz.apache.org/Site-Conf" targetNamespace="http://ofbiz.apache.org/Site-Conf">
instead of 
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

2. The above schema are used into compound-widgets.xsd so that compound widgets use only one consolidated schema. 

3. Update ExampleCompoundWidgets.xml to use the new compound-widgets.xsd. For example
<compound-widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:sc="http://ofbiz.apache.org/Site-Conf"
        xmlns:sm="http://ofbiz.apache.org/Simple-Method"
        xmlns:wf="http://ofbiz.apache.org/Widget-Form"
        xmlns:wt="http://ofbiz.apache.org/Widget-Tree"
        xmlns:wm="http://ofbiz.apache.org/Widget-Menu"
        xmlns:ws="http://ofbiz.apache.org/Widget-Screen"
        xsi:noNamespaceSchemaLocation="../../../../framework/widget/dtd/compound-widgets.xsd">
    
    <sc:site-conf>
        <sc:request-map uri="CompoundWidgets1">
            <sc:security https="true" auth="true"/>
            <sc:event type="simple" invoke="CompoundWidgetsFunc" path="component://example/widget/example/ExampleCompoundWidgets.xml"/>
            <sc:response name="success" type="view" value="CompoundWidgets1"/>
        </sc:request-map>
        <sc:request-map uri="CompoundWidgets2"><sc:security https="true" auth="true"/><sc:response name="success" type="view" value="CompoundWidgets2"/></sc:request-map>

        <sc:view-map name="CompoundWidgets1" type="screen" page="component://example/widget/example/ExampleCompoundWidgets.xml#CompoundWidgets1"/>
        <sc:view-map name="CompoundWidgets2" type="screen" page="component://example/widget/example/ExampleCompoundWidgets.xml#CompoundWidgets2"/>
    </sc:site-conf>
...... the rest

4. Change java code to support reading xml with namespace (i.e. xml for compound widgets)

jleroux: I simply replaced tabs by spaces in Java files and removed this commented out line 
  <compound-widgets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/compound-widgets.xsd">
in ExampleCompoundWidgets.xml

We decided to duplicate the simple-methods.xsd rather than updating all concerned files. Else we would have to update the attributes at document level for rest of the controllers, menus, forms, simple methods and screens. For example, in controller.xml, we would have to change 
  xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/site-conf.xsd\u201d
to 
  xmlns="http://ofbiz.apache.org/sc\u201d xsi:schemaLocation="http://ofbiz.apache.org/dtds/site-conf-ns.xsd\u201d>
But especially we would have to use the same syntax with namespaces prefixes than in ExampleCompoundWidgets.xml (see example above). This can be discussed because with auto-completion it's not a big deal, but could be overwhelming for existing custom projects...

James mentionned that "the schema location at compound-widgets.xsd is relative to the project...". I don't see any problems with that. We can keep as is as long as we maintain the relation (ie if the main XSDs are moved). Moreover with the previous addition of compound-widgets.xsd in widget-catalog.xml it seems all things work correctly (eg w/o the new *-ns.xsd yet committed, the auto-completion works well in ExampleCompoundWidgets.xml



Added:
    ofbiz/trunk/framework/minilang/dtd/simple-methods-ns.xsd   (with props)
    ofbiz/trunk/framework/webapp/dtd/site-conf-ns.xsd   (with props)
    ofbiz/trunk/framework/widget/dtd/widget-form-ns.xsd   (with props)
    ofbiz/trunk/framework/widget/dtd/widget-menu-ns.xsd   (with props)
    ofbiz/trunk/framework/widget/dtd/widget-screen-ns.xsd   (with props)
    ofbiz/trunk/framework/widget/dtd/widget-tree-ns.xsd   (with props)
Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/SimpleMethod.java
    ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Log.java
    ofbiz/trunk/framework/widget/dtd/compound-widgets.xsd
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/WidgetFactory.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/AbstractModelAction.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/FieldInfo.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/model/ModelFormFieldBuilder.java
    ofbiz/trunk/specialpurpose/example/widget/example/ExampleCompoundWidgets.xml

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java?rev=1746302&r1=1746301&r2=1746302&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java Tue May 31 16:48:09 2016
@@ -59,6 +59,7 @@ import org.w3c.dom.DOMConfiguration;
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.bootstrap.DOMImplementationRegistry;
 import org.w3c.dom.ls.DOMImplementationLS;
@@ -690,10 +691,10 @@ public class UtilXml {
 
         if (node != null) {
             do {
+                String nodeName = UtilXml.getNodeNameIgnorePrefix(node);
                 if (node.getNodeType() == Node.ELEMENT_NODE && (childElementName == null ||
-                        childElementName.equals(node.getNodeName()))) {
+                    childElementName.equals(nodeName))) {
                     Element childElement = (Element) node;
-
                     elements.add(childElement);
                 }
             } while ((node = node.getNextSibling()) != null);
@@ -814,8 +815,12 @@ public class UtilXml {
 
         if (node != null) {
             do {
+                String nodeName = node.getLocalName();
+                if (nodeName == null){
+                    nodeName = UtilXml.getNodeNameIgnorePrefix(node);
+                }
                 if (node.getNodeType() == Node.ELEMENT_NODE && (childElementName == null ||
-                        childElementName.equals(node.getLocalName() != null ? node.getLocalName() : node.getNodeName()))) {
+                    childElementName.equals(nodeName))) {
                     Element childElement = (Element) node;
                     return childElement;
                 }
@@ -1147,5 +1152,59 @@ public class UtilXml {
             throw new UnsupportedOperationException();
         }
     }
+    
+    /**
+     * get node name without any prefix
+     * @param node
+     * @return
+     */
+    public static String getNodeNameIgnorePrefix(Node node){
+        if (node==null) return null;
+        String nodeName = node.getNodeName();
+        if (nodeName.contains(":")){
+            // remove any possible prefix
+            nodeName = nodeName.split(":")[1];
+        }
+        return nodeName;
+    }
+    
+    /**
+     * get tag name without any prefix
+     * @param node
+     * @return
+     */
+    public static String getTagNameIgnorePrefix(Element element){
+        if (element==null) return null;
+        String tagName = element.getTagName();
+        if (tagName.contains(":")){
+            // remove any possible prefix
+            tagName = tagName.split(":")[1];
+        }
+        return tagName;
+    }
+    
+    /**
+     * get attribute value ignoring prefix in attribute name
+     * @param node
+     * @return
+     */
+    public static String getAttributeValueIgnorePrefix(Element element, String attributeName){
+        if (element==null) return "";
+        
+        NamedNodeMap attributes = element.getAttributes();
+        if (attributes != null){
+            for (int i = 0, size = attributes.getLength(); i < size; i++)
+            {
+                Node node = attributes.item(i);
+                if (node.getNodeType() == Node.ATTRIBUTE_NODE){
+                    String nodeName = UtilXml.getNodeNameIgnorePrefix(node);
+                    if (nodeName.equals(attributeName)){
+                        return node.getNodeValue();
+                    }
+                }
+            }
+        }
+        return "";
+    }
 
 }