Class SplitIRI

java.lang.Object
org.apache.jena.util.SplitIRI

public class SplitIRI extends Object
Code to split an URI or IRI into prefix and local part. This code does not consider any prefix mapping. The split is based on finding the last / or # character.

Historically, 'prefix' is referred to as 'namespace' reflecting RDF/XML history.

For display, use localname(java.lang.String) and namespace(java.lang.String). These pragmatic follow Turtle (e.g. localname allows a plain trailing dot) but does not escape any characters. These operations are for display (c.f. Object.toString() and do not guarantee a round-trip; namespace+localname may not be the exact input IRI. A URI is split never split before the last / or #, if present. See splitpoint(java.lang.String) for more details.

The functions namespaceTTL(java.lang.String) and localnameTTL(java.lang.String) provide a strict Turtle split, if possible; the local name is escaped if necessary. namespaceTTL(java.lang.String) can be used to build a set of prefix mappings.

The functions namespaceXML(java.lang.String) and localnameXML(java.lang.String) apply the rules for XML qnames.

This code forms the machinery behind Node.getLocalName() Node.getNameSpace() for URI Nodes following the XML rules.

  • Constructor Details

    • SplitIRI

      public SplitIRI()
  • Method Details

    • namespace

      public static String namespace(String string)
      Return the 'namespace' (prefix) for a URI string. Use with localname(java.lang.String). Return the input string if there is no splitpoint.
    • localname

      public static String localname(String string)
      Calculate a localname - do not escape PN_LOCAL_ESC. This is not guaranteed to be legal Turtle. Use with namespace(java.lang.String) Return an empty string if there is no split point.
    • namespaceTTL

      public static String namespaceTTL(String string)
      Return the 'namespace' (prefix) for a URI string, legal for Turtle and goes with localnameTTL(java.lang.String). This operation does not guaratee that the argument has a legal localname.
    • localnameTTL

      public static String localnameTTL(String string)
      Calculate a localname - enforce legal Turtle escapes for localnames (rule PN_LOCAL_ESC), A final '.' is escaped. Return "" for "no split". Use with namespaceTTL(java.lang.String)
    • splitpoint

      public static int splitpoint(String uri)
      Find the URI split point, return the index into the string that is the first character of a legal Turtle local name.

      This is a pragmatic choice, not just finding the maximal point. For example, with escaping '/' can be included but that means http://example/path/abc could split to give http://example/ and path/abc .

      Split URN's after ':'.

      This function does not enforce the Turtle rule that the final character can not be '.'.

      Parameters:
      uri - URI string
      Returns:
      The split point, or -1 for "not found".
    • splitXML

      public static int splitXML(String string)
      Split point, according to XML 1.0 qname rules. This is the longest XML 1.0 NCName at the end of the uri. Return a split at the end of the string if there is no match (e.g. the URI string ends in '/' or '#').
    • splitXML10

      @Deprecated(forRemoval=true) public static int splitXML10(String string)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Retained as a record of previous split handling.
      splitXML with local stricter XML 1.0 rules (only single Java characters)
    • namespaceXML

      public static String namespaceXML(String string)
      Namespace, according to XML 1.0 qname rules. Use with localnameXML(java.lang.String).
    • localnameXML

      public static String localnameXML(String string)
      Localname, according to XML 1.0 qname rules.