Class CSSParser
- Direct Known Subclasses:
CSSOMParser
Additionally to NSAC, it includes several other methods.
By default, the methods that take a Reader
or an InputSource
as argument can process streams up to 0x6000000
(100MB) in size, and
throw a SecurityException
if they hit that limit. See also
setStreamSizeLimit(int)
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Small extension toCSSHandler
to deal with declaration rules.Nested classes/interfaces inherited from interface io.sf.carte.doc.style.css.nsac.Parser
Parser.Flag, Parser.NamespaceMap
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
protected MediaQueryFactory
void
parseDeclarationRule
(Reader reader) void
parseFontFeatureValuesBody
(String blockList) void
parseKeyFramesBody
(String blockList) void
parseMediaQueryList
(String media, MediaQueryFactory queryFactory, MediaQueryHandler mqhandler) Parse a media query string into the given handler.parseMediaQueryList
(String media, Node owner) Parse a media query string.void
parsePageRuleBody
(String blockList) parsePageSelectorList
(String pageSelectorStr) boolean
parsePriority
(Reader reader) Parse a CSS priority value (e.g. "!parsePropertyValue
(InputSource source) parsePropertyValue
(Reader reader) Parse a CSS property value.parsePropertyValue
(String propertyName, Reader reader) parsePseudoElement
(String pseudoElement) void
parseRule
(InputSource source) void
Parse a namespaceless CSS rule.void
parseRule
(Reader reader, Parser.NamespaceMap nsmap) Parse a CSS rule.parseSelectors
(InputSource source) parseSelectors
(Reader reader) Parse a comma separated list of selectors.parseSelectors
(String seltext) parseSelectors
(String selectorText, Parser.NamespaceMap nsmap) Parse a comma separated list of selectors.void
parseStyleDeclaration
(InputSource source) 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.parseSupportsCondition
(String conditionText, CSSRule rule) Parse the condition text of a@supports
rule.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
setStreamSizeLimit
(int streamSizeLimit) Set a new limit for the stream size that can be processed.void
unsetFlag
(Parser.Flag flag) Unset a parser flag.
-
Constructor Details
-
CSSParser
public CSSParser()Instantiate a parser instance with no flags. -
CSSParser
-
-
Method Details
-
setDocumentHandler
Description copied from interface:Parser
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.
- Specified by:
setDocumentHandler
in interfaceParser
- Parameters:
handler
- The document handler.- See Also:
-
setErrorHandler
Description copied from interface:Parser
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.
- Specified by:
setErrorHandler
in interfaceParser
- Parameters:
handler
- The error handler.- See Also:
-
setFlag
Set a parser flag.Currently only
STARHACK
is supported, and it only applies to the parsing of full sheets. -
unsetFlag
Unset a parser flag. -
setStreamSizeLimit
public void setStreamSizeLimit(int streamSizeLimit) Set a new limit for the stream size that can be processed.Calling this method does not affect the parsing that was already ongoing.
- Parameters:
streamSizeLimit
- the new limit to be enforced by new processing by this parser.- Throws:
IllegalArgumentException
- if a limit below 64K was used.
-
parseStyleSheet
public void parseStyleSheet(Reader reader) throws CSSParseException, IOException, IllegalStateException Description copied from interface:Parser
Parse a CSS style sheet.- Specified by:
parseStyleSheet
in interfaceParser
- 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
public void parseStyleSheet(String uri) throws CSSParseException, IOException, IllegalStateException 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.The timeout to establish a connection is of 30 seconds.
Usage of this method may have security implications. Please make sure that the URI being passed is safe to use.
- Specified by:
parseStyleSheet
in interfaceParser
- 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:
-
parseStyleSheet
public void parseStyleSheet(InputSource source) throws CSSParseException, IOException, IllegalStateException, IllegalArgumentException Description copied from interface:Parser
Parse a CSS style sheet.- Specified by:
parseStyleSheet
in interfaceParser
- 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:
-
parseStyleDeclaration
public void parseStyleDeclaration(Reader reader) throws CSSParseException, IOException, IllegalStateException Description copied from interface:Parser
Parse a CSS style declaration (without '{' and '}').- Specified by:
parseStyleDeclaration
in interfaceParser
- 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.
-
parseStyleDeclaration
public void parseStyleDeclaration(InputSource source) throws CSSException, IOException, IllegalStateException -
parseDeclarationRule
- Throws:
CSSParseException
IOException
-
parsePageSelectorList
- Throws:
DOMException
-
parseRule
Description copied from interface:Parser
Parse a namespaceless CSS rule.- Specified by:
parseRule
in interfaceParser
- 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
public void parseRule(Reader reader, Parser.NamespaceMap nsmap) throws CSSParseException, IOException, IllegalStateException Description copied from interface:Parser
Parse a CSS rule.- Specified by:
parseRule
in interfaceParser
- 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.
-
parseRule
- Throws:
CSSParseException
IOException
-
parsePageRuleBody
- Throws:
CSSParseException
-
parseKeyFramesBody
- Throws:
CSSParseException
-
parseFontFeatureValuesBody
- Throws:
CSSParseException
-
parseSupportsCondition
public BooleanCondition parseSupportsCondition(String conditionText, CSSRule rule) throws CSSParseException, CSSBudgetException Parse the condition text of a@supports
rule.- Parameters:
conditionText
- the condition text.rule
- the rule that would process the error. ifnull
, a problem while parsing shall result in an exception. Note thatNOT_SUPPORTED_ERR
exceptions are always thrown instead of being processed by the rule.- Returns:
- the
@supports
condition, ornull
if a rule was specified to handle the errors, and an error was produced. - Throws:
CSSParseException
- if there is a syntax problem and there is no error handler.CSSBudgetException
- if a hard-coded limit in nested expressions was reached.
-
parseMediaQueryList
public void parseMediaQueryList(String media, MediaQueryFactory queryFactory, MediaQueryHandler mqhandler) throws CSSBudgetException Parse a media query string into the given handler.- Specified by:
parseMediaQueryList
in interfaceParser
- 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.
-
parseMediaQueryList
Parse a media query string.- Specified by:
parseMediaQueryList
in interfaceParser
- Parameters:
media
- the media query text.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.
-
getMediaQueryFactory
-
parseSelectors
public SelectorList parseSelectors(Reader reader) throws CSSParseException, CSSBudgetException, IOException Description copied from interface:Parser
Parse a comma separated list of selectors.- Specified by:
parseSelectors
in interfaceParser
- 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.CSSBudgetException
-
parseSelectors
public SelectorList parseSelectors(String selectorText, Parser.NamespaceMap nsmap) throws CSSParseException Description copied from interface:Parser
Parse a comma separated list of selectors.- Specified by:
parseSelectors
in interfaceParser
- 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.
-
parseSelectors
- Throws:
CSSParseException
IOException
-
parseSelectors
- Throws:
CSSException
-
parsePseudoElement
- Throws:
CSSException
-
parsePropertyValue
Description copied from interface:Parser
Parse a CSS property value.- Specified by:
parsePropertyValue
in interfaceParser
- 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.
-
parsePropertyValue
public LexicalUnit parsePropertyValue(String propertyName, Reader reader) throws CSSParseException, IOException - Throws:
CSSParseException
IOException
-
parsePropertyValue
- Throws:
CSSParseException
IOException
-
parsePriority
Description copied from interface:Parser
Parse a CSS priority value (e.g. "!important").- Specified by:
parsePriority
in interfaceParser
- 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.
-
clone
-