/** * Replaces terminating hash ('#') characters with their URL-encoded versions ("%23"). Any non-terminating * hashes will be left as they are (though they are not to be expected if the IRI denotes an URL). * * @param iri * the IRI to sanitize * @return the sanitized IRI */ public static IRI sanitize(IRI iri) { return IRI.create(sanitize(iri.toString())); }
/** * URL-decodes any terminating hash characters ("%23"). Any non-terminating URL-encoded hashes will be * left as they are (since there should be no intermediate hashes in a URL). * * @param iri * the IRI to desanitize * @return the desanitized IRI */ public static IRI desanitize(IRI iri) { return IRI.create(desanitize(iri.toString())); }
/** * Removes either the fragment, or query, or last path component from a URI, whatever it finds first. * * @param iri * @return */ public static IRI upOne(IRI iri) { return upOne(iri.toURI()); }
else if (r instanceof Literal) tgt = org.semanticweb.owlapi.model.IRI.create(((Literal) r).getLexicalForm()); else tgt = org.semanticweb.owlapi.model.IRI.create(r.toString()); tgt = URIUtils.sanitize(tgt); importTargets.add(new IRI(tgt.toString())); } catch (Exception ex) { base = URIUtils.upOne(URI.create(base)).toString(); base += "/";
@Override public String getKey(IRI ontologyIri) { ontologyIri = URIUtils.sanitizeID(ontologyIri); UriRef ur = keymap.getMapping(new OWLOntologyID(ontologyIri)); log.debug("key for {} is {}", ontologyIri, ur); return (ur == null) ? null : ur.getUnicodeString(); }
else if (r instanceof Literal) tgt = org.semanticweb.owlapi.model.IRI.create(((Literal) r).getLexicalForm()); else tgt = org.semanticweb.owlapi.model.IRI.create(r.toString()); tgt = URIUtils.sanitize(tgt); importTargets.add(new IRI(tgt.toString())); } catch (Exception ex) { base = URIUtils.upOne(URI.create(base)).toString(); base += "/";
while (s.endsWith("#")) s = s.substring(0, s.length() - 1); ontologyIri = URIUtils.sanitizeID(ontologyIri); s += ontologyIri;
/** * Provides a standardized string format for an OWL Ontology ID. The string returned is of type * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>":::"</tt> present in <tt>ontologyIRI</tt> or * <tt>versionIRI</tt> will be URL-encoded (i.e. converted to <tt>"%3A%3A%3A"</tt>).<br/> * <br/> * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are sanitized in the process. No other * URL encoding occurs. * * @param id * the OWL ontology ID to encode * @return the string form of this ID. * @see URIUtils#sanitize(IRI) */ public static String encode(OWLOntologyID id) { if (id == null) throw new IllegalArgumentException("Cannot encode a null OWLOntologyID."); if (id.getOntologyIRI() == null) throw new IllegalArgumentException( "Cannot encode an OWLOntologyID that is missing an ontologyIRI."); String s = ""; s += URIUtils.sanitize(id.getOntologyIRI()).toString().replace(":::", "%3A%3A%3A"); if (id.getVersionIRI() != null) s += (":::") + URIUtils.sanitize(id.getVersionIRI()).toString() .replace(":::", "%3A%3A%3A"); return s; }
.upOne(universalPrefix) + "/") + s); changes.add(new AddImport(o, df.getOWLImportsDeclaration(target)));
/** * Extracts an OWL Ontology ID from its standard string form. The string must be of type * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>"%3A%3A%3A"</tt> present in <tt>ontologyIRI</tt> * or <tt>versionIRI</tt> will be URL-decoded (i.e. converted to <tt>":::"</tt>).<br/> * <br/> * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are desanitized in the process. * * @param stringForm * the string to decode * @return the string form of this ID. * @see URIUtils#desanitize(IRI) */ public static OWLOntologyID decode(String stringForm) { if (stringForm == null || stringForm.isEmpty()) throw new IllegalArgumentException( "Supplied string form must be non-null and non-empty."); IRI oiri, viri; String[] split = stringForm.split(":::"); if (split.length >= 1) { oiri = URIUtils.desanitize(IRI.create(split[0].replace("%3A%3A%3A", ":::"))); viri = (split.length > 1) ? URIUtils.desanitize(IRI.create(split[1].replace("%3A%3A%3A", ":::"))) : null; return (viri != null) ? new OWLOntologyID(oiri, viri) : new OWLOntologyID(oiri); } else return null; // Anonymous but versioned ontologies are not acceptable. }
/** * Provides a standardized string format for an OWL Ontology ID. The string returned is of type * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>":::"</tt> present in <tt>ontologyIRI</tt> or * <tt>versionIRI</tt> will be URL-encoded (i.e. converted to <tt>"%3A%3A%3A"</tt>).<br/> * <br/> * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are sanitized in the process. No other * URL encoding occurs. * * @param id * the OWL ontology ID to encode * @return the string form of this ID. * @see URIUtils#sanitize(IRI) */ public static String encode(OWLOntologyID id) { if (id == null) throw new IllegalArgumentException("Cannot encode a null OWLOntologyID."); if (id.getOntologyIRI() == null) throw new IllegalArgumentException( "Cannot encode an OWLOntologyID that is missing an ontologyIRI."); String s = ""; s += URIUtils.sanitize(id.getOntologyIRI()).toString().replace(":::", "%3A%3A%3A"); if (id.getVersionIRI() != null) s += (":::") + URIUtils.sanitize(id.getVersionIRI()).toString() .replace(":::", "%3A%3A%3A"); return s; }
: URIUtils.upOne(universalPrefix) + "/") + s); o.remove(t);
/** * Extracts an OWL Ontology ID from its standard string form. The string must be of type * <tt>ontologyIRI[:::versionIRI]</tt>. Any substring <tt>"%3A%3A%3A"</tt> present in <tt>ontologyIRI</tt> * or <tt>versionIRI</tt> will be URL-decoded (i.e. converted to <tt>":::"</tt>).<br/> * <br/> * Also note that both <tt>ontologyIRI</tt> and <tt>versionIRI</tt> are desanitized in the process. * * @param stringForm * the string to decode * @return the string form of this ID. * @see URIUtils#desanitize(IRI) */ public static OWLOntologyID decode(String stringForm) { if (stringForm == null || stringForm.isEmpty()) throw new IllegalArgumentException( "Supplied string form must be non-null and non-empty."); IRI oiri, viri; String[] split = stringForm.split(":::"); if (split.length >= 1) { oiri = URIUtils.desanitize(IRI.create(split[0].replace("%3A%3A%3A", ":::"))); viri = (split.length > 1) ? URIUtils.desanitize(IRI.create(split[1].replace("%3A%3A%3A", ":::"))) : null; return (viri != null) ? new OWLOntologyID(oiri, viri) : new OWLOntologyID(oiri); } else return null; // Anonymous but versioned ontologies are not acceptable. }
private OWLOntology getOWLOntology(String ontologyId, boolean merge, URI requestUri) { long before = System.currentTimeMillis(); IRI iri = URIUtils.sanitize(IRI.create(ontologyId)); log.debug("Will try to retrieve ontology {} from provider.", iri);
.upOne(universalPrefix) + "/") + s); changes.add(new AddImport(o, df.getOWLImportsDeclaration(target)));
if (reg != null && !reg.isEmpty()) try { srcs.add(new LibrarySource(URIUtils.desanitize(IRI.create(reg)), regMgr)); } catch (Exception e1) { throw new WebApplicationException(e1, BAD_REQUEST);
log.debug("Ontology {} missing from provider. Trying libraries...", key); IRI iri = URIUtils.sanitize(IRI.create(ontologyId));
: URIUtils.upOne(universalPrefix) + "/") + s); o.remove(t);
graphName = new IRI(URIUtils.sanitize(s)); log.debug("Storing ontology with graph ID {}", graphName); try {
UriRef target = new UriRef((managed ? ns + "/" + tid + "/" : URIUtils.upOne(ns) + "/") + s); o.remove(t); newImports.add(new TripleImpl(t.getSubject(), OWL.imports, target));