Package org.idpf.epubcheck.util.css
Class CssParser
- java.lang.Object
-
- org.idpf.epubcheck.util.css.CssParser
-
public final class CssParser extends java.lang.ObjectA CSS parser.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classCssParser.ContextRestrictions
-
Field Summary
Fields Modifier and Type Field Description private CssGrammar.CssSelectorConstructFactorycssSelectorFactoryprivate booleandebugprivate Messagesmessages
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidhandleAtRule(CssToken start, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err)With start token required to be an ATKEYWORD, collect at-rule parameters if any, and if the at-rule has a block, invoke those handlers.private CssGrammar.CssConstructhandleAtRuleParam(CssToken start, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err)With inparam token being the first token of an atrule param, create the construct and return it.private CssGrammar.CssDeclarationhandleDeclaration(CssToken name, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err, boolean isStyleAttribute)With start expected to be an IDENT token representing the property name, build the declaration and return after hitting ';' or '}'.private voidhandleDeclarationBlock(CssToken start, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err)With start token being the first non-ignorable token inside the declaration block, iterate issuing CssDeclaration objects until the block ends.private booleanhandlePropertyValue(CssGrammar.CssDeclaration declaration, CssToken start, CssTokenList.CssTokenIterator iter, boolean isStyleAttribute)Append property value components to declaration.value, return false if fail with iter.last at the the token which caused the fail.private voidhandleRuleSet(CssToken start, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err)With the start token expected to be the first token of a selector group, create and issue the group, then invoke handleDeclarationBlock.private booleanhasRuleSet(CssGrammar.CssAtRule atRule, CssTokenList.CssTokenIterator iter)With iter.last at '{', discover the at-rule type.voidparse(java.io.Reader reader, java.lang.String systemID, CssErrorHandler err, CssContentHandler doc)Parse a CSS document.voidparse(CssSource source, CssErrorHandler err, CssContentHandler doc)Parse a CSS document.voidparseStyleAttribute(java.io.Reader reader, java.lang.String systemID, CssErrorHandler err, CssContentHandler doc)Parse a CSS style attribute.private CssTokenList.CssTokenIteratorscan(java.io.Reader reader, java.lang.String systemID, CssErrorHandler err)
-
-
-
Field Detail
-
debug
private final boolean debug
- See Also:
- Constant Field Values
-
messages
private final Messages messages
-
cssSelectorFactory
private final CssGrammar.CssSelectorConstructFactory cssSelectorFactory
-
-
Constructor Detail
-
CssParser
public CssParser()
Builds a new CSS parser reporting errors in the default locale.The localized constructor
CssParser(Locale)should be preferred over this one, except for tests.
-
CssParser
public CssParser(java.util.Locale locale)
Builds a new CSS parser that will report parsing errors in the given locale.- Parameters:
locale- the locale used in the parsing errors.
-
-
Method Detail
-
parse
public void parse(CssSource source, CssErrorHandler err, CssContentHandler doc) throws java.io.IOException, CssExceptions.CssException
Parse a CSS document.- Throws:
java.io.IOExceptionCssExceptions.CssException
-
parse
public void parse(java.io.Reader reader, java.lang.String systemID, CssErrorHandler err, CssContentHandler doc) throws java.io.IOException, CssExceptions.CssExceptionParse a CSS document.- Throws:
java.io.IOExceptionCssExceptions.CssException
-
parseStyleAttribute
public void parseStyleAttribute(java.io.Reader reader, java.lang.String systemID, CssErrorHandler err, CssContentHandler doc) throws java.io.IOException, CssExceptions.CssExceptionParse a CSS style attribute.- Throws:
java.io.IOExceptionCssExceptions.CssException
-
scan
private CssTokenList.CssTokenIterator scan(java.io.Reader reader, java.lang.String systemID, CssErrorHandler err) throws java.io.IOException, CssExceptions.CssException
- Throws:
java.io.IOExceptionCssExceptions.CssException
-
handleRuleSet
private void handleRuleSet(CssToken start, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err) throws CssExceptions.CssException
With the start token expected to be the first token of a selector group, create and issue the group, then invoke handleDeclarationBlock. At exit the last token returned from the iterator is expected to be '}'.- Throws:
CssExceptions.CssException
-
handleDeclarationBlock
private void handleDeclarationBlock(CssToken start, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err) throws CssExceptions.CssException
With start token being the first non-ignorable token inside the declaration block, iterate issuing CssDeclaration objects until the block ends.- Throws:
CssExceptions.CssException
-
handleDeclaration
private CssGrammar.CssDeclaration handleDeclaration(CssToken name, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err, boolean isStyleAttribute) throws CssExceptions.CssException
With start expected to be an IDENT token representing the property name, build the declaration and return after hitting ';' or '}'. On error, issue to errhandler, return null, caller forwards.- Throws:
CssExceptions.CssException
-
handlePropertyValue
private boolean handlePropertyValue(CssGrammar.CssDeclaration declaration, CssToken start, CssTokenList.CssTokenIterator iter, boolean isStyleAttribute)
Append property value components to declaration.value, return false if fail with iter.last at the the token which caused the fail.
-
handleAtRule
private void handleAtRule(CssToken start, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err) throws CssExceptions.CssException
With start token required to be an ATKEYWORD, collect at-rule parameters if any, and if the at-rule has a block, invoke those handlers.- Throws:
CssExceptions.CssException
-
handleAtRuleParam
private CssGrammar.CssConstruct handleAtRuleParam(CssToken start, CssTokenList.CssTokenIterator iter, CssContentHandler doc, CssErrorHandler err)
With inparam token being the first token of an atrule param, create the construct and return it.- Returns:
- A CssConstruct, or null if fail.
-
hasRuleSet
private boolean hasRuleSet(CssGrammar.CssAtRule atRule, CssTokenList.CssTokenIterator iter)
With iter.last at '{', discover the at-rule type. The contents is a ruleset if '{' comes before ';' or '}'.
-
-