Author: jonesde
Date: Sun May 20 10:11:26 2007
New Revision: 539894

URL: http://svn.apache.org/viewvc?view=rev&rev=539894
Log:
Some fixes for menu widget loading, especially for extended/parent menus which 
now works properly

Modified:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java

Modified: 
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java?view=diff&rev=539894&r1=539893&r2=539894
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java 
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java Sun 
May 20 10:11:26 2007
@@ -30,6 +30,7 @@
 
 import org.ofbiz.base.location.FlexibleLocation;
 import org.ofbiz.base.util.UtilHttp;
+import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.base.util.cache.UtilCache;
 import org.ofbiz.entity.GenericDelegator;
@@ -47,37 +48,9 @@
     
     public static final String module = MenuFactory.class.getName();
 
-    public static final UtilCache menuClassCache = new 
UtilCache("widget.menu.classResource", 0, 0, false);
     public static final UtilCache menuWebappCache = new 
UtilCache("widget.menu.webappResource", 0, 0, false);
     public static final UtilCache menuLocationCache = new 
UtilCache("widget.menu.locationResource", 0, 0, false);
     
-    public static ModelMenu getMenuFromClass(String resourceName, String 
menuName, GenericDelegator delegator, LocalDispatcher dispatcher) 
-            throws IOException, SAXException, ParserConfigurationException {
-        Map modelMenuMap = (Map) menuClassCache.get(resourceName);
-        if (modelMenuMap == null) {
-            synchronized (MenuFactory.class) {
-                modelMenuMap = (Map) menuClassCache.get(resourceName);
-                if (modelMenuMap == null) {
-                    ClassLoader loader = 
Thread.currentThread().getContextClassLoader();
-                    if (loader == null) {
-                        loader = MenuFactory.class.getClassLoader();
-                    }
-                    
-                    URL menuFileUrl = loader.getResource(resourceName);
-                    Document menuFileDoc = 
UtilXml.readXmlDocument(menuFileUrl, true);
-                    modelMenuMap = readMenuDocument(menuFileDoc, delegator, 
dispatcher);
-                    menuClassCache.put(resourceName, modelMenuMap);
-                }
-            }
-        }
-        
-        ModelMenu modelMenu = (ModelMenu) modelMenuMap.get(menuName);
-        if (modelMenu == null) {
-            throw new IllegalArgumentException("Could not find menu with name 
[" + menuName + "] in class resource [" + resourceName + "]");
-        }
-        return modelMenu;
-    }
-    
     public static ModelMenu getMenuFromWebappContext(String resourceName, 
String menuName, HttpServletRequest request) 
             throws IOException, SAXException, ParserConfigurationException {
         String webappName = UtilHttp.getApplicationName(request);
@@ -101,6 +74,10 @@
             }
         }
         
+        if (UtilValidate.isEmpty(modelMenuMap)) {
+            throw new IllegalArgumentException("Could not find menu file in 
webapp resource [" + resourceName + "] in the webapp [" + webappName + "]");
+        }
+        
         ModelMenu modelMenu = (ModelMenu) modelMenuMap.get(menuName);
         if (modelMenu == null) {
             throw new IllegalArgumentException("Could not find menu with name 
[" + menuName + "] in webapp resource [" + resourceName + "] in the webapp [" + 
webappName + "]");
@@ -144,10 +121,14 @@
                 }
             }
         }
+
+        if (UtilValidate.isEmpty(modelMenuMap)) {
+            throw new IllegalArgumentException("Could not find menu file in 
location [" + resourceName + "]");
+        }
         
         ModelMenu modelMenu = (ModelMenu) modelMenuMap.get(menuName);
         if (modelMenu == null) {
-            throw new IllegalArgumentException("Could not find menu with name 
[" + menuName + "] in class resource [" + resourceName + "]");
+            throw new IllegalArgumentException("Could not find menu with name 
[" + menuName + "] in location [" + resourceName + "]");
         }
         return modelMenu;
     }

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java?view=diff&rev=539894&r1=539893&r2=539894
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java 
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java Sun 
May 20 10:11:26 2007
@@ -108,13 +108,12 @@
         // check if there is a parent menu to inherit from
         String parentResource = menuElement.getAttribute("extends-resource");
         String parentMenu = menuElement.getAttribute("extends");
-        //TODO: Modify this to allow for extending a menu with the same name 
but different resource
-        if (parentMenu.length() > 0 && 
!parentMenu.equals(menuElement.getAttribute("name"))) {
+        if (parentMenu.length() > 0 && 
!(parentMenu.equals(menuElement.getAttribute("name")) && 
UtilValidate.isEmpty(parentResource))) {
             ModelMenu parent = null;
             // check if we have a resource name (part of the string before the 
?)
-            if (parentResource.length() > 0) {
+            if (UtilValidate.isNotEmpty(parentResource)) {
                 try {
-                    parent = MenuFactory.getMenuFromClass(parentResource, 
parentMenu, delegator, dispatcher);
+                    parent = MenuFactory.getMenuFromLocation(parentResource, 
parentMenu, delegator, dispatcher);
                 } catch (Exception e) {
                     Debug.logError(e, "Failed to load parent menu definition 
'" + parentMenu + "' at resource '" + parentResource + "'", module);
                 }


Reply via email to