Implemented some more parts of the CSS parser. I added some more comments in to help with implementation later. I have reached a point where I can no longer properly implement the functions since I am currently unable to throughly test. I will come back to this and finish the implementation soon.
2005-12-19 Lillian Angel <[EMAIL PROTECTED]> * javax/swing/text/html/CSSParser.java (CSSParser): Initialized tokenBuffer with some arbitrary size. This makes append much more efficent since a new array will not been created with each append. (append): Fixed append to create a new larger array if needed. (nextToken): Finished implemented. Should decrease the tokenBufferLength if an identifier was read. This way " and ' are not added to the buffer. (parse): Implemented to call the appropriate parsing function based on parameter. (getNextStatement): Implemented. (parseAtRule): Added some helpful comments for implementing. (parseRuleSet): Likewise. (parseIdentifiers): Likewise. (readComment): Likewise. * javax/swing/text/html/StyleSheet.java (addRule): Implemented. (loadRules): Implemented. (importStyleSheet): Removed implementation for now. It causes a loop. Added FIXME (startRule): Implemented. (handleProperty): Implemented. (addSelector): Implemented.
Index: ChangeLog =================================================================== RCS file: /cvsroot/classpath/classpath/ChangeLog,v retrieving revision 1.5866 diff -u -r1.5866 ChangeLog --- ChangeLog 20 Dec 2005 15:59:45 -0000 1.5866 +++ ChangeLog 20 Dec 2005 18:54:07 -0000 @@ -1,5 +1,32 @@ 2005-12-19 Lillian Angel <[EMAIL PROTECTED]> + * javax/swing/text/html/CSSParser.java + (CSSParser): Initialized tokenBuffer with some + arbitrary size. This makes append much more efficent since + a new array will not been created with each append. + (append): Fixed append to create a new larger array if + needed. + (nextToken): Finished implemented. Should decrease the + tokenBufferLength if an identifier was read. This way " and ' + are not added to the buffer. + (parse): Implemented to call the appropriate parsing function + based on parameter. + (getNextStatement): Implemented. + (parseAtRule): Added some helpful comments for implementing. + (parseRuleSet): Likewise. + (parseIdentifiers): Likewise. + (readComment): Likewise. + * javax/swing/text/html/StyleSheet.java + (addRule): Implemented. + (loadRules): Implemented. + (importStyleSheet): Removed implementation for now. It causes + a loop. Added FIXME + (startRule): Implemented. + (handleProperty): Implemented. + (addSelector): Implemented. + +2005-12-19 Lillian Angel <[EMAIL PROTECTED]> + * javax/swing/text/html/BlockView.java (getStyleSheet): Implemented. * javax/swing/text/html/CSSParser.java: New private class, Index: javax/swing/text/html/CSSParser.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/CSSParser.java,v retrieving revision 1.1 diff -u -r1.1 CSSParser.java --- javax/swing/text/html/CSSParser.java 20 Dec 2005 15:59:45 -0000 1.1 +++ javax/swing/text/html/CSSParser.java 20 Dec 2005 18:54:09 -0000 @@ -149,7 +149,8 @@ /** * The character mapping in the document. */ - private static final char[] charMapping = null; // FIXME + // FIXME: What is this used for? + private static final char[] charMapping = null; /** * Set to true if one character has been read ahead. @@ -162,7 +163,7 @@ private int pushedChar; /** - * Temporary place to hold identifiers. + * Temporary place to hold identifiers. */ private StringBuffer unitBuffer; @@ -212,6 +213,7 @@ CSSParser() { unitBuffer = new StringBuffer(); + tokenBuffer = new char[10]; } /** @@ -221,12 +223,18 @@ */ private void append(char c) { - char[] temp = new char[tokenBufferLength + 1]; - if (tokenBuffer != null) - System.arraycopy(tokenBuffer, 0, temp, 0, tokenBufferLength); - temp[tokenBufferLength] = c; + if (tokenBuffer.length >= tokenBufferLength) + { + char[] temp = new char[tokenBufferLength * 2]; + if (tokenBuffer != null) + System.arraycopy(tokenBuffer, 0, temp, 0, tokenBufferLength); + + temp[tokenBufferLength] = c; + tokenBuffer = temp; + } + else + tokenBuffer[tokenBufferLength] = c; tokenBufferLength++; - tokenBuffer = temp; } /** @@ -244,10 +252,12 @@ switch (next) { case '\"': - // FIXME: Not Implemented + if (tokenBufferLength > 0) + tokenBufferLength--; return IDENTIFIER; case '\'': - // FIXME: Not Implemented + if (tokenBufferLength > 0) + tokenBufferLength--; return IDENTIFIER; case '(': return PAREN_OPEN; @@ -301,8 +311,18 @@ { this.reader = reader; this.callback = callback; - // call getNextStatement - // FIXME: Not fully implemented + + try + { + if (!parsingDeclaration) + while(getNextStatement()); + else + parseDeclarationBlock(); + } + catch (IOException ioe) + { + // Nothing to do here. + } } /** @@ -329,16 +349,35 @@ /** * Gets the next statement, returning false if the end is reached. - * A statement is either an @ rule, or a ruleset. + * A statement is either an At-rule, or a ruleset. * - * @return the next statement + * @return false if the end is reached * @throws IOException - any i/o error from the reader */ private boolean getNextStatement() throws IOException { - // get next set and parseRuleSet - // FIXME: Not implemented - return false; + int c = nextToken((char) 0); + switch (c) + { + case PAREN_OPEN: + case BRACE_OPEN: + case BRACKET_OPEN: + parseTillClosed(c); + break; + case BRACKET_CLOSE: + case BRACE_CLOSE: + case PAREN_CLOSE: + throw new IOException("Not a proper statement."); + case IDENTIFIER: + if (tokenBuffer[0] == ('@')) + parseAtRule(); + else + parseRuleSet(); + break; + case END: + return false; + } + return true; } /** @@ -347,8 +386,18 @@ * @throws IOException - any i/o error from the reader */ private void parseAtRule() throws IOException - { + { + // An At-Rule begins with the "@" character followed immediately by a keyword. + // Following the keyword separated by a space is an At-rule statement appropriate + // to the At-keyword used. If the At-Rule is a simple declarative statement + // (charset, import, fontdef), it is terminated by a semi-colon (";".) + // If the At-Rule is a conditional or informative statement (media, page, font-face), + // it is followed by optional arguments and then a style declaration block inside matching + // curly braces ("{", "}".) At-Rules are sometimes nestable, depending on the context. + // If any part of an At-Rule is not understood, it should be ignored. + // FIXME: Not Implemented + // call handleimport } /** @@ -360,6 +409,9 @@ private void parseRuleSet() throws IOException { // call parseDeclarationBlock + // call parse selectors + // call parse identifiers + // call startrule/endrule // FIXME: Not Implemented } @@ -373,6 +425,7 @@ private boolean parseSelectors() throws IOException { // FIXME: Not Implemented + // call handleselector return false; } @@ -414,6 +467,7 @@ private int parseIdentifiers(char c, boolean wantsBlocks) throws IOException { // FIXME: Not implemented + // call handleproperty? return 0; } @@ -461,7 +515,8 @@ */ private void readComment() throws IOException { - // FIXME: Not Implemented + // Should ignore comments. Read until end of comment. + // FIXME: Not implemented } /** Index: javax/swing/text/html/StyleSheet.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/StyleSheet.java,v retrieving revision 1.4 diff -u -r1.4 StyleSheet.java --- javax/swing/text/html/StyleSheet.java 20 Dec 2005 15:59:45 -0000 1.4 +++ javax/swing/text/html/StyleSheet.java 20 Dec 2005 18:54:09 -0000 @@ -42,9 +42,7 @@ import java.awt.Font; import java.awt.Graphics; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.io.Reader; import java.io.Serializable; import java.io.StringReader; @@ -140,8 +138,15 @@ */ public void addRule(String rule) { - // call cssparser.parse - // FIXME: Not implemented. + CssParser cp = new CssParser(); + try + { + cp.parse(base, new StringReader(rule), false, false); + } + catch (IOException io) + { + // Do nothing here. + } } /** @@ -171,8 +176,8 @@ */ public void loadRules(Reader in, URL ref) throws IOException { - // FIXME: Not implemented. - // call parse + CssParser cp = new CssParser(); + cp.parse(ref, in, false, false); } /** @@ -268,16 +273,7 @@ */ public void importStyleSheet(URL url) { - try - { - // FIXME: Need to make sure url points to a valid CSS document. - loadRules(new BufferedReader(new InputStreamReader(url.openStream())), - url); - } - catch (IOException ioe) - { - // Do nothing here. - } + // FIXME: Not implemented } /** @@ -889,7 +885,7 @@ */ public void startRule() { - // FIXME: Not implemented + addSelector(); } /** @@ -920,6 +916,7 @@ { // FIXME: Not implemented // add rules + propertyName = null; } /** @@ -927,12 +924,14 @@ */ private void addSelector() { - Object[] selTokens = selectorTokens.toArray(); - int length = selTokens.length; - Object[] sel = new Object[length]; - System.arraycopy(selTokens, 0, sel, 0, length); - selectors.add(sel); - selectorTokens.clear(); + int length = selectorTokens.size(); + if (length > 0) + { + Object[] sel = new Object[length]; + System.arraycopy(selectorTokens.toArray(), 0, sel, 0, length); + selectors.add(sel); + selectorTokens.clear(); + } } } }
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches