public String getNamespace() { if (localNameIdx < 0) { localNameIdx = URIUtil.getLocalNameIndex(iriString); } return iriString.substring(0, localNameIdx); }
/** * Escapes any character that is not either reserved or in the legal range of unreserved characters, * according to RFC 2396. * * @param unescaped * a (relative or absolute) uri reference. * @return a (relative or absolute) uri reference with all characters that can not appear as-is in a URI * %-escaped. * @see <a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a> */ private static String escapeExcludedChars(String unescaped) { final StringBuilder escaped = new StringBuilder(); for (int i = 0; i < unescaped.length(); i++) { char c = unescaped.charAt(i); if (!isUnreserved(c) && !reserved.contains(c)) { escaped.append("%" + Integer.toHexString((int)c)); } else { escaped.append(c); } } return escaped.toString(); }
/** * Returns the name of the {@code KBObject} if available, otherwise return the local name of its * IRI or, as a last resort, return the full identifier, e.g. if the identifier is not a valid * IRI or if the local name is empty. * * @return a UI-friendly representation of this {@code KBObject}. */ default String getUiLabel() { String name = getName(); if (name != null) { return name; } if (isValidURIReference(getIdentifier())) { int localNameIndex = getLocalNameIndex(getIdentifier()); String label = getIdentifier().substring(localNameIndex).replace('_', ' '); if (isNotBlank(label)) { return label; } else { return getIdentifier(); } } else { return getIdentifier(); } }
@Override public synchronized IRI createIRI(String namespace, String localName) { IRI tempURI = null; // Reuse supplied namespace and local name strings if possible if (URIUtil.isCorrectURISplit(namespace, localName)) { if (namespace.indexOf(':') == -1) { throw new IllegalArgumentException("Not a valid (absolute) URI: " + namespace + localName); } tempURI = new MemIRI(null, namespace, localName); } else { tempURI = super.createIRI(namespace + localName); } return getOrCreateMemURI(tempURI); }
@Override protected Value evaluate(ValueFactory valueFactory, Value arg) throws ValueExprEvaluationException { if (!(arg instanceof Literal)) { throw new ValueExprEvaluationException("Argument must be a string"); } return valueFactory.createLiteral(URIUtil.isValidURIReference(arg.stringValue())); } }
final String escaped = escapeExcludedChars(uriRef); try {
/** * Returns the name of the {@code KBObject} if available, otherwise return the local name of its * IRI or, as a last resort, return the full identifier, e.g. if the identifier is not a valid * IRI or if the local name is empty. * * @return a UI-friendly representation of this {@code KBObject}. */ default String getUiLabel() { String name = getName(); if (name != null) { return name; } if (isValidURIReference(getIdentifier())) { int localNameIndex = getLocalNameIndex(getIdentifier()); String label = getIdentifier().substring(localNameIndex).replace('_', ' '); if (isNotBlank(label)) { return label; } else { return getIdentifier(); } } else { return getIdentifier(); } }
@Override public synchronized IRI createIRI(String namespace, String localName) { IRI tempURI = null; // Reuse supplied namespace and local name strings if possible if (URIUtil.isCorrectURISplit(namespace, localName)) { if (namespace.indexOf(':') == -1) { throw new IllegalArgumentException("Not a valid (absolute) URI: " + namespace + localName); } tempURI = new MemIRI(null, namespace, localName); } else { tempURI = super.createIRI(namespace + localName); } return getOrCreateMemURI(tempURI); }
@Override public void validate(IValidatable<String> validatable) { if (!URIUtil.isValidURIReference(validatable.getValue())) { validatable.error(new ValidationError(this)); } } };
final String escaped = escapeExcludedChars(uriRef); try {
@Override public String getNamespace() { if (localNameIdx < 0) { localNameIdx = URIUtil.getLocalNameIndex(iriString); } return iriString.substring(0, localNameIdx); }
@Override public IRI createIRI(String namespace, String localName) { if (!URIUtil.isCorrectURISplit(namespace, localName)) { return createIRI(namespace + localName); } try { if (!new ParsedIRI(namespace + localName).isAbsolute()) { throw new IllegalArgumentException("Namespace must be absolute"); } return delegate.createIRI(namespace, localName); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
@Override public void validate(IValidatable<String> validatable) { if (!URIUtil.isValidURIReference(validatable.getValue())) { validatable.error(new ValidationError(this)); } } };
/** * Escapes any character that is not either reserved or in the legal range of unreserved characters, * according to RFC 2396. * * @param unescaped * a (relative or absolute) uri reference. * @return a (relative or absolute) uri reference with all characters that can not appear as-is in a URI * %-escaped. * @see <a href="http://www.ietf.org/rfc/rfc2396.txt">RFC 2396</a> */ private static String escapeExcludedChars(String unescaped) { final StringBuilder escaped = new StringBuilder(); for (int i = 0; i < unescaped.length(); i++) { char c = unescaped.charAt(i); if (!isUnreserved(c) && !reserved.contains(c)) { escaped.append("%" + Integer.toHexString((int)c)); } else { escaped.append(c); } } return escaped.toString(); }
@Override public String getLocalName() { if (localNameIdx < 0) { localNameIdx = URIUtil.getLocalNameIndex(iriString); } return iriString.substring(localNameIdx); }
@Override public IRI createIRI(String namespace, String localName) { if (!URIUtil.isCorrectURISplit(namespace, localName)) { return createIRI(namespace + localName); } try { if (!new ParsedIRI(namespace + localName).isAbsolute()) { throw new IllegalArgumentException("Namespace must be absolute"); } return delegate.createIRI(namespace, localName); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
private Value mapValue(Object value, String language, ValueFactory vf) { if (value instanceof IRI) { return (IRI) value; } else if (value instanceof String && URIUtil.isValidURIReference((String) value)) { return vf.createIRI((String) value); } else if (language != null) { return vf.createLiteral((String) value, language); } else { DatatypeMapper mapper = new DefaultDatatypeMapper(); return mapper.getRDFValue(value, vf); } } }
public String getLocalName() { if (localNameIdx < 0) { localNameIdx = URIUtil.getLocalNameIndex(iriString); } return iriString.substring(localNameIdx); }
private Value mapValue(Object value, String language, ValueFactory vf) { if (value instanceof IRI) { return (IRI) value; } else if (value instanceof String && URIUtil.isValidURIReference((String) value)) { return vf.createIRI((String) value); } else if (language != null) { return vf.createLiteral((String) value, language); } else { DatatypeMapper mapper = new DefaultDatatypeMapper(); return mapper.getRDFValue(value, vf); } } }
protected void validate(String data) { if (data == null) throw new IllegalArgumentException("Null not IRI"); URIUtil.getLocalNameIndex(data); }