Revision: 19755
http://sourceforge.net/p/gate/code/19755
Author: ian_roberts
Date: 2016-11-18 19:18:15 +0000 (Fri, 18 Nov 2016)
Log Message:
-----------
Relative paths for URL parameters are once again proper relative URIs (forward
slashes regardless of platform, and proper URI encoding of illegal characters
like spaces). Also reinstated the practice of adding a trailing slash to URIs
that point to a directory.
Fixes #201
Modified Paths:
--------------
gate/trunk/src/main/gate/util/persistence/PersistenceManager.java
Modified: gate/trunk/src/main/gate/util/persistence/PersistenceManager.java
===================================================================
--- gate/trunk/src/main/gate/util/persistence/PersistenceManager.java
2016-11-18 17:58:45 UTC (rev 19754)
+++ gate/trunk/src/main/gate/util/persistence/PersistenceManager.java
2016-11-18 19:18:15 UTC (rev 19755)
@@ -55,6 +55,7 @@
import java.nio.file.FileSystems;
import java.nio.file.LinkOption;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collection;
@@ -287,6 +288,8 @@
}
}
+
+ String relPath = null;
if(pathMarker.equals(relativePathMarker)) {
// In theory we should just relativize here using the original
paths, without
@@ -304,7 +307,7 @@
// path that does not generate any ../ at the beginning of the
relative part, then
// we use that, otherwise we use the real paths
- String relPath = getRelativeFilePathString(outDir, urlFile);
+ relPath = getRelativeFilePathString(outDir, urlFile);
logger.debug("First relative path string attempt got "+relPath);
if(relPath.startsWith("../")) {
// if we want to actually use the real path, we have to be
careful which is the
@@ -328,23 +331,38 @@
}
// if we still get something that starts with ../ then our only
remaining option is
// to find if a parent
- urlString = pathMarker + relPath;
} else if(pathMarker.equals(gatehomePathMarker)) {
- urlString = pathMarker +
getRelativeFilePathString(gateHomePathReal, urlFileReal);
+ relPath = getRelativeFilePathString(gateHomePathReal,
urlFileReal);
} else if(pathMarker.equals(resourceshomePathMarker)) {
- urlString = pathMarker +
getRelativeFilePathString(resourceshomeDirReal, urlFileReal);
+ relPath = getRelativeFilePathString(resourceshomeDirReal,
urlFileReal);
} else {
// this should really never happen!
throw new GateRuntimeException("Unexpected error when persisting
URL "+url);
}
+
+ Path rel = Paths.get(relPath);
+ String uriPath = "";
+ boolean first = true;
+ for(Path component : rel) {
+ if(!first) uriPath += "/";
+ uriPath += component.toString();
+ first = false;
+ }
+ if(urlFile.isDirectory()) {
+ // trailing slash
+ uriPath += "/";
+ }
+ // construct the final properly encoded relative URI
+ URI finalRelUri = new URI(null, null, uriPath, null);
+ urlString = pathMarker + finalRelUri.getRawPath();
} // if protocol is file
else {
// protocol was not file:
urlString = ((URL)source).toExternalForm();
}
}
- catch(ClassCastException cce) {
- throw new PersistenceException(cce);
+ catch(ClassCastException | URISyntaxException e) {
+ throw new PersistenceException(e);
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs