Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/schema_salad/java/main_utils/LoadingOptions.java @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
1 package ${package}.utils; | |
2 | |
3 import java.net.URI; | |
4 import java.util.ArrayList; | |
5 import java.util.Arrays; | |
6 import java.util.List; | |
7 import java.util.Map; | |
8 | |
9 public class LoadingOptions { | |
10 Fetcher fetcher; | |
11 String fileUri; | |
12 Map<String, String> namespaces; | |
13 List<String> schemas; | |
14 Map<String, Map<String, Object>> idx; | |
15 Map<String, String> vocab; | |
16 Map<String, String> rvocab; | |
17 | |
18 LoadingOptions( | |
19 final Fetcher fetcher, | |
20 final String fileUri, | |
21 final Map<String, String> namespaces, | |
22 final List<String> schemas, | |
23 final Map<String, Map<String, Object>> idx) { | |
24 this.fetcher = fetcher; | |
25 this.fileUri = fileUri; | |
26 this.namespaces = namespaces; | |
27 this.schemas = schemas; | |
28 this.idx = idx; | |
29 | |
30 if (namespaces != null) { | |
31 this.vocab = (Map<String, String>) ConstantMaps.vocab.clone(); | |
32 this.rvocab = (Map<String, String>) ConstantMaps.rvocab.clone(); | |
33 for (Map.Entry<String, String> namespaceEntry : namespaces.entrySet()) { | |
34 this.vocab.put(namespaceEntry.getKey(), namespaceEntry.getValue()); | |
35 this.rvocab.put(namespaceEntry.getValue(), namespaceEntry.getKey()); | |
36 } | |
37 } else { | |
38 this.vocab = (Map<String, String>) ConstantMaps.vocab; | |
39 this.rvocab = (Map<String, String>) ConstantMaps.rvocab; | |
40 } | |
41 } | |
42 | |
43 public String expandUrl( | |
44 String url_, | |
45 final String baseUrl, | |
46 final boolean scopedId, | |
47 final boolean vocabTerm, | |
48 final Integer scopedRef) { | |
49 // NOT CONVERTING this - doesn't match type declaration | |
50 // if not isinstance(url, string_types): | |
51 // return url | |
52 String url = url_; | |
53 if (url.equals("@id") || url.equals("@type")) { | |
54 return url; | |
55 } | |
56 | |
57 if (vocabTerm && this.vocab.containsKey(url)) { | |
58 return url; | |
59 } | |
60 | |
61 if (!this.vocab.isEmpty() && url.contains(":")) { | |
62 String prefix = url.split(":", 1)[0]; | |
63 if (this.vocab.containsKey(prefix)) { | |
64 url = this.vocab.get(prefix) + url.substring(prefix.length() + 1); | |
65 } | |
66 } | |
67 | |
68 Uris.UriSplit split = Uris.split(url); | |
69 final String scheme = split.scheme; | |
70 final boolean hasFragment = stringHasContent(split.fragment); | |
71 if (scheme != null | |
72 && ((scheme.length() > 0 | |
73 && (scheme.equals("http") || scheme.equals("https") || scheme.equals("file"))) | |
74 || url.startsWith("$(") | |
75 || url.startsWith("${"))) { | |
76 // pass | |
77 } else if (scopedId && !hasFragment) { | |
78 final Uris.UriSplit splitbase = Uris.split(baseUrl); | |
79 final String frg; | |
80 if (stringHasContent(splitbase.fragment)) { | |
81 frg = splitbase.fragment + "/" + split.path; | |
82 } else { | |
83 frg = split.path; | |
84 } | |
85 String pt; | |
86 if (!splitbase.path.equals("")) { | |
87 pt = splitbase.path; | |
88 } else { | |
89 pt = "/"; | |
90 } | |
91 url = Uris.unsplit(splitbase.scheme, splitbase.netloc, pt, splitbase.query, frg); | |
92 } else if (scopedRef != null && !hasFragment) { | |
93 final Uris.UriSplit splitbase = Uris.split(baseUrl); | |
94 final ArrayList<String> sp = new ArrayList(Arrays.asList(splitbase.fragment.split("/"))); | |
95 int n = scopedRef; | |
96 while (n > 0 && sp.size() > 0) { | |
97 sp.remove(0); | |
98 n -= 1; | |
99 } | |
100 sp.add(url); | |
101 final String fragment = String.join("/", sp); | |
102 url = Uris.unsplit(splitbase.scheme, splitbase.netloc, splitbase.path, splitbase.query, fragment); | |
103 } else { | |
104 url = this.fetcher.urlJoin(baseUrl, url); | |
105 } | |
106 | |
107 if (vocabTerm) { | |
108 split = Uris.split(url); | |
109 if (stringHasContent(split.scheme)) { | |
110 if (this.rvocab.containsKey(url)) { | |
111 return this.rvocab.get(url); | |
112 } | |
113 } else { | |
114 throw new ValidationException("Term '{}' not in vocabulary".format(url)); | |
115 } | |
116 } | |
117 return url; | |
118 } | |
119 | |
120 static boolean stringHasContent(final String s) { | |
121 return s != null && s.length() > 0; | |
122 } | |
123 } |