Class URLFragment

java.lang.Object
org.w3c.epubcheck.util.url.URLFragment

public class URLFragment extends Object
Represents a URL fragment, after parsing micro-syntaxes.
  • Field Details

    • NONE

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

      private final String fragment
    • scheme

      private final String scheme
    • id

      private final String id
    • isMediaFragment

      private final boolean isMediaFragment
    • isValid

      private final boolean isValid
  • Constructor Details

  • Method Details

    • getId

      public 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 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 String toString()
      Overrides:
      toString in class Object
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • parse

      public static URLFragment parse(io.mola.galimatias.URL url, 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)