Class AbstractCSSParser
- Direct Known Subclasses:
CSS3Parser
- Author:
- Ronald Brill
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
addEscapes
(String str) Escapes some chars in the given string.protected Locator
Returns a new locator for the given token.protected CSSParseException
createSkipWarning
(String messageKey, CSSParseException e) protected double
doubleValue
(char op, String s) Parses the sting into an double.protected abstract LexicalUnit
expr()
Process an expression.protected LexicalUnit
functionInternal
(LexicalUnit prev, String funct, LexicalUnit params) Process a function decl.protected DocumentHandler
getDocumentHandler.protected CSSErrorHandler
getErrorHandler.protected InputSource
getInputSource.protected int
Returns the pos of the last numeric char in the given string.protected String
getParserMessage
(String key) abstract String
protected void
handleCharset
(String characterEncoding, Locator locator) charset handler.protected void
end document handler.protected void
end font face handler.protected void
handleEndMedia
(MediaQueryList media) end media handler.protected void
handleEndPage
(String name, String pseudoPage) end page handler.protected void
handleEndSelector
(SelectorList selectors) selector end handler.protected void
handleIgnorableAtRule
(String s, Locator locator) ignorable at rule handler.protected void
handleImportStyle
(String uri, MediaQueryList media, String defaultNamespaceURI, Locator locator) import style handler.protected void
handleProperty
(String name, LexicalUnit value, boolean important, Locator locator) property handler.protected void
start document handler.protected void
handleStartFontFace
(Locator locator) start font face handler.protected void
handleStartMedia
(MediaQueryList media, Locator locator) start media handler.protected void
handleStartPage
(String name, String pseudoPage, Locator locator) start page handler.protected void
handleStartSelector
(SelectorList selectors, Locator locator) selector start handler.protected LexicalUnit
hexColorInternal
(LexicalUnit prev, Token t) Processes a hexadecimal color definition.protected LexicalUnit
hslColorInternal
(LexicalUnit prev, String funct, LexicalUnit param) protected LexicalUnit
hwbColorInternal
(LexicalUnit prev, String funct, LexicalUnit param) protected int
Parses the sting into an integer.protected LexicalUnit
labColorInternal
(LexicalUnit prev, String funct, LexicalUnit param) protected LexicalUnit
lchColorInternal
(LexicalUnit prev, String funct, LexicalUnit param) protected abstract void
Process a media list.protected String
parseMedia
(InputSource source) Parse the given input source and return the media list.boolean
parsePriority
(InputSource source) Parse a CSS priority value (e.g. "!parsePropertyValue
(InputSource source) Parse a CSS property value.void
parseRule
(InputSource source) Parse a CSS rule.parseSelectors
(InputSource source) Parse a comma separated list of selectors.protected abstract SelectorList
Process a selector list.void
parseStyleDeclaration
(InputSource source) Parse a CSS style declaration (without '{' and '}').void
parseStyleSheet
(InputSource source) Parse a CSS document.protected abstract boolean
prio()
Process a prio.protected abstract void
ReInit
(CharStream charStream) Re intit the stream.protected LexicalUnit
rgbColorInternal
(LexicalUnit prev, String funct, LexicalUnit param) void
setDocumentHandler
(DocumentHandler handler) Allow an application to register a document event handler.void
setErrorHandler
(CSSErrorHandler handler) Allow an application to register an error event handler.protected abstract void
Process a style sheet declaration.protected abstract void
Process a style sheet.protected abstract void
Process a style sheet rule.protected CSSParseException
toCSSParseException
(String messageKey, Object[] msgParams, Locator locator) protected CSSParseException
toCSSParseException
(String key, ParseException e) toCSSParseException.protected CSSParseException
toCSSParseException.protected CSSParseException
toCSSParseException.Unescapes escaped characters in the specified string, according to the CSS specification.
-
Constructor Details
-
AbstractCSSParser
public AbstractCSSParser()
-
-
Method Details
-
getDocumentHandler
getDocumentHandler.
- Returns:
- the document handler
-
setDocumentHandler
Allow an application to register a document event handler.If the application does not register a document handler, all document events reported by the CSS parser will be silently ignored (this is the default behaviour implemented by HandlerBase).
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:
-
getErrorHandler
getErrorHandler.
- Returns:
- the error handler
-
setErrorHandler
Allow an application to register an error event handler.If the application does not register an error event handler, all error events reported by the CSS parser will be silently ignored, except for fatalError, which will throw a CSSException (this is the default behaviour implemented by HandlerBase).
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:
-
getInputSource
getInputSource.
- Returns:
- the input source
-
getParserMessage
- Parameters:
key
- the lookup key- Returns:
- the parser message
-
createLocator
Returns a new locator for the given token.- Parameters:
t
- the token to generate the locator for- Returns:
- a new locator
-
addEscapes
Escapes some chars in the given string.- Parameters:
str
- the input- Returns:
- a new string with the escaped values
-
toCSSParseException
toCSSParseException.
- Parameters:
key
- the message lookup keye
- the parse exception- Returns:
- a new CSSParseException
-
toCSSParseException
toCSSParseException.
- Parameters:
e
- the DOMException- Returns:
- a new CSSParseException
-
toCSSParseException
toCSSParseException.
- Parameters:
e
- the TokenMgrException- Returns:
- a new CSSParseException
-
toCSSParseException
protected CSSParseException toCSSParseException(String messageKey, Object[] msgParams, Locator locator) - Parameters:
messageKey
- the message keymsgParams
- the paramslocator
- the locator- Returns:
- a new CSSParseException
-
createSkipWarning
- Parameters:
messageKey
- the message keye
- a CSSParseException- Returns:
- a new CSSParseException
-
parseStyleSheet
Parse a CSS document.The application can use this method to instruct the CSS parser to begin parsing an CSS document from any valid input source (a character stream, a byte stream, or a URI).
Applications may not invoke this method while a parse is in progress (they should create a new Parser instead for each additional CSS document). Once a parse is complete, an application may reuse the same Parser object, possibly with a different input source.
- Parameters:
source
- The input source for the top-level of the CSS document.- Throws:
CSSException
- Any CSS exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.- See Also:
-
parseStyleDeclaration
Parse a CSS style declaration (without '{' and '}').- Parameters:
source
- source to be parsed- Throws:
CSSException
- Any CSS exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parseRule
Parse a CSS rule.- Parameters:
source
- source to be parsed- Throws:
CSSException
- Any CSS exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parseSelectors
Parse a comma separated list of selectors.- Parameters:
source
- source to be parsed- Returns:
- a selector list
- Throws:
CSSException
- Any CSS exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parsePropertyValue
Parse a CSS property value.- Parameters:
source
- source to be parsed- Returns:
- a lexical unit
- Throws:
CSSException
- Any CSS exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parsePriority
Parse a CSS priority value (e.g. "!important").- Parameters:
source
- source to be parsed- Returns:
- true or flase
- Throws:
CSSException
- Any CSS exception, possibly wrapping another exception.IOException
- An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
-
parseMedia
Parse the given input source and return the media list.- Parameters:
source
- the input source- Returns:
- new media list
- Throws:
IOException
- in case of errors
-
getParserVersion
- Returns:
- a string about which CSS language is supported by this parser. For CSS Level 1, it returns "http://www.w3.org/TR/REC-CSS1", for CSS Level 2, it returns "http://www.w3.org/TR/REC-CSS2". Note that a "CSSx" parser can return lexical unit other than those allowed by CSS Level x but this usage is not recommended.
-
ReInit
Re intit the stream.- Parameters:
charStream
- the stream
-
styleSheet
Process a style sheet.- Throws:
CSSParseException
- in case of errorParseException
- in case of error
-
styleDeclaration
Process a style sheet declaration.- Throws:
ParseException
- in case of error
-
styleSheetRuleSingle
Process a style sheet rule.- Throws:
ParseException
- in case of error
-
parseSelectorsInternal
Process a selector list.- Returns:
- the selector list
- Throws:
ParseException
- in case of error
-
expr
Process an expression.- Returns:
- the lexical unit
- Throws:
ParseException
- in case of error
-
prio
Process a prio.- Returns:
- true or false
- Throws:
ParseException
- in case of error
-
mediaList
Process a media list.- Parameters:
ml
- the media list- Throws:
ParseException
- in case of error
-
handleStartDocument
protected void handleStartDocument()start document handler. -
handleEndDocument
protected void handleEndDocument()end document handler. -
handleIgnorableAtRule
ignorable at rule handler.- Parameters:
s
- the rulelocator
- the locator
-
handleCharset
charset handler.- Parameters:
characterEncoding
- the encodinglocator
- the locator
-
handleImportStyle
protected void handleImportStyle(String uri, MediaQueryList media, String defaultNamespaceURI, Locator locator) import style handler.- Parameters:
uri
- the urimedia
- the media query listdefaultNamespaceURI
- the namespace urilocator
- the locator
-
handleStartMedia
start media handler.- Parameters:
media
- the media query listlocator
- the locator
-
handleEndMedia
end media handler.- Parameters:
media
- the media query list
-
handleStartPage
start page handler.- Parameters:
name
- the namepseudoPage
- the pseudo pagelocator
- the locator
-
handleEndPage
end page handler.- Parameters:
name
- the namepseudoPage
- the pseudo page
-
handleStartFontFace
start font face handler.- Parameters:
locator
- the locator
-
handleEndFontFace
protected void handleEndFontFace()end font face handler. -
handleStartSelector
selector start handler.- Parameters:
selectors
- the selector listlocator
- the locator
-
handleEndSelector
selector end handler.- Parameters:
selectors
- the selector list
-
handleProperty
property handler.- Parameters:
name
- the namevalue
- the valueimportant
- important flaglocator
- the locator
-
functionInternal
Process a function decl.- Parameters:
prev
- the previous lexical unitfunct
- the functionparams
- the params- Returns:
- a lexical unit
-
rgbColorInternal
-
hslColorInternal
-
hwbColorInternal
-
labColorInternal
-
lchColorInternal
-
hexColorInternal
Processes a hexadecimal color definition.- Parameters:
prev
- the previous lexical unitt
- the token- Returns:
- a new lexical unit
-
intValue
Parses the sting into an integer.- Parameters:
op
- the sign chars
- the string to parse- Returns:
- the int value
-
doubleValue
Parses the sting into an double.- Parameters:
op
- the sign chars
- the string to parse- Returns:
- the double value
-
getLastNumPos
Returns the pos of the last numeric char in the given string.- Parameters:
s
- the string to parse- Returns:
- the pos
-
unescape
Unescapes escaped characters in the specified string, according to the CSS specification. This could be done directly in the parser, but portions of the lexer would have to be moved to the parser, meaning that the grammar would no longer match the standard grammar specified by the W3C. This would make the parser and lexer much less maintainable.- Parameters:
s
- the string to unescapeunescapeDoubleQuotes
- if true unescape double quotes also- Returns:
- the unescaped string
-
normalizeAndValidatePagePseudoClass
-