Author: adrianc
Date: Thu Apr 4 20:57:46 2013
New Revision: 1464750
URL: http://svn.apache.org/r1464750
Log:
Small optimization for location resolvers - don't go to the file system while
building URLs. This will benefit single box (app server + DB server)
installations.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/location/ComponentLocationResolver.java
ofbiz/trunk/framework/base/src/org/ofbiz/base/location/OFBizHomeLocationResolver.java
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/location/ComponentLocationResolver.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/location/ComponentLocationResolver.java?rev=1464750&r1=1464749&r2=1464750&view=diff
==============================================================================
---
ofbiz/trunk/framework/base/src/org/ofbiz/base/location/ComponentLocationResolver.java
(original)
+++
ofbiz/trunk/framework/base/src/org/ofbiz/base/location/ComponentLocationResolver.java
Thu Apr 4 20:57:46 2013
@@ -18,13 +18,15 @@
*******************************************************************************/
package org.ofbiz.base.location;
+import java.io.File;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import org.ofbiz.base.component.ComponentConfig;
import org.ofbiz.base.component.ComponentException;
import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilURL;
/**
* A special location resolver that uses Strings like URLs, but with more
options
@@ -36,46 +38,44 @@ public class ComponentLocationResolver i
public static final String module =
ComponentLocationResolver.class.getName();
public URL resolveLocation(String location) throws MalformedURLException {
- StringBuffer baseLocation =
ComponentLocationResolver.getBaseLocation(location);
- URL fileUrl = UtilURL.fromFilename(baseLocation.toString());
-
- if (fileUrl == null) {
- Debug.logWarning("Unable to get file URL for component location;
expanded location was [" + baseLocation + "], original location was [" +
location + "]", module);
+ String baseLocation = getBaseLocation(location).toString();
+ if (File.separatorChar != '/') {
+ baseLocation = baseLocation.replace(File.separatorChar, '/');
+ }
+ if (!baseLocation.startsWith("/")) {
+ baseLocation = "/".concat(baseLocation);
+ }
+ try {
+ return new URI("file", null, baseLocation, null).toURL();
+ } catch (URISyntaxException e) {
+ throw new MalformedURLException(e.getMessage());
}
- return fileUrl;
}
- public static StringBuffer getBaseLocation(String location) throws
MalformedURLException {
- StringBuffer baseLocation = new
StringBuffer(FlexibleLocation.stripLocationType(location));
-
+ public static StringBuilder getBaseLocation(String location) throws
MalformedURLException {
+ StringBuilder baseLocation = new
StringBuilder(FlexibleLocation.stripLocationType(location));
// componentName is between the first slash and the second
int firstSlash = baseLocation.indexOf("/");
int secondSlash = baseLocation.indexOf("/", firstSlash + 1);
if (firstSlash != 0 || secondSlash == -1) {
- throw new MalformedURLException("Bad component location [" +
location + "]: base location missing slashes [" + baseLocation + "], first=" +
firstSlash + ", second=" + secondSlash + "; should be like:
component://{component-name}/relative/path");
+ throw new MalformedURLException("Bad component location [" +
location + "]: base location missing slashes [" + baseLocation + "], first = "
+ firstSlash + ", second = " + secondSlash + "; should be like:
component://{component-name}/relative/path");
}
String componentName = baseLocation.substring(firstSlash + 1,
secondSlash);
-
// got the componentName, now remove it from the baseLocation,
removing the second slash too (just in case the rootLocation has one)
baseLocation.delete(0, secondSlash + 1);
-
- String rootLocation;
try {
- rootLocation = ComponentConfig.getRootLocation(componentName);
+ String rootLocation =
ComponentConfig.getRootLocation(componentName);
+ // if there is not a forward slash between the two, add it
+ if (baseLocation.charAt(0) != '/' &&
rootLocation.charAt(rootLocation.length() - 1) != '/') {
+ baseLocation.insert(0, '/');
+ }
+ // insert the root location and we're done
+ baseLocation.insert(0, rootLocation);
+ return baseLocation;
} catch (ComponentException e) {
String errMsg = "Could not get root location for component with
name [" + componentName + "], error was: " + e.toString();
Debug.logError(e, errMsg, module);
throw new MalformedURLException(errMsg);
}
-
- // if there is not a forward slash between the two, add it
- if (baseLocation.charAt(0) != '/' &&
rootLocation.charAt(rootLocation.length() - 1) != '/') {
- baseLocation.insert(0, '/');
- }
-
- // insert the root location and we're done
- baseLocation.insert(0, rootLocation);
-
- return baseLocation;
}
}
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/location/OFBizHomeLocationResolver.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/location/OFBizHomeLocationResolver.java?rev=1464750&r1=1464749&r2=1464750&view=diff
==============================================================================
---
ofbiz/trunk/framework/base/src/org/ofbiz/base/location/OFBizHomeLocationResolver.java
(original)
+++
ofbiz/trunk/framework/base/src/org/ofbiz/base/location/OFBizHomeLocationResolver.java
Thu Apr 4 20:57:46 2013
@@ -18,11 +18,12 @@
*******************************************************************************/
package org.ofbiz.base.location;
+import java.io.File;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
-import org.ofbiz.base.util.UtilURL;
-
/**
* A special location resolver that uses Strings like URLs, but with more
options
*
@@ -38,16 +39,23 @@ public class OFBizHomeLocationResolver i
String errMsg = "The Java environment (-Dxxx=yyy) variable with
name " + envName + " is not set, cannot resolve location.";
throw new MalformedURLException(errMsg);
}
-
StringBuilder baseLocation = new
StringBuilder(FlexibleLocation.stripLocationType(location));
-
// if there is not a forward slash between the two, add it
if (baseLocation.charAt(0) != '/' &&
propValue.charAt(propValue.length() - 1) != '/') {
baseLocation.insert(0, '/');
}
-
baseLocation.insert(0, propValue);
-
- return UtilURL.fromFilename(baseLocation.toString());
+ String fileLocation = baseLocation.toString();
+ if (File.separatorChar != '/') {
+ fileLocation = fileLocation.replace(File.separatorChar, '/');
+ }
+ if (!fileLocation.startsWith("/")) {
+ fileLocation = "/".concat(fileLocation);
+ }
+ try {
+ return new URI("file", null, fileLocation, null).toURL();
+ } catch (URISyntaxException e) {
+ throw new MalformedURLException(e.getMessage());
+ }
}
}