Author: doogie
Date: Wed Oct 17 07:26:43 2007 New Revision: 585518 URL: http://svn.apache.org/viewvc?rev=585518&view=rev Log: 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. Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java?rev=585518&r1=585517&r2=585518&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/container/ComponentContainer.java Wed Oct 17 07:26:43 2007 @@ -101,12 +101,20 @@ // 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 @@ 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 @@ this.loadComponent(config); } } else if (def.type == ComponentLoaderConfig.COMPONENT_DIRECTORY) { - this.loadComponentDirectory(def.location); + this.loadComponentDirectory(location); } } @@ -157,7 +171,7 @@ 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) { |
Free forum by Nabble | Edit this page |