cssparser-0.9.5/0000755000175000017500000000000011420645030013345 5ustar cavedoncavedoncssparser-0.9.5/src/0000755000175000017500000000000011420645030014134 5ustar cavedoncavedoncssparser-0.9.5/src/main/0000755000175000017500000000000011420645030015060 5ustar cavedoncavedoncssparser-0.9.5/src/main/javacc/0000755000175000017500000000000011420645030016307 5ustar cavedoncavedoncssparser-0.9.5/src/main/javacc/SACParserCSSmobileOKBasic1.jj0000644000175000017500000006303110770335722023453 0ustar cavedoncavedon/* * $Id: SACParserCSSmobileOKBasic1.jj,v 1.1 2008/03/20 01:20:18 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2008 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ options { IGNORE_CASE = true; STATIC = false; // UNICODE_INPUT = false; USER_CHAR_STREAM = true; // DEBUG_TOKEN_MANAGER = true; // DEBUG_PARSER = true; } PARSER_BEGIN(SACParserCSSmobileOKBasic1) package com.steadystate.css.parser; import java.io.*; import java.net.*; import java.text.MessageFormat; import java.util.*; import org.w3c.css.sac.*; import com.steadystate.css.parser.*; import com.steadystate.css.parser.selectors.*; /** * @author David Schweinsberg * @version $Id: SACParserCSSmobileOKBasic1.jj,v 1.1 2008/03/20 01:20:18 sdanig Exp $ */ public class SACParserCSSmobileOKBasic1 extends AbstractSACParser implements Parser { private boolean _quiet = true; public SACParserCSSmobileOKBasic1() { this((CharStream) null); } public String getParserVersion() { return "http://www.w3.org/TR/mobileOK-basic10-tests/#validity"; } protected String getGrammarUri() { return "CSSgrammarMobileOKBasic1.0.txt"; } protected Token getToken() { return this.token; } } PARSER_END(SACParserCSSmobileOKBasic1) TOKEN_MGR_DECLS : { private boolean _quiet = true; private ErrorHandler errorHandler; private String trimBy(StringBuffer s, int left, int right) { int end = s.length(); return s.toString().substring(left, end-right); } private String trimUrl(StringBuffer s) { StringBuffer s1 = new StringBuffer( trimBy(s, 4, 1).trim() ); if (s1.length() == 0) { return s1.toString(); } int end = s1.length() - 1; if ((s1.charAt(0) == '"' && s1.charAt(end) == '"') || (s1.charAt(0) == '\'' && s1.charAt(end) == '\'')) return trimBy(s1, 1, 1); else return s1.toString(); } } TOKEN : { < S: ( " "|"\t"|"\r"|"\n"|"\f" )+ > } MORE : { < "/*" > : COMMENT } TOKEN : { < IDENT: ( )* > | < LINK_PSCLASS: ":link" > { matchedToken.image = trimBy(image, 1, 0); } | < VISITED_PSCLASS: ":visited" > { matchedToken.image = trimBy(image, 1, 0); } | < ACTIVE_PSCLASS: ":active" > { matchedToken.image = trimBy(image, 1, 0); } | < FIRST_LINE: ":first-line" > { matchedToken.image = trimBy(image, 1, 0); } | < FIRST_LETTER: ":first-letter" > { matchedToken.image = trimBy(image, 1, 0); } | < HASH: "#" > //| < CLASS: "." > } TOKEN : { < LBRACE: "{" > | < RBRACE: "}" > | < COMMA: "," > | < DOT: "." > | < SEMICOLON: ";" > | < COLON: ":" > | < ASTERISK: "*" > | < SLASH: "/" > | < PLUS: "+" > | < MINUS: "-" > | < EQUALS: "=" > | < GT: ">" > | < LSQUARE: "[" > | < RSQUARE: "]" > } TOKEN : { < STRING: | > { matchedToken.image = trimBy(image, 1, 1); } : DEFAULT | < RROUND: ")" > } // TODO: check url TOKEN : { // < #URL: ["!","#","$","%","&","*"-"~"] | | > // < #URL: ["!","#","$","%","&","*"-"[","]"-"~"] | | > < URL: "url(" ( )* ( | ( ["!","#","$","%","&","*"-"[","]"-"~"] | | )* ) ( )* > { matchedToken.image = trimUrl(image); } : DEFAULT } TOKEN : { < CDO: "" > : DEFAULT | < IMPORT_SYM: "@import" > : DEFAULT | < MEDIA_SYM: "@media" > | < IMPORTANT_SYM: "!" ( )? "important" > : DEFAULT | < ATKEYWORD: "@" > | < EMS: "em" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < EXS: "ex" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_PX: "px" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_CM: "cm" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_MM: "mm" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_IN: "in" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_PT: "pt" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_PC: "pc" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < PERCENTAGE: "%" > { matchedToken.image = trimBy(image, 0, 1); } : DEFAULT | < NUMBER: > : DEFAULT // TODO: check rgb | < RGB: "rgb(" > : DEFAULT | < #NAME: ( )+ > | < #D: ["0"-"9"] > | < NUM: ( )+ | ( )* "." ( )+ > // TODO: check unicoderange | < UNICODERANGE: "U+" ( | ( "-" ) ) > | < #RANGE: | ( ()? | ( ()? | ( ()? | ( ()? | ( ()? | ) ) ) ) ) > | < #Q16: "?" | "??" | "???" | "????" | "?????" | "??????" > | < #Q15: "?" | "??" | "???" | "????" | "?????" > | < #Q14: "?" | "??" | "???" | "????" > | < #Q13: "?" | "??" | "???" > | < #Q12: "?" | "??" > | < #Q11: "?" > // TODO: check latin1 // < LATIN1 : "\u0080"-"\uFFFF" > // < STRINGCHAR : | | [" ","!","#","$","%","&","(", "-", "~"] > // < NMCHAR: ["a"-"z","0"-"9","-"] | | // < NMSTRT: ["a"-"z"] | | > // < NOTNM: ["^", "-", "a-z", "0-9", "\"] | | < #NMSTART: ["a"-"z"] | | > | < #NMCHAR: ["a"-"z","0"-"9","-"] | | > // TODO: check strings //| < #STRING1: "\"" ( ["\t"," ","!","#","$","%","&","("-"~"] | "\\" | "\'" | | )* "\"" > //| < #STRING2: "\'" ( ["\t"," ","!","#","$","%","&","("-"~"] | "\\" | "\"" | | )* "\'" > | < #STRING1: "\"" ( ["\t"," ","!","#","$","%","&","("-"[","]"-"~"] | "\\" | "\'" | | )* "\"" > | < #STRING2: "\'" ( ["\t"," ","!","#","$","%","&","("-"[","]"-"~"] | "\\" | "\"" | | )* "\'" > | < #NONASCII: ["\u0080"-"\uFFFF"] > // TODO: check escape | < #ESCAPE: | ( "\\" [" "-"~","\u0080"-"\uFFFF"] ) > | < #NL: "\n" | "\r\n" | "\r" | "\f" > | < #UNICODE: "\\" ( " " | "\t" | "\r" | "\n" | "\f" )? > | < #HNUM: | | | | | > | < #H: ["0"-"9","a"-"f"] > } SKIP : { < "*/" > : DEFAULT } MORE : { < ~[] > : COMMENT } <*> TOKEN: { < UNKNOWN: ~[] > { if (!_quiet) { System.err.println("Illegal character : " + image.toString()); } } } // // stylesheet // : [S|CDO|CDC]* [ import [S|CDO|CDC]* ]* // [ [ ruleset | media ] [S|CDO|CDC]* ]* // ; // void styleSheet() : { } { try { { this.handleStartDocument(); } styleSheetRuleList() } finally { this.handleEndDocument(); } } // Although the grammar does not include [S|CDO|CDC] but [CDO|CDC], white space // should be allowed void styleSheetRuleList() : { } { ( | | )* ( importRule() ( | | )* )* ( ( styleRule() | mediaRule() | unknownRule() ) ( | | )* )* ( ( styleRule() | mediaRule() | importRuleIgnored() | unknownRule() ) ( | | )* )* } // // This is used by ASTStyleSheet.insertRule to parse a single rule // void styleSheetRuleSingle() : { } { ( importRule() | styleRule() | mediaRule() | unknownRule() ) } void unknownRule() : { Token t; String s; } { try { t = { s = skip(); this.handleIgnorableAtRule(s); } } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidUnknownRule", e)); } } // // import // : IMPORT_SYM S* // [STRING|URI] S* [ medium [ ',' S* medium]* ]? ';' S* // ; // void importRule() : { Token t; SACMediaListImpl ml = new SACMediaListImpl(); } { try { ( )* ( t = | t = ) ( )* ( mediaList(ml) )? { this.handleImportStyle(unescape(t.image), new SACMediaListImpl(), null); } } catch (CSSParseException e) { this.getErrorHandler().error(e); this.error_skipAtRule(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidImportRule", e)); this.error_skipAtRule(); } } void importRuleIgnored() : { Token t; SACMediaListImpl ml = new SACMediaListImpl(); } { { ParseException e = generateParseException(); } try { ( )* ( t = | t = ) ( )* ( mediaList(ml) )? } finally { this.getErrorHandler().error(this.toCSSParseException("invalidImportRuleIgnored", e)); } } // // media // : MEDIA_SYM S* medium [ ',' S* medium ]* '{' S* ruleset* '}' S* // ; // void mediaRule() : { boolean start = false; SACMediaListImpl ml = new SACMediaListImpl(); } { try { ( )* mediaList(ml) { start = true; this.handleStartMedia(ml); } ( )* ( mediaRuleList() )? } catch (CSSParseException e) { this.getErrorHandler().error(e); this.error_skipblock(); } catch(ParseException e) { CSSParseException cpe = this.toCSSParseException("invalidMediaRule", e); this.getErrorHandler().error(cpe); this.getErrorHandler().warning(this.createSkipWarning("ignoringRule", cpe)); this.error_skipblock(); } finally { if (start) { this.handleEndMedia(ml); } } } void mediaList(SACMediaListImpl ml) : { String s; } { try { s = medium() ( ( )* { ml.add(s); } s = medium() )* { ml.add(s); } } catch(ParseException e) { throw this.toCSSParseException("invalidMediaList", e); } } void mediaRuleList() : { } { ( ( styleRule() | unknownRule() ) ( )* )+ } void mediaRuleSingle() : { } { ( styleRule() | unknownRule() ) } // // medium // : IDENT S* // ; // String medium() : { Token t; } { t = ( )* { this.handleMedium(t.image); return t.image; } } // // operator // : '/' | ',' | /* empty */ // ; // LexicalUnit operator(LexicalUnit prev) : { Token t; } { t = ( )* { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_SLASH); } | t = ( )* { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_COMMA); } } // // unary_operator // : '-' | '+' // ; // char unaryOperator() : { } { ( { return '-'; } | { return '+'; } ) } // // property // : IDENT S* // ; // String property() : { Token t; } { t = ( )* { return unescape(t.image); } } // // ruleset // : selector [ ',' S* selector ]* // '{' S* declaration [ ';' S* declaration ]* '}' S* // ; // void styleRule() : { SelectorList selList = null; boolean start = false; boolean noError = true; } { try { selList = selectorList() ( )* { start = true; this.handleStartSelector(selList); } // TODO: css 2 must have at least one declaration too ( declaration() ) ( ( )* ( declaration() )? )* } catch(CSSParseException e) { this.getErrorHandler().error(e); noError = false; this.error_skipblock(); } catch(ParseException e) { this.getErrorHandler().error(this.toCSSParseException("invalidStyleRule", e)); noError = false; this.error_skipblock(); } finally { if (start) { this.handleEndSelector(selList); } } } SelectorList selectorList() : { SelectorListImpl selList = new SelectorListImpl(); Selector sel; } { sel = selector() ( ( )* { selList.add(sel); } sel = selector() )* ( )* { selList.add(sel); return selList; } } // // selector // : simple_selector+ [ pseudo_element ]? // ; // Selector selector() : { Selector sel; } { try { sel = simpleSelector(null, ' ') ( LOOKAHEAD(2) sel = simpleSelector(sel, ' ') )* { this.handleSelector(sel); return sel; } } catch (ParseException e) { throw this.toCSSParseException("invalidSelector", e); //skipSelector(); } } // // simple_selector // : element_name id? class? pseudo_class? /* eg: H1.subject */ // | class? pseudo_class? /* eg: #xyz33 */ // | pseudo_class? /* eg: .author */ // ; // Selector simpleSelector(Selector sel, char comb) : { SimpleSelector simpleSel = null; Condition c = null; } { try { ( ( simpleSel = elementName() ( c = hash(c) )? ( c = _class(c) )? ( c = pseudoClass(c) )? ( c = pseudoElement(c) )? ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( ( c = hash(c) ) ( c = _class(c) )? ( c = pseudoClass(c) )? ( c = pseudoElement(c) )? ) ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( ( c = _class(c) ) ( c = pseudoClass(c) )? ( c = pseudoElement(c) )? ) ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( ( c = pseudoClass(c) ) ( c = pseudoElement(c) )? ) ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( ( c = pseudoElement(c) ) ) ) ) { if (c != null) { simpleSel = this.getSelectorFactory().createConditionalSelector(simpleSel, c); } if (sel != null) { switch (comb) { case ' ': sel = this.getSelectorFactory().createDescendantSelector(sel, simpleSel); break; } } else { sel = simpleSel; } return sel; } } catch (ParseException e) { throw this.toCSSParseException("invalidSimpleSelector", e); } } // // class // : '.' IDENT // ; // Condition _class(Condition pred) : { Token t; } { try { t = { Condition c = this.getConditionFactory().createClassCondition(null, t.image); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidClassSelector", e); } } // // element_name // : IDENT // ; // SimpleSelector elementName() : { Token t; } { try { t= { return this.getSelectorFactory().createElementSelector(null, unescape(t.image)); } | { return this.getSelectorFactory().createElementSelector(null, null); } } catch (ParseException e) { throw this.toCSSParseException("invalidElementName", e); } } // // pseudo // : ':' [ IDENT | S* ')' ] // ; // Condition pseudoClass(Condition pred) : { Condition c; Token t; } { try { ( (t = | t = | t = ) { // There appears to be an issue here regarding "first-letter" & "first-line" //String s = unescape(t.image); String s = t.image; c = this.getConditionFactory().createPseudoClassCondition(null, s); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } ) } catch (ParseException e) { throw this.toCSSParseException("invalidPseudoClass", e); } } // // pseudo // : ':' [ IDENT | S* ')' ] // ; // Condition pseudoElement(Condition pred) : { Condition c; Token t; } { try { ( t = | t = { //String s = unescape(t.image); String s = t.image; // TODO: createPseudoElementCondition c = this.getConditionFactory().createPseudoClassCondition(null, s); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } ) } catch (ParseException e) { throw this.toCSSParseException("invalidPseudoElement", e); } } Condition hash(Condition pred) : { Token t; } { try { t = { Condition c = this.getConditionFactory().createIdCondition(t.image.substring(1)); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidHash", e); } } void styleDeclaration() : { } { // ( )* ( declaration() )? ( ( )* ( declaration() )? )* // } // // declaration // : property ':' S* expr prio? // | // ; // void declaration() : { String p; LexicalUnit e; boolean priority = false; } { try { p = property() ( )* e = expr() ( priority = prio() )? { this.handleProperty(p, e, priority); } } catch (CSSParseException ex) { this.getErrorHandler().error(ex); error_skipdecl(); } catch (ParseException ex) { this.getErrorHandler().error(this.toCSSParseException("invalidDeclaration", ex)); error_skipdecl(); } } // // prio // : IMPORTANT_SYM S* // ; // boolean prio() : { } { ( )* { return true; } } // // expr // : term [ operator term ]* // ; // // TODO: Deal with the operator // LexicalUnit expr() : { LexicalUnit head; LexicalUnit body; } { try { head = term(null) { body = head; } ( ( body = operator(body) )? body = term(body) )* { return head; } } catch (ParseException ex) { throw this.toCSSParseException("invalidExpr", ex); } } // // term // : unary_operator? // [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | // STRING S* | URI S* | RGB S* | hexcolor ] // ; // LexicalUnit term(LexicalUnit prev) : { Token t; char op = ' '; String s; LexicalUnit value = null; // RGBColor color; // HexColor h; // CSSValueImpl value = null; } { /* ( ( op = unaryOperator() )? ( ( t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_NUMBER, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PERCENTAGE, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PX, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_CM, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_MM, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IN, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PT, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PC, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EMS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EXS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_STRING, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_URI, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + t.image ); } | color = rgb() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RGBCOLOR, color ); } | color = hexcolor() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RGBCOLOR, color ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_DIMENSION, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_INHERIT, op + t.image ); } ) ( )* ) { return value; } */ ( op = unaryOperator() )? ( ( t = { try { value = LexicalUnitImpl.createNumber(prev, intValue(op, t.image)); } catch (NumberFormatException e) { value = LexicalUnitImpl.createNumber(prev, floatValue(op, t.image)); } } | t = { value = LexicalUnitImpl.createPercentage(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPixel(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createCentimeter(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createMillimeter(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createInch(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPoint(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPica(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createEm(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createEx(prev, floatValue(op, t.image)); } ) | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_STRING_VALUE, t.image); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_IDENT, t.image); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_URI, t.image); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_UNICODERANGE, t.image); } | value = rgb(prev) | value = hexcolor(prev) ) ( )* { if (value instanceof LexicalUnitImpl) { ((LexicalUnitImpl) value).setLocator(this.getLocator()); } return value; } } // // rgb // : RGB S* expr ')' S* // ; // LexicalUnit rgb(LexicalUnit prev) : { Token t; LexicalUnit params; } { t = ( )* params = expr() { return LexicalUnitImpl.createRgbColor(prev, params); } } // // hexcolor // : HASH // ; // LexicalUnit hexcolor(LexicalUnit prev) : { Token t; } { t = { return this.hexcolorInternal(prev, t); } } JAVACODE void skipSelector() { Token t = getToken(1); while (t.kind != COMMA && t.kind != SEMICOLON && t.kind != LBRACE && t.kind != EOF ) { getNextToken(); t = getToken(1); } } JAVACODE String skip() { StringBuffer sb = new StringBuffer(); int nesting = 0; Token t = getToken(0); if (t.image != null) { sb.append(t.image); } do { t = getNextToken(); if (t.kind == EOF) break; sb.append(t.image); if (t.kind == LBRACE) nesting++; else if (t.kind == RBRACE) nesting--; else if (t.kind == SEMICOLON && nesting <= 0) break; } while ((t.kind != RBRACE) || (nesting > 0)); return sb.toString(); } JAVACODE void error_skipblock() { Token t; int nesting = 0; do { t = getNextToken(); if (t.kind == LBRACE) { nesting++; } else if (t.kind == RBRACE) { nesting--; } else if (t.kind == EOF) { break; } } while ((t.kind != RBRACE) || (nesting > 0)); } JAVACODE void error_skipdecl() { int nesting = 0; Token t = getToken(1); if (t.kind == LBRACE) { error_skipblock(); } else { Token oldToken = t; while (t.kind != SEMICOLON && t.kind != RBRACE && t.kind != EOF ) { oldToken = t; t = getNextToken(); } if (t.kind == RBRACE) { token = oldToken; } } } JAVACODE void error_skipAtRule() { Token t = null; do { t = getNextToken(); } while (t.kind != SEMICOLON); } cssparser-0.9.5/src/main/javacc/SACParserCSS2.jj0000644000175000017500000007707110772225635021104 0ustar cavedoncavedon/* * $Id: SACParserCSS2.jj,v 1.2 2008/03/25 16:43:09 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2008 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ options { IGNORE_CASE = true; STATIC = false; // UNICODE_INPUT = false; USER_CHAR_STREAM = true; // DEBUG_TOKEN_MANAGER = true; // DEBUG_PARSER = true; } PARSER_BEGIN(SACParserCSS2) package com.steadystate.css.parser; import java.io.*; import java.net.*; import java.text.MessageFormat; import java.util.*; import org.w3c.css.sac.*; import com.steadystate.css.parser.selectors.*; import com.steadystate.css.sac.TestCSSParseException; /** * @author David Schweinsberg * @version $Id: SACParserCSS2.jj,v 1.2 2008/03/25 16:43:09 sdanig Exp $ */ public class SACParserCSS2 extends AbstractSACParser implements Parser { private boolean _quiet = true; public SACParserCSS2() { this((CharStream) null); } public String getParserVersion() { return "http://www.w3.org/TR/REC-CSS2/"; } protected String getGrammarUri() { return "http://www.w3.org/TR/REC-CSS2/grammar.html"; } protected Token getToken() { return this.token; } } PARSER_END(SACParserCSS2) TOKEN_MGR_DECLS : { private boolean _quiet = true; private ErrorHandler errorHandler; private String trimBy(StringBuffer s, int left, int right) { int end = s.length(); return s.toString().substring(left, end-right); } private String trimUrl(StringBuffer s) { StringBuffer s1 = new StringBuffer( trimBy(s, 4, 1).trim() ); if (s1.length() == 0) { return s1.toString(); } int end = s1.length() - 1; if ((s1.charAt(0) == '"' && s1.charAt(end) == '"') || (s1.charAt(0) == '\'' && s1.charAt(end) == '\'')) return trimBy(s1, 1, 1); else return s1.toString(); } } TOKEN : { < S: ( " "|"\t"|"\r"|"\n"|"\f" )+ > } MORE : { < "/*" > : COMMENT } SKIP : { < "*/" > : DEFAULT } MORE : { < ~[] > : COMMENT } TOKEN : { < LBRACE: "{" > | < RBRACE: "}" > | < COMMA: "," > | < DOT: "." > | < SEMICOLON: ";" > | < COLON: ":" > | < ASTERISK: "*" > | < SLASH: "/" > | < PLUS: "+" > | < MINUS: "-" > | < EQUALS: "=" > | < GT: ">" > | < LSQUARE: "[" > | < RSQUARE: "]" > } TOKEN : { < HASH: "#" > } TOKEN : { < STRING: | > { matchedToken.image = trimBy(image, 1, 1); } | < RROUND: ")" > } TOKEN : { // < #URL: ["!","#","$","%","&","*"-"~"] | | > < #URL: ["!","#","$","%","&","*"-"[","]"-"~"] | | > | < URI: "url(" ( )* ( | ( )* ) ( )* > { matchedToken.image = trimUrl(image); } } TOKEN : { < CDO: "" > | < INCLUDES: "~=" > | < DASHMATCH: "|=" > | < IMPORT_SYM: "@import" > | < PAGE_SYM: "@page" > | < MEDIA_SYM: "@media" > | < FONT_FACE_SYM: "@font-face" > | < CHARSET_SYM: "@charset" > | < ATKEYWORD: "@" > | < IMPORTANT_SYM: "!" ( )? "important" > | < INHERIT: "inherit" > | < EMS: "em" > { matchedToken.image = trimBy(image, 0, 2); } | < EXS: "ex" > { matchedToken.image = trimBy(image, 0, 2); } | < LENGTH_PX: "px" > { matchedToken.image = trimBy(image, 0, 2); } | < LENGTH_CM: "cm" > { matchedToken.image = trimBy(image, 0, 2); } | < LENGTH_MM: "mm" > { matchedToken.image = trimBy(image, 0, 2); } | < LENGTH_IN: "in" > { matchedToken.image = trimBy(image, 0, 2); } | < LENGTH_PT: "pt" > { matchedToken.image = trimBy(image, 0, 2); } | < LENGTH_PC: "pc" > { matchedToken.image = trimBy(image, 0, 2); } | < ANGLE_DEG: "deg" > { matchedToken.image = trimBy(image, 0, 3); } | < ANGLE_RAD: "rad" > { matchedToken.image = trimBy(image, 0, 3); } | < ANGLE_GRAD: "grad" > { matchedToken.image = trimBy(image, 0, 4); } | < TIME_MS: "ms" > { matchedToken.image = trimBy(image, 0, 2); } | < TIME_S: "s" > { matchedToken.image = trimBy(image, 0, 1); } | < FREQ_HZ: "Hz" > { matchedToken.image = trimBy(image, 0, 2); } | < FREQ_KHZ: "kHz" > { matchedToken.image = trimBy(image, 0, 3); } | < DIMEN: > | < PERCENTAGE: "%" > { matchedToken.image = trimBy(image, 0, 1); } | < NUMBER: > | < RGB: "rgb(" > | < FUNCTION: "(" > | < IDENT: ( )* > | < #NAME: ( )+ > | < NUM: ( ["0"-"9"] )+ | ( ["0"-"9"] )* "." ( ["0"-"9"] )+ > | < UNICODERANGE: "U+" ( | ( "-" ) ) > | < #RANGE: | ( ()? | ( ()? | ( ()? | ( ()? | ( ()? | ) ) ) ) ) > | < #Q16: "?" | "??" | "???" | "????" | "?????" | "??????" > | < #Q15: "?" | "??" | "???" | "????" | "?????" > | < #Q14: "?" | "??" | "???" | "????" > | < #Q13: "?" | "??" | "???" > | < #Q12: "?" | "??" > | < #Q11: "?" > | < #NMSTART: ["_","a"-"z"] | | > | < #NMCHAR: ["_","a"-"z","0"-"9","-"] | | > //| < #STRING1: "\"" ( ["\t"," ","!","#","$","%","&","("-"~"] | "\\" | "\'" | | )* "\"" > //| < #STRING2: "\'" ( ["\t"," ","!","#","$","%","&","("-"~"] | "\\" | "\"" | | )* "\'" > | < #STRING1: "\"" ( ["\t"," ","!","#","$","%","&","("-"[","]"-"~"] | "\\" | "\'" | | )* "\"" > | < #STRING2: "\'" ( ["\t"," ","!","#","$","%","&","("-"[","]"-"~"] | "\\" | "\"" | | )* "\'" > | < #NONASCII: ["\u0080"-"\uFFFF"] > | < #ESCAPE: | ( "\\" [" "-"~","\u0080"-"\uFFFF"] ) > | < #NL: "\n" | "\r\n" | "\r" | "\f" > | < #UNICODE: "\\" ( " " | "\t" | "\r" | "\n" | "\f" )? > | < #HNUM: | | | | | > | < #H: ["0"-"9","a"-"f"] > } <*> TOKEN: { < UNKNOWN: ~[] > { if (!_quiet) { System.err.println("Illegal character : " + image.toString()); } } } // // stylesheet // : [ CHARSET_SYM S* STRING S* ';' ]? // [S|CDO|CDC]* [ import [S|CDO|CDC]* ]* // [ [ ruleset | media | page | font_face ] [S|CDO|CDC]* ]* // ; // void styleSheet() : { } { try { { this.handleStartDocument(); } styleSheetRuleList() } finally { this.handleEndDocument(); } } void styleSheetRuleList() : { } { ( charsetRule() )? ( | | )* ( importRule() ( | | )* )* ( ( styleRule() | mediaRule() | pageRule() | fontFaceRule() | unknownRule() ) ( | | )* )* ( ( styleRule() | mediaRule() | pageRule() | fontFaceRule() | importRuleIgnored() | unknownRule() ) ( | | )* )* } // // This is used by ASTStyleSheet.insertRule to parse a single rule // void styleSheetRuleSingle() : { } { ( charsetRule() | importRule() | styleRule() | mediaRule() | pageRule() | fontFaceRule() | unknownRule() ) } void charsetRule() : { Token t; } { try { ( )* t = ( )* { this.handleCharset(t.toString()); } } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidCharsetRule", e)); } } void unknownRule() : { Token t; String s; } { try { t = { s = skip(); this.handleIgnorableAtRule(s); } } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidUnknownRule", e)); } } // // import // : IMPORT_SYM S* // [STRING|URI] S* [ medium [ ',' S* medium]* ]? ';' S* // ; // void importRule() : { Token t; // String s; SACMediaListImpl ml = new SACMediaListImpl(); } { try { ( )* ( t = | t = ) ( )* ( mediaList(ml) )? { this.handleImportStyle(unescape(t.image), ml, null); } } catch (CSSParseException e) { this.getErrorHandler().error(e); this.error_skipAtRule(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidImportRule", e)); this.error_skipAtRule(); } } void importRuleIgnored() : { Token t; SACMediaListImpl ml = new SACMediaListImpl(); } { { ParseException e = generateParseException(); } try { ( )* ( t = | t = ) ( )* ( mediaList(ml) )? } finally { this.getErrorHandler().error(this.toCSSParseException("invalidImportRuleIgnored", e)); } } // // media // : MEDIA_SYM S* medium [ ',' S* medium ]* '{' S* ruleset* '}' S* // ; // void mediaRule() : { boolean start = false; SACMediaListImpl ml = new SACMediaListImpl(); } { try { ( )* mediaList(ml) { start = true; this.handleStartMedia(ml); } ( )* ( mediaRuleList() )? } catch (CSSParseException e) { this.getErrorHandler().error(e); this.error_skipblock(); } catch(ParseException e) { CSSParseException cpe = this.toCSSParseException("invalidMediaRule", e); this.getErrorHandler().error(cpe); this.getErrorHandler().warning(this.createSkipWarning("ignoringRule", cpe)); this.error_skipblock(); } finally { if (start) { this.handleEndMedia(ml); } } } void mediaList(SACMediaListImpl ml) : { String s; } { try { s = medium() ( ( )* { ml.add(s); } s = medium() )* { ml.add(s); } } catch(ParseException e) { throw this.toCSSParseException("invalidMediaList", e); } } void mediaRuleList() : { } { ( ( styleRule() | pageRule() | unknownRule() ) ( )* )+ } void mediaRuleSingle() : { } { ( styleRule() | pageRule() | unknownRule() ) } // // medium // : IDENT S* // ; // String medium() : { Token t; } { t = ( )* { this.handleMedium(t.image); return t.image; } } // // page // : PAGE_SYM S* IDENT? pseudo_page? S* // '{' S* declaration [ ';' S* declaration ]* '}' S* // ; // void pageRule() : { Token t = null; String s = null; boolean start = false; } { try { ( )* ( LOOKAHEAD(2) ( t = s = pseudoPage() ( )* ) | ( t = ( )* ) | ( s = pseudoPage() ( )* ) )? // ( t = { jjtThis.setIdent( t.image ); } )? // ( s = pseudoPage() { jjtThis.setPseudoPage( s ); } )? ( )* ( )* { start = true; this.handleStartPage((t != null) ? unescape(t.image) : null, s); } ( declaration() )? ( ( )* ( declaration() )? )* } catch(ParseException e) { throw this.toCSSParseException("invalidPageRule", e); } finally { if (start) { this.handleEndPage((t != null) ? unescape(t.image) : null, s); } } } // // pseudoPage // : ':' IDENT // ; // String pseudoPage() : { Token t; } { t = { return t.image; } } // // font_face // : FONT_FACE_SYM S* // '{' S* declaration [ ';' S* declaration ]* '}' S* // ; // void fontFaceRule() : { boolean start = false; } { try { ( )* ( )* { start = true; this.handleStartFontFace(); } ( declaration() )? ( ( )* ( declaration() )? )* } catch(ParseException e) { throw this.toCSSParseException("invalidFontFaceRule", e); } finally { if (start) { this.handleEndFontFace(); } } } // // operator // : '/' S* | ',' S* | // ; // LexicalUnit operator(LexicalUnit prev) : { Token t; } { t = ( )* { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_SLASH); } | t = ( )* { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_COMMA); } } // // combinator // : '+' S* | '>' S* | // ; // char combinator() : { char c = ' '; } { ( { c='+'; } ( )* | { c='>'; } ( )* | ( ( { c='+'; } | { c='>'; } ) ( )* )? ) { return c; } } // // unary_operator // : '-' | '+' // ; // char unaryOperator() : { } { ( { return '-'; } | { return '+'; } ) } // // property // : IDENT S* // ; // String property() : { Token t; } { t = ( )* { return unescape(t.image); } } // // ruleset // : selector [ ',' S* selector ]* // '{' S* declaration [ ';' S* declaration ]* '}' S* // ; // void styleRule() : { SelectorList selList = null; boolean start = false; } { try { selList = selectorList() ( )* { start = true; this.handleStartSelector(selList); } styleDeclaration() /* ( declaration() )? ( ( )* ( declaration() )? )* */ } catch(CSSParseException e) { this.getErrorHandler().error(e); this.getErrorHandler().warning(this.createSkipWarning("ignoringRule", e)); this.error_skipblock(); } catch(ParseException e) { CSSParseException cpe = this.toCSSParseException("invalidStyleRule", e); this.getErrorHandler().error(cpe); this.getErrorHandler().warning(this.createSkipWarning("ignoringFollowingDeclarations", cpe)); this.error_skipblock(); } finally { if (start) { this.handleEndSelector(selList); } } } SelectorList selectorList() : { SelectorListImpl selList = new SelectorListImpl(); Selector sel; } { sel = selector() ( ( )* { selList.add(sel); } sel = selector() )* { selList.add(sel); return selList; } } // // selector // : simple_selector [ combinator simple_selector ]* // ; // Selector selector() : { Selector sel; char comb; } { try { sel = simpleSelector(null, ' ') ( LOOKAHEAD(2) comb = combinator() sel = simpleSelector(sel, comb) )* ( )* { this.handleSelector(sel); return sel; } } catch (ParseException e) { throw this.toCSSParseException("invalidSelector", e); //skipSelector(); } } // // simple_selector // : element_name? [ HASH | class | attrib | pseudo ]* S* // ; // Selector simpleSelector(Selector sel, char comb) : { SimpleSelector simpleSel = null; Condition c = null; } { try { ( ( simpleSel = elementName() ( c = hash(c) | c = _class(c) | c = attrib(c) | c = pseudo(c) )* ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( c = hash(c) | c = _class(c) | c = attrib(c) | c = pseudo(c) )+ ) ) { if (c != null) { simpleSel = this.getSelectorFactory().createConditionalSelector(simpleSel, c); } if (sel != null) { switch (comb) { case ' ': sel = this.getSelectorFactory().createDescendantSelector(sel, simpleSel); break; case '+': sel = this.getSelectorFactory().createDirectAdjacentSelector(sel.getSelectorType(), sel, simpleSel); break; case '>': sel = this.getSelectorFactory().createChildSelector(sel, simpleSel); break; } } else { sel = simpleSel; } return sel; } } catch (ParseException e) { throw this.toCSSParseException("invalidSimpleSelector", e); } } // // class // : '.' IDENT // ; // Condition _class(Condition pred) : { Token t; } { try { t = { Condition c = this.getConditionFactory().createClassCondition(null, t.image); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidClassSelector", e); } } // // element_name // : IDENT | '*' // ; // SimpleSelector elementName() : { Token t; } { try { t= { return this.getSelectorFactory().createElementSelector(null, unescape(t.image)); } | { return this.getSelectorFactory().createElementSelector(null, null); } } catch (ParseException e) { throw this.toCSSParseException("invalidElementName", e); } } // // attrib // : '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S* // [ IDENT | STRING ] S* ]? ']' // ; // Condition attrib(Condition pred) : { Token t; String name = null; String value = null; int type = 0; } { try { ( )* t = { name = unescape(t.image); } ( )* ( ( { type = 1; } | { type = 2; } | { type = 3; } ) ( )* ( t = { value = t.image; } | t = { value = unescape(t.image); } ) ( )* )? { Condition c = null; switch (type) { case 0: c = this.getConditionFactory().createAttributeCondition(name, null, false, null); break; case 1: c = this.getConditionFactory().createAttributeCondition(name, null, false, value); break; case 2: c = this.getConditionFactory().createOneOfAttributeCondition(name, null, false, value); break; case 3: c = this.getConditionFactory().createBeginHyphenAttributeCondition(name, null, false, value); break; } return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidAttrib", e); } } // // pseudo // : ':' [ IDENT | FUNCTION S* IDENT S* ')' ] // ; // Condition pseudo(Condition pred) : { Condition c; Token t; String function; String arg; } { try { ( t = { // There appears to be an issue here regarding "first-letter" & "first-line" //String s = unescape(t.image); String s = t.image; c = this.getConditionFactory().createPseudoClassCondition(null, s); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } | ( t = { function = unescape(t.image); } ( )* t = { arg = unescape(t.image); } ( )* { if (function.equalsIgnoreCase("lang(")) { c = this.getConditionFactory().createLangCondition(unescape(arg)); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } else { c = this.getConditionFactory().createPseudoClassCondition(null, function + arg + ")"); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } /* else { throw new TestCSSParseException( "Invalid pseudo function name " + function, getLocator(), this.getGrammarUri()); } */ } ) ) } catch (ParseException e) { throw this.toCSSParseException("invalidPseudo", e); } } Condition hash(Condition pred) : { Token t; } { try { t = { Condition c = this.getConditionFactory().createIdCondition(t.image.substring(1)); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidHash", e); } } void styleDeclaration() : { } { // ( )* try { ( declaration() )? ( ( )* ( declaration() )? )* } catch (ParseException ex) { this.getErrorHandler().error(this.toCSSParseException("invalidDeclaration", ex)); error_skipdecl(); } // } // // declaration // : property ':' S* expr prio? // | // ; // void declaration() : { String p; LexicalUnit e; boolean priority = false; } { try { p = property() ( )* e = expr() ( priority = prio() )? { this.handleProperty(p, e, priority); } } catch (CSSParseException ex) { this.getErrorHandler().error(ex); error_skipdecl(); } catch (ParseException ex) { this.getErrorHandler().error(this.toCSSParseException("invalidDeclaration", ex)); error_skipdecl(); } } // // prio // : IMPORTANT_SYM S* // ; // boolean prio() : { } { ( )* { return true; } } // // expr // : term [ operator term ]* // ; // // TODO: Deal with the operator // LexicalUnit expr() : { LexicalUnit head; LexicalUnit body; } { try { head = term(null) { body = head; } ( ( body = operator(body) )? body = term(body) )* { return head; } } catch (ParseException ex) { throw this.toCSSParseException("invalidExpr", ex); } } // // term // : unary_operator? // [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* | // TIME S* | FREQ S* | function ] // | STRING S* | IDENT S* | URI S* | RGB S* | UNICODERANGE S* | hexcolor // ; // LexicalUnit term(LexicalUnit prev) : { Token t; char op = ' '; String s; LexicalUnit value = null; // RGBColor color; // HexColor h; // CSSValueImpl value = null; } { /* ( ( op = unaryOperator() )? ( ( t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_NUMBER, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PERCENTAGE, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PX, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_CM, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_MM, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IN, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PT, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PC, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EMS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EXS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_DEG, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RAD, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_GRAD, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_MS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_S, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_HZ, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_KHZ, new Float( op + t.image ) ); } | s = function() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + s ); } ) | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_STRING, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_URI, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + t.image ); } | color = rgb() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RGBCOLOR, color ); } | color = hexcolor() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RGBCOLOR, color ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_DIMENSION, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_INHERIT, op + t.image ); } ) ( )* ) { return value; } */ ( op = unaryOperator() )? ( ( t = { try { value = LexicalUnitImpl.createNumber(prev, intValue(op, t.image)); } catch (NumberFormatException e) { value = LexicalUnitImpl.createNumber(prev, floatValue(op, t.image)); } } | t = { value = LexicalUnitImpl.createPercentage(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPixel(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createCentimeter(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createMillimeter(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createInch(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPoint(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPica(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createEm(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createEx(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createDegree(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createRadian(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createGradian(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createMillisecond(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createSecond(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createHertz(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createKiloHertz(prev, floatValue(op, t.image)); } | value = function(prev) ) | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_STRING_VALUE, unescape(t.image)); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_IDENT, t.image); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_URI, t.image); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_UNICODERANGE, t.image); } | value = rgb(prev) | value = hexcolor(prev) | t = { int n = getLastNumPos(t.image); value = LexicalUnitImpl.createDimension( prev, floatValue(op, t.image.substring(0, n+1)), t.image.substring(n+1)); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_INHERIT, t.image); } ) ( )* { if (value instanceof LexicalUnitImpl) { ((LexicalUnitImpl) value).setLocator(this.getLocator()); } return value; } } // // function // : FUNCTION S* expr ')' S* // ; // LexicalUnit function(LexicalUnit prev) : { Token t; LexicalUnit params; } { t = ( )* params = expr() { return this.functionInternal(prev, t, params); } } // // rgb // : RGB S* expr ')' S* // ; // LexicalUnit rgb(LexicalUnit prev) : { Token t; LexicalUnit params; } { t = ( )* params = expr() { return LexicalUnitImpl.createRgbColor(prev, params); } } // // hexcolor // : HASH S* // ; // LexicalUnit hexcolor(LexicalUnit prev) : { Token t; } { t = { return this.hexcolorInternal(prev, t); } } JAVACODE void skipSelector() { Token t = getToken(1); while (t.kind != COMMA && t.kind != SEMICOLON && t.kind != LBRACE && t.kind != EOF ) { getNextToken(); t = getToken(1); } } JAVACODE String skip() { StringBuffer sb = new StringBuffer(); int nesting = 0; Token t = getToken(0); if (t.image != null) { sb.append(t.image); } do { t = getNextToken(); if (t.kind == EOF) break; sb.append(t.image); if (t.kind == LBRACE) nesting++; else if (t.kind == RBRACE) nesting--; else if (t.kind == SEMICOLON && nesting <= 0) break; } while ((t.kind != RBRACE) || (nesting > 0)); return sb.toString(); } JAVACODE void error_skipblock() { Token t; int nesting = 0; do { t = getNextToken(); if (t.kind == LBRACE) { nesting++; } else if (t.kind == RBRACE) { nesting--; } else if (t.kind == EOF) { break; } } while ((t.kind != RBRACE) || (nesting > 0)); } JAVACODE void error_skipdecl() { int nesting = 0; Token t = getToken(1); if (t.kind == LBRACE) { error_skipblock(); } else { Token oldToken = t; while (t.kind != SEMICOLON && t.kind != RBRACE && t.kind != EOF ) { oldToken = t; t = getNextToken(); } if (t.kind == RBRACE) { token = oldToken; } } } JAVACODE void error_skipAtRule() { Token t = null; do { t = getNextToken(); } while (t.kind != SEMICOLON); }cssparser-0.9.5/src/main/javacc/SACParserCSS1.jj0000644000175000017500000005767210770335722021105 0ustar cavedoncavedon/* * $Id: SACParserCSS1.jj,v 1.1 2008/03/20 01:20:18 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2008 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ options { IGNORE_CASE = true; STATIC = false; // UNICODE_INPUT = false; USER_CHAR_STREAM = true; // DEBUG_TOKEN_MANAGER = true; // DEBUG_PARSER = true; } PARSER_BEGIN(SACParserCSS1) package com.steadystate.css.parser; import java.io.*; import java.net.*; import java.text.MessageFormat; import java.util.*; import org.w3c.css.sac.*; import com.steadystate.css.parser.*; import com.steadystate.css.parser.selectors.*; /** * @author David Schweinsberg * @version $Id: SACParserCSS1.jj,v 1.1 2008/03/20 01:20:18 sdanig Exp $ */ public class SACParserCSS1 extends AbstractSACParser implements Parser { private boolean _quiet = true; public SACParserCSS1() { this((CharStream) null); } public String getParserVersion() { return "http://www.w3.org/TR/REC-CSS1"; } protected String getGrammarUri() { return "http://www.w3.org/TR/REC-CSS1#appendix-b"; } protected Token getToken() { return this.token; } public void mediaList(SACMediaListImpl ml) { } } PARSER_END(SACParserCSS1) TOKEN_MGR_DECLS : { private boolean _quiet = true; private ErrorHandler errorHandler; private String trimBy(StringBuffer s, int left, int right) { int end = s.length(); return s.toString().substring(left, end-right); } private String trimUrl(StringBuffer s) { StringBuffer s1 = new StringBuffer( trimBy(s, 4, 1).trim() ); if (s1.length() == 0) { return s1.toString(); } int end = s1.length() - 1; if ((s1.charAt(0) == '"' && s1.charAt(end) == '"') || (s1.charAt(0) == '\'' && s1.charAt(end) == '\'')) return trimBy(s1, 1, 1); else return s1.toString(); } } TOKEN : { < S: ( " "|"\t"|"\r"|"\n"|"\f" )+ > } MORE : { < "/*" > : COMMENT } TOKEN : { < IDENT: ( )* > | < LINK_PSCLASS: ":link" > { matchedToken.image = trimBy(image, 1, 0); } | < VISITED_PSCLASS: ":visited" > { matchedToken.image = trimBy(image, 1, 0); } | < ACTIVE_PSCLASS: ":active" > { matchedToken.image = trimBy(image, 1, 0); } | < FIRST_LINE: ":first-line" > { matchedToken.image = trimBy(image, 1, 0); } | < FIRST_LETTER: ":first-letter" > { matchedToken.image = trimBy(image, 1, 0); } | < HASH: "#" > //| < CLASS: "." > } TOKEN : { < LBRACE: "{" > | < RBRACE: "}" > | < COMMA: "," > | < DOT: "." > | < SEMICOLON: ";" > | < COLON: ":" > | < ASTERISK: "*" > | < SLASH: "/" > | < PLUS: "+" > | < MINUS: "-" > | < EQUALS: "=" > | < GT: ">" > | < LSQUARE: "[" > | < RSQUARE: "]" > } TOKEN : { < STRING: | > { matchedToken.image = trimBy(image, 1, 1); } : DEFAULT | < RROUND: ")" > } // TODO: check url TOKEN : { // < #URL: ["!","#","$","%","&","*"-"~"] | | > // < #URL: ["!","#","$","%","&","*"-"[","]"-"~"] | | > < URL: "url(" ( )* ( | ( ["!","#","$","%","&","*"-"[","]"-"~"] | | )* ) ( )* > { matchedToken.image = trimUrl(image); } : DEFAULT } TOKEN : { < CDO: "" > : DEFAULT | < IMPORT_SYM: "@import" > : DEFAULT | < IMPORTANT_SYM: "!" ( )? "important" > : DEFAULT | < ATKEYWORD: "@" > | < EMS: "em" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < EXS: "ex" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_PX: "px" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_CM: "cm" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_MM: "mm" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_IN: "in" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_PT: "pt" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < LENGTH_PC: "pc" > { matchedToken.image = trimBy(image, 0, 2); } : DEFAULT | < PERCENTAGE: "%" > { matchedToken.image = trimBy(image, 0, 1); } : DEFAULT | < NUMBER: > : DEFAULT // TODO: check rgb | < RGB: "rgb(" > : DEFAULT | < #NAME: ( )+ > | < #D: ["0"-"9"] > | < NUM: ( )+ | ( )* "." ( )+ > // TODO: check unicoderange | < UNICODERANGE: "U+" ( | ( "-" ) ) > | < #RANGE: | ( ()? | ( ()? | ( ()? | ( ()? | ( ()? | ) ) ) ) ) > | < #Q16: "?" | "??" | "???" | "????" | "?????" | "??????" > | < #Q15: "?" | "??" | "???" | "????" | "?????" > | < #Q14: "?" | "??" | "???" | "????" > | < #Q13: "?" | "??" | "???" > | < #Q12: "?" | "??" > | < #Q11: "?" > // TODO: check latin1 // < LATIN1 : "\u0080"-"\uFFFF" > // < STRINGCHAR : | | [" ","!","#","$","%","&","(", "-", "~"] > // < NMCHAR: ["a"-"z","0"-"9","-"] | | // < NMSTRT: ["a"-"z"] | | > // < NOTNM: ["^", "-", "a-z", "0-9", "\"] | | < #NMSTART: ["a"-"z"] | | > | < #NMCHAR: ["a"-"z","0"-"9","-"] | | > // TODO: check strings //| < #STRING1: "\"" ( ["\t"," ","!","#","$","%","&","("-"~"] | "\\" | "\'" | | )* "\"" > //| < #STRING2: "\'" ( ["\t"," ","!","#","$","%","&","("-"~"] | "\\" | "\"" | | )* "\'" > | < #STRING1: "\"" ( ["\t"," ","!","#","$","%","&","("-"[","]"-"~"] | "\\" | "\'" | | )* "\"" > | < #STRING2: "\'" ( ["\t"," ","!","#","$","%","&","("-"[","]"-"~"] | "\\" | "\"" | | )* "\'" > | < #NONASCII: ["\u0080"-"\uFFFF"] > // TODO: check escape | < #ESCAPE: | ( "\\" [" "-"~","\u0080"-"\uFFFF"] ) > | < #NL: "\n" | "\r\n" | "\r" | "\f" > | < #UNICODE: "\\" ( " " | "\t" | "\r" | "\n" | "\f" )? > | < #HNUM: | | | | | > | < #H: ["0"-"9","a"-"f"] > } SKIP : { < "*/" > : DEFAULT } MORE : { < ~[] > : COMMENT } <*> TOKEN: { < UNKNOWN: ~[] > { if (!_quiet) { System.err.println("Illegal character : " + image.toString()); } } } // // stylesheet // : [S|CDO|CDC]* [ import [S|CDO|CDC]* ]* // [ ruleset [S|CDO|CDC]* ]* // ; // void styleSheet() : { } { try { { this.handleStartDocument(); } styleSheetRuleList() } finally { this.handleEndDocument(); } } // Although the grammar does not include [S|CDO|CDC] but [CDO|CDC], white space // should be allowed void styleSheetRuleList() : { } { ( | | )* ( importRule() ( | | )* )* ( ( styleRule() | unknownRule() ) ( | | )* )* ( ( styleRule() | importRuleIgnored() | unknownRule() ) ( | | )* )* } // // This is used by ASTStyleSheet.insertRule to parse a single rule // void styleSheetRuleSingle() : { } { ( importRule() | styleRule() | unknownRule() ) } void unknownRule() : { Token t; String s; } { try { t = { s = skip(); this.handleIgnorableAtRule(s); } } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidUnknownRule", e)); } } // // import // : IMPORT_SYM S* // [STRING|URI] ';' S* // ; // void importRule() : { Token t; // String s; } { try { ( )* ( t = | t = ) ( )* { this.handleImportStyle(unescape(t.image), new SACMediaListImpl(), null); } } catch (CSSParseException e) { this.getErrorHandler().error(e); this.error_skipAtRule(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidImportRule", e)); this.error_skipAtRule(); } } void importRuleIgnored() : { Token t; } { { ParseException e = generateParseException(); } try { ( )* ( t = | t = ) ( )* } finally { this.getErrorHandler().error(this.toCSSParseException("invalidImportRuleIgnored", e)); } } // // medium // : IDENT S* // ; // String medium() : { Token t; } { t = ( )* { this.handleMedium(t.image); return t.image; } } // // operator // : '/' | ',' | /* empty */ // ; // LexicalUnit operator(LexicalUnit prev) : { Token t; } { t = ( )* { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_SLASH); } | t = ( )* { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_COMMA); } } // // unary_operator // : '-' | '+' // ; // char unaryOperator() : { } { ( { return '-'; } | { return '+'; } ) } // // property // : IDENT S* // ; // String property() : { Token t; } { t = ( )* { return unescape(t.image); } } // // ruleset // : selector [ ',' S* selector ]* // '{' S* declaration [ ';' S* declaration ]* '}' S* // ; // void styleRule() : { SelectorList selList = null; boolean start = false; boolean noError = true; } { try { selList = selectorList() ( )* { start = true; this.handleStartSelector(selList); } // TODO: css 2 must have at least one declaration too ( declaration() ) ( ( )* ( declaration() )? )* } catch(CSSParseException e) { this.getErrorHandler().error(e); noError = false; this.error_skipblock(); } catch(ParseException e) { this.getErrorHandler().error(this.toCSSParseException("invalidStyleRule", e)); noError = false; this.error_skipblock(); } finally { if (start) { this.handleEndSelector(selList); } } } SelectorList selectorList() : { SelectorListImpl selList = new SelectorListImpl(); Selector sel; } { sel = selector() ( ( )* { selList.add(sel); } sel = selector() )* ( )* { selList.add(sel); return selList; } } // // selector // : simple_selector+ [ pseudo_element ]? // ; // Selector selector() : { Selector sel; } { try { sel = simpleSelector(null, ' ') ( LOOKAHEAD(2) sel = simpleSelector(sel, ' ') )* { this.handleSelector(sel); return sel; } } catch (ParseException e) { throw this.toCSSParseException("invalidSelector", e); //skipSelector(); } } // // simple_selector // : element_name id? class? pseudo_class? /* eg: H1.subject */ // | class? pseudo_class? /* eg: #xyz33 */ // | pseudo_class? /* eg: .author */ // ; // Selector simpleSelector(Selector sel, char comb) : { SimpleSelector simpleSel = null; Condition c = null; } { try { ( ( simpleSel = elementName() ( c = hash(c) )? ( c = _class(c) )? ( c = pseudoClass(c) )? ( c = pseudoElement(c) )? ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( ( c = hash(c) ) ( c = _class(c) )? ( c = pseudoClass(c) )? ( c = pseudoElement(c) )? ) ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( ( c = _class(c) ) ( c = pseudoClass(c) )? ( c = pseudoElement(c) )? ) ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( ( c = pseudoClass(c) ) ( c = pseudoElement(c) )? ) ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( ( c = pseudoElement(c) ) ) ) ) { if (c != null) { simpleSel = this.getSelectorFactory().createConditionalSelector(simpleSel, c); } if (sel != null) { switch (comb) { case ' ': sel = this.getSelectorFactory().createDescendantSelector(sel, simpleSel); break; } } else { sel = simpleSel; } return sel; } } catch (ParseException e) { throw this.toCSSParseException("invalidSimpleSelector", e); } } // // class // : '.' IDENT // ; // Condition _class(Condition pred) : { Token t; } { try { t = { Condition c = this.getConditionFactory().createClassCondition(null, t.image); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidClassSelector", e); } } // // element_name // : IDENT // ; // SimpleSelector elementName() : { Token t; } { try { t= { return this.getSelectorFactory().createElementSelector(null, unescape(t.image)); } | { return this.getSelectorFactory().createElementSelector(null, null); } } catch (ParseException e) { throw this.toCSSParseException("invalidElementName", e); } } // // pseudo // : ':' [ IDENT | S* ')' ] // ; // Condition pseudoClass(Condition pred) : { Condition c; Token t; } { try { ( (t = | t = | t = ) { // There appears to be an issue here regarding "first-letter" & "first-line" //String s = unescape(t.image); String s = t.image; c = this.getConditionFactory().createPseudoClassCondition(null, s); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } ) } catch (ParseException e) { throw this.toCSSParseException("invalidPseudoClass", e); } } // // pseudo // : ':' [ IDENT | S* ')' ] // ; // Condition pseudoElement(Condition pred) : { Condition c; Token t; } { try { ( t = | t = { //String s = unescape(t.image); String s = t.image; // TODO: createPseudoElementCondition c = this.getConditionFactory().createPseudoClassCondition(null, s); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } ) } catch (ParseException e) { throw this.toCSSParseException("invalidPseudoElement", e); } } Condition hash(Condition pred) : { Token t; } { try { t = { Condition c = this.getConditionFactory().createIdCondition(t.image.substring(1)); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidHash", e); } } void styleDeclaration() : { } { // ( )* ( declaration() )? ( ( )* ( declaration() )? )* // } // // declaration // : property ':' S* expr prio? // | // ; // void declaration() : { String p; LexicalUnit e; boolean priority = false; } { try { p = property() ( )* e = expr() ( priority = prio() )? { this.handleProperty(p, e, priority); } } catch (CSSParseException ex) { this.getErrorHandler().error(ex); error_skipdecl(); } catch (ParseException ex) { this.getErrorHandler().error(this.toCSSParseException("invalidDeclaration", ex)); error_skipdecl(); } } // // prio // : IMPORTANT_SYM S* // ; // boolean prio() : { } { ( )* { return true; } } // // expr // : term [ operator term ]* // ; // // TODO: Deal with the operator // LexicalUnit expr() : { LexicalUnit head; LexicalUnit body; } { try { head = term(null) { body = head; } ( ( body = operator(body) )? body = term(body) )* { return head; } } catch (ParseException ex) { throw this.toCSSParseException("invalidExpr", ex); } } // // term // : unary_operator? // [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | // STRING S* | URI S* | RGB S* | hexcolor ] // ; // LexicalUnit term(LexicalUnit prev) : { Token t; char op = ' '; String s; LexicalUnit value = null; // RGBColor color; // HexColor h; // CSSValueImpl value = null; } { /* ( ( op = unaryOperator() )? ( ( t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_NUMBER, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PERCENTAGE, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PX, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_CM, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_MM, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IN, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PT, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PC, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EMS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EXS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_STRING, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_URI, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + t.image ); } | color = rgb() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RGBCOLOR, color ); } | color = hexcolor() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RGBCOLOR, color ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_DIMENSION, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_INHERIT, op + t.image ); } ) ( )* ) { return value; } */ ( op = unaryOperator() )? ( ( t = { try { value = LexicalUnitImpl.createNumber(prev, intValue(op, t.image)); } catch (NumberFormatException e) { value = LexicalUnitImpl.createNumber(prev, floatValue(op, t.image)); } } | t = { value = LexicalUnitImpl.createPercentage(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPixel(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createCentimeter(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createMillimeter(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createInch(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPoint(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPica(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createEm(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createEx(prev, floatValue(op, t.image)); } ) | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_STRING_VALUE, t.image); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_IDENT, t.image); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_URI, t.image); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_UNICODERANGE, t.image); } | value = rgb(prev) | value = hexcolor(prev) ) ( )* { if (value instanceof LexicalUnitImpl) { ((LexicalUnitImpl) value).setLocator(this.getLocator()); } return value; } } // // rgb // : RGB S* expr ')' S* // ; // LexicalUnit rgb(LexicalUnit prev) : { Token t; LexicalUnit params; } { t = ( )* params = expr() { return LexicalUnitImpl.createRgbColor(prev, params); } } // // hexcolor // : HASH // ; // LexicalUnit hexcolor(LexicalUnit prev) : { Token t; } { t = { return this.hexcolorInternal(prev, t); } } JAVACODE void skipSelector() { Token t = getToken(1); while (t.kind != COMMA && t.kind != SEMICOLON && t.kind != LBRACE && t.kind != EOF ) { getNextToken(); t = getToken(1); } } JAVACODE String skip() { StringBuffer sb = new StringBuffer(); int nesting = 0; Token t = getToken(0); if (t.image != null) { sb.append(t.image); } do { t = getNextToken(); if (t.kind == EOF) break; sb.append(t.image); if (t.kind == LBRACE) nesting++; else if (t.kind == RBRACE) nesting--; else if (t.kind == SEMICOLON && nesting <= 0) break; } while ((t.kind != RBRACE) || (nesting > 0)); return sb.toString(); } JAVACODE void error_skipblock() { Token t; int nesting = 0; do { t = getNextToken(); if (t.kind == LBRACE) { nesting++; } else if (t.kind == RBRACE) { nesting--; } else if (t.kind == EOF) { break; } } while ((t.kind != RBRACE) || (nesting > 0)); } JAVACODE void error_skipdecl() { int nesting = 0; Token t = getToken(1); if (t.kind == LBRACE) { error_skipblock(); } else { Token oldToken = t; while (t.kind != SEMICOLON && t.kind != RBRACE && t.kind != EOF ) { oldToken = t; t = getNextToken(); } if (t.kind == RBRACE) { token = oldToken; } } } JAVACODE void error_skipAtRule() { Token t = null; do { t = getNextToken(); } while (t.kind != SEMICOLON); } cssparser-0.9.5/src/main/javacc/SACParserCSS21.jj0000644000175000017500000010122110772225635021146 0ustar cavedoncavedon/* * $Id: SACParserCSS21.jj,v 1.3 2008/03/25 16:43:09 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2008 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ options { IGNORE_CASE = true; STATIC = false; // UNICODE_INPUT = false; USER_CHAR_STREAM = true; // DEBUG_TOKEN_MANAGER = true; // DEBUG_PARSER = true; } PARSER_BEGIN(SACParserCSS21) package com.steadystate.css.parser; import java.io.*; import java.net.*; import java.text.MessageFormat; import java.util.*; import org.w3c.css.sac.*; import com.steadystate.css.parser.selectors.*; import com.steadystate.css.sac.TestCSSParseException; /** * @author David Schweinsberg * @version $Id: SACParserCSS21.jj,v 1.3 2008/03/25 16:43:09 sdanig Exp $ */ public class SACParserCSS21 extends AbstractSACParser implements Parser { private boolean _quiet = true; public SACParserCSS21() { this((CharStream) null); } public String getParserVersion() { return "http://www.w3.org/TR/CSS21/"; } protected String getGrammarUri() { return "http://www.w3.org/TR/CSS21/grammar.html"; } protected Token getToken() { return this.token; } } PARSER_END(SACParserCSS21) TOKEN_MGR_DECLS : { private boolean _quiet = true; private ErrorHandler errorHandler; public String splitNumber(StringBuffer pattern) { String regexp = "[0-9]+|[0-9]*.[0-9]+"; int j=1; while(pattern.substring(0, j).matches(regexp)) { j++; } if(pattern.substring(j-1, j).equals(".")) { j++; while(pattern.substring(0, j).matches(regexp)) { j++; } } return pattern.substring(0, j-1); } private String trimBy(StringBuffer s, int left, int right) { int end = s.length(); return s.toString().substring(left, end-right); } private String trimUrl(StringBuffer s) { StringBuffer s1 = new StringBuffer( trimBy(s, 4, 1).trim() ); if (s1.length() == 0) { return s1.toString(); } int end = s1.length() - 1; if ((s1.charAt(0) == '"' && s1.charAt(end) == '"') || (s1.charAt(0) == '\'' && s1.charAt(end) == '\'')) return trimBy(s1, 1, 1); else return s1.toString(); } } TOKEN : { < S: ( " "|"\t"|"\r"|"\n"|"\f" )+ > | < W: ( )? > } MORE : { < "/*" > : COMMENT } SKIP : { < "*/" > : DEFAULT } MORE : { < ~[] > : COMMENT } TOKEN : { < LBRACE: "{" > | < RBRACE: "}" > | < COMMA: "," > | < DOT: "." > | < SEMICOLON: ";" > | < COLON: ":" > | < ASTERISK: "*" > | < SLASH: "/" > | < PLUS: "+" > | < MINUS: "-" > | < EQUALS: "=" > | < LSQUARE: "[" > | < RSQUARE: "]" > | < GREATER: ">" > | < HASH: "#" > | < STRING: | > { matchedToken.image = trimBy(image, 1, 1); } | < RROUND: ")" > //| < INVALID: | > | < #URL: ["!","#","$","%","&","*"-"[","]"-"~"] | | > | < URI: "url(" ( )* ( | ( )* ) ( )* > { matchedToken.image = trimUrl(image); } | < CDO: "" > | < INCLUDES: "~=" > | < DASHMATCH: "|=" > | < IMPORT_SYM: "@import" > | < PAGE_SYM: "@page" > | < MEDIA_SYM: "@media" > | < CHARSET_SYM: "@charset " > | < ATKEYWORD: "@" > | < IMPORTANT_KEYWORD: "important" > | < IMPORTANT_SYM: "!" > | < INHERIT: "inherit" > | < EMS: > { matchedToken.image = splitNumber(image); } | < EXS: > { matchedToken.image = splitNumber(image); } | < LENGTH_PX: > { matchedToken.image = splitNumber(image); } | < LENGTH_CM: > { matchedToken.image = splitNumber(image); } | < LENGTH_MM: > { matchedToken.image = splitNumber(image); } | < LENGTH_IN: > { matchedToken.image = splitNumber(image); } | < LENGTH_PT: > { matchedToken.image = splitNumber(image); } | < LENGTH_PC: > { matchedToken.image = splitNumber(image); } | < ANGLE_DEG: > { matchedToken.image = splitNumber(image); } | < ANGLE_RAD: > { matchedToken.image = splitNumber(image); } | < ANGLE_GRAD: > { matchedToken.image = splitNumber(image); } | < TIME_MS: > { matchedToken.image = splitNumber(image); } | < TIME_S: > { matchedToken.image = splitNumber(image); } | < FREQ_HZ: > { matchedToken.image = splitNumber(image); } | < FREQ_KHZ: > { matchedToken.image = splitNumber(image); } | < DIMENSION: > | < PERCENTAGE: "%" > { matchedToken.image = splitNumber(image); } | < NUMBER: > // handled by FUNCTION in CSS 2.1 | < RGB: "rgb(" > | < FUNCTION: "(" > | < IDENT: ()? ( )* > | < #NAME: ( )+ > | < NUM: ( ["0"-"9"] )+ | ( ["0"-"9"] )* "." ( ["0"-"9"] )+ > | < #Q16: "?" | "??" | "???" | "????" | "?????" | "??????" > | < #Q15: "?" | "??" | "???" | "????" | "?????" > | < #Q14: "?" | "??" | "???" | "????" > | < #Q13: "?" | "??" | "???" > | < #Q12: "?" | "??" > | < #Q11: "?" > | < #NMSTART: ["_","a"-"z"] | | > | < #NMCHAR: ["_","a"-"z","0"-"9","-"] | | > | < #STRING1: "\"" ( ~["\n","\r","\f","\""] | "\\" | )* "\"" > | < #STRING2: "\'" ( ~["\n","\r","\f"] | "\\" | )* "\'" > // TODO: check //| < #INVALID1: "\"" ( ~["\n","\r","\f"] | "\\" | )* > //| < #INVALID2: "\'" ( ~["\n","\r","\f"] | "\\" | )* > | < #NONASCII: ["\u0080"-"\uFFFF"] > | < #ESCAPE: | ( "\\" ~["\r","\n","\f","0"-"9","a"-"f"] ) > | < #NL: "\n" | "\r\n" | "\r" | "\f" > | < #A_LETTER: "a" | "\\" ( "0" | "00" | "000" | "0000" ) ( "41" | "61" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? > | < #C_LETTER: "c" | "\\" ( "0" | "00" | "000" | "0000" ) ( "43" | "63" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? > | < #D_LETTER: "d" | "\\" ( "0" | "00" | "000" | "0000" ) ( "44" | "64" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? > | < #E_LETTER: "e" | "\\" ( "0" | "00" | "000" | "0000" ) ( "45" | "65" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? > | < #G_LETTER: "g" | "\\" ( "0" | "00" | "000" | "0000" ) ( "47" | "67" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "g" > | < #H_LETTER: "h" | "\\" ( "0" | "00" | "000" | "0000" ) ( "48" | "68" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "h" > | < #I_LETTER: "i" | "\\" ( "0" | "00" | "000" | "0000" ) ( "49" | "69" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "i" > | < #K_LETTER: "k" | "\\" ( "0" | "00" | "000" | "0000" ) ( "4b" | "6b" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "k" > | < #M_LETTER: "m" | "\\" ( "0" | "00" | "000" | "0000" ) ( "4d" | "6d" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "m" > | < #N_LETTER: "n" | "\\" ( "0" | "00" | "000" | "0000" ) ( "4e" | "6e" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "n" > | < #P_LETTER: "p" | "\\" ( "0" | "00" | "000" | "0000" ) ( "50" | "70" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "p" > | < #R_LETTER: "r" | "\\" ( "0" | "00" | "000" | "0000" ) ( "52" | "72" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "r" > | < #S_LETTER: "s" | "\\" ( "0" | "00" | "000" | "0000" ) ( "53" | "73" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "s" > | < #T_LETTER: "t" | "\\" ( "0" | "00" | "000" | "0000" ) ( "54" | "74" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "t" > | < #X_LETTER: "x" | "\\" ( "0" | "00" | "000" | "0000" ) ( "58" | "78" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "x" > | < #Z_LETTER: "z" | "\\" ( "0" | "00" | "000" | "0000" ) ( "5a" | "7a" ) ( "\r\n" | [ " ", "\t", "\r", "\n", "\f"])? | "\\" "z" > | < #UNICODE: "\\" ( "\r\n" | ( " " | "\t" | "\r" | "\n" | "\f" )? ) > | < #HNUM: | | | | | > | < #H: ["0"-"9","a"-"f"] > } <*> TOKEN: { < UNKNOWN: ~[] > { if (!_quiet) { System.err.println("Illegal character : " + image.toString()); } } } // // stylesheet // : [ CHARSET_SYM STRING ';' ]? // [S|CDO|CDC]* [ import [S|CDO|CDC]* ]* // [ [ ruleset | media | page ] [S|CDO|CDC]* ]* // ; // void styleSheet() : { } { try { { this.handleStartDocument(); } styleSheetRuleList() } finally { this.handleEndDocument(); } } void styleSheetRuleList() : { } { ( charsetRule() )? ( | | )* ( importRule() ( | | )* )* ( ( styleRule() | mediaRule() | pageRule() ) ( | | )* )* ( ( styleRule() | mediaRule() | pageRule() | importRuleIgnored() ) ( | | )* )* } // // This is used by ASTStyleSheet.insertRule to parse a single rule // void styleSheetRuleSingle() : { } { ( charsetRule() | importRule() | styleRule() | mediaRule() | pageRule() | unknownRule() ) } void charsetRule() : { Token t; } { try { t = { this.handleCharset(t.toString()); } } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidCharsetRule", e)); } } void unknownRule() : { Token t; String s; } { try { t = { s = skip(); this.handleIgnorableAtRule(s); } } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidUnknownRule", e)); } } // // import // : IMPORT_SYM S* // [STRING|URI] S* [ medium [ COMMA S* medium]* ]? ';' S* // ; // void importRule() : { Token t; // String s; SACMediaListImpl ml = new SACMediaListImpl(); } { try { ( )* ( t = | t = ) ( )* ( mediaList(ml) )? { this.handleImportStyle(unescape(t.image), ml, null); } } catch (CSSParseException e) { this.getErrorHandler().error(e); this.error_skipAtRule(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidImportRule", e)); this.error_skipAtRule(); } } void importRuleIgnored() : { Token t; SACMediaListImpl ml = new SACMediaListImpl(); } { { ParseException e = generateParseException(); } try { ( )* ( t = | t = ) ( )* ( mediaList(ml) )? } finally { this.getErrorHandler().error(this.toCSSParseException("invalidImportRuleIgnored", e)); } } // // media // : MEDIA_SYM S* medium [ COMMA S* medium ]* LBRACE S* ruleset* '}' S* // ; // void mediaRule() : { boolean start = false; SACMediaListImpl ml = new SACMediaListImpl(); } { try { ( )* mediaList(ml) { start = true; this.handleStartMedia(ml); } ( )* ( mediaRuleList() )? } catch (CSSParseException e) { this.getErrorHandler().error(e); this.error_skipblock(); } catch(ParseException e) { CSSParseException cpe = this.toCSSParseException("invalidMediaRule", e); this.getErrorHandler().error(cpe); this.getErrorHandler().warning(this.createSkipWarning("ignoringRule", cpe)); this.error_skipblock(); } finally { if (start) { this.handleEndMedia(ml); } } } void mediaList(SACMediaListImpl ml) : { String s; } { try { s = medium() ( ( )* { ml.add(s); } s = medium() )* { ml.add(s); } } catch(ParseException e) { throw this.toCSSParseException("invalidMediaList", e); } } void mediaRuleList() : { } { ( ( styleRule() | pageRule() | unknownRule() ) ( )* )+ } void mediaRuleSingle() : { } { ( styleRule() | pageRule() | unknownRule() ) } // // medium // : IDENT S* // ; // String medium() : { Token t; } { t = ( )* { return t.image; } } // // page // : PAGE_SYM S* pseudo_page? S* // LBRACE S* declaration [ ';' S* declaration ]* '}' S* // ; // void pageRule() : { Token t = null; String s = null; boolean start = false; } { try { ( )* ( LOOKAHEAD(2) ( s = pseudoPage() ( )* ) )? ( )* { start = true; this.handleStartPage((t != null) ? unescape(t.image) : null, s); } ( declaration() )? ( ( )* ( declaration() )? )* } catch(ParseException e) { throw this.toCSSParseException("invalidPageRule", e); } finally { if (start) { this.handleEndPage((t != null) ? unescape(t.image) : null, s); } } } // // pseudoPage // : ':' IDENT // ; // String pseudoPage() : { Token t; } { t = { return t.image; } } // // operator // : '/' S* | COMMA S* | /* empty */ // ; // LexicalUnit operator(LexicalUnit prev) : { Token t; } { t = ( )* { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_SLASH); } | t = ( )* { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_COMMA); } } // // combinator // : PLUS S* // | GREATER S* // | S // ; // char combinator() : { char c = ' '; } { ( { c='+'; } ( )* | { c='>'; } ( )* | ( ( { c='+'; } | { c='>'; } ) ( )* )? ) { return c; } } // // unary_operator // : '-' | PLUS // ; // char unaryOperator() : { } { ( { return '-'; } | { return '+'; } ) } // // property // : IDENT S* // ; // String property() : { Token t; } { t = ( )* { return unescape(t.image); } } // // ruleset // : selector [ COMMA S* selector ]* // LBRACE S* declaration [ ';' S* declaration ]* '}' S* // ; // void styleRule() : { SelectorList selList = null; boolean start = false; } { try { selList = selectorList() ( )* { start = true; this.handleStartSelector(selList); } styleDeclaration() /* ( declaration() )? ( ( )* ( declaration() )? )* */ } catch(CSSParseException e) { this.getErrorHandler().error(e); this.getErrorHandler().warning(this.createSkipWarning("ignoringRule", e)); this.error_skipblock(); } catch(ParseException e) { CSSParseException cpe = this.toCSSParseException("invalidStyleRule", e); this.getErrorHandler().error(cpe); this.getErrorHandler().warning(this.createSkipWarning("ignoringFollowingDeclarations", cpe)); this.error_skipblock(); } finally { if (start) { this.handleEndSelector(selList); } } } SelectorList selectorList() : { SelectorListImpl selList = new SelectorListImpl(); Selector sel; } { sel = selector() ( ( )* { selList.add(sel); } sel = selector() )* { selList.add(sel); return selList; } } // // selector // : simple_selector [ combinator simple_selector ]* // ; // Selector selector() : { Selector sel; char comb; } { try { sel = simpleSelector(null, ' ') ( LOOKAHEAD(2) comb = combinator() sel = simpleSelector(sel, comb) )* ( )* { return sel; } } catch (ParseException e) { throw this.toCSSParseException("invalidSelector", e); //skipSelector(); } } // // simple_selector // : element_name [ HASH | class | attrib | pseudo ]* // | [ HASH | class | attrib | pseudo ]+ // ; // Selector simpleSelector(Selector sel, char comb) : { SimpleSelector simpleSel = null; Condition c = null; } { try { ( ( simpleSel = elementName() ( c = hash(c) | c = _class(c) | c = attrib(c) | c = pseudo(c) )* ) | ( { simpleSel = this.getSelectorFactory().createElementSelector(null, null); } ( c = hash(c) | c = _class(c) | c = attrib(c) | c = pseudo(c) )+ ) ) { if (c != null) { simpleSel = this.getSelectorFactory().createConditionalSelector(simpleSel, c); } if (sel != null) { switch (comb) { case ' ': sel = this.getSelectorFactory().createDescendantSelector(sel, simpleSel); break; case '+': sel = this.getSelectorFactory().createDirectAdjacentSelector(sel.getSelectorType(), sel, simpleSel); break; case '>': sel = this.getSelectorFactory().createChildSelector(sel, simpleSel); break; } } else { sel = simpleSel; } return sel; } } catch (ParseException e) { throw this.toCSSParseException("invalidSimpleSelector", e); } } // // class // : '.' IDENT // ; // Condition _class(Condition pred) : { Token t; } { try { t = { Condition c = this.getConditionFactory().createClassCondition(null, t.image); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidClassSelector", e); } } // // element_name // : IDENT | '*' // ; // SimpleSelector elementName() : { Token t; } { try { t= { return this.getSelectorFactory().createElementSelector(null, unescape(t.image)); } | { return this.getSelectorFactory().createElementSelector(null, null); } } catch (ParseException e) { throw this.toCSSParseException("invalidElementName", e); } } // // attrib // : '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S* // [ IDENT | STRING ] S* ]? ']' // ; // Condition attrib(Condition pred) : { Token t; String name = null; String value = null; int type = 0; } { try { ( )* t = { name = unescape(t.image); } ( )* ( ( { type = 1; } | { type = 2; } | { type = 3; } ) ( )* ( t = { value = t.image; } | t = { value = unescape(t.image); } ) ( )* )? { Condition c = null; switch (type) { case 0: c = this.getConditionFactory().createAttributeCondition(name, null, false, null); break; case 1: c = this.getConditionFactory().createAttributeCondition(name, null, false, value); break; case 2: c = this.getConditionFactory().createOneOfAttributeCondition(name, null, false, value); break; case 3: c = this.getConditionFactory().createBeginHyphenAttributeCondition(name, null, false, value); break; } return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidAttrib", e); } } // // pseudo // : ':' [ IDENT | FUNCTION S* IDENT? S* ')' ] // ; // Condition pseudo(Condition pred) : { Condition c; Token t; String function; String arg = ""; } { try { ( t = { // There appears to be an issue here regarding "first-letter" & "first-line" //String s = unescape(t.image); String s = t.image; c = this.getConditionFactory().createPseudoClassCondition(null, s); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } | ( t = { function = unescape(t.image); } ( )* (t = { arg = unescape(t.image); })? ( )* { if (function.equalsIgnoreCase("lang(")) { c = this.getConditionFactory().createLangCondition(unescape(arg)); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } else { c = this.getConditionFactory().createPseudoClassCondition(null, function + arg + ")"); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } /* else { throw new TestCSSParseException( "Invalid pseudo function name " + function, getLocator(), this.getGrammarUri()); } */ } ) ) } catch (ParseException e) { throw this.toCSSParseException("invalidPseudo", e); } } Condition hash(Condition pred) : { Token t; } { try { t = { Condition c = this.getConditionFactory().createIdCondition(t.image.substring(1)); return (pred == null) ? c : this.getConditionFactory().createAndCondition(pred, c); } } catch (ParseException e) { throw this.toCSSParseException("invalidHash", e); } } void styleDeclaration() : { } { // ( )* try { ( declaration() )? ( ( )* ( declaration() )? )* } catch (ParseException ex) { this.getErrorHandler().error(this.toCSSParseException("invalidDeclaration", ex)); error_skipdecl(); } // } // // declaration // : property ':' S* expr prio? // | // ; // void declaration() : { String p; LexicalUnit e; boolean priority = false; } { try { p = property() ( )* e = expr() ( priority = prio() )? { this.handleProperty(p, e, priority); } } catch (CSSParseException ex) { this.getErrorHandler().error(ex); error_skipdecl(); } catch (ParseException ex) { this.getErrorHandler().error(this.toCSSParseException("invalidDeclaration", ex)); error_skipdecl(); } } // // prio // : IMPORTANT_SYM S* // ; // change to ( )* boolean prio() : { } { ( )* ( )* { return true; } } // // expr // : term [ operator term ]* // ; // // TODO: Deal with the operator // LexicalUnit expr() : { LexicalUnit head; LexicalUnit body; } { try { head = term(null) { body = head; } ( ( body = operator(body) )? body = term(body) )* { return head; } } catch (ParseException ex) { throw this.toCSSParseException("invalidExpr", ex); } } // // term // : unary_operator? // [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* | // TIME S* | FREQ S* ] // | STRING S* | IDENT S* | URI S* | hexcolor | function // ; // LexicalUnit term(LexicalUnit prev) : { Token t; char op = ' '; String s; LexicalUnit value = null; // RGBColor color; // HexColor h; // CSSValueImpl value = null; } { /* ( ( op = unaryOperator() )? ( ( t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_NUMBER, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PERCENTAGE, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PX, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_CM, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_MM, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IN, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PT, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_PC, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EMS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_EXS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_DEG, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RAD, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_GRAD, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_MS, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_S, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_HZ, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_KHZ, new Float( op + t.image ) ); }) | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_STRING, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + t.image ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_URI, op + t.image ); } | color = hexcolor() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_RGBCOLOR, color ); } | s = function() { value = new CSSValueImpl( CSSPrimitiveValue.CSS_IDENT, op + s ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_DIMENSION, new Float( op + t.image ) ); } | t = { value = new CSSValueImpl( CSSPrimitiveValue.CSS_INHERIT, op + t.image ); } ) ( )* ) { return value; } */ ( op = unaryOperator() )? ( ( t = { try { value = LexicalUnitImpl.createNumber(prev, intValue(op, t.image)); } catch (NumberFormatException e) { value = LexicalUnitImpl.createNumber(prev, floatValue(op, t.image)); } } | t = { value = LexicalUnitImpl.createPercentage(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPixel(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createCentimeter(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createMillimeter(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createInch(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPoint(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createPica(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createEm(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createEx(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createDegree(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createRadian(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createGradian(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createMillisecond(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createSecond(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createHertz(prev, floatValue(op, t.image)); } | t = { value = LexicalUnitImpl.createKiloHertz(prev, floatValue(op, t.image)); } | value = function(prev) ) | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_STRING_VALUE, unescape(t.image)); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_IDENT, t.image); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_URI, t.image); } | value = hexcolor(prev) | t = { int n = getLastNumPos(t.image); value = LexicalUnitImpl.createDimension( prev, floatValue(op, t.image.substring(0, n+1)), t.image.substring(n+1)); } | t = { value = new LexicalUnitImpl(prev, LexicalUnit.SAC_INHERIT, t.image); } ) ( )* { if (value instanceof LexicalUnitImpl) { ((LexicalUnitImpl) value).setLocator(this.getLocator()); } return value; } } // // function // : FUNCTION S* expr ')' S* // ; // LexicalUnit function(LexicalUnit prev) : { Token t; LexicalUnit params; } { t = ( )* params = expr() { return this.functionInternal(prev, t, params); } } // // rgb // : RGB S* expr ')' S* // ; // /* LexicalUnit rgb(LexicalUnit prev) : { Token t; LexicalUnit params; } { t = ( )* params = expr() { return LexicalUnitImpl.createRgbColor(prev, params); } } */ // // hexcolor // : HASH S* // ; // LexicalUnit hexcolor(LexicalUnit prev) : { Token t; } { t = { return this.hexcolorInternal(prev, t); } } JAVACODE void skipSelector() { Token t = getToken(1); while (t.kind != COMMA && t.kind != SEMICOLON && t.kind != LBRACE && t.kind != EOF ) { getNextToken(); t = getToken(1); } } JAVACODE String skip() { StringBuffer sb = new StringBuffer(); int nesting = 0; Token t = getToken(0); if (t.image != null) { sb.append(t.image); } do { t = getNextToken(); if (t.kind == EOF) break; sb.append(t.image); if (t.kind == LBRACE) nesting++; else if (t.kind == RBRACE) nesting--; else if (t.kind == SEMICOLON && nesting <= 0) break; } while ((t.kind != RBRACE) || (nesting > 0)); return sb.toString(); } JAVACODE void error_skipblock() { Token t; int nesting = 0; do { t = getNextToken(); if (t.kind == LBRACE) { nesting++; } else if (t.kind == RBRACE) { nesting--; } else if (t.kind == EOF) { break; } } while ((t.kind != RBRACE) || (nesting > 0)); } JAVACODE void error_skipdecl() { int nesting = 0; Token t = getToken(1); if (t.kind == LBRACE) { error_skipblock(); } else { Token oldToken = t; while (t.kind != SEMICOLON && t.kind != RBRACE && t.kind != EOF ) { oldToken = t; t = getNextToken(); } if (t.kind == RBRACE) { token = oldToken; } } } JAVACODE void error_skipAtRule() { Token t = null; do { t = getNextToken(); } while (t.kind != SEMICOLON); }cssparser-0.9.5/src/main/java/0000755000175000017500000000000011420645030016001 5ustar cavedoncavedoncssparser-0.9.5/src/main/java/com/0000755000175000017500000000000011420645030016557 5ustar cavedoncavedoncssparser-0.9.5/src/main/java/com/steadystate/0000755000175000017500000000000011420645030021111 5ustar cavedoncavedoncssparser-0.9.5/src/main/java/com/steadystate/css/0000755000175000017500000000000011420645030021701 5ustar cavedoncavedoncssparser-0.9.5/src/main/java/com/steadystate/css/userdata/0000755000175000017500000000000011420645030023511 5ustar cavedoncavedoncssparser-0.9.5/src/main/java/com/steadystate/css/userdata/UserDataConstants.java0000644000175000017500000000052010770335721027770 0ustar cavedoncavedon/* * Created on 13.04.2006 * */ package com.steadystate.css.userdata; public class UserDataConstants { private static final String KEY_PREFIX = UserDataConstants.class.getPackage().getName(); private UserDataConstants() { } public static final String KEY_LOCATOR = KEY_PREFIX + ".locator"; } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/0000755000175000017500000000000011420645030023175 5ustar cavedoncavedoncssparser-0.9.5/src/main/java/com/steadystate/css/parser/CSSOMParser.java0000644000175000017500000003743310772330067026125 0ustar cavedoncavedon/* * $Id: CSSOMParser.java,v 1.2 2008/03/26 02:08:55 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2008 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import java.io.IOException; import java.util.Properties; import java.util.Stack; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.ErrorHandler; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.LexicalUnit; import org.w3c.css.sac.Parser; import org.w3c.css.sac.SACMediaList; import org.w3c.css.sac.SelectorList; import org.w3c.dom.DOMException; import org.w3c.dom.Node; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSValue; import org.w3c.css.sac.helpers.ParserFactory; import com.steadystate.css.dom.CSSCharsetRuleImpl; import com.steadystate.css.dom.CSSFontFaceRuleImpl; import com.steadystate.css.dom.CSSImportRuleImpl; import com.steadystate.css.dom.CSSMediaRuleImpl; import com.steadystate.css.dom.CSSOMObject; import com.steadystate.css.dom.CSSPageRuleImpl; import com.steadystate.css.dom.CSSRuleListImpl; import com.steadystate.css.dom.CSSStyleDeclarationImpl; import com.steadystate.css.dom.CSSStyleRuleImpl; import com.steadystate.css.dom.CSSStyleSheetImpl; import com.steadystate.css.dom.CSSUnknownRuleImpl; import com.steadystate.css.dom.CSSValueImpl; import com.steadystate.css.dom.MediaListImpl; import com.steadystate.css.dom.Property; import com.steadystate.css.sac.DocumentHandlerExt; import com.steadystate.css.userdata.UserDataConstants; /** * * @author David Schweinsberg * @version $Id: CSSOMParser.java,v 1.2 2008/03/26 02:08:55 sdanig Exp $ */ public class CSSOMParser { private static final String PARSER = "com.steadystate.css.parser.SACParserCSS2"; private static boolean use_internal = false; private Parser _parser = null; private CSSStyleSheetImpl _parentStyleSheet = null; // TODO what is this _parentRule for? It is not read locally. //private CSSRule _parentRule = null; /** Creates new CSSOMParser */ public CSSOMParser() { try { // use the direct method if we already failed once before if(use_internal) { this._parser = new SACParserCSS2(); } else { setProperty("org.w3c.css.sac.parser", PARSER); ParserFactory factory = new ParserFactory(); this._parser = factory.makeParser(); } } catch (Exception e) { use_internal = true; System.err.println(e.getMessage()); e.printStackTrace(); System.err.println("using the default parser instead"); this._parser = new SACParserCSS2(); } } /** * Creates new CSSOMParser * * @param parser the SAC Parser */ public CSSOMParser(Parser parser) { this._parser = parser; } public void setErrorHandler(ErrorHandler eh) { this._parser.setErrorHandler(eh); } /** * Parses a SAC input source into a CSSOM style sheet. * * @param source the SAC input source * @param ownerNode the owner node (see the definition of * ownerNode in org.w3c.dom.css.StyleSheet) * @param href the href (see the definition of href in * org.w3c.dom.css.StyleSheet) * @return the CSSOM style sheet * @throws IOException if the underlying SAC parser throws an IOException */ public CSSStyleSheet parseStyleSheet(InputSource source, Node ownerNode, String href) throws IOException { CSSOMHandler handler = new CSSOMHandler(); handler.setOwnerNode(ownerNode); handler.setHref(href); this._parser.setDocumentHandler(handler); this._parser.parseStyleSheet(source); Object o = handler.getRoot(); if (o instanceof CSSStyleSheet) { return (CSSStyleSheet) handler.getRoot(); } return null; } /** * Parses a SAC input source into a CSSOM style declaration. * * @param source the SAC input source * @return the CSSOM style declaration * @throws IOException if the underlying SAC parser throws an IOException */ public CSSStyleDeclaration parseStyleDeclaration(InputSource source) throws IOException { CSSStyleDeclarationImpl sd = new CSSStyleDeclarationImpl(null); parseStyleDeclaration(sd, source); return sd; } public void parseStyleDeclaration(CSSStyleDeclaration sd, InputSource source) throws IOException { Stack nodeStack = new Stack(); nodeStack.push(sd); CSSOMHandler handler = new CSSOMHandler(nodeStack); this._parser.setDocumentHandler(handler); this._parser.parseStyleDeclaration(source); } public CSSValue parsePropertyValue(InputSource source) throws IOException { CSSOMHandler handler = new CSSOMHandler(); this._parser.setDocumentHandler(handler); return new CSSValueImpl(this._parser.parsePropertyValue(source)); } public CSSRule parseRule(InputSource source) throws IOException { CSSOMHandler handler = new CSSOMHandler(); this._parser.setDocumentHandler(handler); this._parser.parseRule(source); return (CSSRule) handler.getRoot(); } public SelectorList parseSelectors(InputSource source) throws IOException { HandlerBase handler = new HandlerBase(); this._parser.setDocumentHandler(handler); return this._parser.parseSelectors(source); } public void setParentStyleSheet(CSSStyleSheetImpl parentStyleSheet) { this._parentStyleSheet = parentStyleSheet; } protected CSSStyleSheetImpl getParentStyleSheet() { return this._parentStyleSheet; } // See _parentRule /* public void setParentRule(CSSRule parentRule) { _parentRule = parentRule; } */ class CSSOMHandler implements DocumentHandlerExt { private Stack _nodeStack; private Object _root = null; private Node ownerNode; private String href; private Node getOwnerNode() { return this.ownerNode; } private void setOwnerNode(Node ownerNode) { this.ownerNode = ownerNode; } private String getHref() { return this.href; } private void setHref(String href) { this.href = href; } public CSSOMHandler(Stack nodeStack) { this._nodeStack = nodeStack; } public CSSOMHandler() { this._nodeStack = new Stack(); } public Object getRoot() { return this._root; } public void startDocument(InputSource source) throws CSSException { if (this._nodeStack.empty()) { CSSStyleSheetImpl ss = new CSSStyleSheetImpl(); CSSOMParser.this.setParentStyleSheet(ss); ss.setOwnerNode(this.getOwnerNode()); ss.setBaseUri(source.getURI()); ss.setHref(this.getHref()); ss.setMediaText(source.getMedia()); ss.setTitle(source.getTitle()); // Create the rule list CSSRuleListImpl rules = new CSSRuleListImpl(); ss.setCssRules(rules); this._nodeStack.push(ss); this._nodeStack.push(rules); } else { // Error } } public void endDocument(InputSource source) throws CSSException { // Pop the rule list and style sheet nodes this._nodeStack.pop(); this._root = this._nodeStack.pop(); } public void comment(String text) throws CSSException { } public void ignorableAtRule(String atRule) throws CSSException { // Create the unknown rule and add it to the rule list CSSUnknownRuleImpl ir = new CSSUnknownRuleImpl( CSSOMParser.this.getParentStyleSheet(), this.getParentRule(), atRule); this.addLocator(ir); if (!this._nodeStack.empty()) { ((CSSRuleListImpl)this._nodeStack.peek()).add(ir); } else { // _nodeStack.push(ir); this._root = ir; } } public void namespaceDeclaration(String prefix, String uri) throws CSSException { } public void charset(String characterEncoding) throws CSSException { CSSCharsetRuleImpl cr = new CSSCharsetRuleImpl(CSSOMParser.this.getParentStyleSheet(), this.getParentRule(), characterEncoding); this.addLocator(cr); if (!this._nodeStack.empty()) { ((CSSRuleListImpl)this._nodeStack.peek()).add(cr); } else { this._root = cr; } } public void importStyle( String uri, SACMediaList media, String defaultNamespaceURI) throws CSSException { // Create the import rule and add it to the rule list CSSImportRuleImpl ir = new CSSImportRuleImpl( CSSOMParser.this.getParentStyleSheet(), this.getParentRule(), uri, new MediaListImpl(media)); this.addLocator(ir); if (!this._nodeStack.empty()) { ((CSSRuleListImpl)this._nodeStack.peek()).add(ir); } else { // _nodeStack.push(ir); this._root = ir; } } public void startMedia(SACMediaList media) throws CSSException { MediaListImpl ml = new MediaListImpl(media); this.addLocator(ml); // Create the media rule and add it to the rule list CSSMediaRuleImpl mr = new CSSMediaRuleImpl( CSSOMParser.this.getParentStyleSheet(), this.getParentRule(), ml); this.addLocator(mr); if (!this._nodeStack.empty()) { ((CSSRuleListImpl)this._nodeStack.peek()).add(mr); } // Create the rule list CSSRuleListImpl rules = new CSSRuleListImpl(); mr.setRuleList(rules); this._nodeStack.push(mr); this._nodeStack.push(rules); } public void endMedia(SACMediaList media) throws CSSException { // Pop the rule list and media rule nodes this._nodeStack.pop(); this._root = this._nodeStack.pop(); } public void startPage(String name, String pseudo_page) throws CSSException { // Create the page rule and add it to the rule list CSSPageRuleImpl pr = new CSSPageRuleImpl( CSSOMParser.this.getParentStyleSheet(), this.getParentRule(), name, pseudo_page); this.addLocator(pr); if (!this._nodeStack.empty()) { ((CSSRuleListImpl)this._nodeStack.peek()).add(pr); } // Create the style declaration CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(pr); pr.setStyle(decl); this._nodeStack.push(pr); this._nodeStack.push(decl); } public void endPage(String name, String pseudo_page) throws CSSException { // Pop both the style declaration and the page rule nodes this._nodeStack.pop(); this._root = this._nodeStack.pop(); } public void startFontFace() throws CSSException { // Create the font face rule and add it to the rule list CSSFontFaceRuleImpl ffr = new CSSFontFaceRuleImpl( CSSOMParser.this.getParentStyleSheet(), this.getParentRule()); this.addLocator(ffr); if (!this._nodeStack.empty()) { ((CSSRuleListImpl)this._nodeStack.peek()).add(ffr); } // Create the style declaration CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(ffr); ffr.setStyle(decl); this._nodeStack.push(ffr); this._nodeStack.push(decl); } public void endFontFace() throws CSSException { // Pop both the style declaration and the font face rule nodes this._nodeStack.pop(); this._root = this._nodeStack.pop(); } public void startSelector(SelectorList selectors) throws CSSException { // Create the style rule and add it to the rule list CSSStyleRuleImpl sr = new CSSStyleRuleImpl( CSSOMParser.this.getParentStyleSheet(), this.getParentRule(), selectors); this.addLocator(sr); if (!this._nodeStack.empty()) { Object o = this._nodeStack.peek(); ((CSSRuleListImpl)/*this._nodeStack.peek()*/o).add(sr); } // Create the style declaration CSSStyleDeclarationImpl decl = new CSSStyleDeclarationImpl(sr); sr.setStyle(decl); this._nodeStack.push(sr); this._nodeStack.push(decl); } public void endSelector(SelectorList selectors) throws CSSException { // Pop both the style declaration and the style rule nodes this._nodeStack.pop(); this._root = this._nodeStack.pop(); } public void property(String name, LexicalUnit value, boolean important) throws CSSException { CSSStyleDeclarationImpl decl = (CSSStyleDeclarationImpl) this._nodeStack.peek(); try { Property property = new Property(name, new CSSValueImpl(value), important); this.addLocator(property); decl.addProperty(property); } catch (DOMException e) { // call ErrorHandler? } } private CSSRule getParentRule() { if (!this._nodeStack.empty() && this._nodeStack.size() > 1) { Object node = this._nodeStack.get(this._nodeStack.size() - 2); if (node instanceof CSSRule) { return (CSSRule) node; } } return null; } private void addLocator(CSSOMObject cssomObject) { cssomObject.setUserData(UserDataConstants.KEY_LOCATOR, ((AbstractSACParser) CSSOMParser.this._parser).getLocator()); } } public static void setProperty(String key, String val) { Properties props = System.getProperties(); props.put(key, val); System.setProperties(props); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/0000755000175000017500000000000011420645030025200 5ustar cavedoncavedoncssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/LangConditionImpl.java0000644000175000017500000000360710770335721031435 0ustar cavedoncavedon/* * $Id: LangConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: LangConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class LangConditionImpl implements LangCondition, Serializable { private static final long serialVersionUID = 1701599531953055387L; private String lang; public void setLang(String lang) { this.lang = lang; } public LangConditionImpl(String lang) { this.lang = lang; } public LangConditionImpl() { } public short getConditionType() { return Condition.SAC_LANG_CONDITION; } public String getLang() { return this.lang; } public String toString() { return ":lang(" + this.getLang() + ")"; } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/ElementSelectorImpl.java0000644000175000017500000000405010770335721031770 0ustar cavedoncavedon/* * $Id: ElementSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: ElementSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class ElementSelectorImpl implements ElementSelector, Serializable { private static final long serialVersionUID = 7507121069969409061L; private String localName; public void setLocalName(String localName) { this.localName = localName; } public ElementSelectorImpl(String localName) { this. localName = localName; } public ElementSelectorImpl() { } public short getSelectorType() { return Selector.SAC_ELEMENT_NODE_SELECTOR; } public String getNamespaceURI() { return null; } public String getLocalName() { return this.localName; } public String toString() { return (this.getLocalName() != null) ? this.getLocalName() : "*"; } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/AndConditionImpl.java0000644000175000017500000000440410770335721031252 0ustar cavedoncavedon/* * $Id: AndConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: AndConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class AndConditionImpl implements CombinatorCondition, Serializable { private static final long serialVersionUID = -3180583860092672742L; private Condition firstCondition; private Condition secondCondition; public void setFirstCondition(Condition c1) { this.firstCondition = c1; } public void setSecondCondition(Condition c2) { this.secondCondition = c2; } public AndConditionImpl(Condition c1, Condition c2) { this.firstCondition = c1; this.secondCondition = c2; } public AndConditionImpl() { } public short getConditionType() { return Condition.SAC_AND_CONDITION; } public Condition getFirstCondition() { return this.firstCondition; } public Condition getSecondCondition() { return this.secondCondition; } public String toString() { return this.getFirstCondition().toString() + this.getSecondCondition().toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/IdConditionImpl.java0000644000175000017500000000410110770335721031076 0ustar cavedoncavedon/* * $Id: IdConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: IdConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class IdConditionImpl implements AttributeCondition, Serializable { private static final long serialVersionUID = 5955662524656167683L; private String value; public void setValue(String value) { this.value = value; } public IdConditionImpl(String value) { this.value = value; } public IdConditionImpl() { } public short getConditionType() { return Condition.SAC_ID_CONDITION; } public String getNamespaceURI() { return null; } public String getLocalName() { return null; } public boolean getSpecified() { return true; } public String getValue() { return this.value; } public String toString() { return "#" + this.getValue(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/DescendantSelectorImpl.java0000644000175000017500000000462610770335721032460 0ustar cavedoncavedon/* * $Id: DescendantSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: DescendantSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class DescendantSelectorImpl implements DescendantSelector, Serializable { private static final long serialVersionUID = -3620467847449531232L; private Selector ancestorSelector; private SimpleSelector simpleSelector; public void setAncestorSelector(Selector ancestorSelector) { this.ancestorSelector = ancestorSelector; } public void setSimpleSelector(SimpleSelector simpleSelector) { this.simpleSelector = simpleSelector; } public DescendantSelectorImpl(Selector parent, SimpleSelector simpleSelector) { this.ancestorSelector = parent; this.simpleSelector = simpleSelector; } public DescendantSelectorImpl() { } public short getSelectorType() { return Selector.SAC_DESCENDANT_SELECTOR; } public Selector getAncestorSelector() { return this.ancestorSelector; } public SimpleSelector getSimpleSelector() { return this.simpleSelector; } public String toString() { return this.getAncestorSelector().toString() + " " + this.getSimpleSelector().toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/AttributeConditionImpl.java0000644000175000017500000000466510770335721032524 0ustar cavedoncavedon/* * $Id: AttributeConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: AttributeConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class AttributeConditionImpl implements AttributeCondition, Serializable { private static final long serialVersionUID = 9035418830958954213L; private String localName; private String value; public void setLocaleName(String localName) { this.localName = localName; } public void setValue(String value) { this.value = value; } public AttributeConditionImpl(String localName, String value) { this.localName = localName; this.value = value; } public AttributeConditionImpl() { } public short getConditionType() { return Condition.SAC_ATTRIBUTE_CONDITION; } public String getNamespaceURI() { return null; } public String getLocalName() { return this.localName; } public boolean getSpecified() { return true; } public String getValue() { return this.value; } public String toString() { if (this.getValue() != null) { return "[" + this.getLocalName() + "=\"" + this.getValue() + "\"]"; } return "[" + this.getLocalName() + "]"; } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/SelectorFactoryImpl.java0000644000175000017500000000771510770335721032021 0ustar cavedoncavedon/* * $Id: SelectorFactoryImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: SelectorFactoryImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class SelectorFactoryImpl implements SelectorFactory { public ConditionalSelector createConditionalSelector( SimpleSelector selector, Condition condition) throws CSSException { return new ConditionalSelectorImpl(selector, condition); } public SimpleSelector createAnyNodeSelector() throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public SimpleSelector createRootNodeSelector() throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public NegativeSelector createNegativeSelector(SimpleSelector selector) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public ElementSelector createElementSelector(String namespaceURI, String localName) throws CSSException { if (namespaceURI != null) { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } return new ElementSelectorImpl(localName); } public CharacterDataSelector createTextNodeSelector(String data) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public CharacterDataSelector createCDataSectionSelector(String data) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public ProcessingInstructionSelector createProcessingInstructionSelector( String target, String data) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public CharacterDataSelector createCommentSelector(String data) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public ElementSelector createPseudoElementSelector( String namespaceURI, String pseudoName) throws CSSException { if (namespaceURI != null) { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } return new PseudoElementSelectorImpl(pseudoName); } public DescendantSelector createDescendantSelector( Selector parent, SimpleSelector descendant) throws CSSException { return new DescendantSelectorImpl(parent, descendant); } public DescendantSelector createChildSelector( Selector parent, SimpleSelector child) throws CSSException { return new ChildSelectorImpl(parent, child); } public SiblingSelector createDirectAdjacentSelector( short nodeType, Selector child, SimpleSelector directAdjacent) throws CSSException { return new DirectAdjacentSelectorImpl(nodeType, child, directAdjacent); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/ConditionFactoryImpl.java0000644000175000017500000001065010770335721032157 0ustar cavedoncavedon/* * $Id: ConditionFactoryImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: ConditionFactoryImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class ConditionFactoryImpl implements ConditionFactory { public CombinatorCondition createAndCondition( Condition first, Condition second) throws CSSException { return new AndConditionImpl(first, second); } public CombinatorCondition createOrCondition( Condition first, Condition second) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public NegativeCondition createNegativeCondition(Condition condition) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public PositionalCondition createPositionalCondition( int position, boolean typeNode, boolean type) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public AttributeCondition createAttributeCondition( String localName, String namespaceURI, boolean specified, String value) throws CSSException { // if ((namespaceURI != null) || !specified) { // throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); // } else { return new AttributeConditionImpl(localName, value); // } } public AttributeCondition createIdCondition(String value) throws CSSException { return new IdConditionImpl(value); } public LangCondition createLangCondition(String lang) throws CSSException { return new LangConditionImpl(lang); } public AttributeCondition createOneOfAttributeCondition( String localName, String namespaceURI, boolean specified, String value) throws CSSException { // if ((namespaceURI != null) || !specified) { // throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); // } else { return new OneOfAttributeConditionImpl(localName, value); // } } public AttributeCondition createBeginHyphenAttributeCondition( String localName, String namespaceURI, boolean specified, String value) throws CSSException { // if ((namespaceURI != null) || !specified) { // throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); // } else { return new BeginHyphenAttributeConditionImpl(localName, value); // } } public AttributeCondition createClassCondition( String namespaceURI, String value) throws CSSException { return new ClassConditionImpl(value); } public AttributeCondition createPseudoClassCondition( String namespaceURI, String value) throws CSSException { return new PseudoClassConditionImpl(value); } public Condition createOnlyChildCondition() throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public Condition createOnlyTypeCondition() throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public ContentCondition createContentCondition(String data) throws CSSException { throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/ChildSelectorImpl.java0000644000175000017500000000456010770335721031430 0ustar cavedoncavedon/* * $Id: ChildSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: ChildSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class ChildSelectorImpl implements DescendantSelector, Serializable { private static final long serialVersionUID = -5843289529637921083L; private Selector ancestorSelector; private SimpleSelector simpleSelector; public void setAncestorSelector(Selector ancestorSelector) { this.ancestorSelector = ancestorSelector; } public void setSimpleSelector(SimpleSelector simpleSelector) { this.simpleSelector = simpleSelector; } public ChildSelectorImpl(Selector parent, SimpleSelector simpleSelector) { this.ancestorSelector = parent; this.simpleSelector = simpleSelector; } public ChildSelectorImpl() { } public short getSelectorType() { return Selector.SAC_CHILD_SELECTOR; } public Selector getAncestorSelector() { return this.ancestorSelector; } public SimpleSelector getSimpleSelector() { return this.simpleSelector; } public String toString() { return this.ancestorSelector.toString() + " > " + this.simpleSelector.toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/DirectAdjacentSelectorImpl.java0000644000175000017500000000515310770335721033250 0ustar cavedoncavedon/* * $Id: DirectAdjacentSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: DirectAdjacentSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class DirectAdjacentSelectorImpl implements SiblingSelector, Serializable { private static final long serialVersionUID = -7328602345833826516L; private short nodeType; private Selector selector; // child private SimpleSelector siblingSelector; // direct adjacent public void setNodeType(short nodeType) { this.nodeType = nodeType; } public void setSelector(Selector child) { this.selector = child; } public void setSiblingSelector(SimpleSelector directAdjacent) { this.siblingSelector = directAdjacent; } public DirectAdjacentSelectorImpl(short nodeType, Selector child, SimpleSelector directAdjacent) { this.nodeType = nodeType; this.selector = child; this.siblingSelector = directAdjacent; } public DirectAdjacentSelectorImpl() { } public short getNodeType() { return this.nodeType; } public short getSelectorType() { return Selector.SAC_DIRECT_ADJACENT_SELECTOR; } public Selector getSelector() { return this.selector; } public SimpleSelector getSiblingSelector() { return this.siblingSelector; } public String toString() { return this.selector.toString() + " + " + this.siblingSelector.toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/PseudoClassConditionImpl.java0000644000175000017500000000417010770335721032775 0ustar cavedoncavedon/* * $Id: PseudoClassConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: PseudoClassConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class PseudoClassConditionImpl implements AttributeCondition, Serializable { private static final long serialVersionUID = 1798016773089155610L; private String value; public void setValue(String value) { this.value = value; } public PseudoClassConditionImpl(String value) { this.value = value; } public PseudoClassConditionImpl() { } public short getConditionType() { return Condition.SAC_PSEUDO_CLASS_CONDITION; } public String getNamespaceURI() { return null; } public String getLocalName() { return null; } public boolean getSpecified() { return true; } public String getValue() { return this.value; } public String toString() { return ":" + this.getValue(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/CharacterDataSelectorImpl.java0000644000175000017500000000366110770335721033074 0ustar cavedoncavedon/* * $Id: CharacterDataSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: CharacterDataSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class CharacterDataSelectorImpl implements CharacterDataSelector, Serializable { private static final long serialVersionUID = 4635511567927852889L; private String data; public void setData(String data) { this.data = data; } public CharacterDataSelectorImpl(String data) { this.data = data; } public CharacterDataSelectorImpl() { } public short getSelectorType() { return Selector.SAC_CDATA_SECTION_NODE_SELECTOR; } public String getData() { return this.data; } public String toString() { return this.getData(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/PseudoElementSelectorImpl.java0000644000175000017500000000372310770335721033156 0ustar cavedoncavedon/* * $Id: PseudoElementSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import org.w3c.css.sac.*; import java.io.Serializable; /** * * @author David Schweinsberg * @version $Id: PseudoElementSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class PseudoElementSelectorImpl implements ElementSelector, Serializable { private static final long serialVersionUID = 2913936296006875268L; private String localName; public void setLocaleName(String localName) { this.localName = localName; } public PseudoElementSelectorImpl(String localName) { this.localName = localName; } public PseudoElementSelectorImpl() { } public short getSelectorType() { return Selector.SAC_PSEUDO_ELEMENT_SELECTOR; } public String getNamespaceURI() { return null; } public String getLocalName() { return this.localName; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootcssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/BeginHyphenAttributeConditionImpl.javacssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/BeginHyphenAttributeConditionImpl0000644000175000017500000000462610770335721033722 0ustar cavedoncavedon/* * $Id: BeginHyphenAttributeConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: BeginHyphenAttributeConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class BeginHyphenAttributeConditionImpl implements AttributeCondition, Serializable { private static final long serialVersionUID = 6552118983276681650L; private String localName; private String value; public void setLocaleName(String localName) { this.localName = localName; } public void setValue(String value) { this.value = value; } public BeginHyphenAttributeConditionImpl(String localName, String value) { this.localName = localName; this.value = value; } public BeginHyphenAttributeConditionImpl() { } public short getConditionType() { return Condition.SAC_BEGIN_HYPHEN_ATTRIBUTE_CONDITION; } public String getNamespaceURI() { return null; } public String getLocalName() { return this.localName; } public boolean getSpecified() { return true; } public String getValue() { return this.value; } public String toString() { return "[" + this.getLocalName() + "|=\"" + this.getValue() + "\"]"; } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/ClassConditionImpl.java0000644000175000017500000000412410770335721031614 0ustar cavedoncavedon/* * $Id: ClassConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: ClassConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class ClassConditionImpl implements AttributeCondition, Serializable { private static final long serialVersionUID = -2216489300949054242L; private String value; public void setValue(String value) { this.value = value; } public ClassConditionImpl(String value) { this.value = value; } public ClassConditionImpl() { } public short getConditionType() { return Condition.SAC_CLASS_CONDITION; } public String getNamespaceURI() { return null; } public String getLocalName() { return null; } public boolean getSpecified() { return true; } public String getValue() { return this.value; } public String toString() { return "." + this.getValue(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/ConditionalSelectorImpl.java0000644000175000017500000000455010770335721032647 0ustar cavedoncavedon/* * $Id: ConditionalSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: ConditionalSelectorImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class ConditionalSelectorImpl implements ConditionalSelector, Serializable { private static final long serialVersionUID = 7217145899707580586L; private SimpleSelector simpleSelector; private Condition condition; public void setSimpleSelector(SimpleSelector simpleSelector) { this.simpleSelector = simpleSelector; } public void setCondition(Condition condition) { this.condition = condition; } public ConditionalSelectorImpl( SimpleSelector simpleSelector, Condition condition) { this.simpleSelector = simpleSelector; this.condition = condition; } public ConditionalSelectorImpl() { } public short getSelectorType() { return Selector.SAC_CONDITIONAL_SELECTOR; } public SimpleSelector getSimpleSelector() { return this.simpleSelector; } public Condition getCondition() { return this.condition; } public String toString() { return this.simpleSelector.toString() + this.condition.toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/selectors/OneOfAttributeConditionImpl.java0000644000175000017500000000456110770335721033446 0ustar cavedoncavedon/* * $Id: OneOfAttributeConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser.selectors; import java.io.Serializable; import org.w3c.css.sac.*; /** * * @author David Schweinsberg * @version $Id: OneOfAttributeConditionImpl.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ */ public class OneOfAttributeConditionImpl implements AttributeCondition, Serializable { private static final long serialVersionUID = -1371164446179830634L; private String localName; private String value; public void setLocalName(String localName) { this.localName = localName; } public void setValue(String value) { this.value = value; } public OneOfAttributeConditionImpl(String localName, String value) { this.localName = localName; this.value = value; } public OneOfAttributeConditionImpl() { } public short getConditionType() { return Condition.SAC_ONE_OF_ATTRIBUTE_CONDITION; } public String getNamespaceURI() { return null; } public String getLocalName() { return this.localName; } public boolean getSpecified() { return true; } public String getValue() { return this.value; } public String toString() { return "[" + this.getLocalName() + "~=\"" + this.getValue() + "\"]"; } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/SelectorListImpl.java0000644000175000017500000000442610772330067027316 0ustar cavedoncavedon/* * $Id: SelectorListImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import java.io.Serializable; import java.util.*; import org.w3c.css.sac.*; /** * Implementation of {@link SelectorList}. * * @author David Schweinsberg * @version $Id: SelectorListImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ */ public class SelectorListImpl implements SelectorList, Serializable { private static final long serialVersionUID = 7313376916207026333L; private List selectors = new ArrayList(10); public List getSelectors() { return this.selectors; } public void setSelectors(List selectors) { this.selectors = selectors; } public int getLength() { return this.selectors.size(); } public Selector item(int index) { return this.selectors.get(index); } public void add(Selector sel) { this.selectors.add(sel); } public String toString() { StringBuilder sb = new StringBuilder(); int len = getLength(); for (int i = 0; i < len; i++) { sb.append(item(i).toString()); if (i < len - 1) { sb.append(", "); } } return sb.toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/SACMediaListImpl.java0000644000175000017500000000372310772330067027103 0ustar cavedoncavedon/* * $Id: SACMediaListImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import java.util.*; import org.w3c.css.sac.*; /** * Implementation of {@link SACMediaList}. * * @author David Schweinsberg * @version $Id: SACMediaListImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ */ public class SACMediaListImpl implements SACMediaList { private List _selectors = new ArrayList(10); public int getLength() { return this._selectors.size(); } public String item(int index) { return this._selectors.get(index); } public void add(String s) { this._selectors.add(s); } public String toString() { StringBuilder sb = new StringBuilder(); int len = getLength(); for (int i = 0; i < len; i++) { sb.append(item(i)); if (i < len - 1) { sb.append(", "); } } return sb.toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/LocatorImpl.java0000644000175000017500000000625010772330067026302 0ustar cavedoncavedon/* * $Id: LocatorImpl.java,v 1.2 2008/03/26 02:08:55 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import java.io.Serializable; import org.w3c.css.sac.Locator; /** * Implementation of {@link Locator}. * * @author David Schweinsberg * @version $Id: LocatorImpl.java,v 1.2 2008/03/26 02:08:55 sdanig Exp $ */ public class LocatorImpl implements Locator, Serializable { private static final long serialVersionUID = 2240824537064705530L; private String uri; private int lineNumber; private int columnNumber; public String getUri() { return this.uri; } public void setUri(String uri) { this.uri = uri; } public void setLineNumber(int line) { this.lineNumber = line; } public void setColumnNumber(int column) { this.columnNumber = column; } /** Creates new LocatorImpl */ public LocatorImpl(String uri, int line, int column) { this.uri = uri; this.lineNumber = line; this.columnNumber = column; } public LocatorImpl() { } /** * Return the line number where the current document event ends. * Note that this is the line position of the first character * after the text associated with the document event. * @return The line number, or -1 if none is available. * @see #getColumnNumber */ public int getLineNumber() { return this.lineNumber; } /** * Return the URI for the current document event. * *

The parser must resolve the URI fully before passing it to the * application.

* * @return A string containing the URI, or null * if none is available. */ public String getURI() { return this.uri; } /** * Return the column number where the current document event ends. * Note that this is the column number of the first * character after the text associated with the document * event. The first column in a line is position 1. * @return The column number, or -1 if none is available. * @see #getLineNumber */ public int getColumnNumber() { return this.columnNumber; } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/LexicalUnitImpl.java0000644000175000017500000005777710772330067027144 0ustar cavedoncavedon/* * $Id: LexicalUnitImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import java.io.Serializable; import org.w3c.css.sac.*; /** * Implementation of {@link LexicalUnit}. * * @author David Schweinsberg * @version $Id: LexicalUnitImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ */ public class LexicalUnitImpl implements LexicalUnit, Serializable { /* public static final short SAC_OPERATOR_COMMA = 0; public static final short SAC_OPERATOR_PLUS = 1; public static final short SAC_OPERATOR_MINUS = 2; public static final short SAC_OPERATOR_MULTIPLY = 3; public static final short SAC_OPERATOR_SLASH = 4; public static final short SAC_OPERATOR_MOD = 5; public static final short SAC_OPERATOR_EXP = 6; public static final short SAC_OPERATOR_LT = 7; public static final short SAC_OPERATOR_GT = 8; public static final short SAC_OPERATOR_LE = 9; public static final short SAC_OPERATOR_GE = 10; public static final short SAC_OPERATOR_TILDE = 11; public static final short SAC_INHERIT = 12; public static final short SAC_INTEGER = 13; public static final short SAC_REAL = 14; public static final short SAC_EM = 15; public static final short SAC_EX = 16; public static final short SAC_PIXEL = 17; public static final short SAC_INCH = 18; public static final short SAC_CENTIMETER = 19; public static final short SAC_MILLIMETER = 20; public static final short SAC_POINT = 21; public static final short SAC_PICA = 22; public static final short SAC_PERCENTAGE = 23; public static final short SAC_URI = 24; public static final short SAC_COUNTER_FUNCTION = 25; public static final short SAC_COUNTERS_FUNCTION = 26; public static final short SAC_RGBCOLOR = 27; public static final short SAC_DEGREE = 28; public static final short SAC_GRADIAN = 29; public static final short SAC_RADIAN = 30; public static final short SAC_MILLISECOND = 31; public static final short SAC_SECOND = 32; public static final short SAC_HERTZ = 33; public static final short SAC_KILOHERTZ = 34; public static final short SAC_IDENT = 35; public static final short SAC_STRING_VALUE = 36; public static final short SAC_ATTR = 37; public static final short SAC_RECT_FUNCTION = 38; public static final short SAC_UNICODERANGE = 39; public static final short SAC_SUB_EXPRESSION = 40; public static final short SAC_FUNCTION = 41; public static final short SAC_DIMENSION = 42; */ private static final long serialVersionUID = -7260032046960116891L; private short lexicalUnitType; private LexicalUnit nextLexicalUnit; private LexicalUnit previousLexicalUnit; // private int _intVal; private float floatValue; private String dimension; private String functionName; private LexicalUnit parameters; private String stringValue; private Locator locator; public Locator getLocator() { return this.locator; } public void setLocator(Locator locator) { this.locator = locator; } public void setLexicalUnitType(short type) { this.lexicalUnitType = type; } public void setNextLexicalUnit(LexicalUnit next) { this.nextLexicalUnit = next; } public void setPreviousLexicalUnit(LexicalUnit prev) { this.previousLexicalUnit = prev; } public void setFloatValue(float floatVal) { this.floatValue = floatVal; } public String getDimension() { return this.dimension; } public void setDimension(String dimension) { this.dimension = dimension; } public void setFunctionName(String function) { this.functionName = function; } public void setParameters(LexicalUnit params) { this.parameters = params; } public void setStringValue(String stringVal) { this.stringValue = stringVal; } protected LexicalUnitImpl(LexicalUnit previous, short type) { this.lexicalUnitType = type; this.previousLexicalUnit = previous; if (this.previousLexicalUnit != null) { ((LexicalUnitImpl)this.previousLexicalUnit).nextLexicalUnit = this; } } /** * Integer */ protected LexicalUnitImpl(LexicalUnit previous, int value) { this(previous, SAC_INTEGER); // _intVal = value; this.floatValue = value; } /** * Dimension */ protected LexicalUnitImpl(LexicalUnit previous, short type, float value) { this(previous, type); this.floatValue = value; } /** * Unknown dimension */ protected LexicalUnitImpl( LexicalUnit previous, short type, String dimension, float value) { this(previous, type); this.dimension = dimension; this.floatValue = value; } /** * String */ protected LexicalUnitImpl(LexicalUnit previous, short type, String value) { this(previous, type); this.stringValue = value; } /** * Function */ protected LexicalUnitImpl( LexicalUnit previous, short type, String name, LexicalUnit params) { this(previous, type); this.functionName = name; this.parameters = params; } public LexicalUnitImpl() { } public short getLexicalUnitType() { return this.lexicalUnitType; } public LexicalUnit getNextLexicalUnit() { return this.nextLexicalUnit; } public LexicalUnit getPreviousLexicalUnit() { return this.previousLexicalUnit; } public int getIntegerValue() { // return _intVal; return (int) this.floatValue; } public float getFloatValue() { return this.floatValue; } public String getDimensionUnitText() { switch (this.lexicalUnitType) { case SAC_EM: return "em"; case SAC_EX: return "ex"; case SAC_PIXEL: return "px"; case SAC_INCH: return "in"; case SAC_CENTIMETER: return "cm"; case SAC_MILLIMETER: return "mm"; case SAC_POINT: return "pt"; case SAC_PICA: return "pc"; case SAC_PERCENTAGE: return "%"; case SAC_DEGREE: return "deg"; case SAC_GRADIAN: return "grad"; case SAC_RADIAN: return "rad"; case SAC_MILLISECOND: return "ms"; case SAC_SECOND: return "s"; case SAC_HERTZ: return "Hz"; case SAC_KILOHERTZ: return "kHz"; case SAC_DIMENSION: return this.dimension; } return ""; } public String getFunctionName() { return this.functionName; } public LexicalUnit getParameters() { return this.parameters; } public String getStringValue() { return this.stringValue; } public LexicalUnit getSubValues() { return this.parameters; } public String toString() { StringBuilder sb = new StringBuilder(); switch (this.lexicalUnitType) { case SAC_OPERATOR_COMMA: sb.append(","); break; case SAC_OPERATOR_PLUS: sb.append("+"); break; case SAC_OPERATOR_MINUS: sb.append("-"); break; case SAC_OPERATOR_MULTIPLY: sb.append("*"); break; case SAC_OPERATOR_SLASH: sb.append("/"); break; case SAC_OPERATOR_MOD: sb.append("%"); break; case SAC_OPERATOR_EXP: sb.append("^"); break; case SAC_OPERATOR_LT: sb.append("<"); break; case SAC_OPERATOR_GT: sb.append(">"); break; case SAC_OPERATOR_LE: sb.append("<="); break; case SAC_OPERATOR_GE: sb.append(">="); break; case SAC_OPERATOR_TILDE: sb.append("~"); break; case SAC_INHERIT: sb.append("inherit"); break; case SAC_INTEGER: sb.append(String.valueOf(this.getIntegerValue())); break; case SAC_REAL: sb.append(this.trimFloat(this.getFloatValue())); break; case SAC_EM: case SAC_EX: case SAC_PIXEL: case SAC_INCH: case SAC_CENTIMETER: case SAC_MILLIMETER: case SAC_POINT: case SAC_PICA: case SAC_PERCENTAGE: case SAC_DEGREE: case SAC_GRADIAN: case SAC_RADIAN: case SAC_MILLISECOND: case SAC_SECOND: case SAC_HERTZ: case SAC_KILOHERTZ: case SAC_DIMENSION: sb.append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()); break; case SAC_URI: sb.append("url(").append(this.getStringValue()).append(")"); break; case SAC_COUNTER_FUNCTION: sb.append("counter("); appendParams(sb, this.parameters); sb.append(")"); break; case SAC_COUNTERS_FUNCTION: sb.append("counters("); appendParams(sb, this.parameters); sb.append(")"); break; case SAC_RGBCOLOR: sb.append("rgb("); appendParams(sb, this.parameters); sb.append(")"); break; case SAC_IDENT: sb.append(this.getStringValue()); break; case SAC_STRING_VALUE: sb.append("\"").append(this.getStringValue()).append("\""); break; case SAC_ATTR: sb.append("attr("); appendParams(sb, this.parameters); sb.append(")"); break; case SAC_RECT_FUNCTION: sb.append("rect("); appendParams(sb,this. parameters); sb.append(")"); break; case SAC_UNICODERANGE: sb.append(this.getStringValue()); break; case SAC_SUB_EXPRESSION: sb.append(this.getStringValue()); break; case SAC_FUNCTION: sb.append(this.getFunctionName()).append('('); appendParams(sb, this.parameters); sb.append(")"); break; } return sb.toString(); } public String toDebugString() { StringBuilder sb = new StringBuilder(); switch (this.lexicalUnitType) { case SAC_OPERATOR_COMMA: sb.append("SAC_OPERATOR_COMMA"); break; case SAC_OPERATOR_PLUS: sb.append("SAC_OPERATOR_PLUS"); break; case SAC_OPERATOR_MINUS: sb.append("SAC_OPERATOR_MINUS"); break; case SAC_OPERATOR_MULTIPLY: sb.append("SAC_OPERATOR_MULTIPLY"); break; case SAC_OPERATOR_SLASH: sb.append("SAC_OPERATOR_SLASH"); break; case SAC_OPERATOR_MOD: sb.append("SAC_OPERATOR_MOD"); break; case SAC_OPERATOR_EXP: sb.append("SAC_OPERATOR_EXP"); break; case SAC_OPERATOR_LT: sb.append("SAC_OPERATOR_LT"); break; case SAC_OPERATOR_GT: sb.append("SAC_OPERATOR_GT"); break; case SAC_OPERATOR_LE: sb.append("SAC_OPERATOR_LE"); break; case SAC_OPERATOR_GE: sb.append("SAC_OPERATOR_GE"); break; case SAC_OPERATOR_TILDE: sb.append("SAC_OPERATOR_TILDE"); break; case SAC_INHERIT: sb.append("SAC_INHERIT"); break; case SAC_INTEGER: sb.append("SAC_INTEGER(") .append(String.valueOf(this.getIntegerValue())) .append(")"); break; case SAC_REAL: sb.append("SAC_REAL(") .append(this.trimFloat(this.getFloatValue())) .append(")"); break; case SAC_EM: sb.append("SAC_EM(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_EX: sb.append("SAC_EX(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_PIXEL: sb.append("SAC_PIXEL(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_INCH: sb.append("SAC_INCH(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_CENTIMETER: sb.append("SAC_CENTIMETER(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_MILLIMETER: sb.append("SAC_MILLIMETER(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_POINT: sb.append("SAC_POINT(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_PICA: sb.append("SAC_PICA(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_PERCENTAGE: sb.append("SAC_PERCENTAGE(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_DEGREE: sb.append("SAC_DEGREE(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_GRADIAN: sb.append("SAC_GRADIAN(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_RADIAN: sb.append("SAC_RADIAN(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_MILLISECOND: sb.append("SAC_MILLISECOND(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_SECOND: sb.append("SAC_SECOND(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_HERTZ: sb.append("SAC_HERTZ(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_KILOHERTZ: sb.append("SAC_KILOHERTZ(") .append(trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_DIMENSION: sb.append("SAC_DIMENSION(") .append(this.trimFloat(this.getFloatValue())) .append(this.getDimensionUnitText()) .append(")"); break; case SAC_URI: sb.append("SAC_URI(url(") .append(this.getStringValue()) .append("))"); break; case SAC_COUNTER_FUNCTION: sb.append("SAC_COUNTER_FUNCTION(counter("); appendParams(sb, this.parameters); sb.append("))"); break; case SAC_COUNTERS_FUNCTION: sb.append("SAC_COUNTERS_FUNCTION(counters("); appendParams(sb, this.parameters); sb.append("))"); break; case SAC_RGBCOLOR: sb.append("SAC_RGBCOLOR(rgb("); appendParams(sb, this.parameters); sb.append("))"); break; case SAC_IDENT: sb.append("SAC_IDENT(") .append(this.getStringValue()) .append(")"); break; case SAC_STRING_VALUE: sb.append("SAC_STRING_VALUE(\"") .append(this.getStringValue()) .append("\")"); break; case SAC_ATTR: sb.append("SAC_ATTR(attr("); appendParams(sb, this.parameters); sb.append("))"); break; case SAC_RECT_FUNCTION: sb.append("SAC_RECT_FUNCTION(rect("); appendParams(sb, this.parameters); sb.append("))"); break; case SAC_UNICODERANGE: sb.append("SAC_UNICODERANGE(") .append(this.getStringValue()) .append(")"); break; case SAC_SUB_EXPRESSION: sb.append("SAC_SUB_EXPRESSION(") .append(this.getStringValue()) .append(")"); break; case SAC_FUNCTION: sb.append("SAC_FUNCTION(") .append(this.getFunctionName()) .append("("); appendParams(sb, this.parameters); sb.append("))"); break; } return sb.toString(); } private void appendParams(StringBuilder sb, LexicalUnit first) { LexicalUnit l = first; while (l != null) { sb.append(l.toString()); l = l.getNextLexicalUnit(); } } private String trimFloat(float f) { String s = String.valueOf(this.getFloatValue()); return (f - (int) f != 0) ? s : s.substring(0, s.length() - 2); } // TODO what is this method for? It is not used locally. /* private static float value(char op, String s) { return ((op == '-') ? -1 : 1) * Float.valueOf(s).floatValue(); } */ public static LexicalUnit createNumber(LexicalUnit prev, int i) { return new LexicalUnitImpl(prev, i); } public static LexicalUnit createNumber(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_REAL, f); } public static LexicalUnit createPercentage(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_PERCENTAGE, f); } public static LexicalUnit createPixel(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_PIXEL, f); } public static LexicalUnit createCentimeter(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_CENTIMETER, f); } public static LexicalUnit createMillimeter(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_MILLIMETER, f); } public static LexicalUnit createInch(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_INCH, f); } public static LexicalUnit createPoint(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_POINT, f); } public static LexicalUnit createPica(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_PICA, f); } public static LexicalUnit createEm(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_EM, f); } public static LexicalUnit createEx(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_EX, f); } public static LexicalUnit createDegree(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_DEGREE, f); } public static LexicalUnit createRadian(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_RADIAN, f); } public static LexicalUnit createGradian(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_GRADIAN, f); } public static LexicalUnit createMillisecond(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_MILLISECOND, f); } public static LexicalUnit createSecond(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_SECOND, f); } public static LexicalUnit createHertz(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_HERTZ, f); } public static LexicalUnit createDimension(LexicalUnit prev, float f, String dim) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_DIMENSION, dim, f); } public static LexicalUnit createKiloHertz(LexicalUnit prev, float f) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_KILOHERTZ, f); } public static LexicalUnit createCounter(LexicalUnit prev, LexicalUnit params) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_COUNTER_FUNCTION, "counter", params); } public static LexicalUnit createCounters(LexicalUnit prev, LexicalUnit params) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_COUNTERS_FUNCTION, "counters", params); } public static LexicalUnit createAttr(LexicalUnit prev, LexicalUnit params) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_ATTR, "attr", params); } public static LexicalUnit createRect(LexicalUnit prev, LexicalUnit params) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_RECT_FUNCTION, "rect", params); } public static LexicalUnit createRgbColor(LexicalUnit prev, LexicalUnit params) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_RGBCOLOR, "rgb", params); } public static LexicalUnit createFunction(LexicalUnit prev, String name, LexicalUnit params) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_FUNCTION, name, params); } public static LexicalUnit createString(LexicalUnit prev, String value) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_STRING_VALUE, value); } public static LexicalUnit createIdent(LexicalUnit prev, String value) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_IDENT, value); } public static LexicalUnit createURI(LexicalUnit prev, String value) { return new LexicalUnitImpl(prev, LexicalUnit.SAC_URI, value); } public static LexicalUnit createComma(LexicalUnit prev) { return new LexicalUnitImpl(prev, SAC_OPERATOR_COMMA); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/AbstractSACParser.java0000644000175000017500000005351310772331064027326 0ustar cavedoncavedon/* * $Id: AbstractSACParser.java,v 1.4 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 2005-2008 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.text.MessageFormat; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.w3c.css.sac.CSSParseException; import org.w3c.css.sac.ConditionFactory; import org.w3c.css.sac.DocumentHandler; import org.w3c.css.sac.ErrorHandler; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.LexicalUnit; import org.w3c.css.sac.Locator; import org.w3c.css.sac.Parser; import org.w3c.css.sac.SACMediaList; import org.w3c.css.sac.Selector; import org.w3c.css.sac.SelectorFactory; import org.w3c.css.sac.SelectorList; import com.steadystate.css.parser.selectors.ConditionFactoryImpl; import com.steadystate.css.parser.selectors.SelectorFactoryImpl; import com.steadystate.css.sac.DocumentHandlerExt; import com.steadystate.css.sac.TestCSSParseException; /** * Base implementation of {@link Parser}. * * @author koch */ abstract class AbstractSACParser implements Parser { private DocumentHandlerExt documentHandler = null; private ErrorHandler errorHandler = null; private InputSource source = null; private Locale locale = null; private SelectorFactory selectorFactory = null; private ConditionFactory conditionFactory = null; private ResourceBundle sacParserMessages; protected abstract Token getToken(); protected DocumentHandlerExt getDocumentHandler() { if (this.documentHandler == null) { this.setDocumentHandler(new HandlerBase()); } return this.documentHandler; } public void setDocumentHandler(DocumentHandler handler) { if (handler instanceof DocumentHandlerExt) { this.documentHandler = (DocumentHandlerExt) handler; } } protected ErrorHandler getErrorHandler() { if (this.errorHandler == null) { this.setErrorHandler(new HandlerBase()); } return this.errorHandler; } public void setErrorHandler(ErrorHandler eh) { this.errorHandler = eh; } protected InputSource getInputSource() { return this.source; } public void setLocale(Locale locale) { if (this.locale != locale) { this.sacParserMessages = null; } this.locale = locale; } protected Locale getLocale() { if (this.locale == null) { this.setLocale(Locale.getDefault()); } return this.locale; } protected SelectorFactory getSelectorFactory() { if (this.selectorFactory == null) { this.selectorFactory = new SelectorFactoryImpl(); } return this.selectorFactory; } public void setSelectorFactory(SelectorFactory selectorFactory) { this.selectorFactory = selectorFactory; } protected ConditionFactory getConditionFactory() { if (this.conditionFactory == null) { this.conditionFactory = new ConditionFactoryImpl(); } return this.conditionFactory; } public void setConditionFactory(ConditionFactory conditionFactory) { this.conditionFactory = conditionFactory; } protected ResourceBundle getSACParserMessages() { if (this.sacParserMessages == null) { this.sacParserMessages = ResourceBundle.getBundle( "com.steadystate.css.parser.SACParserMessages", this.getLocale()); } return this.sacParserMessages; } public Locator getLocator() { return new LocatorImpl(this.getInputSource().getURI(), this.getToken() == null ? 0 : this.getToken().beginLine, this.getToken() == null ? 0 : this.getToken().beginColumn);//this.locator; } protected String add_escapes(String str) { StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { case 0 : continue; case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } protected CSSParseException toCSSParseException(String key, ParseException e) { String messagePattern1 = this.getSACParserMessages().getString("invalidExpectingOne"); String messagePattern2 = this.getSACParserMessages().getString("invalidExpectingMore"); int maxSize = 0; StringBuilder expected = new StringBuilder(); for (int i = 0; i < e.expectedTokenSequences.length; i++) { if (maxSize < e.expectedTokenSequences[i].length) { maxSize = e.expectedTokenSequences[i].length; } for (int j = 0; j < e.expectedTokenSequences[i].length; j++) { expected.append(e.tokenImage[e.expectedTokenSequences[i][j]]); } //if (e.expectedTokenSequences[i][e.expectedTokenSequences[i].length - 1] != 0) if (i < e.expectedTokenSequences.length - 1) { expected.append(", "); } } StringBuilder invalid = new StringBuilder(); Token tok = e.currentToken.next; for (int i = 0; i < maxSize; i++) { if (i != 0) { invalid.append(" "); } if (tok.kind == 0) { invalid.append(e.tokenImage[0]); break; } invalid.append(this.add_escapes(tok.image)); tok = tok.next; } String s = null; try { s = this.getSACParserMessages().getString(key); } catch (MissingResourceException ex) { s = key; } StringBuffer message = new StringBuffer(s); message.append(' '); if (e.expectedTokenSequences.length == 1) { message.append(MessageFormat.format( messagePattern1, new Object[] {invalid, expected})); } else { message.append(MessageFormat.format( messagePattern2, new Object[] {invalid, expected})); } return new TestCSSParseException(message.toString(), this.getInputSource().getURI(), e.currentToken.next.beginLine, e.currentToken.next.beginColumn, this.getGrammarUri()); } protected CSSParseException toCSSParseException(TokenMgrError e) { String messagePattern = this.getSACParserMessages().getString("tokenMgrError"); return new TestCSSParseException(messagePattern, this.getInputSource().getURI(), 1, 1, this.getGrammarUri()); } protected CSSParseException createSkipWarning(String key, CSSParseException e) { String s = null; try { s = this.getSACParserMessages().getString(key); } catch (MissingResourceException ex) { s = key; } return new TestCSSParseException(s, e.getURI(), e.getLineNumber(), e.getColumnNumber(), this.getGrammarUri()); } public void parseStyleSheet(InputSource source) throws IOException { this.source = source; this.ReInit(getCharStream(source)); try { this.styleSheet(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidStyleSheet", e)); } catch (TokenMgrError e) { this.getErrorHandler().error( this.toCSSParseException(e)); } catch (CSSParseException e) { this.getErrorHandler().error(e); } } public void parseStyleSheet(String uri) throws IOException { this.parseStyleSheet(new InputSource(uri)); } public void parseStyleDeclaration(InputSource source) throws IOException { this.source = source; this.ReInit(getCharStream(source)); try { this.styleDeclaration(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidStyleDeclaration", e)); } } public void parseRule(InputSource source) throws IOException { this.source = source; this.ReInit(getCharStream(source)); try { this.styleSheetRuleSingle(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidRule", e)); } } public SelectorList parseSelectors(InputSource source) throws IOException { this.source = source; this.ReInit(getCharStream(source)); SelectorList sl = null; try { sl = this.selectorList(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidSelectorList", e)); } return sl; } public LexicalUnit parsePropertyValue(InputSource source) throws IOException { this.source = source; this.ReInit(getCharStream(source)); LexicalUnit lu = null; try { lu = expr(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidExpr", e)); } return lu; } public boolean parsePriority(InputSource source) throws IOException { this.source = source; this.ReInit(getCharStream(source)); boolean b = false; try { b = prio(); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidPrio", e)); } return b; } public SACMediaList parseMedia(InputSource source) throws IOException { this.source = source; this.ReInit(this.getCharStream(source)); SACMediaListImpl ml = new SACMediaListImpl(); try { this.mediaList(ml); } catch (ParseException e) { this.getErrorHandler().error( this.toCSSParseException("invalidMediaList", e)); } catch (CSSParseException e) { this.getErrorHandler().error(e); } return ml; } private CharStream getCharStream(InputSource source) throws IOException { if (source.getCharacterStream() != null) { return new ASCII_CharStream( source.getCharacterStream(), 1, 1); } else if (source.getByteStream() != null) { return new ASCII_CharStream(new InputStreamReader( source.getByteStream()), 1, 1); } else if (source.getURI() != null) { return new ASCII_CharStream(new InputStreamReader( new URL(source.getURI()).openStream()), 1, 1); } return null; } public abstract String getParserVersion(); protected abstract String getGrammarUri(); protected abstract void ReInit(CharStream charStream); protected abstract void styleSheet() throws CSSParseException, ParseException; protected abstract void styleDeclaration() throws ParseException; protected abstract void styleSheetRuleSingle() throws ParseException; protected abstract SelectorList selectorList() throws ParseException; protected abstract LexicalUnit expr() throws ParseException; protected abstract boolean prio() throws ParseException; protected abstract void mediaList(SACMediaListImpl ml) throws ParseException; protected void handleStartDocument() { this.getDocumentHandler().startDocument(this.getInputSource()); } protected void handleEndDocument() { this.getDocumentHandler().endDocument(this.getInputSource()); } protected void handleIgnorableAtRule(String s) { this.getDocumentHandler().ignorableAtRule(s); } protected void handleCharset(String characterEncoding) { this.getDocumentHandler().charset(characterEncoding); } protected void handleImportStyle(String uri, SACMediaList media, String defaultNamespaceURI) { this.getDocumentHandler().importStyle(uri, media, defaultNamespaceURI); } protected void handleStartMedia(SACMediaList media) { this.getDocumentHandler().startMedia(media); } protected void handleMedium(String medium) { } protected void handleEndMedia(SACMediaList media) { this.getDocumentHandler().endMedia(media); } protected void handleStartPage(String name, String pseudo_page) { this.getDocumentHandler().startPage(name, pseudo_page); } protected void handleEndPage(String name, String pseudo_page) { this.getDocumentHandler().endPage(name, pseudo_page); } protected void handleStartFontFace() { this.getDocumentHandler().startFontFace(); } protected void handleEndFontFace() { this.getDocumentHandler().endFontFace(); } protected void handleSelector(Selector selector) { } protected void handleStartSelector(SelectorList selectors) { this.getDocumentHandler().startSelector(selectors); } protected void handleEndSelector(SelectorList selectors) { this.getDocumentHandler().endSelector(selectors); } protected void handleProperty(String name, LexicalUnit value, boolean important) { this.getDocumentHandler().property(name, value, important); } protected LexicalUnit functionInternal(LexicalUnit prev, Token t, LexicalUnit params) { if (t.image.equalsIgnoreCase("counter(")) { return LexicalUnitImpl.createCounter(prev, params); } else if (t.image.equalsIgnoreCase("counters(")) { return LexicalUnitImpl.createCounters(prev, params); } else if (t.image.equalsIgnoreCase("attr(")) { return LexicalUnitImpl.createAttr(prev, params); } else if (t.image.equalsIgnoreCase("rect(")) { return LexicalUnitImpl.createRect(prev, params); } return LexicalUnitImpl.createFunction( prev, t.image.substring(0, t.image.length() - 1), params); } protected LexicalUnit hexcolorInternal(LexicalUnit prev, Token t) { // Step past the hash at the beginning int i = 1; int r = 0; int g = 0; int b = 0; int len = t.image.length() - 1; String pattern = this.getSACParserMessages().getString("invalidColor"); try { if (len == 3) { r = Integer.parseInt(t.image.substring(i + 0, i + 1), 16); g = Integer.parseInt(t.image.substring(i + 1, i + 2), 16); b = Integer.parseInt(t.image.substring(i + 2, i + 3), 16); r = (r << 4) | r; g = (g << 4) | g; b = (b << 4) | b; } else if (len == 6) { r = Integer.parseInt(t.image.substring(i + 0, i + 2), 16); g = Integer.parseInt(t.image.substring(i + 2, i + 4), 16); b = Integer.parseInt(t.image.substring(i + 4, i + 6), 16); } else { throw new TestCSSParseException(MessageFormat.format( pattern, new Object[] {t}), this.getInputSource().getURI(), t.beginLine, t.beginColumn, this.getGrammarUri()); } // Turn into an "rgb()" LexicalUnit lr = LexicalUnitImpl.createNumber(null, r); LexicalUnit lc1 = LexicalUnitImpl.createComma(lr); LexicalUnit lg = LexicalUnitImpl.createNumber(lc1, g); LexicalUnit lc2 = LexicalUnitImpl.createComma(lg); LexicalUnit lb = LexicalUnitImpl.createNumber(lc2, b); return LexicalUnitImpl.createRgbColor(prev, lr); } catch (NumberFormatException ex) { throw new TestCSSParseException(MessageFormat.format( pattern, new Object[] {t}), this.getInputSource().getURI(), t.beginLine, t.beginColumn, ex, this.getGrammarUri()); } } int intValue(char op, String s) { return ((op == '-') ? -1 : 1) * Integer.parseInt(s); } float floatValue(char op, String s) { return ((op == '-') ? -1 : 1) * Float.parseFloat(s); } int getLastNumPos(String s) { int i; for (i = 0; i < s.length(); i++) { if (Character.isLetter(s.charAt(i))) { break; } } return i - 1; } /** * Unescapes escaped characters in the specified string, according to the * CSS specification. * * This could be done directly in the parser, but portions of the lexer would have to be moved * to the parser, meaning that the grammar would no longer match the standard grammar specified * by the W3C. This would make the parser and lexer much less maintainable. */ String unescape(String s) { int len = s.length(); StringBuffer buf = new StringBuffer(len); int index = 0; while (index < len) { char c = s.charAt(index); if (c == '\\') { if (++index < len) { c = s.charAt(index); switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': int numValue = Character.digit(c, 16); int count = 0; int p = 16; while (index + 1 < len && count < 6) { c = s.charAt(index+1); if (Character.digit(c, 16) != -1) { numValue = (numValue * 16) + Character.digit(c, 16); p *= 16; index++; } else { if (Character.isWhitespace(c)) { // skip the latest white space index++; } break; } } buf.append((char) numValue); break; case '\n': case '\f': break; case '\r': if (index + 1 < len) { if (s.charAt(index + 1) == '\n') { index ++; } } break; default: buf.append(c); } } else { throw new TestCSSParseException("invalid string " + s, getLocator(), this.getGrammarUri()); } } else { buf.append(c); } index++; } return buf.toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/ASCII_CharStream.java0000644000175000017500000002434310770335721027021 0ustar cavedoncavedon/* Generated By:JavaCC: Do not edit this line. ASCII_CharStream.java Version 0.7pre6 */ package com.steadystate.css.parser; /** * An implementation of interface CharStream, where the stream is assumed to * contain only ASCII characters (without unicode processing). */ public final class ASCII_CharStream implements CharStream { public static final boolean staticFlag = false; int bufsize; int available; int tokenBegin; public int bufpos = -1; private int bufline[]; private int bufcolumn[]; private int column = 0; private int line = 1; private boolean prevCharIsCR = false; private boolean prevCharIsLF = false; private java.io.Reader inputStream; private char[] buffer; private int maxNextCharInd = 0; private int inBuf = 0; private final void ExpandBuff(boolean wrapAround) { char[] newbuffer = new char[this.bufsize + 2048]; int newbufline[] = new int[this.bufsize + 2048]; int newbufcolumn[] = new int[this.bufsize + 2048]; try { if (wrapAround) { System.arraycopy(this.buffer, this.tokenBegin, newbuffer, 0, this.bufsize - this.tokenBegin); System.arraycopy(this.buffer, 0, newbuffer, this.bufsize - this.tokenBegin, this.bufpos); this.buffer = newbuffer; System.arraycopy(this.bufline, this.tokenBegin, newbufline, 0, this.bufsize - this.tokenBegin); System.arraycopy(this.bufline, 0, newbufline, this.bufsize - this.tokenBegin, this.bufpos); this.bufline = newbufline; System.arraycopy(this.bufcolumn, this.tokenBegin, newbufcolumn, 0, this.bufsize - this.tokenBegin); System.arraycopy(this.bufcolumn, 0, newbufcolumn, this.bufsize - this.tokenBegin, this.bufpos); this.bufcolumn = newbufcolumn; this.maxNextCharInd = (this.bufpos += (this.bufsize - this.tokenBegin)); } else { System.arraycopy(this.buffer, this.tokenBegin, newbuffer, 0, this.bufsize - this.tokenBegin); this.buffer = newbuffer; System.arraycopy(this.bufline, this.tokenBegin, newbufline, 0, this.bufsize - this.tokenBegin); this.bufline = newbufline; System.arraycopy(this.bufcolumn, this.tokenBegin, newbufcolumn, 0, this.bufsize - this.tokenBegin); this.bufcolumn = newbufcolumn; this.maxNextCharInd = (this.bufpos -= this.tokenBegin); } } catch (Throwable t) { throw new Error(t.getMessage()); } this.bufsize += 2048; this.available = this.bufsize; this.tokenBegin = 0; } private final void FillBuff() throws java.io.IOException { if (this.maxNextCharInd == this.available) { if (this.available == this.bufsize) { if (this.tokenBegin > 2048) { this.bufpos = this.maxNextCharInd = 0; this.available = this.tokenBegin; } else if (this.tokenBegin < 0) this.bufpos = this.maxNextCharInd = 0; else ExpandBuff(false); } else if (this.available > this.tokenBegin) this.available = this.bufsize; else if ((this.tokenBegin - this.available) < 2048) ExpandBuff(true); else this.available = this.tokenBegin; } int i; try { if ((i = this.inputStream.read(this.buffer, this.maxNextCharInd, this.available - this.maxNextCharInd)) == -1) { this.inputStream.close(); throw new java.io.IOException(); } this.maxNextCharInd += i; return; } catch(java.io.IOException e) { --this.bufpos; backup(0); if (this.tokenBegin == -1) this.tokenBegin = this.bufpos; throw e; } } public final char BeginToken() throws java.io.IOException { this.tokenBegin = -1; char c = readChar(); this.tokenBegin = this.bufpos; return c; } private final void UpdateLineColumn(char c) { this.column++; if (this.prevCharIsLF) { this.prevCharIsLF = false; this.line += (this.column = 1); } else if (this.prevCharIsCR) { this.prevCharIsCR = false; if (c == '\n') { this.prevCharIsLF = true; } else this.line += (this.column = 1); } switch (c) { case '\r' : this.prevCharIsCR = true; break; case '\n' : this.prevCharIsLF = true; break; case '\t' : this.column--; this.column += (8 - (this.column & 07)); break; default : break; } this.bufline[this.bufpos] = this.line; this.bufcolumn[this.bufpos] = this.column; } public final char readChar() throws java.io.IOException { if (this.inBuf > 0) { --this.inBuf; return (char)((char)0xff & this.buffer[(this.bufpos == this.bufsize - 1) ? (this.bufpos = 0) : ++this.bufpos]); } if (++this.bufpos >= this.maxNextCharInd) FillBuff(); char c = (char)((char)0xff & this.buffer[this.bufpos]); UpdateLineColumn(c); return (c); } /** * @deprecated * @see #getEndColumn */ public final int getColumn() { return this.bufcolumn[this.bufpos]; } /** * @deprecated * @see #getEndLine */ public final int getLine() { return this.bufline[this.bufpos]; } public final int getEndColumn() { return this.bufcolumn[this.bufpos]; } public final int getEndLine() { return this.bufline[this.bufpos]; } public final int getBeginColumn() { return this.bufcolumn[this.tokenBegin]; } public final int getBeginLine() { return this.bufline[this.tokenBegin]; } public final void backup(int amount) { this.inBuf += amount; if ((this.bufpos -= amount) < 0) this.bufpos += this.bufsize; } public ASCII_CharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { this.inputStream = dstream; this.line = startline; this.column = startcolumn - 1; this.available = this.bufsize = buffersize; this.buffer = new char[buffersize]; this.bufline = new int[buffersize]; this.bufcolumn = new int[buffersize]; } public ASCII_CharStream(java.io.Reader dstream, int startline, int startcolumn) { this(dstream, startline, startcolumn, 4096); } public void ReInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { this.inputStream = dstream; this.line = startline; this.column = startcolumn - 1; if (this.buffer == null || buffersize != this.buffer.length) { this.available = this.bufsize = buffersize; this.buffer = new char[buffersize]; this.bufline = new int[buffersize]; this.bufcolumn = new int[buffersize]; } this.prevCharIsLF = this.prevCharIsCR = false; this.tokenBegin = this.inBuf = this.maxNextCharInd = 0; this.bufpos = -1; } public void ReInit(java.io.Reader dstream, int startline, int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } public ASCII_CharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); } public ASCII_CharStream(java.io.InputStream dstream, int startline, int startcolumn) { this(dstream, startline, startcolumn, 4096); } public void ReInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096); } public void ReInit(java.io.InputStream dstream, int startline, int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } public final String GetImage() { if (this.bufpos >= this.tokenBegin) return new String(this.buffer, this.tokenBegin, this.bufpos - this.tokenBegin + 1); return new String(this.buffer, this.tokenBegin, this.bufsize - this.tokenBegin) + new String(this.buffer, 0, this.bufpos + 1); } public final char[] GetSuffix(int len) { char[] ret = new char[len]; if ((this.bufpos + 1) >= len) System.arraycopy(this.buffer, this.bufpos - len + 1, ret, 0, len); else { System.arraycopy(this.buffer, this.bufsize - (len - this.bufpos - 1), ret, 0, len - this.bufpos - 1); System.arraycopy(this.buffer, 0, ret, len - this.bufpos - 1, this.bufpos + 1); } return ret; } public void Done() { this.buffer = null; this.bufline = null; this.bufcolumn = null; } /** * Method to adjust line and column numbers for the start of a token.
*/ public void adjustBeginLineColumn(int newLine, int newCol) { int start = this.tokenBegin; int len; if (this.bufpos >= this.tokenBegin) { len = this.bufpos - this.tokenBegin + this.inBuf + 1; } else { len = this.bufsize - this.tokenBegin + this.bufpos + 1 + this.inBuf; } int i = 0, j = 0, k = 0; int nextColDiff = 0, columnDiff = 0; while (i < len && this.bufline[j = start % this.bufsize] == this.bufline[k = ++start % this.bufsize]) { this.bufline[j] = newLine; nextColDiff = columnDiff + this.bufcolumn[k] - this.bufcolumn[j]; this.bufcolumn[j] = newCol + columnDiff; columnDiff = nextColDiff; i++; } if (i < len) { this.bufline[j] = newLine++; this.bufcolumn[j] = newCol + columnDiff; while (i++ < len) { if (this.bufline[j = start % this.bufsize] != this.bufline[++start % this.bufsize]) this.bufline[j] = newLine++; else this.bufline[j] = newLine; } } this.line = this.bufline[j]; this.column = this.bufcolumn[j]; } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/HandlerBase.java0000644000175000017500000000741010772324145026224 0ustar cavedoncavedon/* * $Id: HandlerBase.java,v 1.2 2008/03/26 01:35:33 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import org.w3c.css.sac.*; import com.steadystate.css.sac.DocumentHandlerExt; public class HandlerBase implements DocumentHandlerExt, ErrorHandler { public void startDocument(InputSource source) throws CSSException { } public void endDocument(InputSource source) throws CSSException { } public void comment(String text) throws CSSException { } public void ignorableAtRule(String atRule) throws CSSException { } public void namespaceDeclaration(String prefix, String uri) throws CSSException { } public void importStyle(String uri, SACMediaList media, String defaultNamespaceURI) throws CSSException { } public void startMedia(SACMediaList media) throws CSSException { } public void endMedia(SACMediaList media) throws CSSException { } public void startPage(String name, String pseudo_page) throws CSSException { } public void endPage(String name, String pseudo_page) throws CSSException { } public void startFontFace() throws CSSException { } public void endFontFace() throws CSSException { } public void startSelector(SelectorList selectors) throws CSSException { } public void endSelector(SelectorList selectors) throws CSSException { } public void property(String name, LexicalUnit value, boolean important) throws CSSException { } public void charset(String characterEncoding) throws CSSException { } public void warning(CSSParseException exception) throws CSSException { StringBuilder sb = new StringBuilder(); sb.append(exception.getURI()) .append(" [") .append(exception.getLineNumber()) .append(":") .append(exception.getColumnNumber()) .append("] ") .append(exception.getMessage()); System.err.println(sb.toString()); } public void error(CSSParseException exception) throws CSSException { StringBuilder sb = new StringBuilder(); sb.append(exception.getURI()) .append(" [") .append(exception.getLineNumber()) .append(":") .append(exception.getColumnNumber()) .append("] ") .append(exception.getMessage()); System.err.println(sb.toString()); } public void fatalError(CSSParseException exception) throws CSSException { StringBuilder sb = new StringBuilder(); sb.append(exception.getURI()) .append(" [") .append(exception.getLineNumber()) .append(":") .append(exception.getColumnNumber()) .append("] ") .append(exception.getMessage()); System.err.println(sb.toString()); } } cssparser-0.9.5/src/main/java/com/steadystate/css/parser/ExceptionResource.java0000644000175000017500000000437410770335721027530 0ustar cavedoncavedon/* * $Id: ExceptionResource.java,v 1.1 2008/03/20 01:20:17 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import java.util.ListResourceBundle; public class ExceptionResource extends ListResourceBundle { public Object[][] getContents() { return contents; } static final Object[][] contents = { {"s0", "Syntax error"}, {"s1", "Array out of bounds error"}, {"s2", "This style sheet is read only"}, {"s3", "The text does not represent an unknown rule"}, {"s4", "The text does not represent a style rule"}, {"s5", "The text does not represent a charset rule"}, {"s6", "The text does not represent an import rule"}, {"s7", "The text does not represent a media rule"}, {"s8", "The text does not represent a font face rule"}, {"s9", "The text does not represent a page rule"}, {"s10", "This isn't a Float type"}, {"s11", "This isn't a String type"}, {"s12", "This isn't a Counter type"}, {"s13", "This isn't a Rect type"}, {"s14", "This isn't an RGBColor type"}, {"s15", "A charset rule must be the first rule"}, {"s16", "A charset rule already exists"}, {"s17", "An import rule must preceed all other rules"}, {"s18", "The specified type was not found"} }; } cssparser-0.9.5/src/main/java/com/steadystate/css/sac/0000755000175000017500000000000011420645030022447 5ustar cavedoncavedoncssparser-0.9.5/src/main/java/com/steadystate/css/sac/TestCSSParseException.java0000644000175000017500000000252410770335721027471 0ustar cavedoncavedon/* * Created on 26.01.2006 * */ package com.steadystate.css.sac; import org.w3c.css.sac.CSSParseException; import org.w3c.css.sac.Locator; public class TestCSSParseException extends CSSParseException { private static final long serialVersionUID = -4892920039949256795L; private String testCaseUri; public void setTestCaseUri(String testCaseUri) { this.testCaseUri = testCaseUri; } public TestCSSParseException(String message, Locator locator, String testCaseUri) { super(message, locator); this.setTestCaseUri(testCaseUri); } public TestCSSParseException(String message, Locator locator, Exception e, String testCaseUri) { super(message, locator, e); this.setTestCaseUri(testCaseUri); } public TestCSSParseException(String message, String uri, int lineNumber, int columnNumber, String testCaseUri) { super(message, uri, lineNumber, columnNumber); this.setTestCaseUri(testCaseUri); } public TestCSSParseException(String message, String uri, int lineNumber, int columnNumber, Exception e, String testCaseUri) { super(message, uri, lineNumber, columnNumber, e); this.setTestCaseUri(testCaseUri); } public String getTestCaseUri() { return this.testCaseUri; } } cssparser-0.9.5/src/main/java/com/steadystate/css/sac/DocumentHandlerExt.java0000644000175000017500000000076110770335721027065 0ustar cavedoncavedon/* * Created on 04.12.2007 * */ package com.steadystate.css.sac; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.DocumentHandler; public interface DocumentHandlerExt extends DocumentHandler { /** * Receive notification of a charset at-rule. * * @param characterEncoding the character encoding * @throws CSSException Any CSS exception, possibly wrapping another exception. */ public void charset(String characterEncoding) throws CSSException; } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/0000755000175000017500000000000011420645030022460 5ustar cavedoncavedoncssparser-0.9.5/src/main/java/com/steadystate/css/dom/CounterImpl.java0000644000175000017500000001051210772331064025573 0ustar cavedoncavedon/* * $Id: CounterImpl.java,v 1.3 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.Serializable; import org.w3c.dom.DOMException; import org.w3c.dom.css.Counter; import org.w3c.css.sac.LexicalUnit; /** * Implementation of {@link Counter}. * * @author David Schweinsberg * @version $Id: CounterImpl.java,v 1.3 2008/03/26 02:17:24 sdanig Exp $ */ public class CounterImpl implements Counter, Serializable { private static final long serialVersionUID = 7996279151817598904L; private String identifier; private String listStyle; private String separator; public void setIdentifier(String identifier) { this.identifier = identifier; } public void setListStyle(String listStyle) { this.listStyle = listStyle; } public void setSeparator(String separator) { this.separator = separator; } /** Creates new CounterImpl */ public CounterImpl(boolean separatorSpecified, LexicalUnit lu) throws DOMException { LexicalUnit next = lu; this.identifier = next.getStringValue(); next = next.getNextLexicalUnit(); // ',' if (next != null) { if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { // error throw new DOMException(DOMException.SYNTAX_ERR, "Counter parameters must be separated by ','."); } next = next.getNextLexicalUnit(); if (separatorSpecified && (next != null)) { this.separator = next.getStringValue(); next = next.getNextLexicalUnit(); // ',' if (next != null) { if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { // error throw new DOMException(DOMException.SYNTAX_ERR, "Counter parameters must be separated by ','."); } next = next.getNextLexicalUnit(); } } if (next != null) { this.listStyle = next.getStringValue(); if ((next = next.getNextLexicalUnit()) != null) { // error throw new DOMException(DOMException.SYNTAX_ERR, "Too many parameters for counter function."); } } } } public CounterImpl() { } public String getIdentifier() { return this.identifier; } public String getListStyle() { return this.listStyle; } public String getSeparator() { return this.separator; } public String toString() { StringBuilder sb = new StringBuilder(); if (this.separator == null) { // This is a 'counter()' function sb.append("counter("); } else { // This is a 'counters()' function sb.append("counters("); } sb.append(this.identifier); if (this.separator != null) { sb.append(", \"").append(this.separator).append("\""); } if (this.listStyle != null) { sb.append(", ").append(this.listStyle); } sb.append(")"); return sb.toString(); } }cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSS2PropertiesImpl.java0000644000175000017500000004517610772331064026761 0ustar cavedoncavedon/* * $Id: CSS2PropertiesImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.Serializable; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSS2Properties; /** * Implementation of {@link CSS2Properties}. * * TODO: Implement. * * @author David Schweinsberg * @version $Id: CSS2PropertiesImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class CSS2PropertiesImpl implements CSS2Properties, Serializable { private static final long serialVersionUID = 6769757755750030077L; /** Creates new CSS2PropertiesImpl */ public CSS2PropertiesImpl() { } public String getAzimuth() { return null; } public void setAzimuth(String azimuth) throws DOMException { } public String getBackground() { return null; } public void setBackground(String background) throws DOMException { } public String getBackgroundAttachment() { return null; } public void setBackgroundAttachment(String backgroundAttachment) throws DOMException { } public String getBackgroundColor() { return null; } public void setBackgroundColor(String backgroundColor) throws DOMException { } public String getBackgroundImage() { return null; } public void setBackgroundImage(String backgroundImage) throws DOMException { } public String getBackgroundPosition() { return null; } public void setBackgroundPosition(String backgroundPosition) throws DOMException { } public String getBackgroundRepeat() { return null; } public void setBackgroundRepeat(String backgroundRepeat) throws DOMException { } public String getBorder() { return null; } public void setBorder(String border) throws DOMException { } public String getBorderCollapse() { return null; } public void setBorderCollapse(String borderCollapse) throws DOMException { } public String getBorderColor() { return null; } public void setBorderColor(String borderColor) throws DOMException { } public String getBorderSpacing() { return null; } public void setBorderSpacing(String borderSpacing) throws DOMException { } public String getBorderStyle() { return null; } public void setBorderStyle(String borderStyle) throws DOMException { } public String getBorderTop() { return null; } public void setBorderTop(String borderTop) throws DOMException { } public String getBorderRight() { return null; } public void setBorderRight(String borderRight) throws DOMException { } public String getBorderBottom() { return null; } public void setBorderBottom(String borderBottom) throws DOMException { } public String getBorderLeft() { return null; } public void setBorderLeft(String borderLeft) throws DOMException { } public String getBorderTopColor() { return null; } public void setBorderTopColor(String borderTopColor) throws DOMException { } public String getBorderRightColor() { return null; } public void setBorderRightColor(String borderRightColor) throws DOMException { } public String getBorderBottomColor() { return null; } public void setBorderBottomColor(String borderBottomColor) throws DOMException { } public String getBorderLeftColor() { return null; } public void setBorderLeftColor(String borderLeftColor) throws DOMException { } public String getBorderTopStyle() { return null; } public void setBorderTopStyle(String borderTopStyle) throws DOMException { } public String getBorderRightStyle() { return null; } public void setBorderRightStyle(String borderRightStyle) throws DOMException { } public String getBorderBottomStyle() { return null; } public void setBorderBottomStyle(String borderBottomStyle) throws DOMException { } public String getBorderLeftStyle() { return null; } public void setBorderLeftStyle(String borderLeftStyle) throws DOMException { } public String getBorderTopWidth() { return null; } public void setBorderTopWidth(String borderTopWidth) throws DOMException { } public String getBorderRightWidth() { return null; } public void setBorderRightWidth(String borderRightWidth) throws DOMException { } public String getBorderBottomWidth() { return null; } public void setBorderBottomWidth(String borderBottomWidth) throws DOMException { } public String getBorderLeftWidth() { return null; } public void setBorderLeftWidth(String borderLeftWidth) throws DOMException { } public String getBorderWidth() { return null; } public void setBorderWidth(String borderWidth) throws DOMException { } public String getBottom() { return null; } public void setBottom(String bottom) throws DOMException { } public String getCaptionSide() { return null; } public void setCaptionSide(String captionSide) throws DOMException { } public String getClear() { return null; } public void setClear(String clear) throws DOMException { } public String getClip() { return null; } public void setClip(String clip) throws DOMException { } public String getColor() { return null; } public void setColor(String color) throws DOMException { } public String getContent() { return null; } public void setContent(String content) throws DOMException { } public String getCounterIncrement() { return null; } public void setCounterIncrement(String counterIncrement) throws DOMException { } public String getCounterReset() { return null; } public void setCounterReset(String counterReset) throws DOMException { } public String getCue() { return null; } public void setCue(String cue) throws DOMException { } public String getCueAfter() { return null; } public void setCueAfter(String cueAfter) throws DOMException { } public String getCueBefore() { return null; } public void setCueBefore(String cueBefore) throws DOMException { } public String getCursor() { return null; } public void setCursor(String cursor) throws DOMException { } public String getDirection() { return null; } public void setDirection(String direction) throws DOMException { } public String getDisplay() { return null; } public void setDisplay(String display) throws DOMException { } public String getElevation() { return null; } public void setElevation(String elevation) throws DOMException { } public String getEmptyCells() { return null; } public void setEmptyCells(String emptyCells) throws DOMException { } public String getCssFloat() { return null; } public void setCssFloat(String cssFloat) throws DOMException { } public String getFont() { return null; } public void setFont(String font) throws DOMException { } public String getFontFamily() { return null; } public void setFontFamily(String fontFamily) throws DOMException { } public String getFontSize() { return null; } public void setFontSize(String fontSize) throws DOMException { } public String getFontSizeAdjust() { return null; } public void setFontSizeAdjust(String fontSizeAdjust) throws DOMException { } public String getFontStretch() { return null; } public void setFontStretch(String fontStretch) throws DOMException { } public String getFontStyle() { return null; } public void setFontStyle(String fontStyle) throws DOMException { } public String getFontVariant() { return null; } public void setFontVariant(String fontVariant) throws DOMException { } public String getFontWeight() { return null; } public void setFontWeight(String fontWeight) throws DOMException { } public String getHeight() { return null; } public void setHeight(String height) throws DOMException { } public String getLeft() { return null; } public void setLeft(String left) throws DOMException { } public String getLetterSpacing() { return null; } public void setLetterSpacing(String letterSpacing) throws DOMException { } public String getLineHeight() { return null; } public void setLineHeight(String lineHeight) throws DOMException { } public String getListStyle() { return null; } public void setListStyle(String listStyle) throws DOMException { } public String getListStyleImage() { return null; } public void setListStyleImage(String listStyleImage) throws DOMException { } public String getListStylePosition() { return null; } public void setListStylePosition(String listStylePosition) throws DOMException { } public String getListStyleType() { return null; } public void setListStyleType(String listStyleType) throws DOMException { } public String getMargin() { return null; } public void setMargin(String margin) throws DOMException { } public String getMarginTop() { return null; } public void setMarginTop(String marginTop) throws DOMException { } public String getMarginRight() { return null; } public void setMarginRight(String marginRight) throws DOMException { } public String getMarginBottom() { return null; } public void setMarginBottom(String marginBottom) throws DOMException { } public String getMarginLeft() { return null; } public void setMarginLeft(String marginLeft) throws DOMException { } public String getMarkerOffset() { return null; } public void setMarkerOffset(String markerOffset) throws DOMException { } public String getMarks() { return null; } public void setMarks(String marks) throws DOMException { } public String getMaxHeight() { return null; } public void setMaxHeight(String maxHeight) throws DOMException { } public String getMaxWidth() { return null; } public void setMaxWidth(String maxWidth) throws DOMException { } public String getMinHeight() { return null; } public void setMinHeight(String minHeight) throws DOMException { } public String getMinWidth() { return null; } public void setMinWidth(String minWidth) throws DOMException { } public String getOrphans() { return null; } public void setOrphans(String orphans) throws DOMException { } public String getOutline() { return null; } public void setOutline(String outline) throws DOMException { } public String getOutlineColor() { return null; } public void setOutlineColor(String outlineColor) throws DOMException { } public String getOutlineStyle() { return null; } public void setOutlineStyle(String outlineStyle) throws DOMException { } public String getOutlineWidth() { return null; } public void setOutlineWidth(String outlineWidth) throws DOMException { } public String getOverflow() { return null; } public void setOverflow(String overflow) throws DOMException { } public String getPadding() { return null; } public void setPadding(String padding) throws DOMException { } public String getPaddingTop() { return null; } public void setPaddingTop(String paddingTop) throws DOMException { } public String getPaddingRight() { return null; } public void setPaddingRight(String paddingRight) throws DOMException { } public String getPaddingBottom() { return null; } public void setPaddingBottom(String paddingBottom) throws DOMException { } public String getPaddingLeft() { return null; } public void setPaddingLeft(String paddingLeft) throws DOMException { } public String getPage() { return null; } public void setPage(String page) throws DOMException { } public String getPageBreakAfter() { return null; } public void setPageBreakAfter(String pageBreakAfter) throws DOMException { } public String getPageBreakBefore() { return null; } public void setPageBreakBefore(String pageBreakBefore) throws DOMException { } public String getPageBreakInside() { return null; } public void setPageBreakInside(String pageBreakInside) throws DOMException { } public String getPause() { return null; } public void setPause(String pause) throws DOMException { } public String getPauseAfter() { return null; } public void setPauseAfter(String pauseAfter) throws DOMException { } public String getPauseBefore() { return null; } public void setPauseBefore(String pauseBefore) throws DOMException { } public String getPitch() { return null; } public void setPitch(String pitch) throws DOMException { } public String getPitchRange() { return null; } public void setPitchRange(String pitchRange) throws DOMException { } public String getPlayDuring() { return null; } public void setPlayDuring(String playDuring) throws DOMException { } public String getPosition() { return null; } public void setPosition(String position) throws DOMException { } public String getQuotes() { return null; } public void setQuotes(String quotes) throws DOMException { } public String getRichness() { return null; } public void setRichness(String richness) throws DOMException { } public String getRight() { return null; } public void setRight(String right) throws DOMException { } public String getSize() { return null; } public void setSize(String size) throws DOMException { } public String getSpeak() { return null; } public void setSpeak(String speak) throws DOMException { } public String getSpeakHeader() { return null; } public void setSpeakHeader(String speakHeader) throws DOMException { } public String getSpeakNumeral() { return null; } public void setSpeakNumeral(String speakNumeral) throws DOMException { } public String getSpeakPunctuation() { return null; } public void setSpeakPunctuation(String speakPunctuation) throws DOMException { } public String getSpeechRate() { return null; } public void setSpeechRate(String speechRate) throws DOMException { } public String getStress() { return null; } public void setStress(String stress) throws DOMException { } public String getTableLayout() { return null; } public void setTableLayout(String tableLayout) throws DOMException { } public String getTextAlign() { return null; } public void setTextAlign(String textAlign) throws DOMException { } public String getTextDecoration() { return null; } public void setTextDecoration(String textDecoration) throws DOMException { } public String getTextIndent() { return null; } public void setTextIndent(String textIndent) throws DOMException { } public String getTextShadow() { return null; } public void setTextShadow(String textShadow) throws DOMException { } public String getTextTransform() { return null; } public void setTextTransform(String textTransform) throws DOMException { } public String getTop() { return null; } public void setTop(String top) throws DOMException { } public String getUnicodeBidi() { return null; } public void setUnicodeBidi(String unicodeBidi) throws DOMException { } public String getVerticalAlign() { return null; } public void setVerticalAlign(String verticalAlign) throws DOMException { } public String getVisibility() { return null; } public void setVisibility(String visibility) throws DOMException { } public String getVoiceFamily() { return null; } public void setVoiceFamily(String voiceFamily) throws DOMException { } public String getVolume() { return null; } public void setVolume(String volume) throws DOMException { } public String getWhiteSpace() { return null; } public void setWhiteSpace(String whiteSpace) throws DOMException { } public String getWidows() { return null; } public void setWidows(String widows) throws DOMException { } public String getWidth() { return null; } public void setWidth(String width) throws DOMException { } public String getWordSpacing() { return null; } public void setWordSpacing(String wordSpacing) throws DOMException { } public String getZIndex() { return null; } public void setZIndex(String zIndex) throws DOMException { } }cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSStyleSheetListImpl.java0000644000175000017500000000647410772331064027466 0ustar cavedoncavedon/* * $Id: CSSStyleSheetListImpl.java,v 1.3 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.stylesheets.StyleSheet; import org.w3c.dom.stylesheets.StyleSheetList; /** * Implementation of {@link StyleSheetList}. * * @author Johannes Koch * @version $Id: CSSStyleSheetListImpl.java,v 1.3 2008/03/26 02:17:24 sdanig Exp $ */ public class CSSStyleSheetListImpl implements StyleSheetList { private List cssStyleSheets; public List getCSSStyleSheets() { if (this.cssStyleSheets == null) { this.cssStyleSheets = new ArrayList(); } return this.cssStyleSheets; } public void setCSSStyleSheets(List cssStyleSheets) { this.cssStyleSheets = cssStyleSheets; } /** Creates a new instance of CSSStyleSheetListImpl */ public CSSStyleSheetListImpl() { } // start StyleSheetList public int getLength() { return this.getCSSStyleSheets().size(); } public StyleSheet item(int index) { return this.getCSSStyleSheets().get(index); } /** * Adds a CSSStyleSheet. * * @param cssStyleSheet the CSSStyleSheet */ public void add(CSSStyleSheet cssStyleSheet) { this.getCSSStyleSheets().add(cssStyleSheet); } // end StyleSheetList /** * Merges all StyleSheets in this list into one. * * @return the new (merged) StyleSheet */ public StyleSheet merge() { CSSStyleSheetImpl merged = new CSSStyleSheetImpl(); CSSRuleListImpl cssRuleList = new CSSRuleListImpl(); Iterator it = this.getCSSStyleSheets().iterator(); while (it.hasNext()) { CSSStyleSheetImpl cssStyleSheet = (CSSStyleSheetImpl) it.next(); CSSMediaRuleImpl cssMediaRule = new CSSMediaRuleImpl(merged, null, cssStyleSheet.getMedia()); cssMediaRule.setRuleList( (CSSRuleListImpl) cssStyleSheet.getCssRules()); cssRuleList.add(cssMediaRule); } merged.setCssRules(cssRuleList); merged.setMediaText("all"); return merged; } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/AbstractCSSRuleImpl.java0000644000175000017500000000175110772331064027125 0ustar cavedoncavedon/* * Created on 05.12.2005 * */ package com.steadystate.css.dom; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSStyleSheet; /** * @author koch */ public abstract class AbstractCSSRuleImpl extends CSSOMObjectImpl { protected CSSStyleSheetImpl parentStyleSheet = null; protected CSSRule parentRule = null; public void setParentStyleSheet(CSSStyleSheetImpl parentStyleSheet) { this.parentStyleSheet = parentStyleSheet; } public void setParentRule(CSSRule parentRule) { this.parentRule = parentRule; } public AbstractCSSRuleImpl(CSSStyleSheetImpl parentStyleSheet, CSSRule parentRule) { super(); this.parentStyleSheet = parentStyleSheet; this.parentRule = parentRule; } public AbstractCSSRuleImpl() { } public CSSStyleSheet getParentStyleSheet() { return this.parentStyleSheet; } public CSSRule getParentRule() { return this.parentRule; } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/RGBColorImpl.java0000644000175000017500000000762110772331064025574 0ustar cavedoncavedon/* * $Id: RGBColorImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.Serializable; import org.w3c.css.sac.LexicalUnit; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.RGBColor; /** * Implementation of {@link RGBColor}. * * @author David Schweinsberg * @version $Id: RGBColorImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class RGBColorImpl implements RGBColor, Serializable { private static final long serialVersionUID = 8152675334081993160L; private CSSPrimitiveValue red = null; private CSSPrimitiveValue green = null; private CSSPrimitiveValue blue = null; protected RGBColorImpl(LexicalUnit lu) throws DOMException { LexicalUnit next = lu; this.red = new CSSValueImpl(next, true); next = next.getNextLexicalUnit(); // , if (next != null) { if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { // error throw new DOMException(DOMException.SYNTAX_ERR, "rgb parameters must be separated by ','."); } next = next.getNextLexicalUnit(); if (next != null) { this.green = new CSSValueImpl(next, true); next = next.getNextLexicalUnit(); // , if (next != null) { if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { // error throw new DOMException(DOMException.SYNTAX_ERR, "rgb parameters must be separated by ','."); } next = next.getNextLexicalUnit(); this.blue = new CSSValueImpl(next, true); if ((next = next.getNextLexicalUnit()) != null) { // error throw new DOMException(DOMException.SYNTAX_ERR, "Too many parameters for rgb function."); } } } } } public RGBColorImpl() { } public CSSPrimitiveValue getRed() { return this.red; } public void setRed(CSSPrimitiveValue red) { this.red = red; } public CSSPrimitiveValue getGreen() { return this.green; } public void setGreen(CSSPrimitiveValue green) { this.green = green; } public CSSPrimitiveValue getBlue() { return this.blue; } public void setBlue(CSSPrimitiveValue blue) { this.blue = blue; } public String toString() { return new StringBuffer("rgb(") .append(this.red.toString()).append(", ") .append(this.green.toString()).append(", ") .append(this.blue.toString()).append(")").toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSStyleRuleImpl.java0000644000175000017500000001205210772331064026456 0ustar cavedoncavedon/* * $Id: CSSStyleRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.IOException; import java.io.Serializable; import java.io.StringReader; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.dom.css.CSSStyleRule; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.SelectorList; import com.steadystate.css.parser.CSSOMParser; /** * Implementation of {@link CSSStyleRule}. * * @author David Schweinsberg * @version $Id: CSSStyleRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class CSSStyleRuleImpl extends AbstractCSSRuleImpl implements CSSStyleRule, Serializable { private static final long serialVersionUID = -697009251364657426L; private SelectorList selectors = null; private CSSStyleDeclaration style = null; public SelectorList getSelectors() { return this.selectors; } public void setSelectors(SelectorList selectors) { this.selectors = selectors; } public CSSStyleRuleImpl(CSSStyleSheetImpl parentStyleSheet, CSSRule parentRule, SelectorList selectors) { super(parentStyleSheet, parentRule); this.selectors = selectors; } public CSSStyleRuleImpl() { } public short getType() { return STYLE_RULE; } public String getCssText() { return this.getSelectorText() + " { " + this.getStyle().getCssText() + " }"; } public void setCssText(String cssText) throws DOMException { if (this.parentStyleSheet != null && this.parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { InputSource is = new InputSource(new StringReader(cssText)); CSSOMParser parser = new CSSOMParser(); CSSRule r = parser.parseRule(is); // The rule must be a style rule if (r.getType() == CSSRule.STYLE_RULE) { this.selectors = ((CSSStyleRuleImpl)r).selectors; this.style = ((CSSStyleRuleImpl)r).style; } else { throw new DOMExceptionImpl( DOMException.INVALID_MODIFICATION_ERR, DOMExceptionImpl.EXPECTING_STYLE_RULE); } } catch (CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } } public String getSelectorText() { return this.selectors.toString(); } public void setSelectorText(String selectorText) throws DOMException { if (this.parentStyleSheet != null && this.parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET ); } try { InputSource is = new InputSource(new StringReader(selectorText)); CSSOMParser parser = new CSSOMParser(); this.selectors = parser.parseSelectors(is); } catch (CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } } public CSSStyleDeclaration getStyle() { return this.style; } public void setStyle(CSSStyleDeclaration style) { this.style = style; } public String toString() { return this.getCssText(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/RectImpl.java0000644000175000017500000001201210772331064025046 0ustar cavedoncavedon/* * $Id: RectImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.Serializable; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.Rect; import org.w3c.css.sac.LexicalUnit; /** * Implementation of {@link Rect}. * * @author David Schweinsberg * @version $Id: RectImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class RectImpl implements Rect, Serializable { private static final long serialVersionUID = -7031248513917920621L; private CSSPrimitiveValue left; private CSSPrimitiveValue top; private CSSPrimitiveValue right; private CSSPrimitiveValue bottom; public void setLeft(CSSPrimitiveValue left) { this.left = left; } public void setTop(CSSPrimitiveValue top) { this.top = top; } public void setRight(CSSPrimitiveValue right) { this.right = right; } public void setBottom(CSSPrimitiveValue bottom) { this.bottom = bottom; } /** Creates new RectImpl */ public RectImpl(LexicalUnit lu) throws DOMException { LexicalUnit next = lu; this.left = new CSSValueImpl(next, true); next = next.getNextLexicalUnit(); // , if (next != null) { if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { // error throw new DOMException(DOMException.SYNTAX_ERR, "Rect parameters must be separated by ','."); } next = next.getNextLexicalUnit(); if (next != null) { this.top = new CSSValueImpl(next, true); next = next.getNextLexicalUnit(); // , if (next != null) { if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { // error throw new DOMException(DOMException.SYNTAX_ERR, "Rect parameters must be separated by ','."); } next = next.getNextLexicalUnit(); if (next != null) { this.right = new CSSValueImpl(next, true); next = next.getNextLexicalUnit(); // , if (next != null) { if (next.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) { // error throw new DOMException(DOMException.SYNTAX_ERR, "Rect parameters must be separated by ','."); } next = next.getNextLexicalUnit(); if (next != null) { this.bottom = new CSSValueImpl(next, true); if ((next = next.getNextLexicalUnit()) != null) { // error throw new DOMException(DOMException.SYNTAX_ERR, "Too many parameters for rect function."); } } } } } } } } public RectImpl() { } public CSSPrimitiveValue getTop() { return this.top; } public CSSPrimitiveValue getRight() { return this.right; } public CSSPrimitiveValue getBottom() { return this.bottom; } public CSSPrimitiveValue getLeft() { return this.left; } public String toString() { return new StringBuffer("rect(") .append(this.left).append(", ") .append(this.top).append(", ") .append(this.right).append(", ") .append(this.bottom).append(")").toString(); } }cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSStyleDeclarationImpl.java0000644000175000017500000001356610772330067030011 0ustar cavedoncavedon/* * $Id: CSSStyleDeclarationImpl.java,v 1.4 2008/03/26 02:08:55 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.Serializable; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import org.w3c.css.sac.InputSource; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.dom.css.CSSValue; import com.steadystate.css.parser.CSSOMParser; /** * Implementation of {@link CSSStyleDeclaration}. * * @author David Schweinsberg * @version $Id: CSSStyleDeclarationImpl.java,v 1.4 2008/03/26 02:08:55 sdanig Exp $ */ public class CSSStyleDeclarationImpl implements CSSStyleDeclaration, Serializable { private static final long serialVersionUID = -2373755821317100189L; private CSSRule parentRule; private List properties = new ArrayList(); public void setParentRule(CSSRule parentRule) { this.parentRule = parentRule; } public List getProperties() { return this.properties; } public void setProperties(List properties) { this.properties = properties; } public CSSStyleDeclarationImpl(CSSRule parentRule) { this.parentRule = parentRule; } public CSSStyleDeclarationImpl() { // Empty. } public String getCssText() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.properties.size(); ++i) { Property p = this.properties.get(i); if (p != null) { sb.append(p.toString()); } if (i < this.properties.size() - 1) { sb.append("; "); } } return sb.toString(); } public void setCssText(String cssText) throws DOMException { try { InputSource is = new InputSource(new StringReader(cssText)); CSSOMParser parser = new CSSOMParser(); this.properties.clear(); parser.parseStyleDeclaration(this, is); } catch (Exception e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } } public String getPropertyValue(String propertyName) { Property p = this.getPropertyDeclaration(propertyName); return (p != null) ? p.getValue().toString() : ""; } public CSSValue getPropertyCSSValue(String propertyName) { Property p = this.getPropertyDeclaration(propertyName); return (p != null) ? p.getValue() : null; } public String removeProperty(String propertyName) throws DOMException { for (int i = 0; i < this.properties.size(); i++) { Property p = this.properties.get(i); if (p.getName().equalsIgnoreCase(propertyName)) { this.properties.remove(i); return p.getValue().toString(); } } return ""; } public String getPropertyPriority(String propertyName) { Property p = this.getPropertyDeclaration(propertyName); if (p != null) { return p.isImportant() ? "important" : ""; } return ""; } public void setProperty( String propertyName, String value, String priority ) throws DOMException { try { InputSource is = new InputSource(new StringReader(value)); CSSOMParser parser = new CSSOMParser(); CSSValue expr = parser.parsePropertyValue(is); Property p = this.getPropertyDeclaration(propertyName); boolean important = (priority != null) ? priority.equalsIgnoreCase("important") : false; if (p == null) { p = new Property(propertyName, expr, important); addProperty(p); } else { p.setValue(expr); p.setImportant(important); } } catch (Exception e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } } public int getLength() { return this.properties.size(); } public String item(int index) { Property p = this.properties.get(index); return (p != null) ? p.getName() : ""; } public CSSRule getParentRule() { return this.parentRule; } public void addProperty(Property p) { this.properties.add(p); } public Property getPropertyDeclaration(String name) { for (int i = 0; i < this.properties.size(); i++) { Property p = this.properties.get(i); if (p.getName().equalsIgnoreCase(name)) { return p; } } return null; } public String toString() { return this.getCssText(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/DOMExceptionImpl.java0000644000175000017500000000626010772331064026457 0ustar cavedoncavedon/* * $Id: DOMExceptionImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.util.Locale; import java.util.ResourceBundle; import org.w3c.dom.DOMException; /** * Custom {@link DOMException} extension. * * @author David Schweinsberg * @version $Id: DOMExceptionImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class DOMExceptionImpl extends DOMException { private static final long serialVersionUID = 7365733663951145145L; public static final int SYNTAX_ERROR = 0; public static final int ARRAY_OUT_OF_BOUNDS = 1; public static final int READ_ONLY_STYLE_SHEET = 2; public static final int EXPECTING_UNKNOWN_RULE = 3; public static final int EXPECTING_STYLE_RULE = 4; public static final int EXPECTING_CHARSET_RULE = 5; public static final int EXPECTING_IMPORT_RULE = 6; public static final int EXPECTING_MEDIA_RULE = 7; public static final int EXPECTING_FONT_FACE_RULE = 8; public static final int EXPECTING_PAGE_RULE = 9; public static final int FLOAT_ERROR = 10; public static final int STRING_ERROR = 11; public static final int COUNTER_ERROR = 12; public static final int RECT_ERROR = 13; public static final int RGBCOLOR_ERROR = 14; public static final int CHARSET_NOT_FIRST = 15; public static final int CHARSET_NOT_UNIQUE = 16; public static final int IMPORT_NOT_FIRST = 17; public static final int NOT_FOUND = 18; public static final int NOT_IMPLEMENTED = 19; private static ResourceBundle _exceptionResource = ResourceBundle.getBundle( "com.steadystate.css.parser.ExceptionResource", Locale.getDefault()); public DOMExceptionImpl(short code, int messageKey) { super(code, _exceptionResource.getString(keyString(messageKey))); } public DOMExceptionImpl(int code, int messageKey) { super((short) code, _exceptionResource.getString(keyString(messageKey))); } public DOMExceptionImpl(short code, int messageKey, String info) { super(code, _exceptionResource.getString(keyString(messageKey))); } private static String keyString(int key) { return "s" + String.valueOf(key); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSUnknownRuleImpl.java0000644000175000017500000000735310772331064027025 0ustar cavedoncavedon/* * $Id: CSSUnknownRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.Serializable; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSUnknownRule; /** * Implementation of {@link CSSUnknownRule}. * * TODO: Reinstate setCssText * * @author David Schweinsberg * @version $Id: CSSUnknownRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class CSSUnknownRuleImpl extends AbstractCSSRuleImpl implements CSSUnknownRule, Serializable { private static final long serialVersionUID = -268104019127675990L; String text = null; public String getText() { return this.text; } public void setText(String text) { this.text = text; } public CSSUnknownRuleImpl( CSSStyleSheetImpl parentStyleSheet, CSSRule parentRule, String text) { super(parentStyleSheet, parentRule); this.text = text; } public CSSUnknownRuleImpl() { } public short getType() { return UNKNOWN_RULE; } public String getCssText() { return this.text; } public void setCssText(String cssText) throws DOMException { /* if( _parentStyleSheet != null && _parentStyleSheet.isReadOnly() ) throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET ); try { // // Parse the rule string and retrieve the rule // StringReader sr = new StringReader( cssText ); CSS2Parser parser = new CSS2Parser( sr ); ASTStyleSheetRuleSingle ssrs = parser.styleSheetRuleSingle(); CSSRule r = (CSSRule) ssrs.jjtGetChild( 0 ); // // The rule must be an unknown rule // if( r.getType() == CSSRule.UNKNOWN_RULE ) { _text = ((ASTUnknownRule)r)._text; setChildren( ((SimpleNode)r).getChildren() ); } else { throw new DOMExceptionImpl( DOMException.INVALID_MODIFICATION_ERR, DOMExceptionImpl.EXPECTING_UNKNOWN_RULE ); } } catch( ParseException e ) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage() ); } */ } public CSSStyleSheet getParentStyleSheet() { return this.parentStyleSheet; } public CSSRule getParentRule() { return this.parentRule; } public String toString() { return this.getCssText(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSImportRuleImpl.java0000644000175000017500000001052410772331064026632 0ustar cavedoncavedon/* * $Id: CSSImportRuleImpl.java,v 1.3 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.IOException; import java.io.Serializable; import java.io.StringReader; import org.w3c.dom.DOMException; import org.w3c.dom.stylesheets.MediaList; import org.w3c.dom.css.CSSImportRule; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSStyleSheet; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; import com.steadystate.css.parser.CSSOMParser; /** * Implementation of {@link CSSImportRule}. * * TODO: Implement getStyleSheet() * * @author David Schweinsberg * @version $Id: CSSImportRuleImpl.java,v 1.3 2008/03/26 02:17:24 sdanig Exp $ */ public class CSSImportRuleImpl extends AbstractCSSRuleImpl implements CSSImportRule, Serializable { private static final long serialVersionUID = 7807829682009179339L; String href = null; MediaList media = null; public void setHref(String href) { this.href = href; } public void setMedia(MediaList media) { this.media = media; } public CSSImportRuleImpl( CSSStyleSheetImpl parentStyleSheet, CSSRule parentRule, String href, MediaList media) { super(parentStyleSheet, parentRule); this.href = href; this.media = media; } public CSSImportRuleImpl() { } public short getType() { return IMPORT_RULE; } public String getCssText() { StringBuilder sb = new StringBuilder(); sb.append("@import url(") .append(getHref()) .append(")"); if (getMedia().getLength() > 0) { sb.append(" ").append(getMedia().toString()); } sb.append(";"); return sb.toString(); } public void setCssText(String cssText) throws DOMException { if (this.parentStyleSheet != null && this.parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { InputSource is = new InputSource(new StringReader(cssText)); CSSOMParser parser = new CSSOMParser(); CSSRule r = parser.parseRule(is); // The rule must be an import rule if (r.getType() == CSSRule.IMPORT_RULE) { this.href = ((CSSImportRuleImpl)r).href; this.media = ((CSSImportRuleImpl)r).media; } else { throw new DOMExceptionImpl( DOMException.INVALID_MODIFICATION_ERR, DOMExceptionImpl.EXPECTING_IMPORT_RULE); } } catch (CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } } public String getHref() { return this.href; } public MediaList getMedia() { return this.media; } public CSSStyleSheet getStyleSheet() { return null; } public String toString() { return this.getCssText(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/MediaListImpl.java0000644000175000017500000000775710772331064026050 0ustar cavedoncavedon/* * $Id: MediaListImpl.java,v 1.3 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.IOException; import java.io.Serializable; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import org.w3c.dom.DOMException; import org.w3c.dom.stylesheets.MediaList; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.CSSParseException; import org.w3c.css.sac.SACMediaList; import com.steadystate.css.parser.SACParserCSS2; /** * Implements {@link MediaList}. * * @author David Schweinsberg * @version $Id: MediaListImpl.java,v 1.3 2008/03/26 02:17:24 sdanig Exp $ */ public class MediaListImpl extends CSSOMObjectImpl implements MediaList, Serializable { private static final long serialVersionUID = 6662784733573034870L; private List media = new ArrayList(); public void setMedia(List media) { this.media = media; } private void setMediaList(SACMediaList mediaList) { for (int i = 0; i < mediaList.getLength(); i++) { this.media.add(mediaList.item(i)); } } public MediaListImpl(SACMediaList mediaList) { this.setMediaList(mediaList); } public MediaListImpl() { } public String getMediaText() { StringBuffer sb = new StringBuffer(""); for (int i = 0; i < this.media.size(); i++) { sb.append(this.media.get(i)); if (i < this.media.size() - 1) { sb.append( ", " ); } } return sb.toString(); } public void setMediaText(String mediaText) throws DOMException { InputSource source = new InputSource(new StringReader(mediaText)); try { // TODO get SAC Parser version from System property? SACMediaList sml = new SACParserCSS2().parseMedia(source); this.setMediaList(sml); } catch (CSSParseException e) { throw new DOMException(DOMException.SYNTAX_ERR, e.getLocalizedMessage()); } catch (IOException e) { throw new DOMException(DOMException.NOT_FOUND_ERR, e.getLocalizedMessage()); } } public int getLength() { return this.media.size(); } public String item(int index) { return (index < this.media.size()) ? this.media.get(index) : null; } public void deleteMedium(String oldMedium) throws DOMException { for (int i = 0; i < this.media.size(); i++) { String str = this.media.get(i); if (str.equalsIgnoreCase(oldMedium)) { this.media.remove(i); return; } } throw new DOMExceptionImpl( DOMException.NOT_FOUND_ERR, DOMExceptionImpl.NOT_FOUND); } public void appendMedium(String newMedium) throws DOMException { this.media.add(newMedium); } public String toString() { return this.getMediaText(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSFontFaceRuleImpl.java0000644000175000017500000000715310772331064027051 0ustar cavedoncavedon/* * $Id: CSSFontFaceRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.IOException; import java.io.Serializable; import java.io.StringReader; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSFontFaceRule; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; import com.steadystate.css.parser.CSSOMParser; /** * Implementation of {@link CSSFontFaceRule}. * * @author David Schweinsberg * @version $Id: CSSFontFaceRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class CSSFontFaceRuleImpl extends AbstractCSSRuleImpl implements CSSFontFaceRule, Serializable { private static final long serialVersionUID = -3604191834588759088L; private CSSStyleDeclarationImpl style = null; public CSSFontFaceRuleImpl(CSSStyleSheetImpl parentStyleSheet, CSSRule parentRule) { super(parentStyleSheet, parentRule); } public CSSFontFaceRuleImpl() { } public short getType() { return FONT_FACE_RULE; } public String getCssText() { return "@font-face {" + getStyle().getCssText() + "}"; } public void setCssText(String cssText) throws DOMException { if (this.parentStyleSheet != null && this.parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { InputSource is = new InputSource(new StringReader(cssText)); CSSOMParser parser = new CSSOMParser(); CSSRule r = parser.parseRule(is); // The rule must be a font face rule if (r.getType() == CSSRule.FONT_FACE_RULE) { this.style = ((CSSFontFaceRuleImpl)r).style; } else { throw new DOMExceptionImpl( DOMException.INVALID_MODIFICATION_ERR, DOMExceptionImpl.EXPECTING_FONT_FACE_RULE); } } catch (CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } } public CSSStyleDeclaration getStyle() { return this.style; } public void setStyle(CSSStyleDeclarationImpl style) { this.style = style; } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSCharsetRuleImpl.java0000644000175000017500000000717210772331064026756 0ustar cavedoncavedon/* * $Id: CSSCharsetRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.IOException; import java.io.Serializable; import java.io.StringReader; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSCharsetRule; import org.w3c.dom.css.CSSRule; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.CSSException; import com.steadystate.css.parser.CSSOMParser; /** * Implementation of {@link CSSCharsetRule}. * * @author David Schweinsberg * @version $Id: CSSCharsetRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class CSSCharsetRuleImpl extends AbstractCSSRuleImpl implements CSSCharsetRule, Serializable { private static final long serialVersionUID = -2472209213089007127L; String encoding = null; public CSSCharsetRuleImpl( CSSStyleSheetImpl parentStyleSheet, CSSRule parentRule, String encoding) { super(parentStyleSheet, parentRule); this.encoding = encoding; } public CSSCharsetRuleImpl() { } public short getType() { return CHARSET_RULE; } public String getCssText() { return "@charset \"" + this.getEncoding() + "\";"; } public void setCssText(String cssText) throws DOMException { if (this.parentStyleSheet != null && this.parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { InputSource is = new InputSource(new StringReader(cssText)); CSSOMParser parser = new CSSOMParser(); CSSRule r = parser.parseRule(is); // The rule must be a charset rule if (r.getType() == CSSRule.CHARSET_RULE) { this.encoding = ((CSSCharsetRuleImpl)r).encoding; } else { throw new DOMExceptionImpl( DOMException.INVALID_MODIFICATION_ERR, DOMExceptionImpl.EXPECTING_CHARSET_RULE); } } catch (CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } } public String getEncoding() { return this.encoding; } public void setEncoding(String encoding) throws DOMException { this.encoding = encoding; } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSStyleSheetImpl.java0000644000175000017500000002421410772331064026622 0ustar cavedoncavedon/* * $Id: CSSStyleSheetImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.IOException; import java.io.Serializable; import java.io.StringReader; import org.w3c.dom.DOMException; import org.w3c.dom.Node; import org.w3c.dom.stylesheets.MediaList; import org.w3c.dom.stylesheets.StyleSheet; import org.w3c.dom.css.CSSImportRule; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleSheet; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.SACMediaList; import com.steadystate.css.parser.CSSOMParser; import com.steadystate.css.parser.SACParserCSS2; /** * Implementation of {@link CSSStyleSheet}. * * @author David Schweinsberg * @version $Id: CSSStyleSheetImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class CSSStyleSheetImpl implements CSSStyleSheet, Serializable { private static final long serialVersionUID = -2300541300646796363L; private boolean disabled = false; private Node ownerNode = null; private StyleSheet parentStyleSheet = null; private String href = null; private String title = null; private MediaList media = null; private CSSRule ownerRule = null; private boolean readOnly = false; private CSSRuleList cssRules = null; private String baseUri; public void setMedia(MediaList media) { this.media = media; } private String getBaseUri() { return this.baseUri; } public void setBaseUri(String baseUri) { this.baseUri = baseUri; } public CSSStyleSheetImpl() { } public String getType() { return "text/css"; } public boolean getDisabled() { return this.disabled; } /** * We will need to respond more fully if a stylesheet is disabled, probably * by generating an event for the main application. */ public void setDisabled(boolean disabled) { this.disabled = disabled; } public Node getOwnerNode() { return this.ownerNode; } public StyleSheet getParentStyleSheet() { return this.parentStyleSheet; } public String getHref() { return this.href; } public String getTitle() { return this.title; } public MediaList getMedia() { return this.media; } public CSSRule getOwnerRule() { return this.ownerRule; } public CSSRuleList getCssRules() { if (this.cssRules == null) { this.cssRules = new CSSRuleListImpl(); } return this.cssRules; } public int insertRule(String rule, int index) throws DOMException { if (this.readOnly) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { InputSource is = new InputSource(new StringReader(rule)); CSSOMParser parser = new CSSOMParser(); parser.setParentStyleSheet(this); CSSRule r = parser.parseRule(is); if (getCssRules().getLength() > 0) { // We need to check that this type of rule can legally go into // the requested position. int msg = -1; if (r.getType() == CSSRule.CHARSET_RULE) { // Index must be 0, and there can be only one charset rule if (index != 0) { msg = DOMExceptionImpl.CHARSET_NOT_FIRST; } else if (getCssRules().item(0).getType() == CSSRule.CHARSET_RULE) { msg = DOMExceptionImpl.CHARSET_NOT_UNIQUE; } } else if (r.getType() == CSSRule.IMPORT_RULE) { // Import rules must preceed all other rules (except // charset rules) if (index <= getCssRules().getLength()) { for (int i = 0; i < index; i++) { int rt = getCssRules().item(i).getType(); if ((rt != CSSRule.CHARSET_RULE) || (rt != CSSRule.IMPORT_RULE)) { msg = DOMExceptionImpl.IMPORT_NOT_FIRST; break; } } } } if (msg > -1) { throw new DOMExceptionImpl( DOMException.HIERARCHY_REQUEST_ERR, msg); } } // Insert the rule into the list of rules ((CSSRuleListImpl)getCssRules()).insert(r, index); } catch (ArrayIndexOutOfBoundsException e) { throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, DOMExceptionImpl.ARRAY_OUT_OF_BOUNDS, e.getMessage()); } catch (CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } return index; } public void deleteRule(int index) throws DOMException { if (this.readOnly) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { ((CSSRuleListImpl)getCssRules()).delete(index); } catch (ArrayIndexOutOfBoundsException e) { throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, DOMExceptionImpl.ARRAY_OUT_OF_BOUNDS, e.getMessage()); } } public boolean isReadOnly() { return this.readOnly; } public void setReadOnly(boolean b) { this.readOnly = b; } public void setOwnerNode(Node ownerNode) { this.ownerNode = ownerNode; } public void setParentStyleSheet(StyleSheet parentStyleSheet) { this.parentStyleSheet = parentStyleSheet; } public void setHref(String href) { this.href = href; } public void setTitle(String title) { this.title = title; } public void setMediaText(String mediaText) { InputSource source = new InputSource(new StringReader(mediaText)); try { // TODO get SAC Parser version from System property? SACMediaList sml = new SACParserCSS2().parseMedia(source); this.media = new MediaListImpl(sml); } catch (IOException e) { // TODO handle exception } } public void setOwnerRule(CSSRule ownerRule) { this.ownerRule = ownerRule; } public void setCssRules(CSSRuleList rules) { this.cssRules = rules; } public String toString() { return this.getCssRules().toString(); } /** * Imports referenced CSSStyleSheets. * * @param recursive true if the import should be done * recursively, false otherwise */ public void importImports(boolean recursive) throws DOMException { for (int i = 0; i < this.getCssRules().getLength(); i++) { CSSRule cssRule = this.getCssRules().item(i); if (cssRule.getType() == CSSRule.IMPORT_RULE) { CSSImportRule cssImportRule = (CSSImportRule) cssRule; try { java.net.URI importURI = new java.net.URI(this.getBaseUri()) .resolve(cssImportRule.getHref()); CSSStyleSheetImpl importedCSS = (CSSStyleSheetImpl) new CSSOMParser().parseStyleSheet(new InputSource( importURI.toString()), null, importURI.toString()); if (recursive) { importedCSS.importImports(recursive); } MediaList mediaList = cssImportRule.getMedia(); if (mediaList.getLength() == 0) { mediaList.appendMedium("all"); } CSSMediaRuleImpl cssMediaRule = new CSSMediaRuleImpl(this, null, mediaList); cssMediaRule.setRuleList( (CSSRuleListImpl) importedCSS.getCssRules()); this.deleteRule(i); ((CSSRuleListImpl) this.getCssRules()).insert(cssMediaRule, i); } catch (java.net.URISyntaxException e) { // TODO handle exception throw new DOMException(DOMException.SYNTAX_ERR, e.getLocalizedMessage()); } catch (IOException e) { // TODO handle exception } } } } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSPageRuleImpl.java0000644000175000017500000001071110772331064026232 0ustar cavedoncavedon/* * $Id: CSSPageRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.IOException; import java.io.Serializable; import java.io.StringReader; import org.w3c.dom.DOMException; import org.w3c.dom.css.CSSPageRule; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; import com.steadystate.css.parser.CSSOMParser; /** * Implementation of {@link CSSPageRule}. * * TODO: Implement setSelectorText() * * @author David Schweinsberg * @version $Id: CSSPageRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class CSSPageRuleImpl extends AbstractCSSRuleImpl implements CSSPageRule, Serializable { private static final long serialVersionUID = -6007519872104320812L; private String ident = null; private String pseudoPage = null; private CSSStyleDeclaration style = null; public CSSPageRuleImpl( CSSStyleSheetImpl parentStyleSheet, CSSRule parentRule, String ident, String pseudoPage) { super(parentStyleSheet, parentRule); this.ident = ident; this.pseudoPage = pseudoPage; } public CSSPageRuleImpl() { } public short getType() { return PAGE_RULE; } public String getCssText() { String sel = getSelectorText(); return "@page {" + sel + ((sel.length() > 0) ? " " : "") + getStyle().getCssText() + "}"; } public void setCssText(String cssText) throws DOMException { if (this.parentStyleSheet != null && this.parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { InputSource is = new InputSource(new StringReader(cssText)); CSSOMParser parser = new CSSOMParser(); CSSRule r = parser.parseRule(is); // The rule must be a page rule if (r.getType() == CSSRule.PAGE_RULE) { this.ident = ((CSSPageRuleImpl)r).ident; this.pseudoPage = ((CSSPageRuleImpl)r).pseudoPage; this.style = ((CSSPageRuleImpl)r).style; } else { throw new DOMExceptionImpl( DOMException.INVALID_MODIFICATION_ERR, DOMExceptionImpl.EXPECTING_PAGE_RULE); } } catch (CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } } public String getSelectorText() { return ((this.ident != null) ? this.ident : "") + ((this.pseudoPage != null) ? ":" + this.pseudoPage : ""); } public void setSelectorText(String selectorText) throws DOMException { } public CSSStyleDeclaration getStyle() { return this.style; } public void setIdent(String ident) { this.ident = ident; } public void setPseudoPage(String pseudoPage) { this.pseudoPage = pseudoPage; } public void setStyle(CSSStyleDeclarationImpl style) { this.style = style; } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSValueImpl.java0000644000175000017500000003301110772330067025602 0ustar cavedoncavedon/* * $Id: CSSValueImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.Serializable; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.LexicalUnit; import org.w3c.css.sac.Locator; import org.w3c.dom.DOMException; import org.w3c.dom.css.Counter; import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSValue; import org.w3c.dom.css.CSSValueList; import org.w3c.dom.css.Rect; import org.w3c.dom.css.RGBColor; import com.steadystate.css.parser.CSSOMParser; import com.steadystate.css.parser.LexicalUnitImpl; import com.steadystate.css.userdata.UserDataConstants; /** * The CSSValueImpl class can represent either a * CSSPrimitiveValue or a CSSValueList so that * the type can successfully change when using setCssText. * * TODO: * Float unit conversions, * A means of checking valid primitive types for properties * * @author David Schweinsberg * @version $Id: CSSValueImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ */ public class CSSValueImpl extends CSSOMObjectImpl implements CSSPrimitiveValue, CSSValueList, Serializable { private static final long serialVersionUID = 406281136418322579L; private Object _value = null; public Object getValue() { return this._value; } public void setValue(Object value) { this._value = value; } /** * Constructor */ public CSSValueImpl(LexicalUnit value, boolean forcePrimitive) { if (!forcePrimitive && (value.getNextLexicalUnit() != null)) { this._value = this.getValues(value); } else if (value.getParameters() != null) { if (value.getLexicalUnitType() == LexicalUnit.SAC_RECT_FUNCTION) { // Rect this._value = new RectImpl(value.getParameters()); } else if (value.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) { // RGBColor this._value = new RGBColorImpl(value.getParameters()); } else if (value.getLexicalUnitType() == LexicalUnit.SAC_COUNTER_FUNCTION) { // Counter this._value = new CounterImpl(false, value.getParameters()); } else if (value.getLexicalUnitType() == LexicalUnit.SAC_COUNTERS_FUNCTION) { // Counter this._value = new CounterImpl(true, value.getParameters()); } else { this._value = value; } } else { // We need to be a CSSPrimitiveValue this._value = value; } if (value instanceof LexicalUnitImpl) { Locator locator = ((LexicalUnitImpl) value).getLocator(); if (locator != null) { this.setUserData(UserDataConstants.KEY_LOCATOR, locator); } } } public CSSValueImpl() { } private List getValues(LexicalUnit value) { // We need to be a CSSValueList // Values in an "expr" can be seperated by "operator"s, which are // either '/' or ',' - ignore these operators List values = new ArrayList(); LexicalUnit lu = value; while (lu != null) { if ((lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) && (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_SLASH)) { values.add(new CSSValueImpl(lu, true)); } lu = lu.getNextLexicalUnit(); } return values; } public CSSValueImpl(LexicalUnit value) { this(value, false); } public String getCssText() { if (getCssValueType() == CSS_VALUE_LIST) { // Create the string from the LexicalUnits so we include the correct // operators in the string StringBuilder sb = new StringBuilder(); List list = (List) this._value; java.util.Iterator it = list.iterator(); while (it.hasNext()) { Object o = it.next(); if (o instanceof LexicalUnit) { LexicalUnit lu = (LexicalUnit) ((CSSValueImpl) list.get(0))._value; while (lu != null) { sb.append(lu.toString()); // Step to the next lexical unit, determining what spacing we // need to put around the operators LexicalUnit prev = lu; lu = lu.getNextLexicalUnit(); if ((lu != null) && (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) && (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_SLASH) && (prev.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_SLASH)) { sb.append(" "); } } } else { sb.append(o); } if (it.hasNext()) { sb.append(" "); } } return sb.toString(); } return this._value.toString(); } public void setCssText(String cssText) throws DOMException { try { InputSource is = new InputSource(new StringReader(cssText)); CSSOMParser parser = new CSSOMParser(); CSSValueImpl v2 = (CSSValueImpl) parser.parsePropertyValue(is); this._value = v2._value; } catch (Exception e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage() ); } } public short getCssValueType() { if (this._value instanceof List) { return CSS_VALUE_LIST; } else if ((this._value instanceof LexicalUnit) && (((LexicalUnit) this._value).getLexicalUnitType() == LexicalUnit.SAC_INHERIT)) { return CSS_INHERIT; } return CSS_PRIMITIVE_VALUE; } public short getPrimitiveType() { if (this._value instanceof LexicalUnit) { LexicalUnit lu = (LexicalUnit) this._value; switch (lu.getLexicalUnitType()) { case LexicalUnit.SAC_INHERIT: return CSS_IDENT; case LexicalUnit.SAC_INTEGER: case LexicalUnit.SAC_REAL: return CSS_NUMBER; case LexicalUnit.SAC_EM: return CSS_EMS; case LexicalUnit.SAC_EX: return CSS_EXS; case LexicalUnit.SAC_PIXEL: return CSS_PX; case LexicalUnit.SAC_INCH: return CSS_IN; case LexicalUnit.SAC_CENTIMETER: return CSS_CM; case LexicalUnit.SAC_MILLIMETER: return CSS_MM; case LexicalUnit.SAC_POINT: return CSS_PT; case LexicalUnit.SAC_PICA: return CSS_PC; case LexicalUnit.SAC_PERCENTAGE: return CSS_PERCENTAGE; case LexicalUnit.SAC_URI: return CSS_URI; // case LexicalUnit.SAC_COUNTER_FUNCTION: // case LexicalUnit.SAC_COUNTERS_FUNCTION: // return CSS_COUNTER; // case LexicalUnit.SAC_RGBCOLOR: // return CSS_RGBCOLOR; case LexicalUnit.SAC_DEGREE: return CSS_DEG; case LexicalUnit.SAC_GRADIAN: return CSS_GRAD; case LexicalUnit.SAC_RADIAN: return CSS_RAD; case LexicalUnit.SAC_MILLISECOND: return CSS_MS; case LexicalUnit.SAC_SECOND: return CSS_S; case LexicalUnit.SAC_HERTZ: return CSS_KHZ; case LexicalUnit.SAC_KILOHERTZ: return CSS_HZ; case LexicalUnit.SAC_IDENT: return CSS_IDENT; case LexicalUnit.SAC_STRING_VALUE: return CSS_STRING; case LexicalUnit.SAC_ATTR: return CSS_ATTR; // case LexicalUnit.SAC_RECT_FUNCTION: // return CSS_RECT; case LexicalUnit.SAC_UNICODERANGE: case LexicalUnit.SAC_SUB_EXPRESSION: case LexicalUnit.SAC_FUNCTION: return CSS_STRING; case LexicalUnit.SAC_DIMENSION: return CSS_DIMENSION; } } else if (this._value instanceof RectImpl) { return CSS_RECT; } else if (this._value instanceof RGBColorImpl) { return CSS_RGBCOLOR; } else if (this._value instanceof CounterImpl) { return CSS_COUNTER; } return CSS_UNKNOWN; } public void setFloatValue(short unitType, float floatValue) throws DOMException { this._value = LexicalUnitImpl.createNumber(null, floatValue); } public float getFloatValue(short unitType) throws DOMException { if (this._value instanceof LexicalUnit) { LexicalUnit lu = (LexicalUnit) this._value; return lu.getFloatValue(); } throw new DOMExceptionImpl( DOMException.INVALID_ACCESS_ERR, DOMExceptionImpl.FLOAT_ERROR); // We need to attempt a conversion // return 0; } public void setStringValue(short stringType, String stringValue) throws DOMException { switch (stringType) { case CSS_STRING: this._value = LexicalUnitImpl.createString(null, stringValue); break; case CSS_URI: this._value = LexicalUnitImpl.createURI(null, stringValue); break; case CSS_IDENT: this._value = LexicalUnitImpl.createIdent(null, stringValue); break; case CSS_ATTR: // this._value = LexicalUnitImpl.createAttr(null, stringValue); // break; throw new DOMExceptionImpl( DOMException.NOT_SUPPORTED_ERR, DOMExceptionImpl.NOT_IMPLEMENTED); default: throw new DOMExceptionImpl( DOMException.INVALID_ACCESS_ERR, DOMExceptionImpl.STRING_ERROR); } } /** * TODO: return a value for a list type */ public String getStringValue() throws DOMException { if (this._value instanceof LexicalUnit) { LexicalUnit lu = (LexicalUnit) this._value; if ((lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) || (lu.getLexicalUnitType() == LexicalUnit.SAC_STRING_VALUE) || (lu.getLexicalUnitType() == LexicalUnit.SAC_URI) || (lu.getLexicalUnitType() == LexicalUnit.SAC_INHERIT)) { return lu.getStringValue(); } else if (lu.getLexicalUnitType() == LexicalUnit.SAC_ATTR) { return lu.getParameters().getStringValue(); } } else if (this._value instanceof List) { return null; } throw new DOMExceptionImpl( DOMException.INVALID_ACCESS_ERR, DOMExceptionImpl.STRING_ERROR); } public Counter getCounterValue() throws DOMException { if ((this._value instanceof Counter) == false) { throw new DOMExceptionImpl( DOMException.INVALID_ACCESS_ERR, DOMExceptionImpl.COUNTER_ERROR); } return (Counter) this._value; } public Rect getRectValue() throws DOMException { if ((this._value instanceof Rect) == false) { throw new DOMExceptionImpl( DOMException.INVALID_ACCESS_ERR, DOMExceptionImpl.RECT_ERROR); } return (Rect) this._value; } public RGBColor getRGBColorValue() throws DOMException { if ((this._value instanceof RGBColor) == false) { throw new DOMExceptionImpl( DOMException.INVALID_ACCESS_ERR, DOMExceptionImpl.RGBCOLOR_ERROR); } return (RGBColor) this._value; } public int getLength() { return (this._value instanceof List) ? ((List)this._value).size() : 0; } public CSSValue item(int index) { return (this._value instanceof List) ? ((CSSValue)((List)this._value).get(index)) : null; } public String toString() { return getCssText(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/Property.java0000644000175000017500000000450510770335720025164 0ustar cavedoncavedon/* * $Id: Property.java,v 1.1 2008/03/20 01:20:16 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.Serializable; import org.w3c.dom.css.CSSValue; /** * * @author David Schweinsberg * @version $Id: Property.java,v 1.1 2008/03/20 01:20:16 sdanig Exp $ */ public class Property extends CSSOMObjectImpl implements Serializable { private static final long serialVersionUID = 8720637891949104989L; private String name; private CSSValue value; private boolean important; public void setName(String name) { this.name = name; } /** Creates new Property */ public Property(String name, CSSValue value, boolean important) { this.name = name; this.value = value; this.important = important; } public Property() { } public String getName() { return this.name; } public CSSValue getValue() { return this.value; } public boolean isImportant() { return this.important; } public void setValue(CSSValue value) { this.value = value; } public void setImportant(boolean important) { this.important = important; } public String toString() { return this.name + ": " + this.value.toString() + (this.important ? " !important" : ""); } }cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSRuleListImpl.java0000644000175000017500000000505310772330067026276 0ustar cavedoncavedon/* * $Id: CSSRuleListImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSRuleList; /** * Implementation of {@link CSSRuleList}. * * @author David Schweinsberg * @version $Id: CSSRuleListImpl.java,v 1.3 2008/03/26 02:08:55 sdanig Exp $ */ public class CSSRuleListImpl implements CSSRuleList, Serializable { private static final long serialVersionUID = -1269068897476453290L; private List rules = null; public List getRules() { if (this.rules == null) { this.rules = new ArrayList(); } return this.rules; } public void setRules(List rules) { this.rules = rules; } public CSSRuleListImpl() { } public int getLength() { return this.getRules().size(); } public CSSRule item(int index) { return this.getRules().get(index); } public void add(CSSRule rule) { this.getRules().add(rule); } public void insert(CSSRule rule, int index) { this.getRules().add(index, rule); } public void delete(int index) { this.getRules().remove(index); } public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < this.getLength(); i++ ) { sb.append(this.item(i).toString()).append("\r\n"); } return sb.toString(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSMediaRuleImpl.java0000644000175000017500000001473410772331064026406 0ustar cavedoncavedon/* * $Id: CSSMediaRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.dom; import java.io.IOException; import java.io.Serializable; import java.io.StringReader; import org.w3c.dom.DOMException; import org.w3c.dom.stylesheets.MediaList; import org.w3c.dom.css.CSSMediaRule; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSRuleList; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; import com.steadystate.css.parser.CSSOMParser; /** * Implementation of {@link CSSMediaRule}. * * @author David Schweinsberg * @version $Id: CSSMediaRuleImpl.java,v 1.2 2008/03/26 02:17:24 sdanig Exp $ */ public class CSSMediaRuleImpl extends AbstractCSSRuleImpl implements CSSMediaRule, Serializable { private static final long serialVersionUID = 6603734096445214651L; private MediaList media = null; private CSSRuleList cssRules = null; public void setMedia(MediaList media) { this.media = media; } public void setCssRules(CSSRuleList cssRules) { this.cssRules = cssRules; } public CSSMediaRuleImpl( CSSStyleSheetImpl parentStyleSheet, CSSRule parentRule, MediaList media) { super(parentStyleSheet, parentRule); this.media = media; } public CSSMediaRuleImpl() { } public short getType() { return MEDIA_RULE; } public String getCssText() { StringBuffer sb = new StringBuffer("@media "); sb.append(getMedia().toString()).append(" {"); for (int i = 0; i < getCssRules().getLength(); i++) { CSSRule rule = getCssRules().item(i); sb.append(rule.getCssText()).append(" "); } sb.append("}"); return sb.toString(); } public void setCssText(String cssText) throws DOMException { if (this.parentStyleSheet != null && this.parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { InputSource is = new InputSource(new StringReader(cssText)); CSSOMParser parser = new CSSOMParser(); CSSRule r = parser.parseRule(is); // The rule must be a media rule if (r.getType() == CSSRule.MEDIA_RULE) { this.media = ((CSSMediaRuleImpl)r).media; this.cssRules = ((CSSMediaRuleImpl)r).cssRules; } else { throw new DOMExceptionImpl( DOMException.INVALID_MODIFICATION_ERR, DOMExceptionImpl.EXPECTING_MEDIA_RULE); } } catch (CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } } public MediaList getMedia() { return this.media; } public CSSRuleList getCssRules() { if (this.cssRules == null) { this.cssRules = new CSSRuleListImpl(); } return this.cssRules; } public int insertRule(String rule, int index) throws DOMException { if (this.parentStyleSheet != null && this.parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { InputSource is = new InputSource(new StringReader(rule)); CSSOMParser parser = new CSSOMParser(); parser.setParentStyleSheet(this.parentStyleSheet); // parser._parentRule is never read //parser.setParentRule(_parentRule); CSSRule r = parser.parseRule(is); // Insert the rule into the list of rules ((CSSRuleListImpl)getCssRules()).insert(r, index); } catch (ArrayIndexOutOfBoundsException e) { throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, DOMExceptionImpl.ARRAY_OUT_OF_BOUNDS, e.getMessage()); } catch (CSSException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } catch (IOException e) { throw new DOMExceptionImpl( DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage()); } return index; } public void deleteRule(int index) throws DOMException { if (this.parentStyleSheet != null && this.parentStyleSheet.isReadOnly()) { throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET); } try { ((CSSRuleListImpl)getCssRules()).delete(index); } catch (ArrayIndexOutOfBoundsException e) { throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, DOMExceptionImpl.ARRAY_OUT_OF_BOUNDS, e.getMessage()); } } public void setRuleList(CSSRuleListImpl rules) { this.cssRules = rules; } public String toString() { return this.getCssText(); } } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSOMObject.java0000644000175000017500000000035410772331064025350 0ustar cavedoncavedon/* * Created on 05.12.2005 * */ package com.steadystate.css.dom; /** * @author koch */ public interface CSSOMObject { public Object getUserData(String key); public Object setUserData(String key, Object data); } cssparser-0.9.5/src/main/java/com/steadystate/css/dom/CSSOMObjectImpl.java0000644000175000017500000000151610772331064026173 0ustar cavedoncavedon/* * Created on 05.12.2005 * */ package com.steadystate.css.dom; import java.util.Hashtable; import java.util.Map; /** * Implementation of {@link CSSOMObject}. * * @author koch */ public class CSSOMObjectImpl implements CSSOMObject { private Map userDataMap; public Map getUserDataMap() { if (this.userDataMap == null) { this.userDataMap = new Hashtable(); } return this.userDataMap; } public void setUserDataMap(Map userDataMap) { this.userDataMap = userDataMap; } public CSSOMObjectImpl() { super(); } public Object getUserData(String key) { return this.getUserDataMap().get(key); } public Object setUserData(String key, Object data) { return this.getUserDataMap().put(key, data); } } cssparser-0.9.5/src/main/resources/0000755000175000017500000000000011420645030017072 5ustar cavedoncavedoncssparser-0.9.5/src/main/resources/com/0000755000175000017500000000000011420645030017650 5ustar cavedoncavedoncssparser-0.9.5/src/main/resources/com/steadystate/0000755000175000017500000000000011420645030022202 5ustar cavedoncavedoncssparser-0.9.5/src/main/resources/com/steadystate/css/0000755000175000017500000000000011420645030022772 5ustar cavedoncavedoncssparser-0.9.5/src/main/resources/com/steadystate/css/parser/0000755000175000017500000000000011420645030024266 5ustar cavedoncavedoncssparser-0.9.5/src/main/resources/com/steadystate/css/parser/SACParserMessages.properties0000644000175000017500000000251110770335722031671 0ustar cavedoncavedon# resource bundle for SACParser messages - default invalidExpectingOne=Invalid token \"{0}\". Was expecting: {1}. invalidExpectingMore=Invalid token \"{0}\". Was expecting one of: {1}. invalidColor=Invalid color \"{0}\". invalidStyleSheet=Error in style sheet. invalidRule=Error in rule. invalidUnknownRule=Error in unknown at-rule. invalidCharsetRule=Error in @charset rule. invalidImportRule=Error in @import rule. invalidImportRuleIgnored=@import rule must occur before all other rules, except the @charset rule. invalidPageRule=Error in @page rule. invalidFontFaceRule=Error in @font-face rule. invalidMediaList=Error in media list. invalidMediaRule=Error in @media rule. invalidStyleRule=Error in style rule. invalidStyleDeclaration=Error in style declaration. invalidDeclaration=Error in declaration. invalidSelectorList=Error in selector list. invalidSelector=Error in selector. invalidSimpleSelector=Error in simple selector. invalidClassSelector=Error in class selector. invalidElementName=Error in element name. invalidAttrib=Error in attribute selector. invalidPseudo=Error in pseudo class or element. invalidHash=Error in hash. invalidExpr=Error in expression. invalidPrio=Error in priority. ignoringRule=Ignoring the whole rule. ignoringFollowingDeclarations=Ignoring the following declarations in this rule. tokenMgrError=Lexical error. cssparser-0.9.5/src/main/resources/com/steadystate/css/parser/SACParserMessages_de.properties0000644000175000017500000000266310770335722032351 0ustar cavedoncavedon# resource bundle for SACParser messages - german invalidExpectingOne=Ung\u00fcltiger Token \"{0}\". Erwartet wurde: {1}. invalidExpectingMore=Ung\u00fcltiger Token \"{0}\". Erwartet wurde einer von: {1}. invalidColor=Ung\u00fcltige Farbe \"{0}\". invalidStyleSheet=Fehler im Stylesheet. invalidRule=Fehler in Regel. invalidUnknownRule=Fehler in unbekannter At-Regel. invalidCharsetRule=Fehler in @charset-Regel. invalidImportRule=Fehler in @import-Regel. invalidImportRuleIgnored=@import-Regel muss vor allen anderen Regeln erscheinen, au\u00dfer der @charset-Regel. invalidPageRule=Fehler in @page-Regel. invalidFontFaceRule=Fehler in @font-face-Regel. invalidMediaList=Fehler in Medienliste. invalidMediaRule=Fehler in @media-Regel. invalidStyleRule=Fehler in Style-Regel. invalidStyleDeclaration=Fehler in Styledeklaration. invalidDeclaration=Fehler in Deklaration. invalidSelectorList=Fehler in Selektorliste. invalidSelector=Fehler in Selektor. invalidSimpleSelector=Fehler in einfacher Selektor. invalidClassSelector=Fehler in Klassen-Selektor. invalidElementName=Fehler in Elementname. invalidAttrib=Fehler in Attribut-Selektor. invalidPseudo=Fehler in Pseudo-Klasse oder Pseudo-Element. invalidHash=Fehler in Hash. invalidExpr=Fehler in Ausdruck. invalidPrio=Fehler in Priorit\u00e4t. ignoringRule=Ignoriere die gesamte Regel. ignoringFollowingDeclarations=Ignoriere die folgenden Deklarationen in dieser Regel. tokenMgrError=Lexikalischer Fehler. cssparser-0.9.5/src/main/resources/com/steadystate/css/parser/SACParserMessages_en.properties0000644000175000017500000000251110770335722032353 0ustar cavedoncavedon# resource bundle for SACParser messages - default invalidExpectingOne=Invalid token \"{0}\". Was expecting: {1}. invalidExpectingMore=Invalid token \"{0}\". Was expecting one of: {1}. invalidColor=Invalid color \"{0}\". invalidStyleSheet=Error in style sheet. invalidRule=Error in rule. invalidUnknownRule=Error in unknown at-rule. invalidCharsetRule=Error in @charset rule. invalidImportRule=Error in @import rule. invalidImportRuleIgnored=@import rule must occur before all other rules, except the @charset rule. invalidPageRule=Error in @page rule. invalidFontFaceRule=Error in @font-face rule. invalidMediaList=Error in media list. invalidMediaRule=Error in @media rule. invalidStyleRule=Error in style rule. invalidStyleDeclaration=Error in style declaration. invalidDeclaration=Error in declaration. invalidSelectorList=Error in selector list. invalidSelector=Error in selector. invalidSimpleSelector=Error in simple selector. invalidClassSelector=Error in class selector. invalidElementName=Error in element name. invalidAttrib=Error in attribute selector. invalidPseudo=Error in pseudo class or element. invalidHash=Error in hash. invalidExpr=Error in expression. invalidPrio=Error in priority. ignoringRule=Ignoring the whole rule. ignoringFollowingDeclarations=Ignoring the following declarations in this rule. tokenMgrError=Lexical error. cssparser-0.9.5/src/changes/0000755000175000017500000000000011420645030015544 5ustar cavedoncavedoncssparser-0.9.5/src/changes/changes.xml0000644000175000017500000000610310772564523017716 0ustar cavedoncavedon Changes Daniel Gredler Removed the deprecated classes com.steadystate.css.CSS2Parser, com.steadystate.css.RGBColorImpl and com.steadystate.css.HexColor. Correctly unescape escaped characters in strings. CSSStyleDeclarationImpl.getCssText() fixed to not return curly braces (as per the spec). Removed unused class ParseException (one of two classes with this name). Updated the minimum required Java version to Java 5. Removed the W3C DOM and SAC classes, using instead the classes in the JDK and the official SAC JAR. Moved build system to Maven 2. Added parseMedia() to SACParser. Modified CSSOMParser to allow parser creation within the sandbox. JavaCC-generated files removed from the repository. css2.jj renamed to SACParser.jj. Initial JUnit tests added. Ant buildfile added. Fixed a bug in the '@page' rule where a space after an identifier or a pseudo page caused a parser exception. Made several modifications to provide JDK 1.1 compatability. Fixed a bug that caused negative floating-point values to be excessively trimmed. Updated the SAC to version 1.2. Updated the CSSOM to comply with the W3C recommendation. Made the CSSOM serializable. Implemented the SAC (Simple API for CSS). Converted the CSS DOM to be implemented on top of the SAC. Fixed case-sensitivity bug in ASTStyleDeclaration. Renamed methods in ASTMediaList to bring it into line with CR-DOM-Level-2-20000510. Reduced the number of states in the lexer to simplify matters and to aid with improved handling of invalid statements. cssparser-0.9.5/src/test/0000755000175000017500000000000011420645030015113 5ustar cavedoncavedoncssparser-0.9.5/src/test/java/0000755000175000017500000000000011420645030016034 5ustar cavedoncavedoncssparser-0.9.5/src/test/java/com/0000755000175000017500000000000011420645030016612 5ustar cavedoncavedoncssparser-0.9.5/src/test/java/com/steadystate/0000755000175000017500000000000011420645030021144 5ustar cavedoncavedoncssparser-0.9.5/src/test/java/com/steadystate/css/0000755000175000017500000000000011420645030021734 5ustar cavedoncavedoncssparser-0.9.5/src/test/java/com/steadystate/css/TestSerializable.java0000644000175000017500000000556110770350305026061 0ustar cavedoncavedon/* * TestSerializable.java * * Steady State CSS2 Parser * * Copyright (C) 1999, 2002 Steady State Software Ltd. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library, write to Steady State Software Ltd., * 49 Littleworth, Wing, Buckinghamshire, LU7 0JX, England * * http://www.steadystate.com/css/ * mailto:css@steadystate.co.uk * * $Id: TestSerializable.java,v 1.2 2008/03/20 02:49:41 sdanig Exp $ */ package com.steadystate.css; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.Reader; import junit.framework.TestCase; import org.w3c.css.sac.InputSource; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleSheet; import com.steadystate.css.parser.CSSOMParser; /** * @author David Schweinsberg * @version $Release$ */ public class TestSerializable extends TestCase { public void test() throws Exception { InputStream is = getClass().getClassLoader().getResourceAsStream("html40.css"); assertNotNull(is); CSSOMParser parser = new CSSOMParser(); Reader r = new InputStreamReader(is); InputSource source = new InputSource(r); CSSStyleSheet stylesheet = parser.parseStyleSheet(source, null, null); // Serialize the style sheet File temp = File.createTempFile("temp", "css"); temp.deleteOnExit(); FileOutputStream fo = new FileOutputStream(temp); ObjectOutput oo = new ObjectOutputStream(fo); oo.writeObject(stylesheet); oo.flush(); // Read it back in FileInputStream fi = new FileInputStream(temp); ObjectInput oi = new ObjectInputStream(fi); CSSStyleSheet stylesheet2 = (CSSStyleSheet) oi.readObject(); CSSRuleList rules = stylesheet2.getCssRules(); for (int i = 0; i < rules.getLength(); i++) { CSSRule rule = rules.item(i); System.out.println(rule.getCssText()); } } } cssparser-0.9.5/src/test/java/com/steadystate/css/TestException.java0000644000175000017500000000632410770350305025407 0ustar cavedoncavedon/* * TestException.java * * Steady State CSS2 Parser * * Copyright (C) 1999, 2002 Steady State Software Ltd. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library, write to Steady State Software Ltd., * 49 Littleworth, Wing, Buckinghamshire, LU7 0JX, England * * http://www.steadystate.com/css/ * mailto:css@steadystate.co.uk * * $Id: TestException.java,v 1.2 2008/03/20 02:49:41 sdanig Exp $ */ package com.steadystate.css; import java.io.Reader; import java.io.StringReader; import junit.framework.TestCase; import org.w3c.css.sac.InputSource; import org.w3c.dom.css.CSSMediaRule; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleSheet; import com.steadystate.css.parser.CSSOMParser; /** * Attempts to perform some illegal operations to ensure the correct exceptions are thrown. * * @author David Schweinsberg * @version $Release$ */ public class TestException extends TestCase { public void test() throws Exception { CSSOMParser parser = new CSSOMParser(); Reader r = new StringReader(""); InputSource source = new InputSource(r); CSSStyleSheet stylesheet = parser.parseStyleSheet(source, null, null); stylesheet.insertRule("P { color: blue }", 0); stylesheet.insertRule("@import url(http://www.steadystate.com/primary.css);", 0); stylesheet.insertRule("@charset \"US-ASCII\";", 0); stylesheet.deleteRule(1); CSSRuleList rules = stylesheet.getCssRules(); CSSRule rule = rules.item(1); // rule.setCssText("@import url(bogus.css);"); rule.setCssText("H2 { smell: strong }"); int n = stylesheet.insertRule("@media speech { H1 { voice: male } }", 1); rule = rules.item(n); ((CSSMediaRule) rule).insertRule("P { voice: female }", 1); System.out.println(((CSSMediaRule) rule).getMedia().getMediaText()); ((CSSMediaRule) rule).getMedia().setMediaText("speech, signlanguage"); System.out.println(((CSSMediaRule) rule).getMedia().getMediaText()); ((CSSMediaRule) rule).getMedia().deleteMedium("signlanguage"); System.out.println(((CSSMediaRule) rule).getMedia().getMediaText()); ((CSSMediaRule) rule).getMedia().appendMedium("semaphore"); // ((CSSMediaRule)rule).getMedia().delete("signlanguage"); // Print it out for (int i = 0; i < rules.getLength(); i++) { rule = rules.item(i); System.out.println(rule.getCssText()); } } } cssparser-0.9.5/src/test/java/com/steadystate/css/TestDOM2.java0000644000175000017500000000766510770350305024163 0ustar cavedoncavedon/* * TestDOM_1.java * * Steady State CSS2 Parser * * Copyright (C) 1999, 2002 Steady State Software Ltd. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library, write to Steady State Software Ltd., * 49 Littleworth, Wing, Buckinghamshire, LU7 0JX, England * * http://www.steadystate.com/css/ * mailto:css@steadystate.co.uk * * $Id: TestDOM2.java,v 1.2 2008/03/20 02:49:41 sdanig Exp $ */ package com.steadystate.css; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import junit.framework.TestCase; import org.w3c.css.sac.InputSource; import org.w3c.dom.css.CSSFontFaceRule; import org.w3c.dom.css.CSSImportRule; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleRule; import org.w3c.dom.css.CSSStyleSheet; import com.steadystate.css.parser.CSSOMParser; /** * Tests the CSS DOM implementation by loading a stylesheet and performing a few operations upon it. * * @author David Schweinsberg * @version $Release$ */ public class TestDOM2 extends TestCase { public void test() throws Exception { InputStream is = getClass().getClassLoader().getResourceAsStream("test.css"); assertNotNull(is); Reader r = new InputStreamReader(is); InputSource source = new InputSource(r); CSSOMParser parser = new CSSOMParser(); CSSStyleSheet stylesheet = parser.parseStyleSheet(source, null, null); CSSRuleList rules = stylesheet.getCssRules(); for (int i = 0; i < rules.getLength(); i++) { CSSRule rule = rules.item(i); System.out.println(rule.getCssText()); } // Do some modifications and output the results // Style Rules rules.item(9).setCssText("apple { color: green }"); // GOOD // rules.item(9).setCssText("@font-face { src: url(null) }"); // BAD CSSRule rule = rules.item(9); System.out.println(rule.getCssText()); ((CSSStyleRule) rules.item(9)).setSelectorText("banana"); // GOOD System.out.println(rule.getCssText()); ((CSSStyleRule) rules.item(9)).setSelectorText("banana, orange tangerine, grapefruit"); // GOOD System.out.println(rule.getCssText()); ((CSSStyleRule) rules.item(9)).getStyle().setCssText( "{ color: red green brown; smell: sweet, sour; taste: sweet/tart }"); // GOOD System.out.println(rule.getCssText()); // Import rules stylesheet.insertRule("@import \"thing.css\";", 0); // GOOD // stylesheet.insertRule("@import \"thing.css\";", 10); // BAD rule = rules.item(0); System.out.println(rule.getCssText()); ((CSSImportRule) rules.item(0)).setCssText("@import \"thing-hack.css\";"); System.out.println(rule.getCssText()); // Font-face rules stylesheet.insertRule("@font-face { src: \"#foo\" }", 10); // GOOD rule = rules.item(10); System.out.println(rule.getCssText()); ((CSSFontFaceRule) rules.item(10)).setCssText("@font-face { src: \"#bar\" }"); // GOOD // ((CSSFontFaceRule)rules.item(10)).setCssText("@import \"thing-hack.css\";"); // BAD System.out.println(rule.getCssText()); // Media rules } } cssparser-0.9.5/src/test/java/com/steadystate/css/parser/0000755000175000017500000000000011420645030023230 5ustar cavedoncavedoncssparser-0.9.5/src/test/java/com/steadystate/css/parser/CSSOMParserTest.java0000644000175000017500000001773110772323166027021 0ustar cavedoncavedon/* * $Id: CSSOMParserTest.java,v 1.7 2008/03/26 01:27:18 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import junit.framework.TestCase; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.Parser; import org.w3c.css.sac.SelectorList; import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSRule; import org.w3c.dom.css.CSSRuleList; import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.dom.css.CSSStyleRule; import org.w3c.dom.css.CSSStyleSheet; import org.w3c.dom.css.CSSValue; /** * @author David Schweinsberg * @version $Id: CSSOMParserTest.java,v 1.7 2008/03/26 01:27:18 sdanig Exp $ */ public class CSSOMParserTest extends TestCase { private String _testSelector = "FOO"; private String _testItem = "color"; private String _testValue = "rgb(1, 2, 3)"; private String _testString = _testSelector + "{ " + _testItem + ": " + _testValue + " }"; private CSSOMParser _parser = new CSSOMParser(); public void testParseStyleSheet() throws IOException { Reader r = new StringReader(_testString); InputSource is = new InputSource(r); CSSStyleSheet ss = _parser.parseStyleSheet(is, null, null); CSSRuleList rl = ss.getCssRules(); CSSRule rule = rl.item(0); if (rule.getType() == CSSRule.STYLE_RULE) { CSSStyleRule sr = (CSSStyleRule) rule; assertEquals(sr.getSelectorText(), _testSelector); CSSStyleDeclaration style = sr.getStyle(); assertEquals(style.item(0), _testItem); CSSValue value = style.getPropertyCSSValue(style.item(0)); assertEquals(value.getCssText(), _testValue); } else { fail(); } } public void testParseSelectors() throws Exception { Reader r = new StringReader(_testSelector); InputSource is = new InputSource(r); SelectorList sl = _parser.parseSelectors(is); assertEquals(sl.item(0).toString(), _testSelector); } /** * Regression test for bug 1191376. * * @throws Exception * if any error occurs */ public void testParseStyleDeclaration() throws Exception { Reader r = new StringReader("background-color: white"); InputSource is = new InputSource(r); CSSStyleDeclaration declaration = _parser.parseStyleDeclaration(is); assertEquals(declaration.getLength(), 1); } /** * Regression test for bug 1183734. * * @throws Exception * if any error occurs */ public void testColorFirst() throws Exception { Reader r = new StringReader("background: #e8eff5 url(images/bottom-angle.png) no-repeat"); InputSource is = new InputSource(r); CSSStyleDeclaration d = _parser.parseStyleDeclaration(is); assertEquals("background: rgb(232, 239, 245) url(images/bottom-angle.png) no-repeat", d.getCssText()); Reader r2 = new StringReader("background: red url(images/bottom-angle.png) no-repeat"); InputSource is2 = new InputSource(r2); CSSStyleDeclaration d2 = _parser.parseStyleDeclaration(is2); assertEquals("background: red url(images/bottom-angle.png) no-repeat", d2.getCssText()); Reader r3 = new StringReader("background: rgb(8, 3, 6) url(images/bottom-angle.png) no-repeat"); InputSource is3 = new InputSource(r3); CSSStyleDeclaration d3 = _parser.parseStyleDeclaration(is3); assertEquals("background: rgb(8, 3, 6) url(images/bottom-angle.png) no-repeat", d3.getCssText()); } /** * Regression test for bug 1226128. * * @see CSS Spec * @throws Exception * if an error occurs */ public void testEscapedChars() throws Exception { testEscapedChars(new SACParserCSS2()); testEscapedChars(new SACParserCSS21()); } private void testEscapedChars(Parser p) throws Exception { assertEquals("bogus: \"abc\"", getCssTextFromDeclaration(p, "bogus: 'a\\\rbc'")); assertEquals("bogus: \"abc\"", getCssTextFromDeclaration(p, "bogus: 'a\\\nbc'")); assertEquals("bogus: \"abc\"", getCssTextFromDeclaration(p, "bogus: 'a\\\fbc'")); assertEquals("bogus: \"abc\"", getCssTextFromDeclaration(p, "bogus: 'abc\\\r\n'")); assertEquals("bogus: \"abc\"", getCssTextFromDeclaration(p, "bogus: 'a\\\r\nbc'")); assertEquals("bogus: \"abx\"", getCssTextFromDeclaration(p, "bogus: '\\61\\62x'")); assertEquals("bogus: \"abc\"", getCssTextFromDeclaration(p, "bogus: '\\61\\62\\63'")); assertEquals("bogus: \"abx\"", getCssTextFromDeclaration(p, "bogus: '\\61 \\62x'")); assertEquals("bogus: \"abx\"", getCssTextFromDeclaration(p, "bogus: '\\61\t\\62x'")); assertEquals("bogus: \"abx\"", getCssTextFromDeclaration(p, "bogus: '\\61\n\\62x'")); assertEquals("bogus: \"a'bc\"", getCssTextFromDeclaration(p, "bogus: 'a\\'bc'")); assertEquals("bogus: \"a'bc\"", getCssTextFromDeclaration(p, "bogus: \"a\\'bc\"")); assertEquals("bogus: \"a\"bc\"", getCssTextFromDeclaration(p, "bogus: 'a\\\"bc'")); assertEquals("bogus: \"a\"bc\"", getCssTextFromDeclaration(p, "bogus: \"a\\\"bc\"")); } private String getCssTextFromDeclaration(Parser p, String s) throws Exception { CSSOMParser parser = new CSSOMParser(p); Reader r = new StringReader(s); InputSource is = new InputSource(r); CSSStyleDeclaration d = parser.parseStyleDeclaration(is); return d.getCssText(); } public void testMisc() throws Exception { InputStream is = getClass().getClassLoader().getResourceAsStream("page_test.css"); assertNotNull(is); Reader r = new InputStreamReader(is); InputSource source = new InputSource(r); CSSOMParser parser = new CSSOMParser(); CSSStyleSheet ss = parser.parseStyleSheet(source, null, null); System.out.println(ss.toString()); CSSRuleList rl = ss.getCssRules(); for (int i = 0; i < rl.getLength(); i++) { CSSRule rule = rl.item(i); if (rule.getType() == CSSRule.STYLE_RULE) { CSSStyleRule sr = (CSSStyleRule) rule; CSSStyleDeclaration style = sr.getStyle(); for (int j = 0; j < style.getLength(); j++) { CSSValue value = style.getPropertyCSSValue(style.item(j)); if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { CSSPrimitiveValue pv = (CSSPrimitiveValue) value; System.out.println(">> " + pv.toString()); if (pv.getPrimitiveType() == CSSPrimitiveValue.CSS_COUNTER) { System.out.println("CSS_COUNTER(" + pv.toString() + ")"); } } } } } } } cssparser-0.9.5/src/test/java/com/steadystate/css/parser/SACParserCSS21Test.java0000644000175000017500000000235010770600741027241 0ustar cavedoncavedonpackage com.steadystate.css.parser; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import junit.framework.TestCase; import org.w3c.css.sac.InputSource; import org.w3c.dom.css.CSSStyleSheet; public class SACParserCSS21Test extends TestCase { public void testDojoCSS() throws Exception { InputStream is = getClass().getClassLoader().getResourceAsStream("dojo.css"); assertNotNull(is); Reader r = new InputStreamReader(is); InputSource source = new InputSource(r); SACParserCSS21 sp = new SACParserCSS21(); CSSOMParser parser = new CSSOMParser(sp); CSSStyleSheet sheet = parser.parseStyleSheet(source, null, null); assertEquals(17, sheet.getCssRules().getLength()); } public void testTestCSS() throws Exception { InputStream is = getClass().getClassLoader().getResourceAsStream("test.css"); assertNotNull(is); Reader r = new InputStreamReader(is); InputSource source = new InputSource(r); CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); CSSStyleSheet sheet = parser.parseStyleSheet(source, null, null); assertEquals(21, sheet.getCssRules().getLength()); } } cssparser-0.9.5/src/test/java/com/steadystate/css/parser/ParseTester.java0000644000175000017500000001333610772331213026346 0ustar cavedoncavedon/* * $Id: ParseTester.java,v 1.1 2008/03/26 02:18:51 sdanig Exp $ * * CSS Parser Project * * Copyright (C) 1999-2005 David Schweinsberg. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library: * * http://cssparser.sourceforge.net/ * mailto:davidsch@users.sourceforge.net */ package com.steadystate.css.parser; import java.io.FileReader; import java.io.Reader; import org.w3c.css.sac.CSSException; import org.w3c.css.sac.InputSource; import org.w3c.css.sac.LexicalUnit; import org.w3c.css.sac.Parser; import org.w3c.css.sac.SACMediaList; import org.w3c.css.sac.SelectorList; import org.w3c.css.sac.helpers.ParserFactory; /** * @author David Schweinsberg * @version $Id: ParseTester.java,v 1.1 2008/03/26 02:18:51 sdanig Exp $ */ public class ParseTester extends HandlerBase { private static final String PARSER = "com.steadystate.css.parser.SACParser"; private int _propertyCounter = 0; private int _indentSize = 0; public static void main(String[] args) { new ParseTester().testParsing(); } public void testParsing() { try { CSSOMParser.setProperty("org.w3c.css.sac.parser", PARSER); ParserFactory factory = new ParserFactory(); Parser parser = factory.makeParser(); parser.setDocumentHandler(this); Reader r = new FileReader("stylesheets/test.css"); InputSource is = new InputSource(r); parser.parseStyleSheet(is); } catch (Exception e) { System.err.println("Exception: " + e.getMessage()); } } public void startDocument(InputSource source) throws CSSException { System.out.println("startDocument"); } public void endDocument(InputSource source) throws CSSException { System.out.println("endDocument"); } public void comment(String text) throws CSSException { } public void ignorableAtRule(String atRule) throws CSSException { System.out.println(atRule); } public void namespaceDeclaration(String prefix, String uri) throws CSSException { } public void importStyle(String uri, SACMediaList media, String defaultNamespaceURI) throws CSSException { System.out.print("@import url(" + uri + ")"); if (media.getLength() > 0) { System.out.println(" " + media.toString() + ";"); } else { System.out.println(";"); } } public void startMedia(SACMediaList media) throws CSSException { System.out.println(indent() + "@media " + media.toString() + " {"); incIndent(); } public void endMedia(SACMediaList media) throws CSSException { decIndent(); System.out.println(indent() + "}"); } public void startPage(String name, String pseudo_page) throws CSSException { System.out.print(indent() + "@page"); if (name != null) { System.out.print(" " + name); } if (pseudo_page != null) { System.out.println(" " + pseudo_page); } System.out.println(" {"); this._propertyCounter = 0; incIndent(); } public void endPage(String name, String pseudo_page) throws CSSException { System.out.println(); decIndent(); System.out.println(indent() + "}"); } public void startFontFace() throws CSSException { System.out.println(indent() + "@font-face {"); this._propertyCounter = 0; incIndent(); } public void endFontFace() throws CSSException { System.out.println(); decIndent(); System.out.println(indent() + "}"); } public void startSelector(SelectorList selectors) throws CSSException { System.out.println(indent() + selectors.toString() + " {"); this._propertyCounter = 0; incIndent(); } public void endSelector(SelectorList selectors) throws CSSException { System.out.println(); decIndent(); System.out.println(indent() + "}"); } public void property(String name, LexicalUnit value, boolean important) throws CSSException { if (this._propertyCounter++ > 0) { System.out.println(";"); } System.out.print(indent() + name + ":"); // Iterate through the chain of lexical units LexicalUnit nextVal = value; while (nextVal != null) { // System.out.print(" " + nextVal.toString()); System.out.print(" " + ((LexicalUnitImpl) nextVal).toDebugString()); nextVal = nextVal.getNextLexicalUnit(); } // Is it important? if (important) { System.out.print(" !important"); } } private String indent() { StringBuffer sb = new StringBuffer(16); for (int i = 0; i < this._indentSize; i++) { sb.append(" "); } return sb.toString(); } private void incIndent() { this._indentSize += 4; } private void decIndent() { this._indentSize -= 4; } } cssparser-0.9.5/src/test/java/com/steadystate/css/TestDOM.java0000644000175000017500000001275410770350305024074 0ustar cavedoncavedon/* * TestDOM.java * * Steady State CSS2 Parser * * Copyright (C) 1999, 2002 Steady State Software Ltd. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library, write to Steady State Software Ltd., * 49 Littleworth, Wing, Buckinghamshire, LU7 0JX, England * * http://www.steadystate.com/css/ * mailto:css@steadystate.co.uk * * $Id: TestDOM.java,v 1.2 2008/03/20 02:49:41 sdanig Exp $ */ package com.steadystate.css; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import junit.framework.TestCase; import org.w3c.css.sac.InputSource; import org.w3c.dom.css.CSSPrimitiveValue; import org.w3c.dom.css.CSSStyleDeclaration; import org.w3c.dom.css.CSSValueList; import com.steadystate.css.parser.CSSOMParser; /** * Tests the CSS DOM implementation by loading a stylesheet and performing a few operations upon it. * * @author David Schweinsberg * @version $Release$ */ public class TestDOM extends TestCase { public void test() throws Exception { InputStream is = getClass().getClassLoader().getResourceAsStream("basic.css"); assertNotNull(is); CSSOMParser parser = new CSSOMParser(); Reader r = new InputStreamReader(is); InputSource source = new InputSource(r); CSSStyleDeclaration style = parser.parseStyleDeclaration(source); // Enumerate the properties and retrieve their values System.out.println("No. of properties: " + style.getLength()); for (int i = 0; i < style.getLength(); i++) { String name = style.item(i); System.out.println(name + " : " + style.getPropertyValue(name)); } // Get the style declaration as a single lump of text System.out.println("\ngetCssText"); System.out.println(style.getCssText()); // Directly set the CSS style declaration // NOTE: We must include the braces! System.out.println("\nsetCssText"); style.setCssText("{ alpha: 2; beta: 20px; gamma: 40em; delta: 1mm; epsilon: 24pt }"); System.out.println(style.getCssText()); // Remove some properties, from the middle, beginning, and end System.out.println(); System.out.println("Removing 'gamma'"); System.out.println(style.removeProperty("gamma")); System.out.println("Removing 'alpha'"); System.out.println(style.removeProperty("alpha")); System.out.println("Removing 'epsilon'"); System.out.println(style.removeProperty("epsilon")); // Let's see what remains System.out.println(style.getCssText()); // Use the setProperty method to modify an existing property, // and add a new one. System.out.println(); System.out.println("setting 'beta' to 40px"); style.setProperty("beta", "40px", null); System.out.println("setting 'omega' to 1 with 'important' priority"); style.setProperty("omega", "1", "important"); // Let's look at the changes System.out.println(style.getCssText()); // Work with CSSValues System.out.println(); System.out.println("Retrieving 'beta' as a CSSPrimitiveValue"); CSSPrimitiveValue value = (CSSPrimitiveValue) style.getPropertyCSSValue("beta"); System.out.println("getCssText: 'beta' = " + value.getCssText()); System.out.println("getFloatValue: 'beta' = " + value.getFloatValue(CSSPrimitiveValue.CSS_PX)); System.out.println("Setting 'beta' to 100px"); value.setFloatValue(CSSPrimitiveValue.CSS_PX, 100); System.out .println("Adding a new value, which should end-up as a CSSValueList.\nSetting 'list-test' to 100 200 300"); style.setProperty("list-test", "100 200 300", null); value = (CSSPrimitiveValue) style.getPropertyCSSValue("list-test"); System.out.println("getValueType: 'list-test' = " + value.getCssValueType()); CSSValueList vl = (CSSValueList) style.getPropertyCSSValue("list-test"); for (int i = 0; i < vl.getLength(); i++) { System.out.println("getFloatValue: 'list-test[" + String.valueOf(i) + "]' = " + ((CSSPrimitiveValue) vl.item(i)).getFloatValue(CSSPrimitiveValue.CSS_NUMBER)); } // When a CSSValue is modified, it modifies the declaration System.out.println("Let's see the change within the entire declaration"); System.out.println(style.getCssText()); // Using the setCssText method, we can change the type of value System.out.println("Setting 'list-test' to something completely different, the string 'bogus'."); vl.setCssText("bogus"); System.out.println("What happens..."); System.out.println("getValueType: 'list-test' = " + value.getCssValueType()); System.out.println(style.getCssText()); } } cssparser-0.9.5/src/test/java/com/steadystate/css/dom/0000755000175000017500000000000011420645030022513 5ustar cavedoncavedoncssparser-0.9.5/src/test/java/com/steadystate/css/dom/CSSStyleDeclarationImplTest.java0000644000175000017500000000323210772046545030676 0ustar cavedoncavedonpackage com.steadystate.css.dom; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import junit.framework.TestCase; import org.w3c.css.sac.InputSource; import com.steadystate.css.parser.CSSOMParser; /** * Unit tests for {@link CSSStyleDeclarationImpl}. * * @author Daniel Gredler */ public class CSSStyleDeclarationImplTest extends TestCase { /** * Regression test for bug 1874800. * * @throws Exception * if any error occurs */ public void testCssTextHasNoCurlyBraces() throws Exception { InputStream is = getClass().getClassLoader().getResourceAsStream("basic.css"); assertNotNull(is); CSSOMParser parser = new CSSOMParser(); Reader r = new InputStreamReader(is); InputSource source = new InputSource(r); CSSStyleDeclarationImpl style = (CSSStyleDeclarationImpl) parser.parseStyleDeclaration(source); assertFalse(style.getCssText().contains("{")); assertFalse(style.getCssText().contains("}")); style.setCssText("color: red;"); assertEquals("color: red", style.getCssText()); } /** * Regression test for bug 1691221. * * @throws Exception * if any error occurs */ public void testEmptyUrl() throws Exception { CSSOMParser parser = new CSSOMParser(); Reader r = new StringReader("{ background: url() }"); InputSource source = new InputSource(r); CSSStyleDeclarationImpl style = (CSSStyleDeclarationImpl) parser.parseStyleDeclaration(source); assertEquals("", style.getCssText()); } } cssparser-0.9.5/src/test/resources/0000755000175000017500000000000011420645030017125 5ustar cavedoncavedoncssparser-0.9.5/src/test/resources/yuck.css0000644000175000017500000000016510770335723020630 0ustar cavedoncavedonE[class~="hipster"][thing~="bob"]#myid { att1: hi; foo: bar } E:lang(c)#unique E.hipster#myid { att1: hi; foo: bar } cssparser-0.9.5/src/test/resources/bad.css0000644000175000017500000000011110770335722020371 0ustar cavedoncavedonP { color: yellow; background-color: blue; 1rogue: catch me if you can } cssparser-0.9.5/src/test/resources/test.css0000644000175000017500000001117010770335723020632 0ustar cavedoncavedon /* * This is a test file only - it doesn't represent a usable style sheet, * it is meant only to test the lexer and parser. */ @import url(foo.css); @import "bar.css"; @import url("fineprint.css") print; @import url("bluish.css") projection, tv; @import url(http://www.steadystate.com/primary.css) screen, tv; @import "sounds_good.css" aural; E[class~="hipster"][thing~="bob"]#myid { att1: hi; foo: bar; } E:lang(c)#unique E.hipster#myid { att1: hi; foo: bar; } @media tv, radio { @page { foo: bar; } H1 { fillcolor: blue } } /* @import url(bad_import.css); */ H1, H2 {color:green;background-color:blue} H1, H2 {color: green;background-color: blue} H3, H4 & H5 { color: red; a: red; b: red; c: red; d: red; e: red; f: red; g: red; h: red; i: red; j: red; k: red; l: red; m: red; n: red; o: red; } H6 { color: black } H7 & H8 { color: red; @page { foo: bar } } P[example="public class foo\ {\ private int x;\ \ foo(int x) {\ this.x = x;\ }\ \ }"] { color: red } H1 { color: red; font-style: 12pt } /* Invalid value: 12pt */ P { color: blue; font-vendor: any; /* Invalid prop.: font-vendor */ font-variant: small-caps } EM EM { font-style: normal } H1 { color: red; rotation: 70minutes } IMG { float: left } /* correct CSS2 */ IMG { float: left here } /* "here" is not a value of 'float' */ IMG { background: "red" } /* keywords cannot be quoted in CSS2 */ IMG { border-width: 3 } /* a unit must be specified for length values */ @three-dee { @background-lighting { azimuth: 30deg; elevation: 190deg; } H1 { color: red } } H1 { color: blue !important } P {counter-increment: par-num ! important } H1 {counter-reset: par-num} P:before {content: counter(par-num, upper-roman) ". "} EM { color: #f00 } /* #rgb */ EM { color: #ff0000 } /* #rrggbb */ EM { color: rgb(255,0,0) } /* integer range 0 - 255 */ EM { color: rgb(100%, 0%, 0%) } /* float range 0.0% - 100.0% */ FOO { content: "Argos\t\n" } R1 { a: U+aaaaa-ffffff } R2 { a: U+?????? } R3 { a: U+f????? } R4 { a: U+fffff? } R5 { a: U+ffffff } * {} /* a=0 b=0 c=0 -> specificity = 0 */ LI {} /* a=0 b=0 c=1 -> specificity = 1 */ UL LI {} /* a=0 b=0 c=2 -> specificity = 2 */ UL OL+LI {} /* a=0 b=0 c=3 -> specificity = 3 */ H1 + *[REL=up]{} /* a=0 b=1 c=1 -> specificity = 11 */ UL OL LI.red {} /* a=0 b=1 c=3 -> specificity = 13 */ LI.red.level {} /* a=0 b=2 c=1 -> specificity = 21 */ #x34y {} /* a=1 b=0 c=0 -> specificity = 100 */ DIV > P:first-child { text-indent: 0 } HTML:lang(fr) { quotes: '« ' ' »' } HTML:lang(de) { quotes: '»' '«' '\2039' '\203A' } :lang(fr) > Q { quotes: '« ' ' »' } :lang(de) > Q { quotes: '»' '«' '\2039' '\203A' } H1 { bogus: alpha & beta } H2 { foo: inherit; ;; } /* * Counters and stuff */ P {counter-increment: par-num} H1 {counter-reset: par-num} P:before {content: counter(par-num, upper-roman) ". "} H1:before { content: "Chapter " counter(chapter) ". "; counter-increment: chapter; /* Add 1 to chapter */ counter-reset: section; /* Set section to 0 */ } H2:before { content: counter(chapter) "." counter(section) " "; counter-increment: section; } OL { counter-reset: item } LI { display: block } LI:before { content: counters(item, "."); counter-increment: item } H1:before { content: counter(chno, upper-latin) ". " } H2:before { content: counter(section, upper-roman) " - " } BLOCKQUOTE:after { content: " [" counter(bq, hebrew) "]" } DIV.note:before { content: counter(notecntr, disc) " " } P:before { content: counter(p, none) } /* * Content stuff (w/attr function) */ @media aural { BLOCKQUOTE:after { content: url("beautiful-music.wav") } } IMG:before { content: attr(alt) } H1:before { display: block; text-align: center; content: "chapter\A hoofdstuk\A chapitre" } /* * Clip (w/rect function) */ P { clip: rect(5px, 10px, 10px, 5px); } P { clip: rect(5px, -5px, 10px, 5px); } P { font-size: 12pt; line-height: 12pt } P:first-letter { font-size: 200%; font-style: italic; font-weight: bold; float: left; bogus: foo(p1, p2, "hello", url(primary.css)) } SPAN { text-transform: uppercase } P { color: red; font-size: 12pt } P:first-letter { color: green; font-size: 200% } P:first-line { color: blue } /* * Bug 1226128 (Escaping) */ P { content: "This it the first line\ And this is a continuation of the line" } /* * Bug 1219753 (underscores) */ .infohome{ background-image: url(footer_info_home.gif); height: 53px; background-repeat: no-repeat; } .info_home{ background-image: url(footer_info_home.gif); height: 53px; background-repeat: no-repeat; } cssparser-0.9.5/src/test/resources/v_simple.css0000644000175000017500000000003510770335723021467 0ustar cavedoncavedonh1 { foo: alpha; bar:beta } cssparser-0.9.5/src/test/resources/basic.css0000644000175000017500000000014210770335722020730 0ustar cavedoncavedon{ foo: 1.5; bogus: 3, 2, 1; bar-color: #0FEED0; background: #abc; foreground: rgb( 10, 20, 30 ) } cssparser-0.9.5/src/test/resources/page_test.css0000644000175000017500000000005110770335722021621 0ustar cavedoncavedon@page pageStyle { size: 21.0cm 29.7cm; } cssparser-0.9.5/src/test/resources/atrule.css0000644000175000017500000000021310770335722021142 0ustar cavedoncavedon@charset "UTF-8"; @three-dee { @background-lighting { azimuth: 30deg; elevation: 190deg; } H1 { color: red } } @page { foo: bar } cssparser-0.9.5/src/test/resources/simple.css0000644000175000017500000000046110770335722021144 0ustar cavedoncavedon @import url("fineprint.css") print; @import url(bogus.css); @import url( bogus.css ); @media screen { @three-dee { @background-lighting { azimuth: 30deg; elevation: 190deg; } H1 { color: red } } h1 { foo: bar } h2 { thing: 1; whatsit: 2px } h3 { foo: 2 ! important } } h9 { } b1 & b2 { } cssparser-0.9.5/src/test/resources/html20.css0000644000175000017500000000273710770335722020771 0ustar cavedoncavedon BODY { margin: 1em; font-family: serif; line-height: 1.1; background: white; color: black } H1, H2, H3, H4, H5, H6, P, UL, OL, DIR, MENU, DIV, DT, DD, ADDRESS, BLOCKQUOTE, PRE, BR, HR { display: block } B, STRONG, I, EM, CITE, VAR, TT, CODE, KBD, SAMP, IMG, SPAN { display: inline } LI { display: list-item } H1, H2, H3, H4 { margin-top: 1em; margin-bottom: 1em } H5, H6 { margin-top: 1em } H1 { text-align: center } H1, H2, H4, H6 { font-weight: bold } H3, H5 { font-style: italic } H1 { font-size: xx-large } H2 { font-size: x-large } H3 { font-size: large } B, STRONG { font-weight: bolder } /* relative to the parent */ I, CITE, EM, VAR, ADDRESS, BLOCKQUOTE { font-style: italic } PRE, TT, CODE, KBD, SAMP { font-family: monospace } PRE { white-space: pre } ADDRESS { margin-left: 3em } BLOCKQUOTE { margin-left: 3em; margin-right: 3em } UL, DIR { list-style: disc } OL { list-style: decimal } MENU { margin: 0 } /* tight formatting */ LI { margin-left: 3em } DT { margin-bottom: 0 } DD { margin-top: 0; margin-left: 3em } HR { border-top: solid } /* 'border-bottom' could also have been used */ A:link { color: blue } /* unvisited link */ A:visited { color: red } /* visited links */ A:active { color: lime } /* active links */ /* setting the anchor border around IMG elements requires contextual selectors */ A:link IMG { border: 2px solid blue } A:visited IMG { border: 2px solid red } A:active IMG { border: 2px solid lime } cssparser-0.9.5/src/test/resources/u_simple.css0000644000175000017500000000046310770335723021473 0ustar cavedoncavedonÿþ@media screen { h1 { foo: bar } h2 { thing: 1; whatsit: 2px } h3 { foo: 2 ! important } } foo :lang(c) #bob { a: 1; b: 2; } foo { } cssparser-0.9.5/src/test/resources/test-unicode.css0000644000175000017500000002236510770335723022266 0ustar cavedoncavedonÿþ@charset "UTF-16"; /* * This is a test file only - it doesn't represent a usable style sheet, * it is meant only to test the lexer and parser. */ @import url(foo.css); @import "bar.css"; @import url("fineprint.css") print; @import url("bluish.css") projection, tv; @import url(http://www.steadystate.com/primary.css) screen, tv; @import "sounds_good.css" aural; E[class~="hipster"][thing~="bob"]#myid { att1: hi; foo: bar; } E:lang(c)#unique E.hipster#myid { att1: hi; foo: bar; } @media tv, radio { @page { foo: bar; } H1 { fillcolor: blue } } /* @import url(bad_import.css); */ H1, H2 {color:green;background-color:blue} H1, H2 {color: green;background-color: blue} H3, H4 & H5 { color: red; a: red; b: red; c: red; d: red; e: red; f: red; g: red; h: red; i: red; j: red; k: red; l: red; m: red; n: red; o: red; } H6 { color: black } H7 & H8 { color: red; @page { foo: bar } } P[example="public class foo\ {\ private int x;\ \ foo(int x) {\ this.x = x;\ }\ \ }"] { color: red } H1 { color: red; font-style: 12pt } /* Invalid value: 12pt */ P { color: blue; font-vendor: any; /* Invalid prop.: font-vendor */ font-variant: small-caps } EM EM { font-style: normal } H1 { color: red; rotation: 70minutes } IMG { float: left } /* correct CSS2 */ IMG { float: left here } /* "here" is not a value of 'float' */ IMG { background: "red" } /* keywords cannot be quoted in CSS2 */ IMG { border-width: 3 } /* a unit must be specified for length values */ @three-dee { @background-lighting { azimuth: 30deg; elevation: 190deg; } H1 { color: red } } H1 { color: blue !important } P {counter-increment: par-num ! important } H1 {counter-reset: par-num} P:before {content: counter(par-num, upper-roman) ". "} EM { color: #f00 } /* #rgb */ EM { color: #ff0000 } /* #rrggbb */ EM { color: rgb(255,0,0) } /* integer range 0 - 255 */ EM { color: rgb(100%, 0%, 0%) } /* float range 0.0% - 100.0% */ FOO { content: "Argos\t\n" } R1 { a: U+aaaaa-ffffff } R2 { a: U+?????? } R3 { a: U+f????? } R4 { a: U+fffff? } R5 { a: U+ffffff } * {} /* a=0 b=0 c=0 -> specificity = 0 */ LI {} /* a=0 b=0 c=1 -> specificity = 1 */ UL LI {} /* a=0 b=0 c=2 -> specificity = 2 */ UL OL+LI {} /* a=0 b=0 c=3 -> specificity = 3 */ H1 + *[REL=up]{} /* a=0 b=1 c=1 -> specificity = 11 */ UL OL LI.red {} /* a=0 b=1 c=3 -> specificity = 13 */ LI.red.level {} /* a=0 b=2 c=1 -> specificity = 21 */ #x34y {} /* a=1 b=0 c=0 -> specificity = 100 */ DIV > P:first-child { text-indent: 0 } HTML:lang(fr) { quotes: '« ' ' »' } HTML:lang(de) { quotes: '»' '«' '\2039' '\203A' } :lang(fr) > Q { quotes: '« ' ' »' } :lang(de) > Q { quotes: '»' '«' '\2039' '\203A' } H1 { bogus: alpha & beta } H2 { foo: inherit; ;; } /* * Counters and stuff */ P {counter-increment: par-num} H1 {counter-reset: par-num} P:before {content: counter(par-num, upper-roman) ". "} H1:before { content: "Chapter " counter(chapter) ". "; counter-increment: chapter; /* Add 1 to chapter */ counter-reset: section; /* Set section to 0 */ } H2:before { content: counter(chapter) "." counter(section) " "; counter-increment: section; } OL { counter-reset: item } LI { display: block } LI:before { content: counters(item, "."); counter-increment: item } H1:before { content: counter(chno, upper-latin) ". " } H2:before { content: counter(section, upper-roman) " - " } BLOCKQUOTE:after { content: " [" counter(bq, hebrew) "]" } DIV.note:before { content: counter(notecntr, disc) " " } P:before { content: counter(p, none) } /* * Content stuff (w/attr function) */ @media aural { BLOCKQUOTE:after { content: url("beautiful-music.wav") } } IMG:before { content: attr(alt) } H1:before { display: block; text-align: center; content: "chapter\A hoofdstuk\A chapitre" } /* * Clip (w/rect function) */ P { clip: rect(5px, 10px, 10px, 5px); } P { clip: rect(5px, -5px, 10px, 5px); } P { font-size: 12pt; line-height: 12pt } P:first-letter { font-size: 200%; font-style: italic; font-weight: bold; float: left; bogus: foo(p1, p2, "hello", url(primary.css)) } SPAN { text-transform: uppercase } P { color: red; font-size: 12pt } P:first-letter { color: green; font-size: 200% } P:first-line { color: blue } P { text-indent:-.5in; text-indent:-3.5in }cssparser-0.9.5/src/test/resources/single-color.css0000644000175000017500000000016110770335722022245 0ustar cavedoncavedon@media aural { BLOCKQUOTE:after { content: url("beautiful-music.wav") } } a { content: url("other.wav") } cssparser-0.9.5/src/test/resources/multiple-values.css0000644000175000017500000000003510770335722023000 0ustar cavedoncavedonfoo { a: 1, 2 3, bar 4 } cssparser-0.9.5/src/test/resources/html40.css0000644000175000017500000001026210770335722020763 0ustar cavedoncavedon@charset "US-ASCII"; ADDRESS, BLOCKQUOTE, BODY, DD, DIV, DL, DT, FIELDSET, FORM, FRAME, FRAMESET, H1, H2, H3, H4, H5, H6, IFRAME, NOFRAMES, OBJECT, OL, P, UL, APPLET, CENTER, DIR, HR, MENU, PRE { display: block } LI { display: list-item } HEAD { display: none } TABLE { display: table } TR { display: table-row } THEAD { display: table-header-group } TBODY { display: table-row-group } TFOOT { display: table-footer-group } COL { display: table-column } COLGROUP { display: table-column-group } TD, TH { display: table-cell } CAPTION { display: table-caption } TH { font-weight: bolder; text-align: center } CAPTION { text-align: center } BODY { padding: 8px; line-height: 1.33 } H1 { font-size: 2em; margin: .67em 0 } H2 { font-size: 1.5em; margin: .83em 0 } H3 { font-size: 1.17em; margin: 1em 0 } H4, P, BLOCKQUOTE, UL, FIELDSET, FORM, OL, DL, DIR, MENU { margin: 1.33em 0 } H5 { font-size: .83em; line-height: 1.17em; margin: 1.67em 0 } H6 { font-size: .67em; margin: 2.33em 0 } H1, H2, H3, H4, H5, H6, B, STRONG { font-weight: bolder } BLOCKQUOTE { margin-left: 40px; margin-right: 40px } I, CITE, EM, VAR, ADDRESS { font-style: italic } PRE, TT, CODE, KBD, SAMP { font-family: monospace } PRE { white-space: pre } BIG { font-size: 1.17em } SMALL, SUB, SUP { font-size: .83em } SUB { vertical-align: sub } SUP { vertical-align: super } S, STRIKE, DEL { text-decoration: line-through } HR { border: 1px inset } OL, UL, DIR, MENU, DD { margin-left: 40px } OL { list-style-type: decimal } OL UL, UL OL, UL UL, OL OL { margin-top: 0; margin-bottom: 0 } U, INS { text-decoration: underline } CENTER { text-align: center } BR:before { content: "\A" } /* An example of style for HTML 4.0's ABBR/ACRONYM elements */ ABBR, ACRONYM { font-variant: small-caps; letter-spacing: 0.1em } A[href] { text-decoration: underline } :focus { outline: thin dotted invert } /* Begin bidirectionality settings (do not change) */ BDO[DIR="ltr"] { direction: ltr; unicode-bidi: bidi-override } BDO[DIR="rtl"] { direction: rtl; unicode-bidi: bidi-override } *[DIR="ltr"] { direction: ltr; unicode-bidi: embed } *[DIR="rtl"] { direction: rtl; unicode-bidi: embed } /* Elements that are block-level in HTML4 */ ADDRESS, BLOCKQUOTE, BODY, DD, DIV, DL, DT, FIELDSET, FORM, FRAME, FRAMESET, H1, H2, H3, H4, H5, H6, IFRAME, NOSCRIPT, NOFRAMES, OBJECT, OL, P, UL, APPLET, CENTER, DIR, HR, MENU, PRE, LI, TABLE, TR, THEAD, TBODY, TFOOT, COL, COLGROUP, TD, TH, CAPTION { unicode-bidi: embed } /* End bidi settings */ @media print { @page { margin: 10% } H1, H2, H3, H4, H5, H6 { page-break-after: avoid; page-break-inside: avoid } BLOCKQUOTE, PRE { page-break-inside: avoid } UL, OL, DL { page-break-before: avoid } } @media speech { H1, H2, H3, H4, H5, H6 { voice-family: paul, male; stress: 20; richness: 90 } H1 { pitch: x-low; pitch-range: 90 } H2 { pitch: x-low; pitch-range: 80 } H3 { pitch: low; pitch-range: 70 } H4 { pitch: medium; pitch-range: 60 } H5 { pitch: medium; pitch-range: 50 } H6 { pitch: medium; pitch-range: 40 } LI, DT, DD { pitch: medium; richness: 60 } DT { stress: 80 } PRE, CODE, TT { pitch: medium; pitch-range: 0; stress: 0; richness: 80 } EM { pitch: medium; pitch-range: 60; stress: 60; richness: 50 } STRONG { pitch: medium; pitch-range: 60; stress: 90; richness: 90 } DFN { pitch: high; pitch-range: 60; stress: 60 } S, STRIKE { richness: 0 } I { pitch: medium; pitch-range: 60; stress: 60; richness: 50 } B { pitch: medium; pitch-range: 60; stress: 90; richness: 90 } U { richness: 0 } A:link { voice-family: harry, male } A:visited { voice-family: betty, female } A:active { voice-family: betty, female; pitch-range: 80; pitch: x-high } } cssparser-0.9.5/src/test/resources/dojo.css0000644000175000017500000000434610770600741020610 0ustar cavedoncavedon@import "../../dojo/resources/dojo.css"; /* body { margin: 0px; padding: 0px; font-size: 13px; color: #292929; font-family: Myriad, Lucida Grande, Bitstream Vera Sans, Arial, Helvetica, sans-serif; *font-size: small; *font: x-small; } th, td { font-size: 13px; color: #292929; font-family: Myriad, Lucida Grande, Bitstream Vera Sans, Arial, Helvetica, sans-serif; font-weight: normal; } * body { line-height: 1.25em; } table { border-collapse: collapse; } */ #testLayout { position: relative; left: 0px; top: 0px; width: 100%; height: 100%; border: 1px solid black; border: 0px; } .tabBody { margin: 0px; padding: 0px; /* border: 1px solid black; */ background-color: #DEDEDE; border: 0px; width: 100%; height: 100%; position: absolute; left: 0px; top: 0px; overflow: auto; } #logBody { padding-left: 5px; padding-top: 5px; font-family: Monaco, monospace; font-size: 11px; white-space: pre; } #progressOuter { background:#e9e9e9 url("http://svn.dojotoolkit.org/dojo/dijit/trunk/themes/tundra/dojoTundraGradientBg.png") repeat-x 0 0; /* border-color: #e8e8e8; */ } #progressInner { background: blue url("http://svn.dojotoolkit.org/dojo/dijit/trunk/themes/tundra/bar.gif") repeat-x 0 0; width: 0%; position: relative; left: 0px; top: 0px; height: 100%; } #play, #pause { font-family: Webdings; font-size: 1.4em; border: 1px solid #DEDEDE; cursor: pointer; padding-right: 0.5em; } .header { border: 1px solid #DEDEDE; } button.tab { border-width: 1px 1px 0px 1px; border-style: solid; border-color: #DEDEDE; margin-right: 5px; } #testListContainer { /* border: 1px solid black; */ position: relative; height: 99%; width: 100%; overflow: auto; } #testList { border-collapse: collapse; position: absolute; left: 0px; width: 100%; } #testList > tbody > tr > td { border-bottom: 1px solid #DEDEDE; border-right : 1px solid #DEDEDE; padding: 3px; } #testListHeader th { border-bottom: 1px solid #DEDEDE; border-right : 1px solid #DEDEDE; padding: 3px; font-weight: bolder; font-style: italic; } #toggleButtons { float: left; background-color: #DEDEDE; } tr.inProgress { background-color: #85afde; } tr.success { background-color: #7cdea7; } tr.failure { background-color: #de827b; } cssparser-0.9.5/doc/0000755000175000017500000000000011420645030014112 5ustar cavedoncavedoncssparser-0.9.5/doc/primary.css0000644000175000017500000000365310770335720016327 0ustar cavedoncavedonbody { background: white; color: black; margin: 0; padding: 0; font-family: Verdana, Arial, helvetica, sans-serif } a:link { color: #0000FF; background-color: white; text-decoration: none } a:visited { color: #0000FF; background-color: white; text-decoration: none } a:active { color: #0000FF; background-color: white; text-decoration: none } a:hover { text-decoration: underline } hr { margin: 8pt 10px 0 10px; clear: both; } p, h3, li, pre { margin-left: 64px; margin-right: 64px } h1, h2 { margin-left: 10px; margin-right: 10px; clear: both } h1 { margin-top: 60px; font-family: Georgia, serif; font-size: 48px; font-weight: normal; font-style: italic } h1.centre { margin: 10px 0 0 0; text-align: center } h2 { margin-top: 40px; font-weight: normal; font-style: italic } h3 { font-weight: normal; font-style: italic } ul, table { margin-left: 64px; margin-right: 10px; margin-top: 10px; margin-bottom: 10px } th { text-align: left; vertical-align: top } /* * NAVIGATION */ p.nav { background-color: #00007F; color: white; border-style: none; border-width: thin; padding: 1px 10px 1px 10px; margin: 0 0 0 0; font-family: Tahoma, Arial, helvetica, sans-serif; font-size: 10pt } a.nav { color: white; background-color: #00007F; text-decoration: none } a:link.nav { color: white; background-color: #00007F; text-decoration: none } a:visited.nav { color: white; background-color: #00007F; text-decoration: none } a:active.nav { color: white; background-color: #00007F; text-decoration: none } p.legal { margin-top: 8pt; margin-bottom: 0; margin-left: 10px; font-family: arial, helvetica, sans-serif; font-size: 8pt } img { border-color: white } p.image { margin: 10px 0 0 10px } p.image-c { margin: 10px 0 0 0; text-align: center } /* a.image { color: white; background-color: white } */ address { margin-left: 10px; font-size: 10pt; font-style: italic } cssparser-0.9.5/doc/CSSgrammarMobileOKBasic1.0.txt0000644000175000017500000001331710770335720021433 0ustar cavedoncavedonCSS grammar according to mobileOK Basic 1.0 * *: 0 or more * +: 1 or more * ?: 0 or 1 * |: separates alternatives * [ ]: grouping The productions are: stylesheet : [S|CDO|CDC]* [ import [S|CDO|CDC]* ]* [ [ ruleset | media ] [S|CDO|CDC]* ]* ; import : IMPORT_SYM S* [STRING|URI] S* [ medium [ ',' S* medium]* ]? ';' S* ; media : MEDIA_SYM S* medium [ ',' S* medium ]* '{' S* ruleset* '}' S* ; medium : IDENT S* ; unary_operator : '-' | '+' ; operator : '/' | ',' | /* empty */ ; property : IDENT ; ruleset : selector [ ',' selector ]* '{' declaration [ ';' declaration ]* '}' ; selector : simple_selector+ [ pseudo_element | solitary_pseudo_element ]? | solitary_pseudo_element ; /* An "id" is an ID that is attached to an element type ** on its left, as in: P#p007 ** A "solitary_id" is an ID that is not so attached, ** as in: #p007 ** Analogously for classes and pseudo-classes. */ simple_selector : element_name id? class? pseudo_class? /* eg: H1.subject */ | solitary_id class? pseudo_class? /* eg: #xyz33 */ | solitary_class pseudo_class? /* eg: .author */ | solitary_pseudo_class /* eg: :link */ ; element_name : IDENT ; pseudo_class /* as in: A:link */ : LINK_PSCLASS_AFTER_IDENT | VISITED_PSCLASS_AFTER_IDENT | ACTIVE_PSCLASS_AFTER_IDENT ; solitary_pseudo_class /* as in: :link */ : LINK_PSCLASS | VISITED_PSCLASS | ACTIVE_PSCLASS ; class /* as in: P.note */ : CLASS_AFTER_IDENT ; solitary_class /* as in: .note */ : CLASS ; pseudo_element /* as in: P:first-line */ : FIRST_LETTER_AFTER_IDENT | FIRST_LINE_AFTER_IDENT ; solitary_pseudo_element /* as in: :first-line */ : FIRST_LETTER | FIRST_LINE ; /* There is a constraint on the id and solitary_id that the ** part after the "#" must be a valid HTML ID value; ** e.g., "#x77" is OK, but "#77" is not. */ id : HASH_AFTER_IDENT ; solitary_id : HASH ; declaration : property ':' expr prio? | /* empty */ /* Prevents syntax errors... */ ; prio : IMPORTANT_SYM /* !important */ ; expr : term [ operator term ]* ; term : unary_operator? [ NUMBER | STRING | PERCENTAGE | LENGTH | EMS | EXS | IDENT | hexcolor | URL | RGB ] ; /* There is a constraint on the color that it must ** have either 3 or 6 hex-digits (i.e., [0-9a-fA-F]) ** after the "#"; e.g., "#000" is OK, but "#abcd" is not. */ hexcolor : HASH | HASH_AFTER_IDENT ; The following is the tokenizer, written in flex [16] notation. Note that this assumes an 8-bit implementation of flex. The tokenizer is case-insensitive (flex command line option -i). unicode \\[0-9a-f]{1,4} latin1 [¡-ÿ] escape {unicode}|\\[ -~¡-ÿ] stringchar {escape}|{latin1}|[ !#$%&(-~] nmstrt [a-z]|{latin1}|{escape} nmchar [-a-z0-9]|{latin1}|{escape} ident {nmstrt}{nmchar}* name {nmchar}+ d [0-9] notnm [^-a-z0-9\\]|{latin1} w [ \t\n]* num {d}+|{d}*\.{d}+ string \"({stringchar}|\')*\"|\'({stringchar}|\")*\' %x COMMENT %s AFTER_IDENT %% "/*" {BEGIN(COMMENT);} "*/" {BEGIN(0);} \n {/* ignore */} . {/* ignore */} @import {BEGIN(0); return IMPORT_SYM;} @media {BEGIN(0); return MEDIA_SYM;} "!"{w}important {BEGIN(0); return IMPORTANT_SYM;} {ident} {BEGIN(AFTER_IDENT); return IDENT;} {string} {BEGIN(0); return STRING;} {num} {BEGIN(0); return NUMBER;} {num}"%" {BEGIN(0); return PERCENTAGE;} {num}pt/{notnm} {BEGIN(0); return LENGTH;} {num}mm/{notnm} {BEGIN(0); return LENGTH;} {num}cm/{notnm} {BEGIN(0); return LENGTH;} {num}pc/{notnm} {BEGIN(0); return LENGTH;} {num}in/{notnm} {BEGIN(0); return LENGTH;} {num}px/{notnm} {BEGIN(0); return LENGTH;} {num}em/{notnm} {BEGIN(0); return EMS;} {num}ex/{notnm} {BEGIN(0); return EXS;} ":"link {return LINK_PSCLASS_AFTER_IDENT;} ":"visited {return VISITED_PSCLASS_AFTER_IDENT;} ":"active {return ACTIVE_PSCLASS_AFTER_IDENT;} ":"first-line {return FIRST_LINE_AFTER_IDENT;} ":"first-letter {return FIRST_LETTER_AFTER_IDENT;} "#"{name} {return HASH_AFTER_IDENT;} "."{name} {return CLASS_AFTER_IDENT;} ":"link {BEGIN(AFTER_IDENT); return LINK_PSCLASS;} ":"visited {BEGIN(AFTER_IDENT); return VISITED_PSCLASS;} ":"active {BEGIN(AFTER_IDENT); return ACTIVE_PSCLASS;} ":"first-line {BEGIN(AFTER_IDENT); return FIRST_LINE;} ":"first-letter {BEGIN(AFTER_IDENT); return FIRST_LETTER;} "#"{name} {BEGIN(AFTER_IDENT); return HASH;} "."{name} {BEGIN(AFTER_IDENT); return CLASS;} url\({w}{string}{w}\) | url\({w}([^ \n\'\")]|\\\ |\\\'|\\\"|\\\))+{w}\) {BEGIN(0); return URL;} rgb\({w}{num}%?{w}\,{w}{num}%?{w}\,{w}{num}%?{w}\) {BEGIN(0); return RGB;} [-/+{};,#:] {BEGIN(0); return *yytext;} [ \t]+ {BEGIN(0); /* ignore whitespace */} \n {BEGIN(0); /* ignore whitespace */} \<\!\-\- {BEGIN(0); return CDO;} \-\-\> {BEGIN(0); return CDC;} . {fprintf(stderr, "%d: Illegal character (%d)\n", lineno, *yytext);} cssparser-0.9.5/doc/readme.html0000644000175000017500000000755210770335720016257 0ustar cavedoncavedon Steady State CSS2 Parser README

CSS2 Parser README

What's New

Release 0.9.1

What's Included

primary.css  - Steady State Web style sheet
changes.html - A record of significant changes between releases
license.html - LGPL document
readme.html  - This file
ss_css2.jar  - JAR containing the CSS2 Parser

docs/        - Comceptual documentation for CSS2 Parser (currently empty)
javadoc/     - Javadoc documentation for CSS2 Parser classes
samples/     - Some demonstration applications
src/         - Source code for Parser, W3C DOM, and W3C SAC interfaces
stylesheets/ - Collection of test style sheets

What's Required

To compile the source, you'll need:

Documentation

The Javadoc documentation for the CSS2 Parser can be found in the javadoc directory.

Refer to the Document Object Model Level 2 Style Recommendation for details of the DOM interfaces.

Refer to the SAC: The Simple API for CSS home page for details of the SAC interfaces.

How to Use

Constructors

public CSS2Parser(
	java.io.InputStream stream,
	org.w3c.dom.Node ownerNode,
	String href,
	String title,
	String media )

public CSS2Parser(
	java.io.Reader stream,
	org.w3c.dom.Node ownerNode,
	String href,
	String title,
	String media )

public CSS2Parser( java.io.InputStream stream )

public CSS2Parser( java.io.Reader stream )

Example of usage

com.steadystate.css.CSS2Parser parser = new com.steadystate.css.CSS2Parser(
	new java.io.FileInputStream( href ),
	node,
	href,
	title,
	media );

org.w3c.dom.css.CSSStyleSheet styleSheet = parser.styleSheet();

Some Current Limitations

  • The media attribute of interface StyleSheet is not implemented
  • The parentRule attribute of interface CSSRule is not implemented
  • ImportRule doesn't import a style sheet
  • Conversion between units of CSSPrimitiveValue is not implemented


David Schweinsberg
17th February 2002
cssparser-0.9.5/doc/license.html0000644000175000017500000004700510770335720016441 0ustar cavedoncavedon GNU Lesser General Public License - GNU Project - Free Software Foundation (FSF)

GNU Lesser General Public License

Version 2.1, February 1999

Copyright (C) 1991, 1999 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

[This is the first released version of the Lesser GPL.  It also counts
 as the successor of the GNU Library Public License, version 2, hence
 the version number 2.1.]

TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".

A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.

The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)

"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.

Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.

1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.

You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.

2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:

  • a) The modified work must itself be a software library.
  • b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
  • c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
  • d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.

    (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)

    These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.

    Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.

    In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.

3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.

Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.

This option is useful when you wish to copy part of the code of the Library into a program that is not a library.

4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.

If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.

5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.

However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.

When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.

If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)

Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.

6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.

You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:

  • a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)
  • b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.
  • c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
  • d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
  • e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.

For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.

It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.

7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:

  • a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.
  • b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.

8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.

10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.

11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.

If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.

It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.

This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.

12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.

13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.

14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.

NO WARRANTY

15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


cssparser-0.9.5/pom.xml0000644000175000017500000000655210773012703014677 0ustar cavedoncavedon 4.0.0 net.sourceforge.cssparser cssparser 0.9.5 CSS Parser http://cssparser.sourceforge.net/ A CSS parser which implements SAC (the Simple API for CSS). GNU Lesser General Public License http://www.gnu.org/licenses/lgpl.txt SourceForge http://sourceforge.net/tracker/?group_id=82996 http://cssparser.cvs.sourceforge.net/cssparser cssparser-m2-repo CSS Parser Maven 2 Repository scp://shell.sourceforge.net/home/groups/c/cs/cssparser/htdocs/m2-repo cssparser-m2-snapshot-repo CSS Parser Maven 2 Snapshot Repository scp://shell.sourceforge.net/home/groups/c/cs/cssparser/htdocs/m2-snapshot-repo org.apache.maven.plugins maven-compiler-plugin 1.5 1.5 org.codehaus.mojo javacc-maven-plugin 2.4 javacc javacc org.apache.maven.plugins maven-source-plugin attach-sources verify jar org.apache.maven.plugins maven-changes-plugin changes-report %URL%?group_id=82996&func=detail&atid=567969&aid=%ISSUE% org.apache.maven.plugins maven-javadoc-plugin http://java.sun.com/j2se/1.5.0/docs/api/ http://www.w3.org/Style/CSS/SAC/doc/ org.w3c.css sac 1.3 junit junit 4.4 test