private static CommonTree feedParser(CommonTokenStream source, SourceType type, StyleSheet stylesheet) throws CSSException { CSSParser parser = new CSSParser(source); parser.init(stylesheet); return type.getAST(parser); }
private static CSSTreeParser createParser(Object source, String encoding, SourceType type, Preparator preparator, StyleSheet stylesheet, URL base) throws IOException, CSSException { CSSInputStream input = type.getInput(source, encoding); input.setBase(base); CommonTokenStream tokens = feedLexer(input, stylesheet); CommonTree ast = feedParser(tokens, type, stylesheet); return feedAST(tokens, ast, preparator, stylesheet); }
StyleSheet ret = type.parse(parser); lastPriority = ret.getLastMark(); return ret;
/** * Parses source of given type * * @param source * Source, interpretation depends on {@code type} * @param type * Type of source provided * @param inline * InlineElement * @param inlinePriority * True when the rule should have an 'inline' (greater) priority * @return Created StyleSheet * @throws IOException * When problem with input stream occurs * @throws CSSException * When unrecoverable exception during parsing occurs */ public static StyleSheet parse(Object source, String encoding, SourceType type, Element inline, boolean inlinePriority, URL base) throws IOException, CSSException { StyleSheet sheet = (StyleSheet) CSSFactory.getRuleFactory() .createStyleSheet().unlock(); PriorityStrategy ps = new AtomicPriorityStrategy(lastPriority); Preparator preparator = new SimplePreparator(ps, inline, inlinePriority); CSSTreeParser parser = createParser(source, encoding, type, preparator, sheet, base); StyleSheet ret = type.parse(parser); lastPriority = ret.getLastMark(); return ret; }