svn commit: r476610 - in /incubator/ofbiz/trunk/framework/webapp: dtd/site-conf.xsd src/org/ofbiz/webapp/control/ConfigXMLReader.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r476610 - in /incubator/ofbiz/trunk/framework/webapp: dtd/site-conf.xsd src/org/ofbiz/webapp/control/ConfigXMLReader.java

jonesde
Author: jonesde
Date: Sat Nov 18 13:37:23 2006
New Revision: 476610

URL: http://svn.apache.org/viewvc?view=rev&rev=476610
Log:
Applied patch from Peter Goron to implement include by location from one controller.xml file to another; Jira OFBIZ-370; made small change so that the include element comes first in the controller.xml file

Modified:
    incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
    incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java

Modified: incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd?view=diff&rev=476610&r1=476609&r2=476610
==============================================================================
--- incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd (original)
+++ incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd Sat Nov 18 13:37:23 2006
@@ -18,6 +18,7 @@
     <xs:element name="site-conf">
         <xs:complexType>
             <xs:sequence>
+                <xs:element minOccurs="0" ref="include"/>
                 <xs:element minOccurs="0" ref="description"/>
                 <xs:element minOccurs="0" ref="owner"/>
                 <xs:element ref="errorpage"/>
@@ -87,6 +88,14 @@
             </xs:sequence>
         </xs:complexType>
     </xs:element>
+    <xs:element name="include">
+        <xs:complexType>
+            <xs:attributeGroup ref="attlist.include"/>
+        </xs:complexType>
+    </xs:element>
+    <xs:attributeGroup name="attlist.include">
+        <xs:attribute type="xs:string" name="location" use="required"/>
+    </xs:attributeGroup>
     <xs:element name="request-map">
         <xs:complexType>
             <xs:sequence>

Modified: incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java?view=diff&rev=476610&r1=476609&r2=476610
==============================================================================
--- incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java (original)
+++ incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java Sat Nov 18 13:37:23 2006
@@ -26,6 +26,7 @@
 import javolution.util.FastList;
 import javolution.util.FastMap;
 
+import org.ofbiz.base.location.FlexibleLocation;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
@@ -88,8 +89,7 @@
 
     /** URI Config Variables */
     public static final String INCLUDE = "include";
-    public static final String INCLUDE_FILE = "file";
-    public static final String INCLUDE_URL = "url";
+    public static final String INCLUDE_LOCATION = "location";
 
     public static final String REQUEST_MAPPING = "request-map";
     public static final String REQUEST_URI = "uri";
@@ -167,30 +167,17 @@
         Iterator includeElementIter = includeElementList.iterator();
         while (includeElementIter.hasNext()) {
             Element includeElement = (Element) includeElementIter.next();
-            String includeFile = includeElement.getAttribute(INCLUDE_FILE);
-
-            if ((includeFile != null) && (includeFile.length() > 0)) {
-                File oldFile = new File(xml.getFile());
-                File newFile = new java.io.File("" + oldFile.getParent() + java.io.File.separator + includeFile);
+            String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION);
 
+            if ((includeLocation != null) && (includeLocation.length() > 0)) {
                 try {
-                    Map subMap = loadRequestMap(null, newFile.toURL());
+                    Map subMap = loadRequestMap(null, FlexibleLocation.resolveLocation(includeLocation));
 
                     map.putAll(subMap);
                 } catch (MalformedURLException mue) {
                     mue.printStackTrace();
                 }
             }
-
-            String includeURL = includeElement.getAttribute(INCLUDE_URL);
-            if ((includeURL != null) && (includeURL.length() > 0)) {
-                try {
-                    Map subMap = loadRequestMap(null, new URL(includeURL));
-                    map.putAll(subMap);
-                } catch (MalformedURLException mue) {
-                    mue.printStackTrace();
-                }
-            }
         }
 
         List requestMapElementList = UtilXml.childElementList(root, REQUEST_MAPPING);
@@ -316,30 +303,17 @@
         Iterator includeElementIter = includeElementList.iterator();
         while (includeElementIter.hasNext()) {
             Element includeElement = (Element) includeElementIter.next();
-            String includeFile = includeElement.getAttribute(INCLUDE_FILE);
-
-            if ((includeFile != null) && (includeFile.length() > 0)) {
-                File oldFile = new File(xml.getFile());
-                File newFile = new java.io.File("" + oldFile.getParent() + java.io.File.separator + includeFile);
+            String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION);
 
+            if ((includeLocation != null) && (includeLocation.length() > 0)) {
                 try {
-                    Map subMap = loadRequestMap(null, newFile.toURL());
+                    Map subMap = loadViewMap(null, FlexibleLocation.resolveLocation(includeLocation));
 
                     map.putAll(subMap);
                 } catch (MalformedURLException mue) {
                     mue.printStackTrace();
                 }
             }
-
-            String includeURL = includeElement.getAttribute(INCLUDE_URL);
-            if ((includeURL != null) && (includeURL.length() > 0)) {
-                try {
-                    Map subMap = loadRequestMap(null, new URL(includeURL));
-                    map.putAll(subMap);
-                } catch (MalformedURLException mue) {
-                    mue.printStackTrace();
-                }
-            }
         }
 
         List viewMapElementList = UtilXml.childElementList(root, VIEW_MAPPING);
@@ -634,37 +608,5 @@
             return string;
         else
             return "";
-    }
-
-    public static void main(String args[]) throws Exception {
-        /** Debugging */
-        if (args[0] == null) {
-            System.out.println("Please give a path to the config file you wish to test.");
-            return;
-        }
-        System.out.println("----------------------------------");
-        System.out.println("Request Mappings:");
-        System.out.println("----------------------------------");
-        Map debugMap = getRequestMap(new URL(args[0]));
-        Set debugSet = debugMap.keySet();
-        Iterator i = debugSet.iterator();
-        while (i.hasNext()) {
-            Object o = i.next();
-            String request = (String) o;
-            FastMap thisURI = (FastMap) debugMap.get(o);
-
-            System.out.println(request);
-            Iterator list = ((java.util.Set) thisURI.keySet()).iterator();
-            while (list.hasNext()) {
-                Object lo = list.next();
-                String name = (String) lo;
-                String value = (String) thisURI.get(lo);
-                System.out.println("\t" + name + " -> " + value);
-            }
-        }
-        System.out.println("----------------------------------");
-        System.out.println("End Request Mappings.");
-        System.out.println("----------------------------------");
-        /** End Debugging */
     }
 }