Class Canonicalizer


  • public class Canonicalizer
    extends Object
    Process and validate a css document.
    Author:
    nhant01, GeorgeLuo
    • 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 against
        defaultSpec - 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 content
        topLevel - the relative top level to parse from
        errors - 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 block
        errors - 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 CssValidationException
        Adds one element to either declarations or errors.
        Parameters:
        tokenStream - the css tokens to parse
        declarations - output array for declarations
        errors - 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 CssValidationException
        Consumes one or more tokens from a tokenStream, appending them to a tokenList. If exceeds depth, returns false
        Parameters:
        tokenStream - the stream of token content
        tokenList - 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 CssValidationException
        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. If exceeds depth, returns false.
        Parameters:
        tokenStream - of html document block
        tokenList - output array for tokens.
        depth - to check against exceeding
        Returns:
        true iff depth not exceeded
        Throws:
        CssValidationException - Css Validation Exception