void parseUrl(String atRule) throws CSSException { // @url key dataResourceFunction String[] parts = atRule.substring(0, atRule.length() - 1).split("\\s"); if (parts.length != 3) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, "Incorrect number of parts for @url", null); } CssUrl url = new CssUrl(parts[1], parts[2]); addNode(url); }
void parseEval(String atRule) throws CSSException { // @eval key com.google.Type.staticFunction String[] parts = atRule.substring(0, atRule.length() - 1).split("\\s"); if (parts.length != 3) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, "Incorrect number of parts for @eval", null); } CssEval eval = new CssEval(parts[1], parts[2]); addNode(eval); }
/** * The elif nodes are processed as though they were {@code @if} nodes. The * newly-generated CssIf node will be attached to the last CssIf in the * if/else chain. */ void parseElif(String atRule) throws CSSException { List<CssNode> nodes = currentParent.peek().getNodes(); CssIf lastIf = findLastIfInChain(nodes); if (lastIf == null) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, "@elif must immediately follow an @if or @elif", null); } assert lastIf.getElseNodes().isEmpty(); // @elif -> lif (because parseIf strips the first three chars) parseIf(atRule.substring(2)); // Fix up the structure by remove the newly-created node from the parent // context and moving it to the end of the @if chain lastIf.getElseNodes().add(nodes.remove(nodes.size() - 1)); }
/** * Return an integer value from 0-255 for a component of an RGB color. * * @param color typed value from the CSS parser, which may be an INTEGER or a * PERCENTAGE * @return integer value from 0-255 * @throws IllegalArgumentException if the color is not an INTEGER or * PERCENTAGE value */ private static int getRgbComponentValue(LexicalUnit color) { switch (color.getLexicalUnitType()) { case LexicalUnit.SAC_INTEGER: return Math.min(color.getIntegerValue(), 255); case LexicalUnit.SAC_PERCENTAGE: return (int) Math.min(color.getFloatValue() * 255, 255); default: throw new CSSException(CSSException.SAC_SYNTAX_ERR, "RGB component value must be integer or percentage, was " + color, null); } }
throw new CSSException(CSSException.SAC_SYNTAX_ERR, "Incorrect format for @if predicate", null); case 1: if (predicateParts[0].length() == 0) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, "Incorrect format for @if predicate", null);
/** * The else nodes are processed as though they were written as {@code @elif * true} rules. */ void parseElse(String atRule) throws CSSException { // The last CssIf in the if/else chain CssIf lastIf = findLastIfInChain(currentParent.peek().getNodes()); if (lastIf == null) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, "@else must immediately follow an @if or @elif", null); } // Create the CssIf to hold the @else rules String fakeElif = "@elif (true) " + atRule.substring(atRule.indexOf("{")); parseElif(fakeElif); CssIf elseIf = findLastIfInChain(currentParent.peek().getNodes()); assert lastIf.getElseNodes().size() == 1 && lastIf.getElseNodes().get(0) == elseIf; assert elseIf.getElseNodes().isEmpty(); // Merge the rules into the last CssIf to break the chain and prevent // @else followed by @else lastIf.getElseNodes().clear(); lastIf.getElseNodes().addAll(elseIf.getNodes()); }
throw new CSSException(CSSException.SAC_SYNTAX_ERR, "@def rules must specify an identifier and one or more values", null); throw new CSSException(CSSException.SAC_SYNTAX_ERR, "First lexical unit must be an identifier", null);
private <T extends CssNode & HasNodes> void parseInnerStylesheet( String tagName, T parent, String blockContents) { pushParent(parent); // parse the inner text InputSource s = new InputSource(); s.setCharacterStream(new StringReader(blockContents)); Parser parser = new Parser(); parser.setDocumentHandler(this); parser.setErrorHandler(errors); try { parser.parseStyleSheet(s); } catch (IOException e) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, "Unable to parse " + tagName, e); } if (currentParent.pop() != parent) { // This is a coding error throw new RuntimeException("Incorrect element popped"); } }
void parseSprite(String atRule) throws CSSException { CssSprite sprite = new CssSprite(); currentRule = sprite; addNode(sprite); // Flag to tell startSelector() to use the CssSprite instead of creating // its own CssRule. nextSelectorCreatesRule = false; // parse the inner text InputSource s = new InputSource(); s.setCharacterStream(new StringReader(atRule.substring(7))); Parser parser = new Parser(); parser.setDocumentHandler(this); parser.setErrorHandler(errors); try { parser.parseRule(s); } catch (IOException e) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, "Unable to parse @sprite", e); } }
@Override public PositionalCondition createPositionalCondition( int position, boolean typeNode, boolean type ) throws CSSException { throw new CSSException( "Positional conditions not supported by CSS2" ); }
/** * Creates an root node selector. * * @return the root node selector. * @exception CSSException If this selector is not supported. */ public SimpleSelector createRootNodeSelector() throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); }
/** * Creates a text node selector. * * @param data the data * @return the text node selector * @exception CSSException If this selector is not supported. */ public CharacterDataSelector createTextNodeSelector(String data) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); }
/** * Creates a content condition * * @param data the data in the content * @return A content condition * @exception CSSException if this exception is not supported. */ public ContentCondition createContentCondition(String data) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } }
/** * <b>SAC</b>: Implements {@link * org.w3c.css.sac.ConditionFactory#createOnlyTypeCondition()}. */ public Condition createOnlyTypeCondition() throws CSSException { throw new CSSException("Not implemented in CSS2"); }
/** * <b>SAC</b>: Implements {@link * org.w3c.css.sac.ConditionFactory#createContentCondition(String)}. */ public ContentCondition createContentCondition(String data) throws CSSException { throw new CSSException("Not implemented in CSS2"); } }
throw new CSSException(CSSException.SAC_SYNTAX_ERR, "Incorrect number of parameters to " + VALUE_FUNCTION_NAME, null); throw new CSSException(CSSException.SAC_SYNTAX_ERR, "Incorrect number of parameters to " + LITERAL_FUNCTION_NAME, null); throw new CSSException(CSSException.SAC_SYNTAX_ERR, "The single argument to " + LITERAL_FUNCTION_NAME + " must be a string value", null);
@Override public LangCondition createLangCondition( String lang ) throws CSSException { String mesg = "Lang conditions not supported by RAP - ignored"; reader.addProblem( new CSSException( mesg ) ); return new NullLangCondition(); }
@Override public DescendantSelector createDescendantSelector( Selector parent, SimpleSelector descendant ) throws CSSException { String mesg = "Descendant selectors not supported by RAP - ignored"; reader.addProblem( new CSSException( mesg ) ); return new NullDescendantSelector(); }
@Override public void ignorableAtRule( String atRule ) throws CSSException { log( "ignorableAtRule " + atRule ); reader.addProblem( new CSSException( "unsupported at rule '" + atRule + "' - ignored" ) ); }
public ElementSelector createElementSelector(final String namespaceURI, final String localName, final Locator locator) throws CSSException { if (namespaceURI != null) { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } final ElementSelectorImpl sel = new ElementSelectorImpl(localName); sel.setLocator(locator); return sel; }