/** * Parses a style declaration using the current scanner. */ protected void parseStyleDeclarationInternal() throws CSSException, IOException { nextIgnoreSpaces(); try { parseStyleDeclaration(false); } catch (CSSParseException e) { reportError(e); } finally { scanner.close(); scanner = null; } }
/** * Converts the current lexical unit to a float. */ protected float number(boolean positive) { try { float sgn = (positive) ? 1 : -1; String val = scanner.getStringValue(); nextIgnoreSpaces(); return sgn * Float.parseFloat(val); } catch (NumberFormatException e) { throw createCSSParseException("number.format"); } }
/** * <b>SAC</b>: Implements * {@link org.w3c.css.sac.Parser#parsePropertyValue(InputSource)}. */ public LexicalUnit parsePropertyValue(InputSource source) throws CSSException, IOException { scanner = createScanner(source); return parsePropertyValueInternal(); }
/** * Reports a parsing error. */ protected void reportError(String key, Object[] params) { reportError(createCSSParseException(key, params)); }
/** * <b>SAC</b>: Implements {@link * org.w3c.css.sac.Parser#parseRule(InputSource)}. */ public void parseRule(InputSource source) throws CSSException, IOException { scanner = createScanner(source); parseRuleInternal(); }
scanner = createScanner(source); switch (current) { case LexicalUnits.CHARSET_SYMBOL: if (nextIgnoreSpaces() != LexicalUnits.STRING) { reportError("charset.string"); } else { if (nextIgnoreSpaces() != LexicalUnits.SEMI_COLON) { reportError("semicolon"); next(); skipSpacesAndCDOCDC(); for (;;) { if (current == LexicalUnits.IMPORT_SYMBOL) { nextIgnoreSpaces(); parseImportRule(); nextIgnoreSpaces(); } else { break; switch (current) { case LexicalUnits.PAGE_SYMBOL: nextIgnoreSpaces(); parsePageRule(); break; case LexicalUnits.MEDIA_SYMBOL: nextIgnoreSpaces(); parseMediaRule();
plus = false; case LexicalUnits.PLUS: next(); sgn = true; default: nextIgnoreSpaces(); return CSSLexicalUnit.createInteger( iVal, prev); number(plus), prev); case LexicalUnits.PERCENTAGE: return CSSLexicalUnit.createFloat(LexicalUnit.SAC_PERCENTAGE, number(plus), prev); case LexicalUnits.PT: return CSSLexicalUnit.createFloat(LexicalUnit.SAC_POINT, number(plus), prev); case LexicalUnits.PC: return CSSLexicalUnit.createFloat(LexicalUnit.SAC_PICA, number(plus), prev); case LexicalUnits.PX: return CSSLexicalUnit.createFloat(LexicalUnit.SAC_PIXEL, number(plus), prev); case LexicalUnits.CM: return CSSLexicalUnit.createFloat(LexicalUnit.SAC_CENTIMETER, number(plus), prev); case LexicalUnits.MM: return CSSLexicalUnit.createFloat(LexicalUnit.SAC_MILLIMETER, number(plus), prev); case LexicalUnits.IN:
case LexicalUnits.EOF: if (inSheet) { throw createCSSParseException("eof"); throw createCSSParseException("eof.expected"); nextIgnoreSpaces(); return; case LexicalUnits.SEMI_COLON: nextIgnoreSpaces(); continue; default: throw createCSSParseException("identifier"); case LexicalUnits.IDENTIFIER: if (nextIgnoreSpaces() != LexicalUnits.COLON) { throw createCSSParseException("colon"); nextIgnoreSpaces(); exp = parseExpression(false); } catch (CSSParseException e) { reportError(e); if (current == LexicalUnits.IMPORTANT_SYMBOL) { important = true; nextIgnoreSpaces();
result = selectorFactory.createElementSelector (null, scanner.getStringValue()); next(); break; case LexicalUnits.ANY: next(); default: result = selectorFactory.createElementSelector(null, null); c = conditionFactory.createIdCondition (scanner.getStringValue()); next(); break; case LexicalUnits.DOT: if (next() != LexicalUnits.IDENTIFIER) { throw createCSSParseException("identifier"); next(); break; case LexicalUnits.LEFT_BRACKET: if (nextIgnoreSpaces() != LexicalUnits.IDENTIFIER) { throw createCSSParseException("identifier"); int op = nextIgnoreSpaces(); switch (op) { default: throw createCSSParseException("right.bracket"); case LexicalUnits.RIGHT_BRACKET: next();
/** * Parses a ruleset. */ protected void parseRuleSet() { SelectorList sl = null; try { sl = parseSelectorList(); } catch (CSSParseException e) { reportError(e); return; } try { documentHandler.startSelector(sl); if (current != LexicalUnits.LEFT_CURLY_BRACE) { reportError("left.curly.brace"); if (current == LexicalUnits.RIGHT_CURLY_BRACE) { nextIgnoreSpaces(); } } else { nextIgnoreSpaces(); try { parseStyleDeclaration(true); } catch (CSSParseException e) { reportError(e); } } } finally { documentHandler.endSelector(sl); } }
/** * Parses an import rule. Assumes the current token is '@import'. */ protected void parseImportRule() { String uri = null; switch (current) { default: reportError("string.or.uri"); return; case LexicalUnits.STRING: case LexicalUnits.URI: uri = scanner.getStringValue(); nextIgnoreSpaces(); } CSSSACMediaList ml; if (current != LexicalUnits.IDENTIFIER) { ml = new CSSSACMediaList(); ml.append("all"); } else { ml = parseMediaList(); } documentHandler.importStyle(uri, ml, null); if (current != LexicalUnits.SEMI_COLON) { reportError("semicolon"); } else { next(); } }
LexicalUnit result = parseTerm(null); LexicalUnit curr = result; curr = CSSLexicalUnit.createSimple (LexicalUnit.SAC_OPERATOR_COMMA, curr); nextIgnoreSpaces(); break; case LexicalUnits.DIVIDE: curr = CSSLexicalUnit.createSimple (LexicalUnit.SAC_OPERATOR_SLASH, curr); nextIgnoreSpaces(); throw createCSSParseException ("token", new Object[] {current}); curr = parseTerm(curr); } else { switch (current) { case LexicalUnits.EOF: if (op) { throw createCSSParseException ("token", new Object[] {current}); curr = parseTerm(curr);
Selector result = parseSimpleSelector(); case LexicalUnits.COLON: if (pseudoElement != null) { throw createCSSParseException("pseudo.element.position"); parseSimpleSelector()); break; case LexicalUnits.PLUS: if (pseudoElement != null) { throw createCSSParseException("pseudo.element.position"); nextIgnoreSpaces(); result = selectorFactory.createDirectAdjacentSelector ((short)1, result, parseSimpleSelector()); break; case LexicalUnits.PRECEDE: if (pseudoElement != null) { throw createCSSParseException("pseudo.element.position"); nextIgnoreSpaces(); result = selectorFactory.createChildSelector (result, parseSimpleSelector());
/** * Parses the priority using the current scanner. */ protected boolean parsePriorityInternal() throws CSSException, IOException { nextIgnoreSpaces(); scanner.close(); scanner = null; switch (current) { case LexicalUnits.EOF: return false; case LexicalUnits.IMPORT_SYMBOL: return true; default: reportError("token", new Object[] {current}); return false; } }
/** * Parses selectors using the current scanner. */ protected SelectorList parseSelectorsInternal() throws CSSException, IOException { nextIgnoreSpaces(); SelectorList ret = parseSelectorList(); scanner.close(); scanner = null; return ret; }
/** * Parses a rule using the current scanner. */ protected void parseRuleInternal() throws CSSException, IOException { nextIgnoreSpaces(); parseRule(); scanner.close(); scanner = null; }
/** * <b>SAC</b>: Implements {@link * org.w3c.css.sac.Parser#parseStyleDeclaration(InputSource)}. */ public void parseStyleDeclaration(InputSource source) throws CSSException, IOException { scanner = createScanner(source); parseStyleDeclarationInternal(); }
/** * <b>SAC</b>: Implements {@link * org.w3c.css.sac.Parser#parseSelectors(InputSource)}. */ public SelectorList parseSelectors(InputSource source) throws CSSException, IOException { scanner = createScanner(source); return parseSelectorsInternal(); }
/** * <b>SAC</b>: Implements * {@link org.w3c.css.sac.Parser#parsePriority(InputSource)}. */ public boolean parsePriority(InputSource source) throws CSSException, IOException { scanner = createScanner(source); return parsePriorityInternal(); }
/** * Parses a selector list */ protected SelectorList parseSelectorList() { CSSSelectorList result = new CSSSelectorList(); result.append(parseSelector()); for (;;) { if (current != LexicalUnits.COMMA) { return result; } nextIgnoreSpaces(); result.append(parseSelector()); } }