rename URL to JsonLdUrl to avoid confusion with java.net.URL · fekepp/jsonld-java@c48be11 · GitHub
Skip to content

Commit c48be11

Browse files
committed
rename URL to JsonLdUrl to avoid confusion with java.net.URL
1 parent 41f6f08 commit c48be11

7 files changed

Lines changed: 66 additions & 67 deletions

File tree

core/src/main/java/com/github/jsonldjava/core/Context.java

Lines changed: 5 additions & 5 deletions

core/src/main/java/com/github/jsonldjava/core/DocumentLoader.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public RemoteDocument loadDocument(String url) throws JsonLdError {
4242

4343
/**
4444
* Returns a Map, List, or String containing the contents of the JSON
45-
* resource resolved from the URL.
45+
* resource resolved from the JsonLdUrl.
4646
*
4747
* @param url
48-
* The URL to resolve
48+
* The JsonLdUrl to resolve
4949
* @return The Map, List, or String that represent the JSON resource
50-
* resolved from the URL
50+
* resolved from the JsonLdUrl
5151
* @throws JsonParseException
5252
* If the JSON was not valid.
5353
* @throws IOException
@@ -79,21 +79,21 @@ public static Object fromURL(java.net.URL url) throws JsonParseException, IOExce
7979
}
8080

8181
/**
82-
* Opens an {@link InputStream} for the given {@link URL}, including support
83-
* for http and https URLs that are requested using Content Negotiation with
84-
* application/ld+json as the preferred content type.
82+
* Opens an {@link InputStream} for the given {@link JsonLdUrl}, including
83+
* support for http and https URLs that are requested using Content
84+
* Negotiation with application/ld+json as the preferred content type.
8585
*
8686
* @param url
87-
* The URL identifying the source.
87+
* The JsonLdUrl identifying the source.
8888
* @return An InputStream containing the contents of the source.
8989
* @throws IOException
90-
* If there was an error resolving the URL.
90+
* If there was an error resolving the JsonLdUrl.
9191
*/
9292
public static InputStream openStreamFromURL(java.net.URL url) throws IOException {
9393
final String protocol = url.getProtocol();
9494
if (!protocol.equalsIgnoreCase("http") && !protocol.equalsIgnoreCase("https")) {
9595
// Can't use the HTTP client for those!
96-
// Fallback to Java's built-in URL handler. No need for
96+
// Fallback to Java's built-in JsonLdUrl handler. No need for
9797
// Accept headers as it's likely to be file: or jar:
9898
return url.openStream();
9999
}

core/src/main/java/com/github/jsonldjava/core/JsonLdUtils.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import com.fasterxml.jackson.core.JsonParseException;
1515
import com.github.jsonldjava.utils.Obj;
16-
import com.github.jsonldjava.utils.URL;
16+
import com.github.jsonldjava.utils.JsonLdUrl;
1717

1818
public class JsonLdUtils {
1919

@@ -269,9 +269,9 @@ static void addValue(Map<String, Object> subject, String property, Object value)
269269
*
270270
* @return the absolute IRI.
271271
*
272-
* TODO: the URL class isn't as forgiving as the Node.js url parser,
273-
* we may need to re-implement the parser here to support the
274-
* flexibility required
272+
* TODO: the JsonLdUrl class isn't as forgiving as the Node.js url
273+
* parser, we may need to re-implement the parser here to support
274+
* the flexibility required
275275
*/
276276
private static String prependBase(Object baseobj, String iri) {
277277
// already an absolute IRI
@@ -280,15 +280,15 @@ private static String prependBase(Object baseobj, String iri) {
280280
}
281281

282282
// parse base if it is a string
283-
URL base;
283+
JsonLdUrl base;
284284
if (isString(baseobj)) {
285-
base = URL.parse((String) baseobj);
285+
base = JsonLdUrl.parse((String) baseobj);
286286
} else {
287-
// assume base is already a URL
288-
base = (URL) baseobj;
287+
// assume base is already a JsonLdUrl
288+
base = (JsonLdUrl) baseobj;
289289
}
290290

291-
final URL rel = URL.parse(iri);
291+
final JsonLdUrl rel = JsonLdUrl.parse(iri);
292292

293293
// start hierarchical part
294294
String hierPart = base.protocol;
@@ -318,7 +318,7 @@ private static String prependBase(Object baseobj, String iri) {
318318
}
319319

320320
// remove slashes anddots in path
321-
path = URL.removeDotSegments(path, !"".equals(hierPart));
321+
path = JsonLdUrl.removeDotSegments(path, !"".equals(hierPart));
322322

323323
// add query and hash
324324
if (!"".equals(rel.query)) {
@@ -421,11 +421,11 @@ static boolean validateTypeValue(Object v) throws JsonLdError {
421421
* @return the relative IRI if relative to base, otherwise the absolute IRI.
422422
*/
423423
private static String removeBase(Object baseobj, String iri) {
424-
URL base;
424+
JsonLdUrl base;
425425
if (isString(baseobj)) {
426-
base = URL.parse((String) baseobj);
426+
base = JsonLdUrl.parse((String) baseobj);
427427
} else {
428-
base = (URL) baseobj;
428+
base = (JsonLdUrl) baseobj;
429429
}
430430

431431
// establish base root
@@ -444,7 +444,7 @@ else if (iri.indexOf("//") != 0) {
444444
}
445445

446446
// remove root from IRI and parse remainder
447-
final URL rel = URL.parse(iri.substring(root.length()));
447+
final JsonLdUrl rel = JsonLdUrl.parse(iri.substring(root.length()));
448448

449449
// remove path segments that match
450450
final List<String> baseSegments = _split(base.normalizedPath, "/");
@@ -762,14 +762,14 @@ static boolean isBlankNode(Object v) {
762762
}
763763

764764
/**
765-
* Resolves external @context URLs using the given URL resolver. Each
766-
* instance of @context in the input that refers to a URL will be replaced
767-
* with the JSON @context found at that URL.
765+
* Resolves external @context URLs using the given JsonLdUrl resolver. Each
766+
* instance of @context in the input that refers to a JsonLdUrl will be
767+
* replaced with the JSON @context found at that JsonLdUrl.
768768
*
769769
* @param input
770770
* the JSON-LD input with possible contexts.
771771
* @param resolver
772-
* (url, callback(err, jsonCtx)) the URL resolver to use.
772+
* (url, callback(err, jsonCtx)) the JsonLdUrl resolver to use.
773773
* @param callback
774774
* (err, input) called once the operation completes.
775775
* @throws JsonLdError
@@ -799,7 +799,7 @@ private static void resolve(Object input, Map<String, Object> cycles) throws Jso
799799
final List<String> queue = new ArrayList<String>();
800800
for (final String url : urls.keySet()) {
801801
if (Boolean.FALSE.equals(urls.get(url))) {
802-
// validate URL
802+
// validate JsonLdUrl
803803
if (!regex.matcher(url).matches()) {
804804
throw new JsonLdError(JsonLdError.Error.UNKNOWN_ERROR);
805805
}
@@ -810,7 +810,7 @@ private static void resolve(Object input, Map<String, Object> cycles) throws Jso
810810
// resolve URLs in queue
811811
int count = queue.size();
812812
for (final String url : queue) {
813-
// check for context URL cycle
813+
// check for context JsonLdUrl cycle
814814
if (cycles.containsKey(url)) {
815815
throw new JsonLdError(JsonLdError.Error.UNKNOWN_ERROR);
816816
}
@@ -890,7 +890,7 @@ private static boolean findContextUrls(Object input, Map<String, Object> urls, B
890890
((List) ctx).set(i, _ctx);
891891
}
892892
}
893-
// @context URL found
893+
// @context JsonLdUrl found
894894
else if (!urls.containsKey(_ctx)) {
895895
urls.put((String) _ctx, Boolean.FALSE);
896896
}
@@ -903,7 +903,7 @@ else if (ctx instanceof String) {
903903
if (replace) {
904904
((Map) input).put(key, urls.get(ctx));
905905
}
906-
// @context URL found
906+
// @context JsonLdUrl found
907907
else if (!urls.containsKey(ctx)) {
908908
urls.put((String) ctx, Boolean.FALSE);
909909
}

core/src/main/java/com/github/jsonldjava/utils/JSONUtils.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.io.StringReader;
99
import java.io.StringWriter;
1010
import java.io.Writer;
11-
import java.net.URL;
1211
import java.util.List;
1312
import java.util.Map;
1413

@@ -156,11 +155,11 @@ public static Object fromString(String jsonString) throws JsonParseException, IO
156155

157156
/**
158157
* Parses a JSON-LD document, from the contents of the JSON resource
159-
* resolved from the URL, to an object that can be used as input for the
160-
* {@link JsonLdApi} and {@link JsonLdProcessor} methods.
158+
* resolved from the JsonLdUrl, to an object that can be used as input for
159+
* the {@link JsonLdApi} and {@link JsonLdProcessor} methods.
161160
*
162161
* @param url
163-
* The URL to resolve
162+
* The JsonLdUrl to resolve
164163
* @return A JSON Object.
165164
* @throws JsonParseException
166165
* If there was a JSON related error during parsing.
@@ -210,21 +209,21 @@ protected static HttpClient getHttpClient() {
210209
}
211210

212211
/**
213-
* Opens an {@link InputStream} for the given {@link URL}, including support
214-
* for http and https URLs that are requested using Content Negotiation with
215-
* application/ld+json as the preferred content type.
212+
* Opens an {@link InputStream} for the given {@link JsonLdUrl}, including
213+
* support for http and https URLs that are requested using Content
214+
* Negotiation with application/ld+json as the preferred content type.
216215
*
217216
* @param url
218-
* The URL identifying the source.
217+
* The JsonLdUrl identifying the source.
219218
* @return An InputStream containing the contents of the source.
220219
* @throws IOException
221-
* If there was an error resolving the URL.
220+
* If there was an error resolving the JsonLdUrl.
222221
*/
223222
protected static InputStream openStreamFromURL(java.net.URL url) throws IOException {
224223
final String protocol = url.getProtocol();
225224
if (!protocol.equalsIgnoreCase("http") && !protocol.equalsIgnoreCase("https")) {
226225
// Can't use the HTTP client for those!
227-
// Fallback to Java's built-in URL handler. No need for
226+
// Fallback to Java's built-in JsonLdUrl handler. No need for
228227
// Accept headers as it's likely to be file: or jar:
229228
return url.openStream();
230229
}

core/src/main/java/com/github/jsonldjava/utils/URL.java renamed to core/src/main/java/com/github/jsonldjava/utils/JsonLdUrl.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.regex.Matcher;
99
import java.util.regex.Pattern;
1010

11-
public class URL {
11+
public class JsonLdUrl {
1212

1313
public String href = "";
1414
public String protocol = "";
@@ -34,8 +34,8 @@ public class URL {
3434
private static Pattern parser = Pattern
3535
.compile("^(?:([^:\\/?#]+):)?(?:\\/\\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\\/?#]*)(?::(\\d*))?))?((((?:[^?#\\/]*\\/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)");
3636

37-
public static URL parse(String url) {
38-
final URL rval = new URL();
37+
public static JsonLdUrl parse(String url) {
38+
final JsonLdUrl rval = new JsonLdUrl();
3939
rval.href = url;
4040

4141
final Matcher matcher = parser.matcher(url);
@@ -103,12 +103,12 @@ public static URL parse(String url) {
103103
}
104104

105105
/**
106-
* Removes dot segments from a URL path.
106+
* Removes dot segments from a JsonLdUrl path.
107107
*
108108
* @param path
109109
* the path to remove dot segments from.
110110
* @param hasAuthority
111-
* true if the URL has an authority, false if not.
111+
* true if the JsonLdUrl has an authority, false if not.
112112
*/
113113
public static String removeDotSegments(String path, boolean hasAuthority) {
114114
String rval = "";
@@ -158,15 +158,15 @@ public static String removeDotSegments(String path, boolean hasAuthority) {
158158
}
159159

160160
public static String removeBase(Object baseobj, String iri) {
161-
if (baseobj == null) {
162-
return iri;
163-
}
164-
165-
URL base;
161+
if (baseobj == null) {
162+
return iri;
163+
}
164+
165+
JsonLdUrl base;
166166
if (baseobj instanceof String) {
167-
base = URL.parse((String) baseobj);
167+
base = JsonLdUrl.parse((String) baseobj);
168168
} else {
169-
base = (URL) baseobj;
169+
base = (JsonLdUrl) baseobj;
170170
}
171171

172172
// establish base root
@@ -185,7 +185,7 @@ else if (iri.indexOf("//") != 0) {
185185
}
186186

187187
// remove root from IRI and parse remainder
188-
final URL rel = URL.parse(iri.substring(root.length()));
188+
final JsonLdUrl rel = JsonLdUrl.parse(iri.substring(root.length()));
189189

190190
// remove path segments that match
191191
final List<String> baseSegments = new ArrayList<String>(Arrays.asList(base.normalizedPath
@@ -274,7 +274,7 @@ public static String resolve(String baseUri, String pathToResolve) {
274274
// java doesn't discard unnecessary dot segments
275275
String path = uri.getPath();
276276
if (path != null) {
277-
path = URL.removeDotSegments(uri.getPath(), true);
277+
path = JsonLdUrl.removeDotSegments(uri.getPath(), true);
278278
}
279279
return new URI(uri.getScheme(), uri.getAuthority(), path, uri.getQuery(),
280280
uri.getFragment()).toString();
@@ -284,12 +284,12 @@ public static String resolve(String baseUri, String pathToResolve) {
284284
}
285285

286286
/**
287-
* Parses the authority for the pre-parsed given URL.
287+
* Parses the authority for the pre-parsed given JsonLdUrl.
288288
*
289289
* @param parsed
290-
* the pre-parsed URL.
290+
* the pre-parsed JsonLdUrl.
291291
*/
292-
private static void parseAuthority(URL parsed) {
292+
private static void parseAuthority(JsonLdUrl parsed) {
293293
// parse authority for unparsed relative network-path reference
294294
if (parsed.href.indexOf(":") == -1 && parsed.href.indexOf("//") == 0
295295
&& "".equals(parsed.host)) {

core/src/test/java/com/github/jsonldjava/utils/EarlTestSuite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public EarlTestSuite(String manifestURL) throws IOException {
3434
* Loads an earl test suite
3535
*
3636
* @param manifestURL
37-
* the URL of the manifest file
37+
* the JsonLdUrl of the manifest file
3838
* @param cacheDir
3939
* the base directory to cache the files into
4040
* @param etag
@@ -101,7 +101,7 @@ manifestFile, new JsonLdOptions(manifestURL) {
101101
}
102102

103103
public String getFile(String url) throws IOException {
104-
final URL url_ = URL.parse(url.toString());
104+
final JsonLdUrl url_ = JsonLdUrl.parse(url.toString());
105105
final String fn = this.cacheDir + url_.file + "." + this.etag;
106106
final File f = new File(fn);
107107

@@ -135,7 +135,7 @@ public String getFile(String url) throws IOException {
135135
}
136136

137137
private static String getCacheDir(String url) {
138-
final URL url_ = URL.parse(url);
138+
final JsonLdUrl url_ = JsonLdUrl.parse(url);
139139
String dir = url_.path.substring(0, url_.path.lastIndexOf("/") + 1);
140140
if (!FILE_SEP.equals("/")) {
141141
dir = dir.replace("/", FILE_SEP);

tools/src/main/java/com/github/jsonldjava/tools/Playground.java

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)