From bca4f0d9cf381d931ae875e1925e6f0cae85cb8b Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Wed, 17 Oct 2007 14:26:43 +0000 Subject: [PATCH] If a path in ofbiz-component.xml is not absolute, try to load the sub-files relative to the location of the ofbiz-component.xml file. This is from https://issues.apache.org/jira/browse/OFBIZ-1280. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@585518 13f79535-47bb-0310-9956-ffa450edef68 --- .../base/container/ComponentContainer.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java b/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java index be0ce3a2c3..fa8335f978 100644 --- a/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java +++ b/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java @@ -101,12 +101,20 @@ public class ComponentContainer implements Container { // get the components to load List components = ComponentLoaderConfig.getRootComponents(loaderConfig); + String parentPath; + try { + parentPath = new File(System.getProperty("ofbiz.home")).getCanonicalFile().toString().replaceAll("\\\\", "/"); + } catch (MalformedURLException e) { + throw new ComponentException(e.getMessage(), e); + } catch (IOException e) { + throw new ComponentException(e.getMessage(), e); + } // load each component if (components != null) { Iterator ci = components.iterator(); while (ci.hasNext()) { ComponentLoaderConfig.ComponentDef def = (ComponentLoaderConfig.ComponentDef) ci.next(); - this.loadComponentFromConfig(def); + this.loadComponentFromConfig(parentPath, def); } } @@ -120,11 +128,17 @@ public class ComponentContainer implements Container { Debug.logInfo("All components loaded", module); } - private void loadComponentFromConfig(ComponentLoaderConfig.ComponentDef def) { + private void loadComponentFromConfig(String parentPath, ComponentLoaderConfig.ComponentDef def) { + String location; + if (def.location.startsWith("/")) { + location = def.location; + } else { + location = parentPath + "/" + def.location; + } if (def.type == ComponentLoaderConfig.SINGLE_COMPONENT) { ComponentConfig config = null; try { - config = ComponentConfig.getComponentConfig(def.name, def.location); + config = ComponentConfig.getComponentConfig(def.name, location); if (UtilValidate.isEmpty(def.name)) { def.name = config.getGlobalName(); } @@ -137,7 +151,7 @@ public class ComponentContainer implements Container { this.loadComponent(config); } } else if (def.type == ComponentLoaderConfig.COMPONENT_DIRECTORY) { - this.loadComponentDirectory(def.location); + this.loadComponentDirectory(location); } } @@ -157,7 +171,7 @@ public class ComponentContainer implements Container { Iterator i = componentsToLoad.iterator(); while (i.hasNext()) { ComponentLoaderConfig.ComponentDef def = (ComponentLoaderConfig.ComponentDef) i.next(); - this.loadComponentFromConfig(def); + this.loadComponentFromConfig(parentPath.toString(), def); } } } catch (MalformedURLException e) {