Package org.w3c.epubcheck.util.url
Class URLFragment
- java.lang.Object
-
- org.w3c.epubcheck.util.url.URLFragment
-
public class URLFragment extends java.lang.ObjectRepresents a URL fragment, after parsing micro-syntaxes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classURLFragment.Parser
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Stringfragmentprivate java.lang.Stringidprivate booleanisMediaFragmentprivate booleanisValidstatic URLFragmentNONERepresents a non-existent fragment, for whichexists()returnsfalseprivate java.lang.Stringscheme
-
Constructor Summary
Constructors Modifier Constructor Description privateURLFragment(URLFragment.Parser parser)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)booleanexists()java.lang.StringgetId()Returns the element ID represented by this fragment if this is an ID-based fragment, or the empty string otherwise.java.lang.StringgetScheme()Returns the scheme represented by this fragment if this is an scheme-based fragment, or the empty string otherwise.inthashCode()booleanisEmpty()booleanisMediaFragment()booleanisValid()static URLFragmentparse(io.mola.galimatias.URL url)Parse the fragment of the given URL, according to the default rules (XML MIME type), seeparse(URL, String).static URLFragmentparse(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.StringtoString()
-
-
-
Field Detail
-
NONE
public static final URLFragment NONE
Represents a non-existent fragment, for whichexists()returnsfalse
-
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
-
-
Constructor Detail
-
URLFragment
private URLFragment(URLFragment.Parser parser)
-
-
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:
trueiff the URL from which this was parsed had a fragment.
-
isEmpty
public boolean isEmpty()
- Returns:
trueiff this fragment is the empty string or represents a non-existent fragment.
-
isValid
public boolean isValid()
- Returns:
trueiff this fragment is valid according to its target MIME type.
-
isMediaFragment
public boolean isMediaFragment()
- Returns:
trueiff this fragment is a media fragment.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.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, returnsNONEHTML 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 URLmimetype- 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), seeparse(URL, String).- Parameters:
url- a URL- Returns:
- a parsed fragment (cannot be
null)
-
-