public StylesheetFactoryImpl(UserAgentCallback userAgentCallback) { _userAgentCallback = userAgentCallback; _cssParser = new CSSParser(new CSSErrorHandler() { public void error(String uri, String message) { XRLog.cssParse(Level.WARNING, "(" + uri + ") " + message); } }); }
private void pseudo(Selector selector) throws IOException { //System.out.println("pseudo()"); Token t = next(); if (t == Token.TK_COLON) { t = next(); switch (t.getType()) { case Token.COLON: t = next(); addPseudoElement(t, selector); break; case Token.IDENT: addPseudoClassOrElement(t, selector); break; case Token.FUNCTION: addPseudoClassOrElementFunction(t, selector); break; default: push(t); throw new CSSParseException(t, new Token[] { Token.TK_IDENT, Token.TK_FUNCTION }, getCurrentLine()); } } else { push(t); throw new CSSParseException(t, Token.TK_COLON, getCurrentLine()); } }
private int convertToInteger(char hexchar1, char hexchar2) { int result = convertToInteger(hexchar1); result <<= 4; result |= convertToInteger(hexchar2); return result; }
Token t = la(); if (t == Token.TK_IDENT) { String propertyName = property(); CSSName cssName = CSSName.getByPropertyName(propertyName); boolean valid = checkCSSName(cssName, propertyName); t = next(); if (t == Token.TK_COLON) { skip_whitespace(); List values = expr( cssName == CSSName.FONT_FAMILY || cssName == CSSName.FONT_SHORTHAND || t = la(); if (t == Token.TK_IMPORTANT_SYM) { prio(); important = true; t = la(); if (! (t == Token.TK_SEMICOLON || t == Token.TK_RBRACE || t == Token.TK_EOF)) { throw new CSSParseException( t, new Token[] { Token.TK_SEMICOLON, Token.TK_RBRACE }, getCurrentLine()); cssName, values, ruleset.getOrigin(), important, !inFontFace)); } catch (CSSParseException e) {
private PropertyValue function() throws IOException { Token t = next(); if (t == Token.TK_FUNCTION) { String f = getTokenValue(t); skip_whitespace(); List params = expr(false); t = next(); if (t != Token.TK_RPAREN) { push(t); throw new CSSParseException(t, Token.TK_RPAREN, getCurrentLine()); result = new PropertyValue(createRGBColorFromFunction(params)); } else if (f.equals("cmyk(")) { if (! isSupportCMYKColors()) { throw new CSSParseException( "The current output device does not support CMYK colors", getCurrentLine()); result = new PropertyValue(createCMYKColorFromFunction(params)); } else { result = new PropertyValue(new FSFunction(f.substring(0, f.length()-1), params)); skip_whitespace(); } else { push(t); throw new CSSParseException(t, Token.TK_FUNCTION, getCurrentLine());
Token t = la(); switch (t.getType()) { case Token.ASTERISK: case Token.IDENT: case Token.VERTICAL_BAR: NamespacePair pair = typed_value(false); selector.setNamespaceURI(pair.getNamespaceURI()); selector.setName(pair.getName()); t = la(); switch (t.getType()) { case Token.HASH: t = next(); selector.addIDCondition(getTokenValue(t, true)); break; case Token.PERIOD: class_selector(selector); break; case Token.LBRACKET: attrib(selector); break; case Token.COLON: pseudo(selector); break; default: boolean found = false; LOOP: while (true) { t = la();
private PropertyValue hexcolor() throws IOException { //System.out.println("hexcolor()"); PropertyValue result = null; Token t = next(); if (t == Token.TK_HASH) { String s = getTokenValue(t); if ((s.length() != 3 && s.length() != 6) || ! isHexString(s)) { push(t); throw new CSSParseException('#' + s + " is not a valid color definition", getCurrentLine()); } FSRGBColor color = null; if (s.length() == 3) { color = new FSRGBColor( convertToInteger(s.charAt(0), s.charAt(0)), convertToInteger(s.charAt(1), s.charAt(1)), convertToInteger(s.charAt(2), s.charAt(2))); } else { /* s.length == 6 */ color = new FSRGBColor( convertToInteger(s.charAt(0), s.charAt(1)), convertToInteger(s.charAt(2), s.charAt(3)), convertToInteger(s.charAt(4), s.charAt(5))); } result = new PropertyValue(color); skip_whitespace(); } else { push(t); throw new CSSParseException(t, Token.TK_HASH, getCurrentLine()); } return result; }
selectors.add(simple_selector(ruleset)); LOOP: while (true) { Token t = la(); switch (t.getType()) { case Token.PLUS: case Token.GREATER: case Token.S: combinators.add(combinator()); t = la(); switch (t.getType()) { case Token.IDENT: case Token.LBRACKET: case Token.COLON: selectors.add(simple_selector(ruleset)); break; default: throw new CSSParseException(t, new Token[] { Token.TK_IDENT, Token.TK_ASTERISK, Token.TK_HASH, Token.TK_PERIOD, Token.TK_LBRACKET, Token.TK_COLON }, getCurrentLine()); ruleset.addFSSelector(mergeSimpleSelectors(selectors, combinators));
for (int i = 0; i < 40; i++) { long start = System.currentTimeMillis(); CSSParser p = new CSSParser(errorHandler); p.parseStylesheet(null, 0, new StringReader(longTest.toString())); long end = System.currentTimeMillis(); for (int i = 0; i < 10; i++) { long start = System.currentTimeMillis(); CSSParser p = new CSSParser(errorHandler); p.parseStylesheet(null, 0, new StringReader(longTest.toString())); long end = System.currentTimeMillis(); CSSParser p = new CSSParser(errorHandler); long start = System.currentTimeMillis(); for (int j = 0; j < 10000; j++) { p.parseStylesheet(null, 0, new StringReader(test));
var parser = new CSSParser(); var serialized = parser.parse(cssString, false, true);
parser = new CSSParser(); sheet = parser.parse(ss, false, true);