]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 package org.simantics.graph.query;
2
3 import org.simantics.databoard.util.URIStringUtils;
4
5 public class UriUtils {
6
7         public static Path uriToPath(String uri) {
8                 String[] segments;
9                 Path cur;
10                 if(uri.startsWith("http:/")) {
11                         if(uri.length() == 6)
12                                 return Paths.Root;
13                         segments = uri.substring(7).split("/");
14                         cur = Paths.Root;
15                 }
16                 else {
17                         int p = uri.indexOf('/');
18                         if(p == -1)
19                                 return new PathRoot(uri);
20                         else {
21                                 segments = uri.substring(p+1).split("/");
22                                 cur = new PathRoot(uri.substring(0, p));
23                         }
24                 }
25
26                 for(String segment : segments)
27                         cur = new PathChild(segment, cur);
28                 return cur;
29         }
30         
31         public static Path uriToPathUnescaped(String uri) {
32                 String[] segments;
33                 Path cur;
34                 if(uri.startsWith("http:/")) {
35                         if(uri.length() == 6)
36                                 return Paths.Root;
37                         segments = uri.substring(7).split("/");
38                         cur = Paths.Root;
39                 }
40                 else {
41                         int p = uri.indexOf('/');
42                         if(p == -1)
43                                 return new PathRoot(URIStringUtils.unescape(uri));
44                         else {
45                                 segments = uri.substring(p+1).split("/");
46                                 cur = new PathRoot(URIStringUtils.unescape(uri.substring(0, p)));
47                         }
48                 }
49
50                 for(String segment : segments)
51                         cur = new PathChild(URIStringUtils.unescape(segment), cur);
52                 return cur;
53         }
54         
55 }