Author: adrianc
Date: Tue Oct 22 04:17:55 2013
New Revision: 1534488

URL: http://svn.apache.org/r1534488
Log:
Reformatted ConfigXMLReader.java - no functional change. This is in preparation 
for some refactoring.

Modified:
    
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java?rev=1534488&r1=1534487&r2=1534488&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java 
(original)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java 
Tue Oct 22 04:17:55 2013
@@ -53,17 +53,78 @@ public class ConfigXMLReader {
 
     public static final String module = ConfigXMLReader.class.getName();
     public static final String controllerXmlFileName = 
"/WEB-INF/controller.xml";
-
     private static final UtilCache<URL, ControllerConfig> controllerCache = 
UtilCache.createUtilCache("webapp.ControllerConfig");
     private static final UtilCache<String, List<ControllerConfig>> 
controllerSearchResultsCache = 
UtilCache.createUtilCache("webapp.ControllerSearchResults");
+    public static final RequestResponse emptyNoneRequestResponse = 
RequestResponse.createEmptyNoneRequestResponse();
 
-    public static URL getControllerConfigURL(ServletContext context) {
-        try {
-            return context.getResource(controllerXmlFileName);
-        } catch (MalformedURLException e) {
-            Debug.logError(e, "Error Finding XML Config File: " + 
controllerXmlFileName, module);
+    public static Set<String> findControllerFilesWithRequest(String 
requestUri, String controllerPartialPath) throws GeneralException {
+        Set<String> allControllerRequestSet = FastSet.newInstance();
+        if (UtilValidate.isEmpty(requestUri)) {
+            return allControllerRequestSet;
+        }
+        String cacheId = controllerPartialPath != null ? controllerPartialPath 
: "NOPARTIALPATH";
+        List<ControllerConfig> controllerConfigs = 
controllerSearchResultsCache.get(cacheId);
+        if (controllerConfigs == null) {
+            try {
+                // find controller.xml file with webappMountPoint + "/WEB-INF" 
in the path
+                List<File> controllerFiles = FileUtil.findXmlFiles(null, 
controllerPartialPath, "site-conf", "site-conf.xsd");
+                controllerConfigs = FastList.newInstance();
+                for (File controllerFile : controllerFiles) {
+                    URL controllerUrl = null;
+                    try {
+                        controllerUrl = controllerFile.toURI().toURL();
+                    } catch (MalformedURLException mue) {
+                        throw new GeneralException(mue);
+                    }
+                    ControllerConfig cc = 
ConfigXMLReader.getControllerConfig(controllerUrl);
+                    controllerConfigs.add(cc);
+                }
+                controllerConfigs = 
controllerSearchResultsCache.putIfAbsentAndGet(cacheId, controllerConfigs);
+            } catch (IOException e) {
+                throw new GeneralException("Error finding controller XML files 
to lookup request references: " + e.toString(), e);
+            }
+        }
+        if (controllerConfigs != null) {
+            for (ControllerConfig cc : controllerConfigs) {
+                // make sure it has the named request in it
+                if (cc.requestMapMap.get(requestUri) != null) {
+                    String requestUniqueId = cc.url.toExternalForm() + "#" + 
requestUri;
+                    allControllerRequestSet.add(requestUniqueId);
+                    // Debug.logInfo("========== In 
findControllerFilesWithRequest found controller with request here [" + 
requestUniqueId + "]", module);
+                }
+            }
+        }
+        return allControllerRequestSet;
+    }
+
+    public static Set<String> findControllerRequestUniqueForTargetType(String 
target, String urlMode) throws GeneralException {
+        if (UtilValidate.isEmpty(urlMode)) {
+            urlMode = "intra-app";
+        }
+        int indexOfDollarSignCurlyBrace = target.indexOf("${");
+        int indexOfQuestionMark = target.indexOf("?");
+        if (indexOfDollarSignCurlyBrace >= 0 && (indexOfQuestionMark < 0 || 
indexOfQuestionMark > indexOfDollarSignCurlyBrace)) {
+            // we have an expanded string in the requestUri part of the 
target, not much we can do about that...
             return null;
         }
+        if ("intra-app".equals(urlMode)) {
+            // look through all controller.xml files and find those with the 
request-uri referred to by the target
+            String requestUri = UtilHttp.getRequestUriFromTarget(target);
+            Set<String> controllerLocAndRequestSet = 
ConfigXMLReader.findControllerFilesWithRequest(requestUri, null);
+            // if (controllerLocAndRequestSet.size() > 0) 
Debug.logInfo("============== In findRequestNamesLinkedtoInWidget, 
controllerLocAndRequestSet: " + controllerLocAndRequestSet, module);
+            return controllerLocAndRequestSet;
+        } else if ("inter-app".equals(urlMode)) {
+            String webappMountPoint = 
UtilHttp.getWebappMountPointFromTarget(target);
+            if (webappMountPoint != null)
+                webappMountPoint += "/WEB-INF";
+            String requestUri = UtilHttp.getRequestUriFromTarget(target);
+
+            Set<String> controllerLocAndRequestSet = 
ConfigXMLReader.findControllerFilesWithRequest(requestUri, webappMountPoint);
+            // if (controllerLocAndRequestSet.size() > 0) 
Debug.logInfo("============== In findRequestNamesLinkedtoInWidget, 
controllerLocAndRequestSet: " + controllerLocAndRequestSet, module);
+            return controllerLocAndRequestSet;
+        } else {
+            return FastSet.newInstance();
+        }
     }
 
     public static ControllerConfig getControllerConfig(URL url) {
@@ -74,147 +135,163 @@ public class ConfigXMLReader {
         return controllerConfig;
     }
 
+    public static URL getControllerConfigURL(ServletContext context) {
+        try {
+            return context.getResource(controllerXmlFileName);
+        } catch (MalformedURLException e) {
+            Debug.logError(e, "Error Finding XML Config File: " + 
controllerXmlFileName, module);
+            return null;
+        }
+    }
+
+    /** Loads the XML file and returns the root element */
+    public static Element loadDocument(URL location) {
+        Document document;
+        try {
+            document = UtilXml.readXmlDocument(location, true);
+            Element rootElement = document.getDocumentElement();
+            // rootElement.normalize();
+            if (Debug.verboseOn())
+                Debug.logVerbose("Loaded XML Config - " + location, module);
+            return rootElement;
+        } catch (Exception e) {
+            Debug.logError(e, module);
+        }
+        return null;
+    }
+
     public static class ControllerConfig {
         public URL url;
-
         private String errorpage;
         private String protectView;
         private String owner;
         private String securityClass;
         private String defaultRequest;
         private String statusCode;
-
         private List<URL> includes = FastList.newInstance();
         private Map<String, Event> firstVisitEventList = FastMap.newInstance();
         private Map<String, Event> preprocessorEventList = 
FastMap.newInstance();
         private Map<String, Event> postprocessorEventList = 
FastMap.newInstance();
         private Map<String, Event> afterLoginEventList = FastMap.newInstance();
         private Map<String, Event> beforeLogoutEventList = 
FastMap.newInstance();
-
         private Map<String, String> eventHandlerMap = FastMap.newInstance();
         private Map<String, String> viewHandlerMap = FastMap.newInstance();
-
         private Map<String, RequestMap> requestMapMap = FastMap.newInstance();
         private Map<String, ViewMap> viewMapMap = FastMap.newInstance();
 
         public ControllerConfig(URL url) {
             this.url = url;
-
             Element rootElement = loadDocument(url);
             if (rootElement != null) {
                 long startTime = System.currentTimeMillis();
-
                 loadIncludes(rootElement);
                 loadGeneralConfig(rootElement);
                 loadHandlerMap(rootElement);
                 loadRequestMap(rootElement);
                 loadViewMap(rootElement);
-
                 if (Debug.infoOn()) {
-                    double totalSeconds = (System.currentTimeMillis() - 
startTime)/1000.0;
+                    double totalSeconds = (System.currentTimeMillis() - 
startTime) / 1000.0;
                     String locString = this.url.toExternalForm();
                     Debug.logInfo("controller loaded: " + totalSeconds + "s, " 
+ this.requestMapMap.size() + " requests, " + this.viewMapMap.size() + " views 
in " + locString, module);
                 }
             }
         }
 
-        public String getErrorpage() {
-            if (errorpage != null) {
-                return errorpage;
-            }
-            for (URL includeLocation: includes) {
+        public Map<String, Event> getAfterLoginEventList() {
+            MapContext<String, Event> result = MapContext.getMapContext();
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                String errorpage = controllerConfig.getErrorpage();
-                if (errorpage != null) {
-                    return errorpage;
-                }
+                result.push(controllerConfig.getAfterLoginEventList());
             }
-            return null;
+            result.push(afterLoginEventList);
+            return result;
         }
 
-        public String getProtectView() {
-            if (protectView != null) {
-                return protectView;
-            }
-            for (URL includeLocation: includes) {
+        public Map<String, Event> getBeforeLogoutEventList() {
+            MapContext<String, Event> result = MapContext.getMapContext();
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                String protectView = controllerConfig.getProtectView();
-                if (protectView != null) {
-                    return protectView;
-                }
+                result.push(controllerConfig.getBeforeLogoutEventList());
             }
-            return null;
+            result.push(beforeLogoutEventList);
+            return result;
         }
 
-        public String getStatusCode() {
-            if (statusCode != null) {
-                return statusCode;
+        public String getDefaultRequest() {
+            if (defaultRequest != null) {
+                return defaultRequest;
             }
-            for (URL includeLocation: includes) {
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                String statusCode = controllerConfig.getStatusCode();
-                if (statusCode != null) {
-                    return statusCode;
+                String defaultRequest = controllerConfig.getDefaultRequest();
+                if (defaultRequest != null) {
+                    return defaultRequest;
                 }
             }
             return null;
         }
 
-        public String getOwner() {
-            if (owner != null) {
-                return owner;
+        public String getErrorpage() {
+            if (errorpage != null) {
+                return errorpage;
             }
-            for (URL includeLocation: includes) {
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                String owner = controllerConfig.getOwner();
-                if (owner != null) {
-                    return owner;
+                String errorpage = controllerConfig.getErrorpage();
+                if (errorpage != null) {
+                    return errorpage;
                 }
             }
             return null;
         }
 
-        public String getSecurityClass() {
-            if (securityClass != null) {
-                return securityClass;
+        public Map<String, String> getEventHandlerMap() {
+            MapContext<String, String> result = MapContext.getMapContext();
+            for (URL includeLocation : includes) {
+                ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
+                result.push(controllerConfig.getEventHandlerMap());
             }
-            for (URL includeLocation: includes) {
+            result.push(eventHandlerMap);
+            return result;
+        }
+
+        public Map<String, Event> getFirstVisitEventList() {
+            MapContext<String, Event> result = MapContext.getMapContext();
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                String securityClass = controllerConfig.getSecurityClass();
-                if (securityClass != null) {
-                    return securityClass;
-                }
+                result.push(controllerConfig.getFirstVisitEventList());
             }
-            return null;
+            result.push(firstVisitEventList);
+            return result;
         }
 
-        public String getDefaultRequest() {
-            if (defaultRequest != null) {
-                return defaultRequest;
+        public String getOwner() {
+            if (owner != null) {
+                return owner;
             }
-            for (URL includeLocation: includes) {
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                String defaultRequest = controllerConfig.getDefaultRequest();
-                if (defaultRequest != null) {
-                    return defaultRequest;
+                String owner = controllerConfig.getOwner();
+                if (owner != null) {
+                    return owner;
                 }
             }
             return null;
         }
 
-        public Map<String, Event> getFirstVisitEventList() {
+        public Map<String, Event> getPostprocessorEventList() {
             MapContext<String, Event> result = MapContext.getMapContext();
-            for (URL includeLocation: includes) {
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                result.push(controllerConfig.getFirstVisitEventList());
+                result.push(controllerConfig.getPostprocessorEventList());
             }
-            result.push(firstVisitEventList);
+            result.push(postprocessorEventList);
             return result;
         }
 
         public Map<String, Event> getPreprocessorEventList() {
             MapContext<String, Event> result = MapContext.getMapContext();
-            for (URL includeLocation: includes) {
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
                 result.push(controllerConfig.getPreprocessorEventList());
             }
@@ -222,49 +299,61 @@ public class ConfigXMLReader {
             return result;
         }
 
-        public Map<String, Event> getPostprocessorEventList() {
-            MapContext<String, Event> result = MapContext.getMapContext();
-            for (URL includeLocation: includes) {
+        public String getProtectView() {
+            if (protectView != null) {
+                return protectView;
+            }
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                result.push(controllerConfig.getPostprocessorEventList());
+                String protectView = controllerConfig.getProtectView();
+                if (protectView != null) {
+                    return protectView;
+                }
             }
-            result.push(postprocessorEventList);
-            return result;
+            return null;
         }
 
-        public Map<String, Event> getAfterLoginEventList() {
-            MapContext<String, Event> result = MapContext.getMapContext();
-            for (URL includeLocation: includes) {
+        public Map<String, RequestMap> getRequestMapMap() {
+            MapContext<String, RequestMap> result = MapContext.getMapContext();
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                result.push(controllerConfig.getAfterLoginEventList());
+                result.push(controllerConfig.getRequestMapMap());
             }
-            result.push(afterLoginEventList);
+            result.push(requestMapMap);
             return result;
         }
 
-        public Map<String, Event> getBeforeLogoutEventList() {
-            MapContext<String, Event> result = MapContext.getMapContext();
-            for (URL includeLocation: includes) {
+        public String getSecurityClass() {
+            if (securityClass != null) {
+                return securityClass;
+            }
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                result.push(controllerConfig.getBeforeLogoutEventList());
+                String securityClass = controllerConfig.getSecurityClass();
+                if (securityClass != null) {
+                    return securityClass;
+                }
             }
-            result.push(beforeLogoutEventList);
-            return result;
+            return null;
         }
 
-        public Map<String, String> getEventHandlerMap() {
-            MapContext<String, String> result = MapContext.getMapContext();
-            for (URL includeLocation: includes) {
+        public String getStatusCode() {
+            if (statusCode != null) {
+                return statusCode;
+            }
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                result.push(controllerConfig.getEventHandlerMap());
+                String statusCode = controllerConfig.getStatusCode();
+                if (statusCode != null) {
+                    return statusCode;
+                }
             }
-            result.push(eventHandlerMap);
-            return result;
+            return null;
         }
 
         public Map<String, String> getViewHandlerMap() {
             MapContext<String, String> result = MapContext.getMapContext();
-            for (URL includeLocation: includes) {
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
                 result.push(controllerConfig.getViewHandlerMap());
             }
@@ -272,19 +361,9 @@ public class ConfigXMLReader {
             return result;
         }
 
-        public Map<String, RequestMap> getRequestMapMap() {
-            MapContext<String, RequestMap> result = MapContext.getMapContext();
-            for (URL includeLocation: includes) {
-                ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
-                result.push(controllerConfig.getRequestMapMap());
-            }
-            result.push(requestMapMap);
-            return result;
-        }
-
         public Map<String, ViewMap> getViewMapMap() {
             MapContext<String, ViewMap> result = MapContext.getMapContext();
-            for (URL includeLocation: includes) {
+            for (URL includeLocation : includes) {
                 ControllerConfig controllerConfig = 
getControllerConfig(includeLocation);
                 result.push(controllerConfig.getViewMapMap());
             }
@@ -292,25 +371,10 @@ public class ConfigXMLReader {
             return result;
         }
 
-        protected void loadIncludes(Element rootElement) {
-            for (Element includeElement: UtilXml.childElementList(rootElement, 
"include")) {
-                String includeLocation = 
includeElement.getAttribute("location");
-                if (UtilValidate.isNotEmpty(includeLocation)) {
-                    try {
-                        URL urlLocation = 
FlexibleLocation.resolveLocation(includeLocation);
-                        includes.add(urlLocation);
-                    } catch (MalformedURLException mue) {
-                        Debug.logError(mue, "Error processing include at [" + 
includeLocation + "]:" + mue.toString(), module);
-                    }
-                }
-            }
-        }
-
         protected void loadGeneralConfig(Element rootElement) {
             if (rootElement == null) {
                 rootElement = loadDocument(this.url);
             }
-
             this.errorpage = UtilXml.childElementValue(rootElement, 
"errorpage");
             this.statusCode = UtilXml.childElementValue(rootElement, 
"status-code");
             Element protectElement = UtilXml.firstChildElement(rootElement, 
"protect");
@@ -323,11 +387,10 @@ public class ConfigXMLReader {
             if (defaultRequestElement != null) {
                 this.defaultRequest = 
defaultRequestElement.getAttribute("request-uri");
             }
-
             // first visit event
             Element firstvisitElement = UtilXml.firstChildElement(rootElement, 
"firstvisit");
             if (firstvisitElement != null) {
-                for (Element eventElement: 
UtilXml.childElementList(firstvisitElement, "event")) {
+                for (Element eventElement : 
UtilXml.childElementList(firstvisitElement, "event")) {
                     String eventName = eventElement.getAttribute("name");
                     if (UtilValidate.isEmpty(eventName)) {
                         eventName = eventElement.getAttribute("type") + "::" + 
eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
@@ -335,11 +398,10 @@ public class ConfigXMLReader {
                     this.firstVisitEventList.put(eventName, new 
Event(eventElement));
                 }
             }
-
             // preprocessor events
             Element preprocessorElement = 
UtilXml.firstChildElement(rootElement, "preprocessor");
             if (preprocessorElement != null) {
-                for (Element eventElement: 
UtilXml.childElementList(preprocessorElement, "event")) {
+                for (Element eventElement : 
UtilXml.childElementList(preprocessorElement, "event")) {
                     String eventName = eventElement.getAttribute("name");
                     if (UtilValidate.isEmpty(eventName)) {
                         eventName = eventElement.getAttribute("type") + "::" + 
eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
@@ -347,11 +409,10 @@ public class ConfigXMLReader {
                     this.preprocessorEventList.put(eventName, new 
Event(eventElement));
                 }
             }
-
             // postprocessor events
             Element postprocessorElement = 
UtilXml.firstChildElement(rootElement, "postprocessor");
             if (postprocessorElement != null) {
-                for (Element eventElement: 
UtilXml.childElementList(postprocessorElement, "event")) {
+                for (Element eventElement : 
UtilXml.childElementList(postprocessorElement, "event")) {
                     String eventName = eventElement.getAttribute("name");
                     if (UtilValidate.isEmpty(eventName)) {
                         eventName = eventElement.getAttribute("type") + "::" + 
eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
@@ -359,11 +420,10 @@ public class ConfigXMLReader {
                     this.postprocessorEventList.put(eventName, new 
Event(eventElement));
                 }
             }
-
             // after-login events
             Element afterLoginElement = UtilXml.firstChildElement(rootElement, 
"after-login");
             if (afterLoginElement != null) {
-                for (Element eventElement: 
UtilXml.childElementList(afterLoginElement, "event")) {
+                for (Element eventElement : 
UtilXml.childElementList(afterLoginElement, "event")) {
                     String eventName = eventElement.getAttribute("name");
                     if (UtilValidate.isEmpty(eventName)) {
                         eventName = eventElement.getAttribute("type") + "::" + 
eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
@@ -371,11 +431,10 @@ public class ConfigXMLReader {
                     this.afterLoginEventList.put(eventName, new 
Event(eventElement));
                 }
             }
-
             // before-logout events
             Element beforeLogoutElement = 
UtilXml.firstChildElement(rootElement, "before-logout");
             if (beforeLogoutElement != null) {
-                for (Element eventElement: 
UtilXml.childElementList(beforeLogoutElement, "event")) {
+                for (Element eventElement : 
UtilXml.childElementList(beforeLogoutElement, "event")) {
                     String eventName = eventElement.getAttribute("name");
                     if (UtilValidate.isEmpty(eventName)) {
                         eventName = eventElement.getAttribute("type") + "::" + 
eventElement.getAttribute("path") + "::" + eventElement.getAttribute("invoke");
@@ -389,9 +448,9 @@ public class ConfigXMLReader {
             if (rootElement == null) {
                 rootElement = loadDocument(this.url);
             }
-            if (rootElement == null) return;
-
-            for (Element handlerElement: UtilXml.childElementList(rootElement, 
"handler")) {
+            if (rootElement == null)
+                return;
+            for (Element handlerElement : 
UtilXml.childElementList(rootElement, "handler")) {
                 String name = handlerElement.getAttribute("name");
                 String type = handlerElement.getAttribute("type");
                 String className = handlerElement.getAttribute("class");
@@ -404,13 +463,27 @@ public class ConfigXMLReader {
             }
         }
 
+        protected void loadIncludes(Element rootElement) {
+            for (Element includeElement : 
UtilXml.childElementList(rootElement, "include")) {
+                String includeLocation = 
includeElement.getAttribute("location");
+                if (UtilValidate.isNotEmpty(includeLocation)) {
+                    try {
+                        URL urlLocation = 
FlexibleLocation.resolveLocation(includeLocation);
+                        includes.add(urlLocation);
+                    } catch (MalformedURLException mue) {
+                        Debug.logError(mue, "Error processing include at [" + 
includeLocation + "]:" + mue.toString(), module);
+                    }
+                }
+            }
+        }
+
         public void loadRequestMap(Element root) {
             if (root == null) {
                 root = loadDocument(this.url);
             }
-            if (root == null) return;
-
-            for (Element requestMapElement: UtilXml.childElementList(root, 
"request-map")) {
+            if (root == null)
+                return;
+            for (Element requestMapElement : UtilXml.childElementList(root, 
"request-map")) {
                 RequestMap requestMap = new RequestMap(requestMapElement);
                 this.requestMapMap.put(requestMap.uri, requestMap);
             }
@@ -420,10 +493,9 @@ public class ConfigXMLReader {
             if (rootElement == null) {
                 rootElement = loadDocument(this.url);
             }
-
-            if (rootElement == null) return;
-
-            for (Element viewMapElement: UtilXml.childElementList(rootElement, 
"view-map")) {
+            if (rootElement == null)
+                return;
+            for (Element viewMapElement : 
UtilXml.childElementList(rootElement, "view-map")) {
                 ViewMap viewMap = new ViewMap(viewMapElement);
                 this.viewMapMap.put(viewMap.name, viewMap);
             }
@@ -431,98 +503,31 @@ public class ConfigXMLReader {
 
     }
 
-    public static Set<String> findControllerFilesWithRequest(String 
requestUri, String controllerPartialPath) throws GeneralException {
-        Set<String> allControllerRequestSet = FastSet.newInstance();
-
-        if (UtilValidate.isEmpty(requestUri)) {
-            return allControllerRequestSet;
-        }
-
-        String cacheId = controllerPartialPath != null ? controllerPartialPath 
: "NOPARTIALPATH";
-        List<ControllerConfig> controllerConfigs = 
controllerSearchResultsCache.get(cacheId);
-
-        if (controllerConfigs == null) {
-            try {
-                // find controller.xml file with webappMountPoint + "/WEB-INF" 
in the path
-                List<File> controllerFiles = FileUtil.findXmlFiles(null, 
controllerPartialPath, "site-conf", "site-conf.xsd");
-
-                controllerConfigs = FastList.newInstance();
-                for (File controllerFile: controllerFiles) {
-                    URL controllerUrl = null;
-                    try {
-                        controllerUrl = controllerFile.toURI().toURL();
-                    } catch (MalformedURLException mue) {
-                        throw new GeneralException(mue);
-                    }
-                    ControllerConfig cc = 
ConfigXMLReader.getControllerConfig(controllerUrl);
-                    controllerConfigs.add(cc);
-                }
-
-                controllerConfigs = 
controllerSearchResultsCache.putIfAbsentAndGet(cacheId, controllerConfigs);
-            } catch (IOException e) {
-                throw new GeneralException("Error finding controller XML files 
to lookup request references: " + e.toString(), e);
-            }
-        }
+    public static class Event {
+        public String type;
+        public String path;
+        public String invoke;
+        public boolean globalTransaction = true;
+        public Metrics metrics = null;
 
-        if (controllerConfigs != null) {
-            for (ControllerConfig cc: controllerConfigs) {
-                // make sure it has the named request in it
-                if (cc.requestMapMap.get(requestUri) != null) {
-                    String requestUniqueId = cc.url.toExternalForm() + "#" + 
requestUri;
-                    allControllerRequestSet.add(requestUniqueId);
-                    // Debug.logInfo("========== In 
findControllerFilesWithRequest found controller with request here [" + 
requestUniqueId + "]", module);
-                }
+        public Event(Element eventElement) {
+            this.type = eventElement.getAttribute("type");
+            this.path = eventElement.getAttribute("path");
+            this.invoke = eventElement.getAttribute("invoke");
+            this.globalTransaction = 
!"false".equals(eventElement.getAttribute("global-transaction"));
+            // Get metrics.
+            Element metricsElement = UtilXml.firstChildElement(eventElement, 
"metric");
+            if (metricsElement != null) {
+                this.metrics = MetricsFactory.getInstance(metricsElement);
             }
         }
 
-        return allControllerRequestSet;
-    }
-
-    public static Set<String> findControllerRequestUniqueForTargetType(String 
target, String urlMode) throws GeneralException {
-        if (UtilValidate.isEmpty(urlMode)) {
-            urlMode = "intra-app";
-        }
-
-        int indexOfDollarSignCurlyBrace = target.indexOf("${");
-        int indexOfQuestionMark = target.indexOf("?");
-        if (indexOfDollarSignCurlyBrace >= 0 && (indexOfQuestionMark < 0 || 
indexOfQuestionMark > indexOfDollarSignCurlyBrace)) {
-            // we have an expanded string in the requestUri part of the 
target, not much we can do about that...
-            return null;
-        }
-
-        if ("intra-app".equals(urlMode)) {
-            // look through all controller.xml files and find those with the 
request-uri referred to by the target
-            String requestUri = UtilHttp.getRequestUriFromTarget(target);
-
-            Set<String> controllerLocAndRequestSet = 
ConfigXMLReader.findControllerFilesWithRequest(requestUri, null);
-            // if (controllerLocAndRequestSet.size() > 0) 
Debug.logInfo("============== In findRequestNamesLinkedtoInWidget, 
controllerLocAndRequestSet: " + controllerLocAndRequestSet, module);
-            return controllerLocAndRequestSet;
-        } else if ("inter-app".equals(urlMode)) {
-            String webappMountPoint = 
UtilHttp.getWebappMountPointFromTarget(target);
-            if (webappMountPoint != null) webappMountPoint += "/WEB-INF";
-            String requestUri = UtilHttp.getRequestUriFromTarget(target);
-
-            Set<String> controllerLocAndRequestSet = 
ConfigXMLReader.findControllerFilesWithRequest(requestUri, webappMountPoint);
-            // if (controllerLocAndRequestSet.size() > 0) 
Debug.logInfo("============== In findRequestNamesLinkedtoInWidget, 
controllerLocAndRequestSet: " + controllerLocAndRequestSet, module);
-            return controllerLocAndRequestSet;
-        } else {
-            return FastSet.newInstance();
-        }
-    }
-
-    /** Loads the XML file and returns the root element */
-    public static Element loadDocument(URL location) {
-        Document document;
-        try {
-            document = UtilXml.readXmlDocument(location, true);
-            Element rootElement = document.getDocumentElement();
-            // rootElement.normalize();
-            if (Debug.verboseOn()) Debug.logVerbose("Loaded XML Config - " + 
location, module);
-            return rootElement;
-        } catch (Exception e) {
-            Debug.logError(e, module);
+        public Event(String type, String path, String invoke, boolean 
globalTransaction) {
+            this.type = type;
+            this.path = path;
+            this.invoke = invoke;
+            this.globalTransaction = globalTransaction;
         }
-        return null;
     }
 
     public static class RequestMap {
@@ -531,26 +536,21 @@ public class ConfigXMLReader {
         public boolean trackVisit = true;
         public boolean trackServerHit = true;
         public String description;
-
         public Event event;
-
         public boolean securityHttps = false;
         public boolean securityAuth = false;
         public boolean securityCert = false;
         public boolean securityExternalView = true;
         public boolean securityDirectRequest = true;
-
         public Map<String, RequestResponse> requestResponseMap = 
FastMap.newInstance();
         public Metrics metrics = null;
 
         public RequestMap(Element requestMapElement) {
-
             // Get the URI info
             this.uri = requestMapElement.getAttribute("uri");
             this.edit = 
!"false".equals(requestMapElement.getAttribute("edit"));
             this.trackServerHit = 
!"false".equals(requestMapElement.getAttribute("track-serverhit"));
             this.trackVisit = 
!"false".equals(requestMapElement.getAttribute("track-visit"));
-
             // Check for security
             Element securityElement = 
UtilXml.firstChildElement(requestMapElement, "security");
             if (securityElement != null) {
@@ -560,18 +560,15 @@ public class ConfigXMLReader {
                 this.securityExternalView = 
!"false".equals(securityElement.getAttribute("external-view"));
                 this.securityDirectRequest = 
!"false".equals(securityElement.getAttribute("direct-request"));
             }
-
             // Check for event
             Element eventElement = 
UtilXml.firstChildElement(requestMapElement, "event");
             if (eventElement != null) {
                 this.event = new Event(eventElement);
             }
-
             // Check for description
             this.description = UtilXml.childElementValue(requestMapElement, 
"description");
-
             // Get the response(s)
-            for (Element responseElement: 
UtilXml.childElementList(requestMapElement, "response")) {
+            for (Element responseElement : 
UtilXml.childElementList(requestMapElement, "response")) {
                 RequestResponse response = new 
RequestResponse(responseElement);
                 requestResponseMap.put(response.name, response);
             }
@@ -583,35 +580,16 @@ public class ConfigXMLReader {
         }
     }
 
-    public static class Event {
-        public String type;
-        public String path;
-        public String invoke;
-        public boolean globalTransaction = true;
-        public Metrics metrics = null;
-
-        public Event(Element eventElement) {
-            this.type = eventElement.getAttribute("type");
-            this.path = eventElement.getAttribute("path");
-            this.invoke = eventElement.getAttribute("invoke");
-            this.globalTransaction = 
!"false".equals(eventElement.getAttribute("global-transaction"));
-            // Get metrics.
-            Element metricsElement = UtilXml.firstChildElement(eventElement, 
"metric");
-            if (metricsElement != null) {
-                this.metrics = MetricsFactory.getInstance(metricsElement);
-            }
-        }
+    public static class RequestResponse {
 
-        public Event(String type, String path, String invoke, boolean 
globalTransaction) {
-            this.type = type;
-            this.path = path;
-            this.invoke = invoke;
-            this.globalTransaction = globalTransaction;
+        public static RequestResponse createEmptyNoneRequestResponse() {
+            RequestResponse requestResponse = new RequestResponse();
+            requestResponse.name = "empty-none";
+            requestResponse.type = "none";
+            requestResponse.value = null;
+            return requestResponse;
         }
-    }
 
-    public static final RequestResponse emptyNoneRequestResponse = 
RequestResponse.createEmptyNoneRequestResponse();
-    public static class RequestResponse {
         public String name;
         public String type;
         public String value;
@@ -622,6 +600,9 @@ public class ConfigXMLReader {
         public Map<String, String> redirectParameterMap = 
FastMap.newInstance();
         public Map<String, String> redirectParameterValueMap = 
FastMap.newInstance();
 
+        public RequestResponse() {
+        }
+
         public RequestResponse(Element responseElement) {
             this.name = responseElement.getAttribute("name");
             this.type = responseElement.getAttribute("type");
@@ -630,26 +611,17 @@ public class ConfigXMLReader {
             this.saveLastView = 
"true".equals(responseElement.getAttribute("save-last-view"));
             this.saveCurrentView = 
"true".equals(responseElement.getAttribute("save-current-view"));
             this.saveHomeView = 
"true".equals(responseElement.getAttribute("save-home-view"));
-            for (Element redirectParameterElement: 
UtilXml.childElementList(responseElement, "redirect-parameter")) {
+            for (Element redirectParameterElement : 
UtilXml.childElementList(responseElement, "redirect-parameter")) {
                 if 
(UtilValidate.isNotEmpty(redirectParameterElement.getAttribute("value"))) {
                     
this.redirectParameterValueMap.put(redirectParameterElement.getAttribute("name"),
 redirectParameterElement.getAttribute("value"));
                 } else {
                     String from = 
redirectParameterElement.getAttribute("from");
-                    if (UtilValidate.isEmpty(from)) from = 
redirectParameterElement.getAttribute("name");
+                    if (UtilValidate.isEmpty(from))
+                        from = redirectParameterElement.getAttribute("name");
                     
this.redirectParameterMap.put(redirectParameterElement.getAttribute("name"), 
from);
                 }
             }
         }
-
-        public RequestResponse() { }
-
-        public static RequestResponse createEmptyNoneRequestResponse() {
-            RequestResponse requestResponse = new RequestResponse();
-            requestResponse.name = "empty-none";
-            requestResponse.type = "none";
-            requestResponse.value = null;
-            return requestResponse;
-        }
     }
 
     public static class ViewMap {


Reply via email to