Package dev.amp.validator.css
Class Canonicalizer
- java.lang.Object
-
- dev.amp.validator.css.Canonicalizer
-
public class Canonicalizer extends Object
Process and validate a css document.- Author:
- nhant01, GeorgeLuo
-
-
Constructor Summary
Constructors Constructor Description Canonicalizer(Map<String,CssSpecUtils.BlockType> atRuleSpec, CssSpecUtils.BlockType defaultSpec)Constructor for canonicalizer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleanconsumeAComponentValue(TokenStream tokenStream, List<com.steadystate.css.parser.Token> tokenList, int depth)Consumes one or more tokens from a tokenStream, appending them to a tokenList.static booleanconsumeAFunction(TokenStream tokenStream, List<com.steadystate.css.parser.Token> tokenList, int depth)Appends a function's contents to a tokenList, consuming from the stream all those tokens that it adds to the tokenList, including the function token and end grouping token.voidparseADeclaration(TokenStream tokenStream, List<Declaration> declarations, List<ErrorToken> errors)Adds one element to either declarations or errors.List<Declaration>parseAListOfDeclarations(List<com.steadystate.css.parser.Token> tokenList, List<ErrorToken> errors)returns a list of Declarations from css contentList<Rule>parseAListOfRules(List<com.steadystate.css.parser.Token> tokenList, boolean topLevel, List<ErrorToken> errors)Parses and returns a list of rules, such as at the top level of a stylesheet.
-
-
-
Constructor Detail
-
Canonicalizer
public Canonicalizer(@Nonnull Map<String,CssSpecUtils.BlockType> atRuleSpec, @Nonnull CssSpecUtils.BlockType defaultSpec)Constructor for canonicalizer.- Parameters:
atRuleSpec- the AtRule Spec to validate againstdefaultSpec- the block type to process as
-
-
Method Detail
-
parseAListOfRules
public List<Rule> parseAListOfRules(@Nonnull List<com.steadystate.css.parser.Token> tokenList, boolean topLevel, @Nonnull List<ErrorToken> errors) throws CssValidationException
Parses and returns a list of rules, such as at the top level of a stylesheet. Return list has only QualifiedRule's and AtRule's as top level elements.- Parameters:
tokenList- the css contenttopLevel- the relative top level to parse fromerrors- output array for the errors.- Returns:
- list of rules
- Throws:
CssValidationException- Css Validation Exception
-
parseAListOfDeclarations
public List<Declaration> parseAListOfDeclarations(@Nonnull List<com.steadystate.css.parser.Token> tokenList, @Nonnull List<ErrorToken> errors) throws CssValidationException
returns a list of Declarations from css content- Parameters:
tokenList- of tokens within a blockerrors- output array for the errors.- Returns:
- a list of Declarations
- Throws:
CssValidationException- Css Validation Exception
-
parseADeclaration
public void parseADeclaration(@Nonnull TokenStream tokenStream, @Nonnull List<Declaration> declarations, @Nonnull List<ErrorToken> errors) throws CssValidationExceptionAdds one element to either declarations or errors.- Parameters:
tokenStream- the css tokens to parsedeclarations- output array for declarationserrors- output array for the errors.- Throws:
CssValidationException- Css Validation Exception
-
consumeAComponentValue
public static boolean consumeAComponentValue(@Nonnull TokenStream tokenStream, @Nonnull List<com.steadystate.css.parser.Token> tokenList, int depth) throws CssValidationExceptionConsumes one or more tokens from a tokenStream, appending them to a tokenList. If exceeds depth, returns false- Parameters:
tokenStream- the stream of token contenttokenList- output array for tokens.depth- the depth to check against exceeding- Returns:
- true iff finished consuming without exceeding depth
- Throws:
CssValidationException- Css Validation Exception
-
consumeAFunction
public static boolean consumeAFunction(@Nonnull TokenStream tokenStream, @Nonnull List<com.steadystate.css.parser.Token> tokenList, int depth) throws CssValidationExceptionAppends a function's contents to a tokenList, consuming from the stream all those tokens that it adds to the tokenList, including the function token and end grouping token. If exceeds depth, returns false.- Parameters:
tokenStream- of html document blocktokenList- output array for tokens.depth- to check against exceeding- Returns:
- true iff depth not exceeded
- Throws:
CssValidationException- Css Validation Exception
-
-