Here are the examples of the java api class com.github.jsonldjava.utils.JsonLdUrl taken from open source projects.
1. JsonLdUtils#removeBase()
Project: Web-Karma
File: JsonLdUtils.java
File: JsonLdUtils.java
/** * Removes a base IRI from the given absolute IRI. * * @param base * the base IRI. * @param iri * the absolute IRI. * * @return the relative IRI if relative to base, otherwise the absolute IRI. */ private static String removeBase(Object baseobj, String iri) { JsonLdUrl base; if (isString(baseobj)) { base = JsonLdUrl.parse((String) baseobj); } else { base = (JsonLdUrl) baseobj; } // establish base root String root = ""; if (!"".equals(base.href)) { root += (base.protocol) + "//" + base.authority; } else // support network-path reference with empty base if (iri.indexOf("//") != 0) { root += "//"; } // IRI not relative to base if (iri.indexOf(root) != 0) { return iri; } // remove root from IRI and parse remainder final JsonLdUrl rel = JsonLdUrl.parse(iri.substring(root.length())); // remove path segments that match final List<String> baseSegments = _split(base.normalizedPath, "/"); final List<String> iriSegments = _split(rel.normalizedPath, "/"); while (!baseSegments.isEmpty() && !iriSegments.isEmpty()) { if (!baseSegments.get(0).equals(iriSegments.get(0))) { break; } if (!baseSegments.isEmpty()) { baseSegments.remove(0); } if (!iriSegments.isEmpty()) { iriSegments.remove(0); } } // use '../' for each non-matching base segment String rval = ""; if (!baseSegments.isEmpty()) { // don't count empty first segment, it means base began with '/' if (!base.normalizedPath.endsWith("/") || "".equals(baseSegments.get(0))) { baseSegments.remove(baseSegments.size() - 1); } for (int i = 0; i < baseSegments.size(); ++i) { rval += "../"; } } // prepend remaining segments rval += _join(iriSegments, "/"); // add query and hash if (!"".equals(rel.query)) { rval += "?" + rel.query; } if (!"".equals(rel.hash)) { rval += rel.hash; } if ("".equals(rval)) { rval = "./"; } return rval; }
2. JsonLdUtils#prependBase()
Project: Web-Karma
File: JsonLdUtils.java
File: JsonLdUtils.java
/** * Prepends a base IRI to the given relative IRI. * * @param base * the base IRI. * @param iri * the relative IRI. * * @return the absolute IRI. * * TODO: the JsonLdUrl class isn't as forgiving as the Node.js url * parser, we may need to re-implement the parser here to support * the flexibility required */ private static String prependBase(Object baseobj, String iri) { // already an absolute IRI if (iri.indexOf(":") != -1) { return iri; } // parse base if it is a string JsonLdUrl base; if (isString(baseobj)) { base = JsonLdUrl.parse((String) baseobj); } else { // assume base is already a JsonLdUrl base = (JsonLdUrl) baseobj; } final JsonLdUrl rel = JsonLdUrl.parse(iri); // start hierarchical part String hierPart = base.protocol; if (!"".equals(rel.authority)) { hierPart += "//" + rel.authority; } else if (!"".equals(base.href)) { hierPart += "//" + base.authority; } // per RFC3986 normalize String path; // IRI represents an absolute path if (rel.pathname.indexOf("/") == 0) { path = rel.pathname; } else { path = base.pathname; // append relative path to the end of the last directory from base if (!"".equals(rel.pathname)) { path = path.substring(0, path.lastIndexOf("/") + 1); if (path.length() > 0 && !path.endsWith("/")) { path += "/"; } path += rel.pathname; } } // remove slashes anddots in path path = JsonLdUrl.removeDotSegments(path, !"".equals(hierPart)); // add query and hash if (!"".equals(rel.query)) { path += "?" + rel.query; } if (!"".equals(rel.hash)) { path += rel.hash; } final String rval = hierPart + path; if ("".equals(rval)) { return "./"; } return rval; }
3. JsonLdUtils#removeBase()
Project: jsonld-java
File: JsonLdUtils.java
File: JsonLdUtils.java
/** * Removes a base IRI from the given absolute IRI. * * @param base * the base IRI. * @param iri * the absolute IRI. * * @return the relative IRI if relative to base, otherwise the absolute IRI. */ private static String removeBase(Object baseobj, String iri) { JsonLdUrl base; if (isString(baseobj)) { base = JsonLdUrl.parse((String) baseobj); } else { base = (JsonLdUrl) baseobj; } // establish base root String root = ""; if (!"".equals(base.href)) { root += (base.protocol) + "//" + base.authority; } else // support network-path reference with empty base if (iri.indexOf("//") != 0) { root += "//"; } // IRI not relative to base if (iri.indexOf(root) != 0) { return iri; } // remove root from IRI and parse remainder final JsonLdUrl rel = JsonLdUrl.parse(iri.substring(root.length())); // remove path segments that match final List<String> baseSegments = _split(base.normalizedPath, "/"); final List<String> iriSegments = _split(rel.normalizedPath, "/"); while (baseSegments.size() > 0 && iriSegments.size() > 0) { if (!baseSegments.get(0).equals(iriSegments.get(0))) { break; } if (baseSegments.size() > 0) { baseSegments.remove(0); } if (iriSegments.size() > 0) { iriSegments.remove(0); } } // use '../' for each non-matching base segment String rval = ""; if (baseSegments.size() > 0) { // don't count empty first segment, it means base began with '/' if (!base.normalizedPath.endsWith("/") || "".equals(baseSegments.get(0))) { baseSegments.remove(baseSegments.size() - 1); } for (int i = 0; i < baseSegments.size(); ++i) { rval += "../"; } } // prepend remaining segments rval += _join(iriSegments, "/"); // add query and hash if (!"".equals(rel.query)) { rval += "?" + rel.query; } if (!"".equals(rel.hash)) { rval += rel.hash; } if ("".equals(rval)) { rval = "./"; } return rval; }
4. JsonLdUtils#prependBase()
Project: jsonld-java
File: JsonLdUtils.java
File: JsonLdUtils.java
/** * Prepends a base IRI to the given relative IRI. * * @param base * the base IRI. * @param iri * the relative IRI. * * @return the absolute IRI. * * TODO: the JsonLdUrl class isn't as forgiving as the Node.js url * parser, we may need to re-implement the parser here to support * the flexibility required */ private static String prependBase(Object baseobj, String iri) { // already an absolute IRI if (iri.indexOf(":") != -1) { return iri; } // parse base if it is a string JsonLdUrl base; if (isString(baseobj)) { base = JsonLdUrl.parse((String) baseobj); } else { // assume base is already a JsonLdUrl base = (JsonLdUrl) baseobj; } final JsonLdUrl rel = JsonLdUrl.parse(iri); // start hierarchical part String hierPart = base.protocol; if (!"".equals(rel.authority)) { hierPart += "//" + rel.authority; } else if (!"".equals(base.href)) { hierPart += "//" + base.authority; } // per RFC3986 normalize String path; // IRI represents an absolute path if (rel.pathname.indexOf("/") == 0) { path = rel.pathname; } else { path = base.pathname; // append relative path to the end of the last directory from base if (!"".equals(rel.pathname)) { path = path.substring(0, path.lastIndexOf("/") + 1); if (path.length() > 0 && !path.endsWith("/")) { path += "/"; } path += rel.pathname; } } // remove slashes anddots in path path = JsonLdUrl.removeDotSegments(path, !"".equals(hierPart)); // add query and hash if (!"".equals(rel.query)) { path += "?" + rel.query; } if (!"".equals(rel.hash)) { path += rel.hash; } final String rval = hierPart + path; if ("".equals(rval)) { return "./"; } return rval; }