- All Known Implementing Classes:
CSSOMParser
,CSSParser
Based on SAC's Parser
interface by Philippe Le Hegaret.
Compared to SAC, this interface replaces some of the methods that use an
InputSource
with a Reader
. The reason is that, in opinion of
the NSAC author, the InputSource
(a concept coming from SAX) adds
bloat and in the worst case may widen the attack surface if the application
using the library is somehow abused. It is generally better that the main
application takes the responsibility of opening connections to files or
remote sources.
The reference implementation includes the replaced InputSource
methods, in case you want to use them.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
NSAC parser flags: theParser.Flag.STARHACK
,Parser.Flag.IEVALUES
,Parser.Flag.IEPRIO
andParser.Flag.IEPRIOCHAR
flags are supported.static interface
Interface giving access to namespace URI from the prefix. -
Method Summary
Modifier and TypeMethodDescriptionvoid
parseMediaQueryList
(String media, MediaQueryFactory queryFactory, MediaQueryHandler mqhandler) Parse a media query string into the given handler.parseMediaQueryList
(String media, Node owner) Parse an individual list of media queries.boolean
parsePriority
(Reader reader) Parse a CSS priority value (e.g. "!parsePropertyValue
(Reader reader) Parse a CSS property value.parsePseudoElement
(String pseudoElement) Parse a pseudo-element.void
Parse a namespaceless CSS rule.void
parseRule
(Reader reader, Parser.NamespaceMap nsmap) Parse a CSS rule.parseSelectors
(Reader reader) Parse a comma separated list of selectors.parseSelectors
(String selectorText, Parser.NamespaceMap nsmap) Parse a comma separated list of selectors.void
parseStyleDeclaration
(Reader reader) Parse a CSS style declaration (without '{' and '}').void
parseStyleSheet
(InputSource source) Parse a CSS style sheet.void
parseStyleSheet
(Reader reader) Parse a CSS style sheet.void
parseStyleSheet
(String uri) Parse a CSS sheet from a URI.void
setDocumentHandler
(CSSHandler handler) Allow an application to set a document event handler.void
setErrorHandler
(CSSErrorHandler handler) Allow an application to set an error event handler.void
setFlag
(Parser.Flag flag) Set a parser flag.void
unsetFlag
(Parser.Flag flag) Unset a parser flag.
-
Method Details
-
setFlag
Set a parser flag.- Parameters:
flag
- the flag.
-
unsetFlag
Unset a parser flag.- Parameters:
flag
- the flag.
-
setDocumentHandler
Allow an application to set a document event handler.Applications may register a new or different handler in the middle of a parse, and the CSS parser must begin using the new handler immediately.
- Parameters:
handler
- The document handler.- See Also:
-
setErrorHandler
Allow an application to set an error event handler.If the application does not register an error event handler, any error will result in a CSSParseException being thrown.
Applications may register a new or different handler in the middle of a parse, and the CSS parser must begin using the new handler immediately.
- Parameters:
handler
- The error handler.- See Also:
-
parseStyleSheet
void parseStyleSheet(InputSource source) throws CSSParseException, IOException, IllegalStateException, IllegalArgumentException Parse a CSS style sheet.Note: in addition to the listed exceptions, this method may raise runtime exceptions produced by the
CSSHandler
.- Parameters:
source
- the input source of the CSS sheet.- Throws:
CSSParseException
- if an error was found and no error handler was set.IOException
- if a I/O error was found while retrieving the sheet.IllegalStateException
- if theCSSHandler
is not set.IllegalArgumentException
- if no stream could be obtained from thesource
.- See Also:
-
parseStyleSheet
Parse a CSS style sheet.Note: in addition to the listed exceptions, this method may raise runtime exceptions produced by the
CSSHandler
.- Parameters:
reader
- the character stream containing the CSS sheet.- Throws:
CSSParseException
- if an error was found and no error handler was set.IOException
- if a I/O error was found while retrieving the sheet.IllegalStateException
- if theCSSHandler
is not set.- See Also:
-
parseStyleSheet
Parse a CSS sheet from a URI.The sheet is parsed as a rule list, that is, XML's
CDO
-CDC
comments are not expected.Usage of this method may have security implications. Please make sure that the URI being passed is safe to use.
Note: in addition to the listed exceptions, this method may raise runtime exceptions produced by the
CSSHandler
.- Parameters:
uri
- The URI locating the sheet.- Throws:
CSSParseException
- if an error was found and no error handler was set.IOException
- ifuri
is an invalid URL or a I/O error was found while retrieving the sheet.IllegalStateException
- if theCSSHandler
is not set.- See Also:
-
parseSelectors
Parse a comma separated list of selectors.- Parameters:
reader
- the character stream containing the selector list.- Returns:
- the selector list.
- Throws:
CSSParseException
- if an error was found and no error handler was set.IOException
- if a I/O error was found while retrieving the list.
-
parseSelectors
SelectorList parseSelectors(String selectorText, Parser.NamespaceMap nsmap) throws CSSParseException Parse a comma separated list of selectors.- Parameters:
selectorText
- theString
containing the selector list.nsmap
- the namespace map to apply to the selector list, if it contains namespace prefixes.- Returns:
- the selector list.
- Throws:
CSSParseException
- if an error was found and no error handler was set.
-
parseStyleDeclaration
void parseStyleDeclaration(Reader reader) throws CSSParseException, IOException, IllegalStateException Parse a CSS style declaration (without '{' and '}').- Parameters:
reader
- the character stream containing the CSS style declaration.- Throws:
CSSParseException
- if an error was found and no error handler was set.IOException
- if a I/O error was found while retrieving the declaration.IllegalStateException
- if theCSSHandler
is not set.
-
parsePropertyValue
Parse a CSS property value.- Parameters:
reader
- the character stream containing the CSS property value.- Returns:
- the lexical unit containing the value, possibly chained to subsequent lexical units.
- Throws:
CSSParseException
- if an error was found and no error handler was set.IOException
- if a I/O error was found while retrieving the value.NullPointerException
- ifreader
isnull
.
-
parsePriority
Parse a CSS priority value (e.g. "!important").- Parameters:
reader
- the character stream containing the CSS priority.- Returns:
true
if the priority is important.- Throws:
IOException
- if a I/O error was found while retrieving the priority.NullPointerException
- ifreader
isnull
.
-
parseRule
Parse a namespaceless CSS rule.Note: in addition to the listed exceptions, this method may raise runtime exceptions produced by the
CSSHandler
.- Parameters:
reader
- the character stream containing the CSS rule.- Throws:
CSSParseException
- if an error was found and no error handler was set.IOException
- if a I/O error was found while retrieving the rule.IllegalStateException
- if theCSSHandler
is not set.
-
parseRule
void parseRule(Reader reader, Parser.NamespaceMap nsmap) throws CSSParseException, IOException, IllegalStateException Parse a CSS rule.Note: in addition to the listed exceptions, this method may raise runtime exceptions produced by the
CSSHandler
.- Parameters:
reader
- the character stream containing the CSS rule.nsmap
- the namespace map.- Throws:
CSSParseException
- if an error was found and no error handler was set.IOException
- if a I/O error was found while retrieving the rule.IllegalStateException
- if theCSSHandler
is not set.
-
parseMediaQueryList
Parse an individual list of media queries.- Parameters:
media
- the string representation of the list of media queries.owner
- the node that owns the responsibility to handle the errors in the query list.- Returns:
- the media query list.
- Throws:
CSSBudgetException
- if a hard-coded limit in nested expressions was reached.
-
parseMediaQueryList
void parseMediaQueryList(String media, MediaQueryFactory queryFactory, MediaQueryHandler mqhandler) throws CSSBudgetException Parse a media query string into the given handler.- Parameters:
media
- the media query text.queryFactory
- the query factory.mqhandler
- the media query list handler.- Throws:
CSSBudgetException
- if a hard-coded limit in nested expressions was reached.
-
parsePseudoElement
Parse a pseudo-element.- Parameters:
pseudoElement
- the string representation of a pseudo-element.- Returns:
- the pseudo-element condition.
- Throws:
CSSException
- if the argument is not a parsable pseudo-element.
-