Author: jonesde
Date: Sun May 20 10:12:32 2007
New Revision: 539896
URL: http://svn.apache.org/viewvc?view=rev&rev=539896
Log:
Applied fix from trunk for revision: 539894
Modified:
ofbiz/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java
ofbiz/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java
Modified:
ofbiz/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java
URL:
http://svn.apache.org/viewvc/ofbiz/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java?view=diff&rev=539896&r1=539895&r2=539896
==============================================================================
---
ofbiz/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java
(original)
+++
ofbiz/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/MenuFactory.java
Sun May 20 10:12:32 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/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java
URL:
http://svn.apache.org/viewvc/ofbiz/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java?view=diff&rev=539896&r1=539895&r2=539896
==============================================================================
---
ofbiz/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java
(original)
+++
ofbiz/branches/release4.0/framework/widget/src/org/ofbiz/widget/menu/ModelMenu.java
Sun May 20 10:12:32 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);
}