Revision: 19757
          http://sourceforge.net/p/gate/code/19757
Author:   markagreenwood
Date:     2016-11-19 02:02:34 +0000 (Sat, 19 Nov 2016)
Log Message:
-----------
pulled in Ian's persistence fix from trunk before I forget

Modified Paths:
--------------
    
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java

Property Changed:
----------------
    gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/

Index: gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence
===================================================================
--- gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence        
2016-11-19 01:55:44 UTC (rev 19756)
+++ gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence        
2016-11-19 02:02:34 UTC (rev 19757)

Property changes on: 
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence
___________________________________________________________________
Added: svn:mergeinfo
## -0,0 +1,8 ##
+/gate/branches/cl-experiment/src/main/java/gate/util/persistence:15466-15613
+/gate/branches/new-ontology-api/src/main/java/gate/util/persistence:10584-11598
+/gate/branches/release-7.0/src/main/java/gate/util/persistence:15335-15398
+/gate/branches/release-8.1/src/main/java/gate/util/persistence:18736-18747
+/gate/branches/sawdust/src/main/java/gate/util/persistence:17055-17079
+/gate/tags/release-7.0/src/main/java/gate/util/persistence:15399-15407
+/gate/trunk/src/main/gate/util/persistence:19180-19756
+/gate/trunk/src/main/java/gate/util/persistence:3-7,19180-19248
\ No newline at end of property
Modified: 
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java
        2016-11-19 01:55:44 UTC (rev 19756)
+++ 
gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java
        2016-11-19 02:02:34 UTC (rev 19757)
@@ -56,6 +56,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;
@@ -298,6 +299,8 @@
                
               }
             }
+
+            String relPath = null;
                         
             if(pathMarker.equals(relativePathMarker)) {
               // In theory we should just relativize here using the original 
paths, without
@@ -315,7 +318,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 
@@ -339,23 +342,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

Reply via email to