svn commit: r638242 - in /ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control: ConfigXMLReader.java RequestHandler.java RequestManager.java

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

svn commit: r638242 - in /ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control: ConfigXMLReader.java RequestHandler.java RequestManager.java

jonesde
Author: jonesde
Date: Mon Mar 17 23:55:09 2008
New Revision: 638242

URL: http://svn.apache.org/viewvc?rev=638242&view=rev
Log:
Refactored to put the request response options in their own Map to be cleaner and avoid conflicts

Modified:
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.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=638242&r1=638241&r2=638242&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 Mon Mar 17 23:55:09 2008
@@ -65,7 +65,7 @@
         
         public Map configMap = FastMap.newInstance();
         public Map handlerMap = FastMap.newInstance();
-        public Map<String, Map<String, String>> requestMap = FastMap.newInstance();
+        public Map<String, Map<String, Object>> requestMap = FastMap.newInstance();
         public Map<String, Map<String, String>> viewMap = FastMap.newInstance();
         public String defaultRequest = null;
 
@@ -103,8 +103,8 @@
     public static final String REQUEST_TRACK_VISIT = "track-visit";
 
     public static final String REQUEST_DESCRIPTION = "description";
-    public static final String ERROR_PAGE = "error";
-    public static final String NEXT_PAGE = "success";
+    public static final String ERROR_PAGE_DEFAULT = "error";
+    public static final String NEXT_PAGE_DEFAULT = "success";
 
     public static final String SECURITY = "security";
     public static final String SECURITY_HTTPS = "https";
@@ -123,6 +123,7 @@
     public static final String RESPONSE_NAME = "name";
     public static final String RESPONSE_TYPE = "type";
     public static final String RESPONSE_VALUE = "value";
+    public static final String RESPONSE_MAP = "response-map";
 
     /** View Config Variables */
     public static final String VIEW_MAPPING = "view-map";
@@ -139,7 +140,7 @@
     public static final String HANDLER_NAME = "name";
     public static final String HANDLER_TYPE = "type";
     public static final String HANDLER_CLASS = "class";
-
+    
     /** Loads the XML file and returns the root element */
     public static Element loadDocument(URL location) {
         Document document;
@@ -156,15 +157,15 @@
     }
 
     /** Gets a Map of request mappings. */
-    public static Map getRequestMap(URL xml) {
+    public static Map<String, Map<String, Object>> getRequestMap(URL xml) {
         ControllerConfig controllerConfig = getControllerConfig(xml);
         return controllerConfig != null ? controllerConfig.requestMap : null;
     }
 
     /** Gets a FastMap of request mappings. */
-    public static Map<String, Map<String, String>> loadRequestMap(Element root, URL xml) {
+    public static Map<String, Map<String, Object>> loadRequestMap(Element root, URL xml) {
         long startTime = System.currentTimeMillis();
-        Map<String, Map<String, String>> map = FastMap.newInstance();
+        Map<String, Map<String, Object>> map = FastMap.newInstance();
         if (root == null) {
             root = loadDocument(xml);
         }
@@ -192,7 +193,7 @@
             Element requestMapElement = (Element) requestMapElementIter.next();
             
             // Create a URI-MAP for each element found.
-            Map<String, String> uriMap = FastMap.newInstance();
+            Map<String, Object> uriMap = FastMap.newInstance();
 
             // Get the URI info.
             String uri = requestMapElement.getAttribute(REQUEST_URI);
@@ -250,6 +251,9 @@
             uriMap.put(REQUEST_DESCRIPTION, UtilValidate.isNotEmpty(description) ? description : "");
 
             // Get the response(s).
+            Map<String, String> responseMap = FastMap.newInstance();
+            uriMap.put(RESPONSE_MAP, responseMap);
+            
             List<? extends Element> responseElementList = UtilXml.childElementList(requestMapElement, RESPONSE);
             Iterator<? extends Element> responseElementIter = responseElementList.iterator();
             while (responseElementIter.hasNext()) {
@@ -257,7 +261,8 @@
                 String name = responseElement.getAttribute(RESPONSE_NAME);
                 String type = responseElement.getAttribute(RESPONSE_TYPE);
                 String value = responseElement.getAttribute(RESPONSE_VALUE);
-                uriMap.put(name, type + ":" + value);
+                
+                responseMap.put(name, type + ":" + value);
             }
 
             if (uri != null) {
@@ -274,7 +279,7 @@
             while (i.hasNext()) {
                 Object o = i.next();
                 String request = (String) o;
-                Map<String, String> thisURI = map.get(o);
+                Map<String, Object> thisURI = map.get(o);
 
                 StringBuilder verboseMessageBuffer = new StringBuilder();
 
@@ -282,7 +287,7 @@
                 while (debugIter.hasNext()) {
                     Object lo = debugIter.next();
                     String name = (String) lo;
-                    String value = (String) thisURI.get(lo);
+                    String value = thisURI.get(lo).toString();
 
                     verboseMessageBuffer.append("[").append(name).append("=>").append(value).append("]");
                 }
@@ -298,15 +303,15 @@
     }
 
     /** Gets a FastMap of view mappings. */
-    public static Map getViewMap(URL xml) {
+    public static Map<String, Map<String, String>> getViewMap(URL xml) {
         ControllerConfig controllerConfig = getControllerConfig(xml);
         return controllerConfig != null ? controllerConfig.viewMap : null;
     }
 
     /** Gets a FastMap of view mappings. */
-    public static Map loadViewMap(Element root, URL xml) {
+    public static Map<String, Map<String, String>> loadViewMap(Element root, URL xml) {
         long startTime = System.currentTimeMillis();
-        FastMap map = FastMap.newInstance();
+        Map<String, Map<String, String>> map = FastMap.newInstance();
         if (root == null) {
             root = loadDocument(xml);
         }
@@ -315,8 +320,8 @@
             return map;
         }
 
-        List includeElementList = UtilXml.childElementList(root, INCLUDE);
-        Iterator includeElementIter = includeElementList.iterator();
+        List<? extends Element> includeElementList = UtilXml.childElementList(root, INCLUDE);
+        Iterator<? extends Element> includeElementIter = includeElementList.iterator();
         while (includeElementIter.hasNext()) {
             Element includeElement = (Element) includeElementIter.next();
             String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION);
@@ -330,12 +335,12 @@
             }
         }
 
-        List viewMapElementList = UtilXml.childElementList(root, VIEW_MAPPING);
-        Iterator viewMapElementIter = viewMapElementList.iterator();
+        List<? extends Element> viewMapElementList = UtilXml.childElementList(root, VIEW_MAPPING);
+        Iterator<? extends Element> viewMapElementIter = viewMapElementList.iterator();
         while (viewMapElementIter.hasNext()) {
             Element viewMapElement = (Element) viewMapElementIter.next();
             // Create a URI-MAP for each element found.
-            FastMap uriMap = FastMap.newInstance();
+            Map<String, String> uriMap = FastMap.newInstance();
 
             // Get the view info.
             String name = viewMapElement.getAttribute(VIEW_NAME);

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=638242&r1=638241&r2=638242&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Mon Mar 17 23:55:09 2008
@@ -306,25 +306,25 @@
             }
         }
 
-         // If error, then display more error messages:
-         if ("error".equals(eventReturnString)) {
-             if (Debug.errorOn()) {
-                 String errorMessageHeader = "Request " + requestUri + " caused an error with the following message: ";
-                 if (request.getAttribute("_ERROR_MESSAGE_") != null) {
-                     Debug.logError(errorMessageHeader + request.getAttribute("_ERROR_MESSAGE_"), module);
-                 }
-                 if (request.getAttribute("_ERROR_MESSAGE_LIST_") != null) {
-                     Debug.logError(errorMessageHeader + request.getAttribute("_ERROR_MESSAGE_LIST_"), module);
-                 }
-             }
-         }
+        // If error, then display more error messages:
+        if ("error".equals(eventReturnString)) {
+            if (Debug.errorOn()) {
+                String errorMessageHeader = "Request " + requestUri + " caused an error with the following message: ";
+                if (request.getAttribute("_ERROR_MESSAGE_") != null) {
+                    Debug.logError(errorMessageHeader + request.getAttribute("_ERROR_MESSAGE_"), module);
+                }
+                if (request.getAttribute("_ERROR_MESSAGE_LIST_") != null) {
+                    Debug.logError(errorMessageHeader + request.getAttribute("_ERROR_MESSAGE_LIST_"), module);
+                }
+            }
+        }
 
         // Process the eventReturn.
-        String eventReturn = requestManager.getRequestAttribute(requestUri, eventReturnString);
-        if (Debug.verboseOn()) Debug.logVerbose("[Response Qualified]: " + eventReturn + " sessionId=" + UtilHttp.getSessionId(request), module);
+        String eventReturnBasedResponse = requestManager.getRequestResponseValue(requestUri, eventReturnString);
+        if (Debug.verboseOn()) Debug.logVerbose("[Response Qualified]: " + eventReturnBasedResponse + " sessionId=" + UtilHttp.getSessionId(request), module);
 
         // Set the next view (don't use event return if success, default to nextView (which is set to eventReturn later if null); also even if success if it is a type "none" response ignore the nextView, ie use the eventReturn)
-        if (eventReturn != null && (!"success".equals(eventReturnString) || eventReturn.startsWith("none:"))) nextView = eventReturn;
+        if (eventReturnBasedResponse != null && (!"success".equals(eventReturnString) || eventReturnBasedResponse.startsWith("none:"))) nextView = eventReturnBasedResponse;
         if (Debug.verboseOn()) Debug.logVerbose("[Event Response Mapping]: " + nextView + " sessionId=" + UtilHttp.getSessionId(request), module);
 
         // get the previous request info

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java?rev=638242&r1=638241&r2=638242&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestManager.java Mon Mar 17 23:55:09 2008
@@ -108,16 +108,33 @@
     }
 
     public String getRequestAttribute(String uriStr, String attribute) {
-        Map uri = getRequestMapMap(uriStr);
+        Map<String, Object> uri = getRequestMapMap(uriStr);
 
         if (uri != null && attribute != null) {
-            return (String) uri.get(attribute);
+            String value = (String) uri.get(attribute);
+            if (value == null) {
+                // not found, try the response Map (though better to hit that directly when desired)
+                Map<String, String> responseMap = (Map<String, String>) uri.get(ConfigXMLReader.RESPONSE_MAP);
+                value = responseMap.get(attribute);
+            }
+            return value;
         } else {
             Debug.logInfo("[RequestManager.getRequestAttribute] Value for attribute \"" + attribute +
                 "\" of uri \"" + uriStr + "\" not found", module);
             return null;
         }
     }
+    
+    public String getRequestResponseValue(String uriStr, String responseName) {
+        if (responseName == null) return null;
+        
+        Map<String, Object> uri = getRequestMapMap(uriStr);
+        if (uri == null) return null;
+        Map<String, String> responseMap = (Map<String, String>) uri.get(ConfigXMLReader.RESPONSE_MAP);
+        if (responseMap == null) return null;
+        
+        return responseMap.get(responseName);
+    }
 
     /** Gets the event class from the requestMap */
     public String getEventPath(String uriStr) {
@@ -175,10 +192,10 @@
 
     /** Gets the view name from the requestMap */
     public String getViewName(String uriStr) {
-        Map uri = getRequestMapMap(uriStr);
+        Map<String, Object> uri = getRequestMapMap(uriStr);
 
         if (uri != null)
-            return (String) uri.get(ConfigXMLReader.NEXT_PAGE);
+            return (String) ((Map<String, String>) uri.get(ConfigXMLReader.RESPONSE_MAP)).get(ConfigXMLReader.NEXT_PAGE_DEFAULT);
         else {
             Debug.logWarning("[RequestManager.getViewName] View name for uri \"" + uriStr + "\" not found", module);
             return null;
@@ -253,7 +270,7 @@
         //Debug.logInfo("RequestMapMap is: " + uri, module);
 
         if (uri != null) {
-            String errorViewUri = (String) uri.get(ConfigXMLReader.ERROR_PAGE);
+            String errorViewUri = (String) ((Map<String, String>) uri.get(ConfigXMLReader.RESPONSE_MAP)).get(ConfigXMLReader.ERROR_PAGE_DEFAULT);
             //Debug.logInfo("errorViewUri is: " + errorViewUri, module);
             String returnPage = getViewPage(errorViewUri);
             //Debug.logInfo("Got returnPage for ErrorPage: " + returnPage, module);