*/
public static void convertNetworkPlace(NetworkPlace networkPlace) throws Exception {
if(Util.isNullOrTrimmedBlank(networkPlace.getScheme())) {
String path = networkPlace.getPath();
Replacer r = new Replacer() {
public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
String match = matcher.group();
String key = match.substring(2, match.length() - 1);
try {
int idx = key.indexOf(":");
if (idx == -1) {
throw new Exception("String replacement pattern is in incorrect format for " + key
+ ". Must be <TYPE>:<key>");
}
String type = key.substring(0, idx);
key = key.substring(idx + 1);
return "_prototype_" + type + "_" + key + "_";
}
catch(Exception e) {
NetworkPlaceInstall.log.error("Failed to replace.", e);
}
return "prototype";
}
};
// Replace all replacement variables with prototype values
ReplacementEngine engine = new ReplacementEngine();
engine.addPattern(NetworkPlaceInstall.VARIABLE_PATTERN, r, null);
path = engine.replace(path);
//
URI newUri = null;
// Is it a UNC path
if(path.startsWith("\\\\")) {
try {
newUri = new URI("smb:" + path.replace('\\', '/'));
}
catch(MalformedURIException murie) {
murie.printStackTrace();
}
}
// Is this a supported RI?
if(newUri == null) {
int idx = path.indexOf(':');
if(idx > 1) { // index of 1 would mean a windows absolute path
// Is it an non windows absolute file URI?
String rpath = path.substring(idx + 1);
String scheme = path.substring(0, idx);
if(scheme.equals("file")) {
if(rpath.startsWith("//") && !rpath.startsWith("///") &&
( rpath.length() < 4 || rpath.charAt(3) != ':' ) ) {
path = scheme + ":/" + rpath;
}
}
newUri = new URI(path);
}
}
// Is it a local file? (wont work for replacements)
boolean switchSlash = false;
if(newUri == null) {
if(path.contains("\\")) {
switchSlash = true;
}
try {
String scheme;
if(path.toLowerCase().endsWith(".jar")) {
scheme = "jar";
} else if(path.toLowerCase().endsWith(".zip")) {
scheme = "zip";
} else {
scheme = "file";
}
newUri = new URI(scheme + ":///" + DAVUtilities.stripLeadingSlash(path.replace('\\', '/')));
} catch (MalformedURIException e) {
e.printStackTrace();
}
}
// Convert the network place if required
if(newUri != null) {
engine = new ReplacementEngine();
r = new Replacer() {
public String getReplacement(Pattern pattern, Matcher matcher, String replacementPattern) {
String match = matcher.group();
String key = match.substring(11, match.length() - 1);
try {
int idx = key.indexOf("_");