|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.text.html.CSSParser
A CSS parser. This works by way of a delegate that implements the CSSParserCallback interface. The delegate is notified of the following events:
handleImport
handleSelector
. This is invoked for each
string. For example if the Reader contained p, bar , a {}, the delegate
would be notified 4 times, for 'p,' 'bar' ',' and 'a'.
startRule
handleProperty
. This
is invoked one per property/value key, eg font size: foo;, would
cause the delegate to be notified once with a value of 'font size'.
handleValue
, this is notified
for the total value.
endRule
This will preserve case. If the callback wishes to treat certain poritions case insensitively (such as selectors), it should use toLowerCase, or something similar.
Nested Class Summary | |
(package private) static interface |
CSSParser.CSSParserCallback
|
Field Summary | |
private static int |
BRACE_CLOSE
|
private static int |
BRACE_OPEN
|
private static int |
BRACKET_CLOSE
|
private static int |
BRACKET_OPEN
|
private CSSParser.CSSParserCallback |
callback
Notified of state. |
private static char[] |
charMapping
|
private boolean |
didPushChar
Set to true if one character has been read ahead. |
private boolean |
encounteredRuleSet
Set to true when the first non @ rule is encountered. |
private static int |
END
|
private static int |
IDENTIFIER
|
private static int |
PAREN_CLOSE
|
private static int |
PAREN_OPEN
|
private int |
pushedChar
The read ahead character. |
private Reader |
reader
Holds the incoming CSS rules. |
private boolean |
readWS
Set to true if any whitespace is read. |
private int |
stackCount
Number of valid blocks. |
private char[] |
tokenBuffer
nextToken() inserts the string here. |
private int |
tokenBufferLength
Current number of chars in tokenBufferLength. |
private StringBuffer |
unitBuffer
Temporary place to hold identifiers. |
private int[] |
unitStack
Used to indicate blocks. |
Constructor Summary | |
(package private) |
CSSParser()
|
Method Summary | |
private void |
append(char character)
|
private void |
endBlock(int endToken)
Called when an end block is encountered )]} |
private boolean |
getIdentifier(char stopChar)
Gets an identifier, returning true if the length of the string is greater than 0, stopping when stopChar , whitespace, or one of {}()[] is
hit. |
private boolean |
getNextStatement()
Gets the next statement, returning false if the end is reached. |
private boolean |
inBlock()
|
private int |
nextToken(char idChar)
Fetches the next token. |
(package private) void |
parse(Reader reader,
CSSParser.CSSParserCallback callback,
boolean inRule)
|
private void |
parseAtRule()
Parses an @ rule, stopping at a matching brace pair, or ;. |
private int |
parseDeclaration()
Parses a single declaration, which is an identifier a : and another identifier. |
private void |
parseDeclarationBlock()
Parses a declaration block. |
private int |
parseIdentifiers(char extraChar,
boolean wantsBlocks)
Parses identifiers until extraChar is encountered,
returning the ending token, which will be IDENTIFIER if extraChar
is found. |
private void |
parseRuleSet()
Parses the next rule set, which is a selector followed by a declaration block. |
private boolean |
parseSelectors()
Parses a set of selectors, returning false if the end of the stream is reached. |
private void |
parseTillClosed(int openToken)
Parses till a matching block close is encountered. |
private void |
pushChar(int tempChar)
Supports one character look ahead, this will throw if called twice in a row. |
private int |
readChar()
Reads a character from the stream. |
private void |
readComment()
Parses a comment block. |
private void |
readTill(char stopChar)
Reads till a stopChar is encountered, escaping characters
as necessary. |
private int |
readWS()
Skips any white space, returning the character after the white space. |
private void |
startBlock(int startToken)
Called when a block start is encountered ({[. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final int IDENTIFIER
private static final int BRACKET_OPEN
private static final int BRACKET_CLOSE
private static final int BRACE_OPEN
private static final int BRACE_CLOSE
private static final int PAREN_OPEN
private static final int PAREN_CLOSE
private static final int END
private static final char[] charMapping
private boolean didPushChar
private int pushedChar
private StringBuffer unitBuffer
private int[] unitStack
private int stackCount
private Reader reader
private boolean encounteredRuleSet
private CSSParser.CSSParserCallback callback
private char[] tokenBuffer
private int tokenBufferLength
private boolean readWS
Constructor Detail |
CSSParser()
Method Detail |
void parse(Reader reader, CSSParser.CSSParserCallback callback, boolean inRule) throws IOException
IOException
private boolean getNextStatement() throws IOException
IOException
private void parseAtRule() throws IOException
IOException
private void parseRuleSet() throws IOException
IOException
private boolean parseSelectors() throws IOException
IOException
private void parseDeclarationBlock() throws IOException
IOException
private int parseDeclaration() throws IOException
IOException
private int parseIdentifiers(char extraChar, boolean wantsBlocks) throws IOException
extraChar
is encountered,
returning the ending token, which will be IDENTIFIER if extraChar
is found.
IOException
private void parseTillClosed(int openToken) throws IOException
IOException
private int nextToken(char idChar) throws IOException
IOException
private boolean getIdentifier(char stopChar) throws IOException
stopChar
, whitespace, or one of {}()[] is
hit.
IOException
private void readTill(char stopChar) throws IOException
stopChar
is encountered, escaping characters
as necessary.
IOException
private void append(char character)
private void readComment() throws IOException
IOException
private void startBlock(int startToken)
private void endBlock(int endToken)
private boolean inBlock()
private int readWS() throws IOException
IOException
private int readChar() throws IOException
IOException
private void pushChar(int tempChar)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |