Class URLFragment


  • public class URLFragment
    extends java.lang.Object
    Represents a URL fragment, after parsing micro-syntaxes.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  URLFragment.Parser  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String fragment  
      private java.lang.String id  
      private boolean isMediaFragment  
      private boolean isValid  
      static URLFragment NONE
      Represents a non-existent fragment, for which exists() returns false
      private java.lang.String scheme  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      boolean exists()  
      java.lang.String getId()
      Returns the element ID represented by this fragment if this is an ID-based fragment, or the empty string otherwise.
      java.lang.String getScheme()
      Returns the scheme represented by this fragment if this is an scheme-based fragment, or the empty string otherwise.
      int hashCode()  
      boolean isEmpty()  
      boolean isMediaFragment()  
      boolean isValid()  
      static URLFragment parse​(io.mola.galimatias.URL url)
      Parse the fragment of the given URL, according to the default rules (XML MIME type), see parse(URL, String).
      static URLFragment parse​(io.mola.galimatias.URL url, java.lang.String mimetype)
      Parse the fragment of the given URL, according to the rules defined for the given MIME type.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NONE

        public static final URLFragment NONE
        Represents a non-existent fragment, for which exists() returns false
      • fragment

        private final java.lang.String fragment
      • scheme

        private final java.lang.String scheme
      • id

        private final java.lang.String id
      • isMediaFragment

        private final boolean isMediaFragment
      • isValid

        private final boolean isValid
    • Method Detail

      • getId

        public java.lang.String getId()
        Returns the element ID represented by this fragment if this is an ID-based fragment, or the empty string otherwise.
        Returns:
        an element ID or the empty string.
      • getScheme

        public java.lang.String getScheme()
        Returns the scheme represented by this fragment if this is an scheme-based fragment, or the empty string otherwise.
        Returns:
        a scheme name or the empty string.
      • exists

        public boolean exists()
        Returns:
        true iff the URL from which this was parsed had a fragment.
      • isEmpty

        public boolean isEmpty()
        Returns:
        true iff this fragment is the empty string or represents a non-existent fragment.
      • isValid

        public boolean isValid()
        Returns:
        true iff this fragment is valid according to its target MIME type.
      • isMediaFragment

        public boolean isMediaFragment()
        Returns:
        true iff this fragment is a media fragment.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • parse

        public static URLFragment parse​(io.mola.galimatias.URL url,
                                        java.lang.String mimetype)
        Parse the fragment of the given URL, according to the rules defined for the given MIME type. If the URL has no fragment, returns NONE

        HTML types "application/xhtml+xml" and "text/html"

        The following fragment patterns are supported:

        • regular ID-based fragments (`#name`)
        • scheme-based fragments (`#name(something)`)
        • media fragments (`#name=value`, with name one of `t|xywh|track|id|xyn|xyr`
        • fragment directives (`#name:~:text=range`)

        Note that this deviates from the HTML standard in the following way:

        • HTML does not define specific logic for scheme-based or media fragments, which must be treated like any other IDs. However, EPUB makes use of them notably for EPUB CFI or region-based navigation.
        • Fragment directives (as used in text fragments), is an incubating standard (at the time of writing) and is likely not well supported by reading system, but its syntax is specific enough to lower the risk of false-positive.

        SVG type "image/svg+xml"

        The following fragment patterns are supported:

        • shorthand bare form names (#name). Validation checks that the name is an XML NCName.
        • SVG view specification (#svgView(…)). Validation currently does not look into the parenthesis content.
        • basic media fragments (#xywh=0,0,50,50). Validation checks the syntax of spatial and temporal dimensions.

        Other type

        Any other type is assumed to be XML. The following fragment patterns are supported:

        • shorthand bare form names (#name). Validation checks that the name is an XML NCName.
        • scheme-based fragments (`#name(something)`). No validation of the scheme name or syntax.
        Parameters:
        url - a URL
        mimetype - the MIME type of the URL target
        Returns:
        a parsed fragment (cannot be null)
      • parse

        public static URLFragment parse​(io.mola.galimatias.URL url)
        Parse the fragment of the given URL, according to the default rules (XML MIME type), see parse(URL, String).
        Parameters:
        url - a URL
        Returns:
        a parsed fragment (cannot benull)