- All Implemented Interfaces:
IRI
java.net.URI covers IRIs. This provides a
fast checking operation which does not copy the various parts of the IRI and which
creates a single object. The cost of extracting and allocating strings happen when
the getter for the component is called. java.net.URI parses and allocates
and follows RFC 2396 with modifications (several of which are in RFC 3986). See
RFC3986 for operations involving IRI3986. This package implements
the algorithms specified in RFC 3986 operations for:
- Checking a string matches the IRI grammar.
- Extracting components of an IRI
- Normalizing an IRI
- Resolving an IRI against a base IRI.
- Rebuilding an IRI from components.
- Scheme specific rules for Linked Data usage of HTTP IRIs and URNs.
Some additional check for RFC 8141 for URNs are included such as being of the form
urn:NID:NSS. Restrictions and limitations:
- No normal form C checking when checking (currently). See
Normalizer.isNormalized(CharSequence, java.text.Normalizer.Form).
Check conformance with the RFC 3986 grammar:
RFC3986.check(string);Check conformance with the RFC 3986 grammar and any applicable scheme specific rules:
RFC3986.check(string, true);Validate and extract the components of IRI:
IRI3986 iri = RFC3986.create(string);
iri.getPath();
...
Resolve:
IRI3986 base = ...
IRI3986 iri = RFC3986.create(string);
IRI3986 iri2 = iri.resolve(base);
Normalize:
IRI3986 base = ...
IRI3986 iri = RFC3986.create(string);
IRI3986 iri2 = iri.normalize();
-
Method Summary
Modifier and TypeMethodDescriptionstatic IRI3986Build aIRI3986from components.static IRI3986Create anIRI3986object or throw an exception if there is a syntax error.static IRI3986Create anIRI3986object; report errors and warnings.static IRI3986createSyntax(String iristr) Create anIRI3986object or throw an exception if there is a syntax error.booleanJava equals.voidforEachViolation(Consumer<Violation> action) Call a consumer function for any violations recorded for this IRI.fragment()booleanbooleaninthashCode()Java hashCode.booleanhasHost()booleanhasPath()booleanhasPort()booleanhasQuery()booleanbooleanbooleanDoes this IRI have any scheme specific issues?booleanhasViolations(Severity levelSeverity) Return true if this IRI has any violations greater than (and not equal to) the severity argument.host()booleanbooleanbooleanbooleanTest whether the IRI is RFC 3986 compatible;that is, has only ASCII characters.booleanpath()String[]port()query()rebuild()RFC 3986 : 5.3.relativize(IRI iri) Return (if possible), an IRI that is relative to the base argument.Resolve an IRI, using this as the base.scheme()final Stringstr()The IRI in string form.toString()Human-readable appearance.userInfo()Return an immutable list of the violations for this IRI.
-
Method Details
-
create
Create anIRI3986object or throw an exception if there is a syntax error.This operation also checks conformance to the rules of the IRI schemes for some IRI schemes (http/https, urn:uuid, urn, file, did). These violations are accessed with
hasViolations()andforEachViolation(java.util.function.Consumer<org.apache.jena.rfc3986.Violation>).See
Violationsfor the mapping from issue to a warning or an error.See
Issuefor the scheme specific issues covered. -
createSyntax
Create anIRI3986object or throw an exception if there is a syntax error.This operation does not check conformance to the rules of IRI schemes.
Prefer
create(String)which records scheme-violations.See
Violationsfor the mapping from issue to a warning or an error.See
Issuefor the scheme specific issues covered. -
createAny
Create anIRI3986object; report errors and warnings. This operation always returns an object; it does not throw an exception, nor return null.Errors and warning may be accessed with
hasViolations()andforEachViolation(java.util.function.Consumer<org.apache.jena.rfc3986.Violation>).This operation checks the resulting IRI conforms to URI scheme specific rules only if the syntax as an IRI is valid.
-
str
The IRI in string form. This is guaranteed to parse to a ".equals" IRI. -
hasViolations
public boolean hasViolations()Does this IRI have any scheme specific issues?The normal way to create IRIs,
create(java.lang.String)throws anIRIParseException. Parse errors in IRI string areIRIParseExceptions (unlesscreateAny(java.lang.String)is used). In addition to parsing, IRIs are checked for some of the scheme-specific issues in the standards. See enumIssue.These are recorded in the IRI object; they do not automatically cause exceptions. See
Violationsfor mapping issues to warnings and errors. -
hasViolations
Return true if this IRI has any violations greater than (and not equal to) the severity argument. -
forEachViolation
Call a consumer function for any violations recorded for this IRI.The normal way to create IRIs,
create(java.lang.String), throws anIRIParseExceptionif the IRI string does not match the grammar of RFC 3986/3987 and other RFCs. In addition to parsing, IRIs are checked for scheme-specific issues in the standards. See enumIssuefor the issues covered.Issues are recorded as
Violations. These are recorded in the IRI object; they do not automatically cause exceptions. SeeViolationsfor mapping issues to warnings and errors.See
createAny(java.lang.String)for an operation to create a IRI that records parse exceptions are does not throw exception. -
violations
Return an immutable list of the violations for this IRI. SeeforEachViolation(Consumer). -
toString
Human-readable appearance. Usestr()to a string to use in code. -
hasScheme
public boolean hasScheme() -
scheme
-
hasAuthority
public boolean hasAuthority()- Specified by:
hasAuthorityin interfaceIRI
-
authority
-
hasUserInfo
public boolean hasUserInfo()- Specified by:
hasUserInfoin interfaceIRI
-
userInfo
-
hasHost
public boolean hasHost() -
host
-
hasPort
public boolean hasPort() -
port
-
hasPath
public boolean hasPath() -
path
-
pathSegments
- Specified by:
pathSegmentsin interfaceIRI
-
hasQuery
public boolean hasQuery() -
query
-
hasFragment
public boolean hasFragment()- Specified by:
hasFragmentin interfaceIRI
-
fragment
-
isAbsolute
public boolean isAbsolute()- Specified by:
isAbsolutein interfaceIRI
-
isRelative
public boolean isRelative()- Specified by:
isRelativein interfaceIRI
-
isRootless
public boolean isRootless()RFC 3986, Section 3. IRI has a scheme, no authority (no //) and is path-rootless (does not start with /) e.g. URN's.- Specified by:
isRootlessin interfaceIRI
-
isHierarchical
public boolean isHierarchical()- Specified by:
isHierarchicalin interfaceIRI
-
isRFC3986
public boolean isRFC3986()Test whether the IRI is RFC 3986 compatible;that is, has only ASCII characters. -
normalize
-
relativize
Return (if possible), an IRI that is relative to the base argument.The base must have a scheme, and must not have a query string.
Any fragment on the base IRI is lost.
If no relative IRI can be found, return null.
-
resolve
Resolve an IRI, using this as the base. RFC 3986 section 5 -
build
public static IRI3986 build(String scheme, String authority, String path, String query, String fragment) Build aIRI3986from components. -
rebuild
RFC 3986 : 5.3. Component Recomposition -
hashCode
public int hashCode()Description copied from interface:IRIJava hashCode. -
equals
Description copied from interface:IRIJava equals. IRI implementations must provide value-based equality and hashCode. That is, two IRI objects with the same components are ".equals" and have the same ".hashCode". (Like java.lang.String where "same chars" means "equals".)Specifically, if two IRI objects are parsed from the same string or return the same "str()" they are .equals and also have the same .hashCode.
-