├── .gitignore ├── doc └── javadoc │ ├── package-list │ ├── resources │ └── inherit.gif │ ├── index.html │ ├── allclasses-noframe.html │ ├── stylesheet.css │ ├── allclasses-frame.html │ ├── com │ └── osbcp │ │ └── cssparser │ │ ├── package-frame.html │ │ ├── class-use │ │ ├── CSSParser.html │ │ ├── IncorrectFormatException.html │ │ └── Rule.html │ │ ├── package-tree.html │ │ └── package-use.html │ ├── deprecated-list.html │ ├── constant-values.html │ ├── src-html │ └── com │ │ └── osbcp │ │ └── cssparser │ │ ├── Selector.html │ │ ├── IncorrectFormatException.html │ │ ├── IncorrectFormatException.ErrorCode.html │ │ └── PropertyValue.html │ ├── index-files │ ├── index-2.html │ ├── index-5.html │ ├── index-9.html │ ├── index-3.html │ ├── index-6.html │ ├── index-10.html │ ├── index-11.html │ ├── index-1.html │ ├── index-7.html │ ├── index-4.html │ └── index-8.html │ ├── serialized-form.html │ └── overview-tree.html ├── libs ├── asm-3.1.jar ├── pmd-4.2.5.jar ├── jaxen-1.1.1.jar ├── commons-io-2.1.jar ├── checkstyle-5.3-all.jar ├── junit-pmd-test-wrapper-1.2.jar └── junit-checkstyle-test-wrapper-1.2.jar ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── CHANGES ├── .classpath ├── NOTICE ├── src └── com │ └── osbcp │ └── cssparser │ ├── package-info.java │ ├── State.java │ ├── Selector.java │ ├── Chars.java │ ├── PropertyValue.java │ ├── IncorrectFormatException.java │ └── Rule.java ├── test └── com │ └── osbcp │ └── cssparser │ ├── code │ ├── TestPMDTest.java │ ├── pmd.xml │ ├── TestCheckstyle.java │ └── checkstyle.xml │ ├── SelectorTest.java │ ├── PropertyValueTest.java │ ├── RuleTest.java │ ├── CSSParserFailingTests.java │ └── CSSParserTest.java └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ -------------------------------------------------------------------------------- /doc/javadoc/package-list: -------------------------------------------------------------------------------- 1 | com.osbcp.cssparser 2 | -------------------------------------------------------------------------------- /libs/asm-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/corgrath/osbcp-css-parser/HEAD/libs/asm-3.1.jar -------------------------------------------------------------------------------- /libs/pmd-4.2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/corgrath/osbcp-css-parser/HEAD/libs/pmd-4.2.5.jar -------------------------------------------------------------------------------- /libs/jaxen-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/corgrath/osbcp-css-parser/HEAD/libs/jaxen-1.1.1.jar -------------------------------------------------------------------------------- /libs/commons-io-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/corgrath/osbcp-css-parser/HEAD/libs/commons-io-2.1.jar -------------------------------------------------------------------------------- /libs/checkstyle-5.3-all.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/corgrath/osbcp-css-parser/HEAD/libs/checkstyle-5.3-all.jar -------------------------------------------------------------------------------- /doc/javadoc/resources/inherit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/corgrath/osbcp-css-parser/HEAD/doc/javadoc/resources/inherit.gif -------------------------------------------------------------------------------- /libs/junit-pmd-test-wrapper-1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/corgrath/osbcp-css-parser/HEAD/libs/junit-pmd-test-wrapper-1.2.jar -------------------------------------------------------------------------------- /libs/junit-checkstyle-test-wrapper-1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/corgrath/osbcp-css-parser/HEAD/libs/junit-checkstyle-test-wrapper-1.2.jar -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | github_java_osbcp_css_parser 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Sat Feb 04 20:02:30 CET 2012 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.6 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | v1.5 2012-04-28 Christoffer Pettersson 2 | 3 | * The parser can now handle nested comments. 4 | Thanks to Justin Marsan (HammHetfield) for reporting the bug. 5 | 6 | 7 | v1.4 2012-03-11 Christoffer Pettersson 8 | 9 | * The parser now gives an error if it founds another colon : while reading the value. 10 | 11 | 12 | v1.3 2012-02-08 Christoffer Pettersson 13 | 14 | * It is now possible to have duplicate property names in a rule 15 | 16 | 17 | v1.2 2012-06-07 Christoffer Pettersson 18 | 19 | * Added IncorrectFormatException.ErrorCode for more specific exceptions 20 | * Added support for values with data URIs 21 | 22 | 23 | v1.1 2012-02-06 Christoffer Pettersson 24 | 25 | * While inside the INSIDE_PROPERTY_NAME and a colon : is read, a IncorrectFormatException is thrown 26 | 27 | 28 | v1.0 2012-02-05 Christoffer Pettersson 29 | 30 | * Initial release -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | OSBCP CSS Parser 2 | Copyright 2012 Christoffer Pettersson, christoffer@christoffer.me. 3 | 4 | 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | 18 | 19 | 20 | This project includes PMD, Copyright (c) 2002-2009, InfoEther, Inc. 21 | All rights reserved. http://pmd.sourceforge.net/ 22 | 23 | This product includes software developed in part by support from the Defense 24 | Advanced Research Project Agency (DARPA) -------------------------------------------------------------------------------- /src/com/osbcp/cssparser/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | /** 19 | * Main package. 20 | * 21 | * @author Christoffer Pettersson 22 | */ 23 | 24 | package com.osbcp.cssparser; -------------------------------------------------------------------------------- /src/com/osbcp/cssparser/State.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | /** 21 | * Different states to aid the CSS parser. 22 | * 23 | * @author Christoffer Pettersson 24 | */ 25 | 26 | enum State { 27 | 28 | /** 29 | * Inside a selector 30 | */ 31 | INSIDE_SELECTOR, 32 | 33 | /** 34 | * Inside a comment. 35 | */ 36 | INSIDE_COMMENT, 37 | 38 | /** 39 | * Inside a property value. 40 | */ 41 | INSIDE_PROPERTY_NAME, 42 | 43 | /** 44 | * Inside value. 45 | */ 46 | INSIDE_VALUE, 47 | 48 | /** 49 | * Inside value and also inside ( 50 | */ 51 | INSIDE_VALUE_ROUND_BRACKET; 52 | 53 | } -------------------------------------------------------------------------------- /doc/javadoc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Generated Documentation (Untitled) 8 | 9 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | <H2> 28 | Frame Alert</H2> 29 | 30 | <P> 31 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. 32 | <BR> 33 | Link to<A HREF="com/osbcp/cssparser/package-summary.html">Non-frame version.</A> 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/javadoc/allclasses-noframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | All Classes 20 |
21 | 22 | 23 | 24 | 37 | 38 |
CSSParser 25 |
26 | IncorrectFormatException 27 |
28 | IncorrectFormatException.ErrorCode 29 |
30 | PropertyValue 31 |
32 | Rule 33 |
34 | Selector 35 |
36 |
39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /doc/javadoc/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | 3 | /* Define colors, fonts and other style attributes here to override the defaults */ 4 | 5 | /* Page background color */ 6 | body { background-color: #FFFFFF; color:#000000 } 7 | 8 | /* Headings */ 9 | h1 { font-size: 145% } 10 | 11 | /* Table colors */ 12 | .TableHeadingColor { background: #CCCCFF; color:#000000 } /* Dark mauve */ 13 | .TableSubHeadingColor { background: #EEEEFF; color:#000000 } /* Light mauve */ 14 | .TableRowColor { background: #FFFFFF; color:#000000 } /* White */ 15 | 16 | /* Font used in left-hand frame lists */ 17 | .FrameTitleFont { font-size: 100%; font-family: Helvetica, Arial, sans-serif; color:#000000 } 18 | .FrameHeadingFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } 19 | .FrameItemFont { font-size: 90%; font-family: Helvetica, Arial, sans-serif; color:#000000 } 20 | 21 | /* Navigation bar fonts and colors */ 22 | .NavBarCell1 { background-color:#EEEEFF; color:#000000} /* Light mauve */ 23 | .NavBarCell1Rev { background-color:#00008B; color:#FFFFFF} /* Dark Blue */ 24 | .NavBarFont1 { font-family: Arial, Helvetica, sans-serif; color:#000000;color:#000000;} 25 | .NavBarFont1Rev { font-family: Arial, Helvetica, sans-serif; color:#FFFFFF;color:#FFFFFF;} 26 | 27 | .NavBarCell2 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} 28 | .NavBarCell3 { font-family: Arial, Helvetica, sans-serif; background-color:#FFFFFF; color:#000000} 29 | 30 | -------------------------------------------------------------------------------- /test/com/osbcp/cssparser/code/TestPMDTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser.code; 19 | 20 | import org.junit.Test; 21 | 22 | import com.osbcp.junitpmdtestwrapper.JUnitPMDTestWrapper; 23 | 24 | /** 25 | * Contains the PMD tests 26 | * 27 | * @author Christoffer Pettersson 28 | */ 29 | 30 | public class TestPMDTest { 31 | 32 | /** 33 | * Tests the SRC-folder 34 | * 35 | * @throws Exception If any errors occur 36 | */ 37 | 38 | @Test 39 | public void testSrc() throws Exception { 40 | JUnitPMDTestWrapper.run(this, "./src/", "pmd.xml"); 41 | } 42 | 43 | /** 44 | * Tests the TEST-folder 45 | * 46 | * @throws Exception If any errors occur 47 | */ 48 | 49 | @Test 50 | public void testTest() throws Exception { 51 | JUnitPMDTestWrapper.run(this, "./test/", "pmd.xml"); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /doc/javadoc/allclasses-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | All Classes 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | All Classes 20 |
21 | 22 | 23 | 24 | 37 | 38 |
CSSParser 25 |
26 | IncorrectFormatException 27 |
28 | IncorrectFormatException.ErrorCode 29 |
30 | PropertyValue 31 |
32 | Rule 33 |
34 | Selector 35 |
36 |
39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /test/com/osbcp/cssparser/code/pmd.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/com/osbcp/cssparser/Selector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | /** 21 | * Represents a CSS selector. 22 | * 23 | * @author Christoffer Pettersson 24 | */ 25 | 26 | public final class Selector { 27 | 28 | private String name; 29 | 30 | /** 31 | * Creates a new selector. 32 | * 33 | * @param name Selector name. 34 | */ 35 | 36 | public Selector(final String name) { 37 | this.name = name; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return name; 43 | } 44 | 45 | @Override 46 | public boolean equals(final Object object) { 47 | 48 | if (object instanceof Selector) { 49 | 50 | Selector target = (Selector) object; 51 | 52 | return target.name.equalsIgnoreCase(name); 53 | 54 | } 55 | 56 | return false; 57 | 58 | } 59 | 60 | @Override 61 | public int hashCode() { 62 | return toString().hashCode(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /test/com/osbcp/cssparser/SelectorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | import junit.framework.Assert; 21 | 22 | import org.junit.Test; 23 | 24 | public final class SelectorTest { 25 | 26 | @Test 27 | public void testHashCode() { 28 | 29 | Selector selector = new Selector("div"); 30 | 31 | Assert.assertEquals(selector.toString().hashCode(), selector.hashCode()); 32 | 33 | } 34 | 35 | @Test 36 | public void testEqualsNull() { 37 | 38 | Selector selector1 = new Selector("div1"); 39 | Selector selector2 = null; 40 | 41 | Assert.assertFalse(selector1.equals(selector2)); 42 | 43 | } 44 | 45 | @Test 46 | public void testEquals() { 47 | 48 | Selector selector1a = new Selector("div1"); 49 | Selector selector1b = new Selector("div1"); 50 | Selector selector2 = new Selector("div2"); 51 | 52 | Assert.assertFalse(selector1a.equals(selector2)); 53 | Assert.assertTrue(selector1a.equals(selector1b)); 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /test/com/osbcp/cssparser/code/TestCheckstyle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser.code; 19 | 20 | import org.junit.Test; 21 | 22 | import com.osbcp.junitcheckstyletestwrapper.JUnitCheckstyleTestWrapper; 23 | import com.osbcp.junitpmdtestwrapper.JUnitPMDTestWrapper; 24 | 25 | /** 26 | * Contains the Checkstyle tests 27 | * 28 | * @author Christoffer Pettersson 29 | */ 30 | 31 | public class TestCheckstyle { 32 | 33 | /** 34 | * Tests the SRC-folder 35 | * 36 | * @throws Exception If any errors occur 37 | */ 38 | 39 | @Test 40 | public void testSrc() throws Exception { 41 | JUnitCheckstyleTestWrapper.run(this, "./src/", "checkstyle.xml"); 42 | } 43 | 44 | /** 45 | * Tests the TEST-folder 46 | * 47 | * @throws Exception If any errors occur 48 | */ 49 | 50 | @Test 51 | public void testTest() throws Exception { 52 | JUnitPMDTestWrapper.run(this, "./test/", "pmd.xml"); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /test/com/osbcp/cssparser/code/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/com/osbcp/cssparser/Chars.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | /** 21 | * List of known characters. 22 | * 23 | * @author Christoffer Pettersson 24 | */ 25 | 26 | final class Chars { 27 | 28 | /** 29 | * The character '*'. 30 | */ 31 | 32 | static final Character STAR = '*'; 33 | 34 | /** 35 | * The character '/'. 36 | */ 37 | static final Character SLASH = '/'; 38 | 39 | /** 40 | * The character ','. 41 | */ 42 | static final Character COMMA = ','; 43 | 44 | /** 45 | * The character '{'. 46 | */ 47 | static final Character BRACKET_BEG = '{'; 48 | 49 | /** 50 | * The character '}'. 51 | */ 52 | static final Character BRACKET_END = '}'; 53 | 54 | /** 55 | * The character ':'. 56 | */ 57 | static final Character COLON = ':'; 58 | 59 | /** 60 | * The character ';'. 61 | */ 62 | static final Character SEMI_COLON = ';'; 63 | 64 | /** 65 | * The character '('. 66 | */ 67 | static final Character ROUND_BRACKET_BEG = '('; 68 | 69 | /** 70 | * The character ')'. 71 | */ 72 | static final Character ROUND_BRACKET_END = ')'; 73 | 74 | } 75 | -------------------------------------------------------------------------------- /test/com/osbcp/cssparser/PropertyValueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | import junit.framework.Assert; 21 | 22 | import org.junit.Test; 23 | 24 | public final class PropertyValueTest { 25 | 26 | @Test 27 | public void testGetters() { 28 | 29 | PropertyValue propertyValue = new PropertyValue("width", "100px"); 30 | 31 | Assert.assertEquals(propertyValue.getProperty(), "width"); 32 | Assert.assertEquals(propertyValue.getValue(), "100px"); 33 | 34 | } 35 | 36 | @Test 37 | public void testHashCode() { 38 | 39 | PropertyValue propertyValue = new PropertyValue("width", "100px"); 40 | 41 | Assert.assertEquals(propertyValue.toString().hashCode(), propertyValue.hashCode()); 42 | 43 | } 44 | 45 | @Test 46 | public void testEquals() { 47 | 48 | PropertyValue selector1a = new PropertyValue("width", "100%"); 49 | PropertyValue selector1b = new PropertyValue("width", "100%"); 50 | PropertyValue selector2 = new PropertyValue("width", "200%"); 51 | PropertyValue selectorNull = null; 52 | 53 | Assert.assertTrue(selector1a.equals(selector1b)); 54 | Assert.assertFalse(selector1a.equals(selector2)); 55 | Assert.assertFalse(selector1a.equals(selectorNull)); 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /doc/javadoc/com/osbcp/cssparser/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.osbcp.cssparser 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | com.osbcp.cssparser 20 | 21 | 22 | 33 | 34 |
23 | Classes  24 | 25 |
26 | CSSParser 27 |
28 | PropertyValue 29 |
30 | Rule 31 |
32 | Selector
35 | 36 | 37 | 38 | 39 | 44 | 45 |
40 | Enums  41 | 42 |
43 | IncorrectFormatException.ErrorCode
46 | 47 | 48 | 49 | 50 | 55 | 56 |
51 | Exceptions  52 | 53 |
54 | IncorrectFormatException
57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /test/com/osbcp/cssparser/RuleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import junit.framework.Assert; 24 | 25 | import org.junit.Test; 26 | 27 | public final class RuleTest { 28 | 29 | @Test 30 | public void testBasic() { 31 | 32 | Selector selector = new Selector("div"); 33 | 34 | Rule rule = new Rule(selector); 35 | 36 | Assert.assertEquals(selector, rule.getSelectors().get(0)); 37 | 38 | } 39 | 40 | @Test 41 | public void testRemoveSelector() { 42 | 43 | Selector selector = new Selector("div"); 44 | 45 | Rule rule = new Rule(selector); 46 | rule.removeSelector(selector); 47 | 48 | Assert.assertEquals(0, rule.getSelectors().size()); 49 | 50 | } 51 | 52 | @Test 53 | public void testRemovePropertyValue() { 54 | 55 | Selector selector = new Selector("div"); 56 | PropertyValue propertyValue = new PropertyValue("width", "100px"); 57 | Rule rule = new Rule(selector); 58 | rule.addPropertyValue(propertyValue); 59 | 60 | rule.removePropertyValue(propertyValue); 61 | 62 | Assert.assertEquals(0, rule.getPropertyValues().size()); 63 | 64 | } 65 | 66 | @Test 67 | public void testAddSelectors() { 68 | 69 | List selectors = new ArrayList(); 70 | selectors.add(new Selector("div")); 71 | selectors.add(new Selector("table")); 72 | 73 | Rule rule = new Rule(selectors); 74 | rule.addSelectors(selectors); 75 | 76 | Assert.assertEquals(4, rule.getSelectors().size()); 77 | 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/com/osbcp/cssparser/PropertyValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | /** 21 | * Represents a property and its value of a CSS rule. 22 | * 23 | * @author Christoffer Pettersson 24 | */ 25 | 26 | public final class PropertyValue { 27 | 28 | private String property; 29 | private String value; 30 | 31 | /** 32 | * Creates a new PropertyValue based on a property and its value. 33 | * 34 | * @param property The CSS property (such as 'width' or 'color'). 35 | * @param value The value of the property (such as '100px' or 'red'). 36 | */ 37 | 38 | public PropertyValue(final String property, final String value) { 39 | this.property = property; 40 | this.value = value; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return property + ": " + value; 46 | } 47 | 48 | @Override 49 | public boolean equals(final Object object) { 50 | 51 | if (object instanceof PropertyValue) { 52 | 53 | PropertyValue target = (PropertyValue) object; 54 | 55 | return target.property.equalsIgnoreCase(property) && target.value.equalsIgnoreCase(value); 56 | 57 | } 58 | 59 | return false; 60 | 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return toString().hashCode(); 66 | } 67 | 68 | /** 69 | * Returns the property. 70 | * 71 | * @return The property. 72 | */ 73 | 74 | public String getProperty() { 75 | return property; 76 | } 77 | 78 | /** 79 | * Returns the value. 80 | * 81 | * @return The value. 82 | */ 83 | 84 | public String getValue() { 85 | return value; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /test/com/osbcp/cssparser/CSSParserFailingTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | import junit.framework.Assert; 21 | 22 | import org.junit.Test; 23 | 24 | import com.osbcp.cssparser.IncorrectFormatException.ErrorCode; 25 | 26 | public final class CSSParserFailingTests { 27 | 28 | @Test 29 | public void testCommaFirstAsSelector() throws Exception { 30 | 31 | try { 32 | CSSParser.parse("alpha { width: 100px; } , beta { height: 200px; } "); 33 | Assert.fail(); 34 | } catch (IncorrectFormatException e) { 35 | Assert.assertEquals(ErrorCode.FOUND_COLON_WHEN_READING_SELECTOR_NAME, e.getErrorCode()); 36 | } 37 | 38 | } 39 | 40 | @Test 41 | public void testValueShouldEndWithSemiColon() throws Exception { 42 | 43 | try { 44 | CSSParser.parse("alpha { width: 100px }"); 45 | Assert.fail(); 46 | } catch (IncorrectFormatException e) { 47 | Assert.assertEquals(ErrorCode.FOUND_END_BRACKET_BEFORE_SEMICOLON, e.getErrorCode()); 48 | } 49 | 50 | } 51 | 52 | @Test 53 | public void testMissingColon() throws Exception { 54 | 55 | try { 56 | CSSParser.parse("alpha { color red; }"); 57 | Assert.fail(); 58 | } catch (IncorrectFormatException e) { 59 | Assert.assertEquals(ErrorCode.FOUND_SEMICOLON_WHEN_READING_PROPERTY_NAME, e.getErrorCode()); 60 | } 61 | 62 | } 63 | 64 | @Test 65 | public void testMissingSemiColon() throws Exception { 66 | 67 | try { 68 | CSSParser.parse("alpha { border: 1px solid green background-color:white; left: 0px; }"); 69 | Assert.fail(); 70 | } catch (IncorrectFormatException e) { 71 | Assert.assertEquals(ErrorCode.FOUND_COLON_WHILE_READING_VALUE, e.getErrorCode()); 72 | } 73 | 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/com/osbcp/cssparser/IncorrectFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | /** 21 | * An exception that is thrown when the CSS parser finds a character it shouldn't have. 22 | * 23 | * @author Christoffer Pettersson 24 | */ 25 | 26 | public class IncorrectFormatException extends Exception { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | private final ErrorCode errorCode; 31 | 32 | /** 33 | * Creates a new IncorrectFormatExeption with an error message; 34 | * 35 | * @param errorCode S unique error code associated with the error. 36 | * @param message Error message describing the problem. 37 | */ 38 | 39 | IncorrectFormatException(final ErrorCode errorCode, final String message) { 40 | super(message); 41 | this.errorCode = errorCode; 42 | } 43 | 44 | /** 45 | * Returns a unique error code associated with the error. 46 | * 47 | * @return A unique error code associated with the error. 48 | */ 49 | 50 | public ErrorCode getErrorCode() { 51 | return errorCode; 52 | } 53 | 54 | /** 55 | * List of unique error codes. 56 | * 57 | * @author Christoffer Pettersson 58 | */ 59 | 60 | public enum ErrorCode { 61 | 62 | /** 63 | * When the parse founds a semicolon ; when reading the property name. 64 | */ 65 | FOUND_SEMICOLON_WHEN_READING_PROPERTY_NAME, 66 | 67 | /** 68 | * When the parse founds an end bracket } before the value's semicolon ; ending. 69 | */ 70 | FOUND_END_BRACKET_BEFORE_SEMICOLON, 71 | 72 | /** 73 | * When the parse founds a colon , before reading a real selector name. 74 | */ 75 | FOUND_COLON_WHEN_READING_SELECTOR_NAME, 76 | 77 | /** 78 | * When the parse the value a colon : was found. 79 | */ 80 | FOUND_COLON_WHILE_READING_VALUE; 81 | 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project is abandoned 2 | ======================================== 3 | I am sorry to say but this project is abandoned, and I stopped maintaining it back in 2012, as my focus has shifted from Java. 4 | 5 | However, there might be an active fork with improvements. Please check the fork tree below. 6 | https://github.com/corgrath/osbcp-css-parser/network 7 | 8 | Again, I am so sorry but I highly appreciate all the stars and forks this project has gotten :-) 9 | 10 | -- Christoffer 11 | 12 | 13 | OSBCP CSS Parser 14 | ======================================== 15 | 16 | A simple CSS parser in Java. 17 | 18 | An oh, it is also very strict. If it finds an unexpected character in your CSS it self-destructs, taking you with you - making it a great tool to validate strict CSS. 19 | 20 | 21 | Code examples 22 | ======================================== 23 | 24 | As String directly: 25 | ```java 26 | List rules = CSSParser.parse("div { width: 100px; -mozilla-opacity: 345; }"); 27 | ``` 28 | Or from a file (using [Apache Commons IO](http://commons.apache.org/io/)): 29 | ```java 30 | String contents = IOUtils.toString(this.getClass().getResourceAsStream("stylesheet.css")); 31 | 32 | List rules = CSSParser.parse(contents); 33 | ``` 34 | To print it all out: 35 | ```java 36 | for (Rule rule : rules) { 37 | 38 | System.out.println(rule); 39 | 40 | } 41 | ``` 42 | Or go into details: 43 | ```java 44 | for (Rule rule : rules) { 45 | 46 | // Get all the selectors (such as 'table', 'table td', 'a') 47 | List selectors = rule.getSelectors(); 48 | 49 | // Get all the property (such as 'width') and its value (such as '100px') 50 | List propertyValues = rule.getPropertyValues(); 51 | 52 | } 53 | ``` 54 | Please view the JavaDoc for more informaton. 55 | 56 | 57 | Download 58 | ======================================== 59 | Download the latest version here: 60 | 61 | https://github.com/corgrath/osbcp-css-parser/downloads/ 62 | 63 | JavaDoc 64 | ======================================== 65 | 66 | http://dl.dropbox.com/u/8183146/persistent/projects/java_osbcp_css_parser/javadoc/index.html 67 | 68 | Reporting bugs 69 | ======================================== 70 | 71 | Please create an issue here: 72 | 73 | https://github.com/corgrath/osbcp-css-parser/issues 74 | 75 | Test coverage 76 | ======================================== 77 | 78 | Version 1.2 79 | 80 | ![Code coverage](http://dl.dropbox.com/u/8183146/persistent/projects/java_osbcp_css_parser/code_coverage12.png "Code coverage") 81 | 82 | 83 | Code is also checked with [PMD](http://pmd.sourceforge.net/) and [Checkstyle](http://checkstyle.sourceforge.net/). 84 | 85 | 86 | Changes 87 | ======================================== 88 | 89 | v1.5 2012-04-28 Christoffer Pettersson 90 | 91 | * The parser can now handle nested comments. 92 | Thanks to Justin Marsan (HammHetfield) for reporting the bug. 93 | 94 | 95 | v1.4 2012-03-11 Christoffer Pettersson 96 | 97 | * The parser now gives an error if it founds another colon : while reading the value. 98 | 99 | 100 | v1.3 2012-02-08 Christoffer Pettersson 101 | 102 | * It is now possible to have duplicate property names in a rule 103 | 104 | 105 | v1.2 2012-06-07 Christoffer Pettersson 106 | 107 | * Added IncorrectFormatException.ErrorCode for more specific exceptions 108 | * Added support for values with data URIs 109 | 110 | 111 | v1.1 2012-02-06 Christoffer Pettersson 112 | 113 | * While inside the INSIDE_PROPERTY_NAME and a colon : is read, a IncorrectFormatException is thrown 114 | 115 | 116 | v1.0 2012-02-05 Christoffer Pettersson 117 | 118 | * Initial release 119 | 120 | 121 | License 122 | ======================================== 123 | 124 | OSBCP CSS Parser 125 | Copyright 2012 Christoffer Pettersson, christoffer[at]christoffer.me. 126 | 127 | Licensed under the Apache License, Version 2.0 128 | -------------------------------------------------------------------------------- /src/com/osbcp/cssparser/Rule.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Iterator; 22 | import java.util.List; 23 | 24 | /** 25 | * Represents a CSS rule. 26 | * 27 | * @author Christoffer Pettersson 28 | */ 29 | 30 | public final class Rule { 31 | 32 | private List selectors; 33 | private List propertyValues; 34 | 35 | /** 36 | * Creates a rule with a single selector. 37 | * 38 | * @param selector A selector that the rule should initial with. 39 | */ 40 | 41 | public Rule(final Selector selector) { 42 | this(); 43 | this.selectors.add(selector); 44 | } 45 | 46 | /** 47 | * Creates an empty rule. 48 | */ 49 | 50 | public Rule() { 51 | this(new ArrayList()); 52 | } 53 | 54 | /** 55 | * Creates a new rule based on a list of selectors. 56 | * 57 | * @param selectors A list of selectors that the rule should initial with. 58 | */ 59 | 60 | public Rule(final List selectors) { 61 | this.selectors = selectors; 62 | this.propertyValues = new ArrayList(); 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | 68 | StringBuilder out = new StringBuilder(); 69 | 70 | // for (String selectorString : selectors) { 71 | // 72 | // out.append(selectorString + ","); 73 | // out.append(implode(selectors) + " {\n"); 74 | // 75 | // } 76 | 77 | out.append(implode(selectors) + " {\n"); 78 | for (PropertyValue propertyValue : propertyValues) { 79 | out.append("\t" + propertyValue + ";\n"); 80 | } 81 | out.append("}\n"); 82 | 83 | return out.toString(); 84 | } 85 | 86 | /** 87 | * Adds a property value to the rule. 88 | * 89 | * @param propertyValue The property value that should be attached. 90 | */ 91 | 92 | public void addPropertyValue(final PropertyValue propertyValue) { 93 | propertyValues.add(propertyValue); 94 | } 95 | 96 | /** 97 | * Returns a list of all property values attached to the rule. 98 | * 99 | * @return A list of all property values attached to the rule. 100 | */ 101 | 102 | public List getPropertyValues() { 103 | return propertyValues; 104 | } 105 | 106 | /** 107 | * Returns a list of all selectors attached to the rule. 108 | * 109 | * @return A list of all selectors attached to the rule. 110 | */ 111 | 112 | public List getSelectors() { 113 | return selectors; 114 | } 115 | 116 | /** 117 | * Adds a list of selectors to the existing list of selectors. 118 | * 119 | * @param selectors A list of selectors that should be appended. 120 | */ 121 | 122 | public void addSelectors(final List selectors) { 123 | this.selectors.addAll(selectors); 124 | } 125 | 126 | // 127 | // @Override 128 | // public boolean equals(final Object object) { 129 | // 130 | // if (object instanceof Rule) { 131 | // 132 | // Rule target = (Rule) object; 133 | // 134 | // return target.name.equalsIgnoreCase(name); 135 | // 136 | // } 137 | // 138 | // return false; 139 | // 140 | // } 141 | // 142 | // @Override 143 | // public int hashCode() { 144 | // return toString().hashCode(); 145 | // } 146 | 147 | /** 148 | * Implodes the list of selectors into a pretty String. 149 | * 150 | * @param values A list of selectors. 151 | * @return A fancy String. 152 | */ 153 | 154 | private String implode(final List values) { 155 | 156 | StringBuilder sb = new StringBuilder(); 157 | 158 | Iterator iterator = values.iterator(); 159 | 160 | while (iterator.hasNext()) { 161 | 162 | Selector selector = iterator.next(); 163 | 164 | sb.append(selector.toString()); 165 | 166 | if (iterator.hasNext()) { 167 | sb.append(", "); 168 | } 169 | 170 | } 171 | 172 | return sb.toString(); 173 | 174 | } 175 | 176 | /** 177 | * Removes a property value from the rule. 178 | * 179 | * @param propertyValue The property value that should be removed. 180 | */ 181 | 182 | public void removePropertyValue(final PropertyValue propertyValue) { 183 | propertyValues.remove(propertyValue); 184 | } 185 | 186 | /** 187 | * Adds a selector to the rule. 188 | * 189 | * @param selector The selector that should be attached to the rule. 190 | */ 191 | 192 | public void addSelector(final Selector selector) { 193 | selectors.add(selector); 194 | } 195 | 196 | /** 197 | * Removes a selector from the rule. 198 | * 199 | * @param selector The selector that should be removed from the rule. 200 | */ 201 | 202 | public void removeSelector(final Selector selector) { 203 | selectors.remove(selector); 204 | } 205 | 206 | } 207 | -------------------------------------------------------------------------------- /doc/javadoc/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Deprecated List 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 |
81 |
82 |

83 | Deprecated API

84 |
85 |
86 | Contents
    87 |
88 | 89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 111 | 114 | 115 | 116 | 117 | 120 | 136 | 137 |
112 | 113 |
138 | 139 | 140 | 141 |
142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /doc/javadoc/constant-values.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Constant Field Values 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 |
81 |
82 |

83 | Constant Field Values

84 |
85 |
86 | Contents
    87 |
88 | 89 |
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 111 | 114 | 115 | 116 | 117 | 120 | 136 | 137 |
112 | 113 |
138 | 139 | 140 | 141 |
142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /doc/javadoc/src-html/com/osbcp/cssparser/Selector.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
  4 | 001    /*
  5 | 002     * Licensed under the Apache License, Version 2.0 (the "License");
  6 | 003     * you may not use this file except in compliance with the License.
  7 | 004     * You may obtain a copy of the License at
  8 | 005     *
  9 | 006     * http://www.apache.org/licenses/LICENSE-2.0
 10 | 007     *
 11 | 008     * Unless required by applicable law or agreed to in writing, software
 12 | 009     * distributed under the License is distributed on an "AS IS" BASIS,
 13 | 010     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14 | 011     * See the License for the specific language governing permissions and
 15 | 012     * limitations under the License.
 16 | 013     * 
 17 | 014     * See the NOTICE file distributed with this work for additional
 18 | 015     * information regarding copyright ownership.
 19 | 016     */
 20 | 017    
 21 | 018    package com.osbcp.cssparser;
 22 | 019    
 23 | 020    /**
 24 | 021     * Represents a CSS selector.
 25 | 022     * 
 26 | 023     * @author <a href="mailto:christoffer@christoffer.me">Christoffer Pettersson</a>
 27 | 024     */
 28 | 025    
 29 | 026    public final class Selector {
 30 | 027    
 31 | 028            private String name;
 32 | 029    
 33 | 030            /**
 34 | 031             * Creates a new selector.
 35 | 032             * 
 36 | 033             * @param name Selector name.
 37 | 034             */
 38 | 035    
 39 | 036            public Selector(final String name) {
 40 | 037                    this.name = name;
 41 | 038            }
 42 | 039    
 43 | 040            @Override
 44 | 041            public String toString() {
 45 | 042                    return name;
 46 | 043            }
 47 | 044    
 48 | 045            @Override
 49 | 046            public boolean equals(final Object object) {
 50 | 047    
 51 | 048                    if (object instanceof Selector) {
 52 | 049    
 53 | 050                            Selector target = (Selector) object;
 54 | 051    
 55 | 052                            return target.name.equalsIgnoreCase(name);
 56 | 053    
 57 | 054                    }
 58 | 055    
 59 | 056                    return false;
 60 | 057    
 61 | 058            }
 62 | 059    
 63 | 060            @Override
 64 | 061            public int hashCode() {
 65 | 062                    return toString().hashCode();
 66 | 063            }
 67 | 064    
 68 | 065    }
 69 | 
 70 | 
 71 | 
 72 | 
 73 | 
 74 | 
 75 | 
 76 | 
 77 | 
 78 | 
 79 | 
 80 | 
 81 | 
 82 | 
 83 | 
 84 | 
 85 | 
 86 | 
 87 | 
 88 | 
 89 | 
 90 | 
 91 | 
 92 | 
 93 | 
 94 | 
 95 | 
 96 | 
 97 | 
 98 | 
 99 | 
100 | 
101 | 
102 | 
103 | 
104 | 
105 | 
106 | 
107 | 
108 | 
109 | 
110 | 
111 | 
112 | 
113 | 
114 | 
115 | 
116 | 
117 | 
118 | 
119 | 
120 | 
121 | 
122 | 
123 | 
124 | 
125 | 
126 | 
127 | 
128 | 
129 | 
130 | 131 | 132 | -------------------------------------------------------------------------------- /doc/javadoc/com/osbcp/cssparser/class-use/CSSParser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.osbcp.cssparser.CSSParser 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 |
81 |
82 |

83 | Uses of Class
com.osbcp.cssparser.CSSParser

84 |
85 | No usage of com.osbcp.cssparser.CSSParser 86 |

87 |


88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 109 | 112 | 113 | 114 | 115 | 118 | 134 | 135 |
110 | 111 |
136 | 137 | 138 | 139 |
140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /doc/javadoc/com/osbcp/cssparser/class-use/IncorrectFormatException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.osbcp.cssparser.IncorrectFormatException 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 |
81 |
82 |

83 | Uses of Class
com.osbcp.cssparser.IncorrectFormatException

84 |
85 | No usage of com.osbcp.cssparser.IncorrectFormatException 86 |

87 |


88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 109 | 112 | 113 | 114 | 115 | 118 | 134 | 135 |
110 | 111 |
136 | 137 | 138 | 139 |
140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | C-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | C

83 |
84 |
com.osbcp.cssparser - package com.osbcp.cssparser
Main package.
CSSParser - Class in com.osbcp.cssparser
Main logic for the CSS parser.
85 |
86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 107 | 110 | 111 | 112 | 113 | 116 | 132 | 133 |
108 | 109 |
134 | 135 | 136 | 137 | A C E G H I P R S T V
138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | H-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | H

83 |
84 |
hashCode() - 85 | Method in class com.osbcp.cssparser.PropertyValue 86 |
  87 |
hashCode() - 88 | Method in class com.osbcp.cssparser.Selector 89 |
  90 |
91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 113 | 116 | 117 | 118 | 119 | 122 | 138 | 139 |
114 | 115 |
140 | 141 | 142 | 143 | A C E G H I P R S T V
144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-9.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | S-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | S

83 |
84 |
Selector - Class in com.osbcp.cssparser
Represents a CSS selector.
Selector(String) - 85 | Constructor for class com.osbcp.cssparser.Selector 86 |
Creates a new selector. 87 |
88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 110 | 113 | 114 | 115 | 116 | 119 | 135 | 136 |
111 | 112 |
137 | 138 | 139 | 140 | A C E G H I P R S T V
141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | E-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | E

83 |
84 |
equals(Object) - 85 | Method in class com.osbcp.cssparser.PropertyValue 86 |
  87 |
equals(Object) - 88 | Method in class com.osbcp.cssparser.Selector 89 |
  90 |
91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 113 | 116 | 117 | 118 | 119 | 122 | 138 | 139 |
114 | 115 |
140 | 141 | 142 | 143 | A C E G H I P R S T V
144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | I-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | I

83 |
84 |
IncorrectFormatException - Exception in com.osbcp.cssparser
An exception that is thrown when the CSS parser finds a character it shouldn't have.
IncorrectFormatException.ErrorCode - Enum in com.osbcp.cssparser
List of unique error codes.
85 |
86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 107 | 110 | 111 | 112 | 113 | 116 | 132 | 133 |
108 | 109 |
134 | 135 | 136 | 137 | A C E G H I P R S T V
138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /doc/javadoc/serialized-form.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Serialized Form 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 |
81 |
82 |

83 | Serialized Form

84 |
85 |
86 | 87 | 88 | 89 | 91 | 92 |
90 | Package com.osbcp.cssparser
93 | 94 |

95 | 96 | 97 | 98 | 100 | 101 |
99 | Class com.osbcp.cssparser.IncorrectFormatException extends java.lang.Exception implements Serializable
102 | 103 |

104 | serialVersionUID: 1L 105 | 106 |

107 | 108 | 109 | 110 | 112 | 113 |
111 | Serialized Fields
114 | 115 |

116 | errorCode

117 |
118 | IncorrectFormatException.ErrorCode errorCode
119 |
120 |
121 |
122 |
123 | 124 |

125 |


126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 147 | 150 | 151 | 152 | 153 | 156 | 172 | 173 |
148 | 149 |
174 | 175 | 176 | 177 |
178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-10.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | T-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | T

83 |
84 |
toString() - 85 | Method in class com.osbcp.cssparser.PropertyValue 86 |
  87 |
toString() - 88 | Method in class com.osbcp.cssparser.Rule 89 |
  90 |
toString() - 91 | Method in class com.osbcp.cssparser.Selector 92 |
  93 |
94 |
95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 116 | 119 | 120 | 121 | 122 | 125 | 141 | 142 |
117 | 118 |
143 | 144 | 145 | 146 | A C E G H I P R S T V
147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-11.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | V-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | V

83 |
84 |
valueOf(String) - 85 | Static method in enum com.osbcp.cssparser.IncorrectFormatException.ErrorCode 86 |
Returns the enum constant of this type with the specified name. 87 |
values() - 88 | Static method in enum com.osbcp.cssparser.IncorrectFormatException.ErrorCode 89 |
Returns an array containing the constants of this enum type, in 90 | the order they are declared. 91 |
92 |
93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 114 | 117 | 118 | 119 | 120 | 123 | 139 | 140 |
115 | 116 |
141 | 142 | 143 | 144 | A C E G H I P R S T V
145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /doc/javadoc/overview-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Class Hierarchy 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 |
81 |
82 |

83 | Hierarchy For All Packages

84 |
85 |
86 |
Package Hierarchies:
com.osbcp.cssparser
87 |
88 |

89 | Class Hierarchy 90 |

91 |
    92 |
  • java.lang.Object 99 |
100 |

101 | Enum Hierarchy 102 |

103 |
    104 |
  • java.lang.Object 109 |
110 |
111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 132 | 135 | 136 | 137 | 138 | 141 | 157 | 158 |
133 | 134 |
159 | 160 | 161 | 162 |
163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | A-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | A

83 |
84 |
addPropertyValue(PropertyValue) - 85 | Method in class com.osbcp.cssparser.Rule 86 |
Adds a property value to the rule. 87 |
addSelector(Selector) - 88 | Method in class com.osbcp.cssparser.Rule 89 |
Adds a selector to the rule. 90 |
addSelectors(List<Selector>) - 91 | Method in class com.osbcp.cssparser.Rule 92 |
Adds a list of selectors to the existing list of selectors. 93 |
94 |
95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 116 | 119 | 120 | 121 | 122 | 125 | 141 | 142 |
117 | 118 |
143 | 144 | 145 | 146 | A C E G H I P R S T V
147 | 148 | 149 | 150 | -------------------------------------------------------------------------------- /doc/javadoc/com/osbcp/cssparser/package-tree.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.osbcp.cssparser Class Hierarchy 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 |
81 |
82 |

83 | Hierarchy For Package com.osbcp.cssparser 84 |

85 |
86 |

87 | Class Hierarchy 88 |

89 |
    90 |
  • java.lang.Object 97 |
98 |

99 | Enum Hierarchy 100 |

101 |
    102 |
  • java.lang.Object 107 |
108 |
109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 130 | 133 | 134 | 135 | 136 | 139 | 155 | 156 |
131 | 132 |
157 | 158 | 159 | 160 |
161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-7.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | P-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | P

83 |
84 |
parse(String) - 85 | Static method in class com.osbcp.cssparser.CSSParser 86 |
Reads CSS as a String and returns back a list of Rules. 87 |
PropertyValue - Class in com.osbcp.cssparser
Represents a property and its value of a CSS rule.
PropertyValue(String, String) - 88 | Constructor for class com.osbcp.cssparser.PropertyValue 89 |
Creates a new PropertyValue based on a property and its value. 90 |
91 |
92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 113 | 116 | 117 | 118 | 119 | 122 | 138 | 139 |
114 | 115 |
140 | 141 | 142 | 143 | A C E G H I P R S T V
144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /doc/javadoc/com/osbcp/cssparser/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Package com.osbcp.cssparser 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 |
81 |
82 |

83 | Uses of Package
com.osbcp.cssparser

84 |
85 | 86 | 87 | 88 | 90 | 91 | 92 | 96 | 97 | 98 | 102 | 103 | 104 | 108 | 109 | 110 | 114 | 115 |
89 | Classes in com.osbcp.cssparser used by com.osbcp.cssparser
IncorrectFormatException.ErrorCode 93 | 94 |
95 |           List of unique error codes.
PropertyValue 99 | 100 |
101 |           Represents a property and its value of a CSS rule.
Rule 105 | 106 |
107 |           Represents a CSS rule.
Selector 111 | 112 |
113 |           Represents a CSS selector.
116 |   117 |

118 |


119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 140 | 143 | 144 | 145 | 146 | 149 | 165 | 166 |
141 | 142 |
167 | 168 | 169 | 170 |
171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /doc/javadoc/com/osbcp/cssparser/class-use/Rule.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class com.osbcp.cssparser.Rule 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 |
81 |
82 |

83 | Uses of Class
com.osbcp.cssparser.Rule

84 |
85 | 86 | 87 | 88 | 90 | 91 |
89 | Uses of Rule in com.osbcp.cssparser
92 |   93 |

94 | 95 | 96 | 97 | 98 | 99 | 100 | 102 | 106 | 107 |
Methods in com.osbcp.cssparser that return types with arguments of type Rule
101 | static java.util.List<Rule>CSSParser.parse(java.lang.String css) 103 | 104 |
105 |           Reads CSS as a String and returns back a list of Rules.
108 |   109 |

110 |


111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 132 | 135 | 136 | 137 | 138 | 141 | 157 | 158 |
133 | 134 |
159 | 160 | 161 | 162 |
163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /doc/javadoc/src-html/com/osbcp/cssparser/IncorrectFormatException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
  4 | 001    /*
  5 | 002     * Licensed under the Apache License, Version 2.0 (the "License");
  6 | 003     * you may not use this file except in compliance with the License.
  7 | 004     * You may obtain a copy of the License at
  8 | 005     *
  9 | 006     * http://www.apache.org/licenses/LICENSE-2.0
 10 | 007     *
 11 | 008     * Unless required by applicable law or agreed to in writing, software
 12 | 009     * distributed under the License is distributed on an "AS IS" BASIS,
 13 | 010     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14 | 011     * See the License for the specific language governing permissions and
 15 | 012     * limitations under the License.
 16 | 013     * 
 17 | 014     * See the NOTICE file distributed with this work for additional
 18 | 015     * information regarding copyright ownership.
 19 | 016     */
 20 | 017    
 21 | 018    package com.osbcp.cssparser;
 22 | 019    
 23 | 020    /**
 24 | 021     * An exception that is thrown when the CSS parser finds a character it shouldn't have.
 25 | 022     * 
 26 | 023     * @author <a href="mailto:christoffer@christoffer.me">Christoffer Pettersson</a>
 27 | 024     */
 28 | 025    
 29 | 026    public class IncorrectFormatException extends Exception {
 30 | 027    
 31 | 028            private static final long serialVersionUID = 1L;
 32 | 029    
 33 | 030            private ErrorCode errorCode;
 34 | 031    
 35 | 032            /**
 36 | 033             * Creates a new IncorrectFormatExeption with an error message;
 37 | 034             * 
 38 | 035             * @param errorCode S unique error code associated with the error.
 39 | 036             * @param message Error message describing the problem.
 40 | 037             */
 41 | 038    
 42 | 039            IncorrectFormatException(final ErrorCode errorCode, final String message) {
 43 | 040                    super(message);
 44 | 041                    this.errorCode = errorCode;
 45 | 042            }
 46 | 043    
 47 | 044            /**
 48 | 045             * Returns a unique error code associated with the error.
 49 | 046             * 
 50 | 047             * @return A unique error code associated with the error.
 51 | 048             */
 52 | 049    
 53 | 050            public ErrorCode getErrorCode() {
 54 | 051                    return errorCode;
 55 | 052            }
 56 | 053    
 57 | 054            /**
 58 | 055             * List of unique error codes.
 59 | 056             * 
 60 | 057             * @author <a href="mailto:christoffer@christoffer.me">Christoffer Pettersson</a>
 61 | 058             */
 62 | 059    
 63 | 060            public enum ErrorCode {
 64 | 061    
 65 | 062                    /**
 66 | 063                     * When the parse founds a semicolon ; when reading the property name.
 67 | 064                     */
 68 | 065                    FOUND_SEMICOLON_WHEN_READING_PROPERTY_NAME,
 69 | 066    
 70 | 067                    /**
 71 | 068                     * When the parse founds an end bracket } before the value's semicolon ; ending.
 72 | 069                     */
 73 | 070                    FOUND_END_BRACKET_BEFORE_SEMICOLON,
 74 | 071    
 75 | 072                    /**
 76 | 073                     * When the parse founds a colon , before reading a real selector name.
 77 | 074                     */
 78 | 075                    FOUND_COLON_WHEN_READING_SELECTOR_NAME;
 79 | 076    
 80 | 077            }
 81 | 078    
 82 | 079    }
 83 | 
 84 | 
 85 | 
 86 | 
 87 | 
 88 | 
 89 | 
 90 | 
 91 | 
 92 | 
 93 | 
 94 | 
 95 | 
 96 | 
 97 | 
 98 | 
 99 | 
100 | 
101 | 
102 | 
103 | 
104 | 
105 | 
106 | 
107 | 
108 | 
109 | 
110 | 
111 | 
112 | 
113 | 
114 | 
115 | 
116 | 
117 | 
118 | 
119 | 
120 | 
121 | 
122 | 
123 | 
124 | 
125 | 
126 | 
127 | 
128 | 
129 | 
130 | 
131 | 
132 | 
133 | 
134 | 
135 | 
136 | 
137 | 
138 | 
139 | 
140 | 
141 | 
142 | 
143 | 
144 | 145 | 146 | -------------------------------------------------------------------------------- /doc/javadoc/src-html/com/osbcp/cssparser/IncorrectFormatException.ErrorCode.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
  4 | 001    /*
  5 | 002     * Licensed under the Apache License, Version 2.0 (the "License");
  6 | 003     * you may not use this file except in compliance with the License.
  7 | 004     * You may obtain a copy of the License at
  8 | 005     *
  9 | 006     * http://www.apache.org/licenses/LICENSE-2.0
 10 | 007     *
 11 | 008     * Unless required by applicable law or agreed to in writing, software
 12 | 009     * distributed under the License is distributed on an "AS IS" BASIS,
 13 | 010     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14 | 011     * See the License for the specific language governing permissions and
 15 | 012     * limitations under the License.
 16 | 013     * 
 17 | 014     * See the NOTICE file distributed with this work for additional
 18 | 015     * information regarding copyright ownership.
 19 | 016     */
 20 | 017    
 21 | 018    package com.osbcp.cssparser;
 22 | 019    
 23 | 020    /**
 24 | 021     * An exception that is thrown when the CSS parser finds a character it shouldn't have.
 25 | 022     * 
 26 | 023     * @author <a href="mailto:christoffer@christoffer.me">Christoffer Pettersson</a>
 27 | 024     */
 28 | 025    
 29 | 026    public class IncorrectFormatException extends Exception {
 30 | 027    
 31 | 028            private static final long serialVersionUID = 1L;
 32 | 029    
 33 | 030            private ErrorCode errorCode;
 34 | 031    
 35 | 032            /**
 36 | 033             * Creates a new IncorrectFormatExeption with an error message;
 37 | 034             * 
 38 | 035             * @param errorCode S unique error code associated with the error.
 39 | 036             * @param message Error message describing the problem.
 40 | 037             */
 41 | 038    
 42 | 039            IncorrectFormatException(final ErrorCode errorCode, final String message) {
 43 | 040                    super(message);
 44 | 041                    this.errorCode = errorCode;
 45 | 042            }
 46 | 043    
 47 | 044            /**
 48 | 045             * Returns a unique error code associated with the error.
 49 | 046             * 
 50 | 047             * @return A unique error code associated with the error.
 51 | 048             */
 52 | 049    
 53 | 050            public ErrorCode getErrorCode() {
 54 | 051                    return errorCode;
 55 | 052            }
 56 | 053    
 57 | 054            /**
 58 | 055             * List of unique error codes.
 59 | 056             * 
 60 | 057             * @author <a href="mailto:christoffer@christoffer.me">Christoffer Pettersson</a>
 61 | 058             */
 62 | 059    
 63 | 060            public enum ErrorCode {
 64 | 061    
 65 | 062                    /**
 66 | 063                     * When the parse founds a semicolon ; when reading the property name.
 67 | 064                     */
 68 | 065                    FOUND_SEMICOLON_WHEN_READING_PROPERTY_NAME,
 69 | 066    
 70 | 067                    /**
 71 | 068                     * When the parse founds an end bracket } before the value's semicolon ; ending.
 72 | 069                     */
 73 | 070                    FOUND_END_BRACKET_BEFORE_SEMICOLON,
 74 | 071    
 75 | 072                    /**
 76 | 073                     * When the parse founds a colon , before reading a real selector name.
 77 | 074                     */
 78 | 075                    FOUND_COLON_WHEN_READING_SELECTOR_NAME;
 79 | 076    
 80 | 077            }
 81 | 078    
 82 | 079    }
 83 | 
 84 | 
 85 | 
 86 | 
 87 | 
 88 | 
 89 | 
 90 | 
 91 | 
 92 | 
 93 | 
 94 | 
 95 | 
 96 | 
 97 | 
 98 | 
 99 | 
100 | 
101 | 
102 | 
103 | 
104 | 
105 | 
106 | 
107 | 
108 | 
109 | 
110 | 
111 | 
112 | 
113 | 
114 | 
115 | 
116 | 
117 | 
118 | 
119 | 
120 | 
121 | 
122 | 
123 | 
124 | 
125 | 
126 | 
127 | 
128 | 
129 | 
130 | 
131 | 
132 | 
133 | 
134 | 
135 | 
136 | 
137 | 
138 | 
139 | 
140 | 
141 | 
142 | 
143 | 
144 | 145 | 146 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | G-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | G

83 |
84 |
getErrorCode() - 85 | Method in exception com.osbcp.cssparser.IncorrectFormatException 86 |
Returns a unique error code associated with the error. 87 |
getProperty() - 88 | Method in class com.osbcp.cssparser.PropertyValue 89 |
Returns the property. 90 |
getPropertyValues() - 91 | Method in class com.osbcp.cssparser.Rule 92 |
Returns a list of all property values attached to the rule. 93 |
getSelectors() - 94 | Method in class com.osbcp.cssparser.Rule 95 |
Returns a list of all selectors attached to the rule. 96 |
getValue() - 97 | Method in class com.osbcp.cssparser.PropertyValue 98 |
Returns the value. 99 |
100 |
101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 122 | 125 | 126 | 127 | 128 | 131 | 147 | 148 |
123 | 124 |
149 | 150 | 151 | 152 | A C E G H I P R S T V
153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /doc/javadoc/index-files/index-8.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | R-Index 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 50 | 53 | 54 | 55 | 56 | 59 | 75 | 76 |
51 | 52 |
77 | 78 | 79 | 80 | A C E G H I P R S T V
81 |

82 | R

83 |
84 |
removePropertyValue(PropertyValue) - 85 | Method in class com.osbcp.cssparser.Rule 86 |
Removes a property value from the rule. 87 |
removeSelector(Selector) - 88 | Method in class com.osbcp.cssparser.Rule 89 |
Removes a selector from the rule. 90 |
Rule - Class in com.osbcp.cssparser
Represents a CSS rule.
Rule(Selector) - 91 | Constructor for class com.osbcp.cssparser.Rule 92 |
Creates a rule with a single selector. 93 |
Rule() - 94 | Constructor for class com.osbcp.cssparser.Rule 95 |
Creates an empty rule. 96 |
Rule(List<Selector>) - 97 | Constructor for class com.osbcp.cssparser.Rule 98 |
Creates a new rule based on a list of selectors. 99 |
100 |
101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 122 | 125 | 126 | 127 | 128 | 131 | 147 | 148 |
123 | 124 |
149 | 150 | 151 | 152 | A C E G H I P R S T V
153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /doc/javadoc/src-html/com/osbcp/cssparser/PropertyValue.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
  4 | 001    /*
  5 | 002     * Licensed under the Apache License, Version 2.0 (the "License");
  6 | 003     * you may not use this file except in compliance with the License.
  7 | 004     * You may obtain a copy of the License at
  8 | 005     *
  9 | 006     * http://www.apache.org/licenses/LICENSE-2.0
 10 | 007     *
 11 | 008     * Unless required by applicable law or agreed to in writing, software
 12 | 009     * distributed under the License is distributed on an "AS IS" BASIS,
 13 | 010     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14 | 011     * See the License for the specific language governing permissions and
 15 | 012     * limitations under the License.
 16 | 013     * 
 17 | 014     * See the NOTICE file distributed with this work for additional
 18 | 015     * information regarding copyright ownership.
 19 | 016     */
 20 | 017    
 21 | 018    package com.osbcp.cssparser;
 22 | 019    
 23 | 020    /**
 24 | 021     * Represents a property and its value of a CSS rule.
 25 | 022     * 
 26 | 023     * @author <a href="mailto:christoffer@christoffer.me">Christoffer Pettersson</a>
 27 | 024     */
 28 | 025    
 29 | 026    public final class PropertyValue {
 30 | 027    
 31 | 028            private String property;
 32 | 029            private String value;
 33 | 030    
 34 | 031            /**
 35 | 032             * Creates a new PropertyValue based on a property and its value.
 36 | 033             * 
 37 | 034             * @param property The CSS property (such as 'width' or 'color').
 38 | 035             * @param value The value of the property (such as '100px' or 'red').
 39 | 036             */
 40 | 037    
 41 | 038            public PropertyValue(final String property, final String value) {
 42 | 039                    this.property = property;
 43 | 040                    this.value = value;
 44 | 041            }
 45 | 042    
 46 | 043            @Override
 47 | 044            public String toString() {
 48 | 045                    return property + ": " + value;
 49 | 046            }
 50 | 047    
 51 | 048            @Override
 52 | 049            public boolean equals(final Object object) {
 53 | 050    
 54 | 051                    if (object instanceof PropertyValue) {
 55 | 052    
 56 | 053                            PropertyValue target = (PropertyValue) object;
 57 | 054    
 58 | 055                            return target.property.equalsIgnoreCase(property) && target.value.equalsIgnoreCase(value);
 59 | 056    
 60 | 057                    }
 61 | 058    
 62 | 059                    return false;
 63 | 060    
 64 | 061            }
 65 | 062    
 66 | 063            @Override
 67 | 064            public int hashCode() {
 68 | 065                    return toString().hashCode();
 69 | 066            }
 70 | 067    
 71 | 068            /**
 72 | 069             * Returns the property.
 73 | 070             * 
 74 | 071             * @return The property.
 75 | 072             */
 76 | 073    
 77 | 074            public String getProperty() {
 78 | 075                    return property;
 79 | 076            }
 80 | 077    
 81 | 078            /**
 82 | 079             * Returns the value.
 83 | 080             * 
 84 | 081             * @return The value.
 85 | 082             */
 86 | 083    
 87 | 084            public String getValue() {
 88 | 085                    return value;
 89 | 086            }
 90 | 087    
 91 | 088    }
 92 | 
 93 | 
 94 | 
 95 | 
 96 | 
 97 | 
 98 | 
 99 | 
100 | 
101 | 
102 | 
103 | 
104 | 
105 | 
106 | 
107 | 
108 | 
109 | 
110 | 
111 | 
112 | 
113 | 
114 | 
115 | 
116 | 
117 | 
118 | 
119 | 
120 | 
121 | 
122 | 
123 | 
124 | 
125 | 
126 | 
127 | 
128 | 
129 | 
130 | 
131 | 
132 | 
133 | 
134 | 
135 | 
136 | 
137 | 
138 | 
139 | 
140 | 
141 | 
142 | 
143 | 
144 | 
145 | 
146 | 
147 | 
148 | 
149 | 
150 | 
151 | 
152 | 
153 | 154 | 155 | -------------------------------------------------------------------------------- /test/com/osbcp/cssparser/CSSParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | * 14 | * See the NOTICE file distributed with this work for additional 15 | * information regarding copyright ownership. 16 | */ 17 | 18 | package com.osbcp.cssparser; 19 | 20 | import java.util.List; 21 | 22 | import junit.framework.Assert; 23 | 24 | import org.apache.commons.io.IOUtils; 25 | import org.junit.Test; 26 | 27 | public final class CSSParserTest { 28 | 29 | @Test 30 | public void testNull() throws Exception { 31 | CSSParser.parse(null); 32 | } 33 | 34 | @Test 35 | public void testEmpty() throws Exception { 36 | CSSParser.parse(" "); 37 | CSSParser.parse(" \n "); 38 | CSSParser.parse(" \n \t "); 39 | CSSParser.parse(" \n \t \r "); 40 | } 41 | 42 | @Test 43 | public void testComments() throws Exception { 44 | CSSParser.parse(" /* this should be ok */ "); 45 | CSSParser.parse(" /** JavaDoc comment **/ "); 46 | CSSParser.parse(" /** comment with \n new line **/ "); 47 | CSSParser.parse(" /* double **/ /** comment */ "); 48 | } 49 | 50 | @Test 51 | public void testBasicSingle() throws Exception { 52 | 53 | List rules = CSSParser.parse("div { width: 100px; }"); 54 | 55 | Assert.assertEquals(1, rules.size()); 56 | 57 | Rule rule = rules.get(0); 58 | 59 | Assert.assertEquals("div", rule.getSelectors().get(0).toString()); 60 | Assert.assertEquals("width", rule.getPropertyValues().get(0).getProperty()); 61 | Assert.assertEquals("100px", rule.getPropertyValues().get(0).getValue()); 62 | 63 | } 64 | 65 | @Test 66 | public void testCommentInsideRule() throws Exception { 67 | 68 | List rules = CSSParser.parse("table /* and a comment here */ td { width: 100px; /* should be ignored */ text-decoration: underlined; }"); 69 | 70 | Assert.assertEquals(1, rules.size()); 71 | 72 | Rule rule = rules.get(0); 73 | Assert.assertEquals("table td", rule.getSelectors().get(0).toString()); 74 | Assert.assertEquals("width", rule.getPropertyValues().get(0).getProperty()); 75 | Assert.assertEquals("100px", rule.getPropertyValues().get(0).getValue()); 76 | Assert.assertEquals("text-decoration", rule.getPropertyValues().get(1).getProperty()); 77 | Assert.assertEquals("underlined", rule.getPropertyValues().get(1).getValue()); 78 | 79 | } 80 | 81 | @Test 82 | public void testBase64() throws Exception { 83 | 84 | List rules = CSSParser.parse("image { background-image:url(data:image/gif;base64,ABC123/ABC123=ABC123);}"); 85 | 86 | Assert.assertEquals(1, rules.size()); 87 | 88 | Rule rule = rules.get(0); 89 | Assert.assertEquals("image", rule.getSelectors().get(0).toString()); 90 | 91 | Assert.assertEquals("background-image", rule.getPropertyValues().get(0).getProperty()); 92 | Assert.assertEquals("url(data:image/gif;base64,ABC123/ABC123=ABC123)", rule.getPropertyValues().get(0).getValue()); 93 | 94 | } 95 | 96 | @Test 97 | public void testEmptPropertyValues() throws Exception { 98 | 99 | List rules = CSSParser.parse("its-all-empty { /*empty*/ } empty { }"); 100 | 101 | Assert.assertEquals(0, rules.size()); 102 | 103 | } 104 | 105 | @Test 106 | public void testDoubleComments() throws Exception { 107 | 108 | List rules = CSSParser.parse("its-all-empty { /* /* double comment */ } empty { height: 200px; /* /* double comment */width: 100px; }"); 109 | 110 | System.out.println(rules); 111 | 112 | Assert.assertEquals(1, rules.size()); 113 | 114 | Rule rule = rules.get(0); 115 | 116 | Assert.assertEquals("height", rule.getPropertyValues().get(0).getProperty()); 117 | Assert.assertEquals("200px", rule.getPropertyValues().get(0).getValue()); 118 | 119 | Assert.assertEquals("width", rule.getPropertyValues().get(1).getProperty()); 120 | Assert.assertEquals("100px", rule.getPropertyValues().get(1).getValue()); 121 | 122 | } 123 | 124 | @Test 125 | public void testBasicMultipleValues() throws Exception { 126 | 127 | List rules = CSSParser.parse("div { width: 100px; -mozilla-opacity: 345; } /* a comment */ beta{height:200px;display:blocked;}table td{}"); 128 | 129 | Assert.assertEquals(2, rules.size()); 130 | 131 | Rule rule = rules.get(0); 132 | Assert.assertEquals("div", rule.getSelectors().get(0).toString()); 133 | Assert.assertEquals("width", rule.getPropertyValues().get(0).getProperty()); 134 | Assert.assertEquals("100px", rule.getPropertyValues().get(0).getValue()); 135 | Assert.assertEquals("-mozilla-opacity", rule.getPropertyValues().get(1).getProperty()); 136 | Assert.assertEquals("345", rule.getPropertyValues().get(1).getValue()); 137 | 138 | rule = rules.get(1); 139 | Assert.assertEquals("beta", rule.getSelectors().get(0).toString()); 140 | Assert.assertEquals("height", rule.getPropertyValues().get(0).getProperty()); 141 | Assert.assertEquals("200px", rule.getPropertyValues().get(0).getValue()); 142 | Assert.assertEquals("display", rule.getPropertyValues().get(1).getProperty()); 143 | Assert.assertEquals("blocked", rule.getPropertyValues().get(1).getValue()); 144 | 145 | } 146 | 147 | @Test 148 | public void testDuplicatePropertiesSameOrder() throws Exception { 149 | 150 | List rules = CSSParser.parse("product-row { background: #ABC123; border: 1px black solid; border: none;background: url(http://www.domain.com/image.jpg);}"); 151 | 152 | Rule rule = rules.get(0); 153 | Assert.assertEquals("product-row", rule.getSelectors().get(0).toString()); 154 | 155 | Assert.assertEquals("background", rule.getPropertyValues().get(0).getProperty()); 156 | Assert.assertEquals("#ABC123", rule.getPropertyValues().get(0).getValue()); 157 | 158 | Assert.assertEquals("border", rule.getPropertyValues().get(1).getProperty()); 159 | Assert.assertEquals("1px black solid", rule.getPropertyValues().get(1).getValue()); 160 | 161 | Assert.assertEquals("border", rule.getPropertyValues().get(2).getProperty()); 162 | Assert.assertEquals("none", rule.getPropertyValues().get(2).getValue()); 163 | 164 | Assert.assertEquals("background", rule.getPropertyValues().get(3).getProperty()); 165 | Assert.assertEquals("url(http://www.domain.com/image.jpg)", rule.getPropertyValues().get(3).getValue()); 166 | 167 | } 168 | 169 | @Test 170 | public void testMultipleSelectors() throws Exception { 171 | 172 | List rules = CSSParser.parse("alpha, beta { width: 100px; text-decoration: underlined; } gamma delta { } epsilon, /* some comment */ zeta { height: 34px; } "); 173 | 174 | Assert.assertEquals(2, rules.size()); 175 | 176 | /* 177 | * Rule 1 178 | */ 179 | 180 | Rule rule = rules.get(0); 181 | Assert.assertEquals("alpha", rule.getSelectors().get(0).toString()); 182 | Assert.assertEquals("beta", rule.getSelectors().get(1).toString()); 183 | 184 | Assert.assertEquals("width", rule.getPropertyValues().get(0).getProperty()); 185 | Assert.assertEquals("100px", rule.getPropertyValues().get(0).getValue()); 186 | Assert.assertEquals("text-decoration", rule.getPropertyValues().get(1).getProperty()); 187 | Assert.assertEquals("underlined", rule.getPropertyValues().get(1).getValue()); 188 | 189 | /* 190 | * Rule 2 191 | */ 192 | 193 | rule = rules.get(1); 194 | Assert.assertEquals("epsilon", rule.getSelectors().get(0).toString()); 195 | Assert.assertEquals("zeta", rule.getSelectors().get(1).toString()); 196 | 197 | Assert.assertEquals("height", rule.getPropertyValues().get(0).getProperty()); 198 | Assert.assertEquals("34px", rule.getPropertyValues().get(0).getValue()); 199 | 200 | } 201 | 202 | @Test 203 | public void testFileBasic() throws Exception { 204 | 205 | String contents = IOUtils.toString(this.getClass().getResourceAsStream("css.css"), "UTF-8"); 206 | 207 | List rules = CSSParser.parse(contents); 208 | 209 | for (Rule rule : rules) { 210 | System.out.println(rule); 211 | } 212 | 213 | } 214 | } 215 | --------------------------------------------------------------------------------