]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph/src/org/simantics/graph/query/UriUtils.java
Escape/unescape names of the externals when converting to/from URIs
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / query / UriUtils.java
index ef22553244d78de555f5ee2a2ed1d3cc809c1eec..6911f782d75e24a902476187fd428f2a7bd2f404 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.graph.query;
 
+import org.simantics.databoard.util.URIStringUtils;
 
 public class UriUtils {
 
@@ -27,4 +28,28 @@ public class UriUtils {
                return cur;
        }
        
+       public static Path uriToPathUnescaped(String uri) {
+               String[] segments;
+               Path cur;
+               if(uri.startsWith("http:/")) {
+                       if(uri.length() == 6)
+                               return Paths.Root;
+                       segments = uri.substring(7).split("/");
+                       cur = Paths.Root;
+               }
+               else {
+                       int p = uri.indexOf('/');
+                       if(p == -1)
+                               return new PathRoot(URIStringUtils.unescape(uri));
+                       else {
+                               segments = uri.substring(p+1).split("/");
+                               cur = new PathRoot(URIStringUtils.unescape(uri.substring(0, p)));
+                       }
+               }
+
+               for(String segment : segments)
+                       cur = new PathChild(URIStringUtils.unescape(segment), cur);
+               return cur;
+       }
+       
 }