APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.text.html

pack-priv Class CSSParser

extends Object
Class Inheritance
Imports
java.io.*

A CSS parser. This works by way of a delegate that implements the CSSParserCallback interface. The delegate is notified of the following events: This will parse much more than CSS 1, and loosely implements the recommendation for Forward-compatible parsing in section 7.1 of the CSS spec found at: http://www.w3.org/TR/REC-CSS1.

If parsing results in an error, a RuntimeException will be thrown.

This will preserve case. If the callback wishes to treat certain portions case-insensitively (such as selectors), it should use toLowerCase, or something similar.

Author
Scott Violet

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private static final int
private CSSParser.CSSParserCallback
callback

Notified of state.

private static final char[]
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 final int
private static final int
private static final int
private static final int
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

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
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()

Returns: true if currently in a block.

private int
nextToken(char idChar)

Fetches the next token.

pack-priv 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 ({[.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BRACE_CLOSEback to summary
private static final int BRACE_CLOSE
BRACE_OPENback to summary
private static final int BRACE_OPEN
BRACKET_CLOSEback to summary
private static final int BRACKET_CLOSE
BRACKET_OPENback to summary
private static final int BRACKET_OPEN
callbackback to summary
private CSSParser.CSSParserCallback callback

Notified of state.

charMappingback to summary
private static final char[] charMapping
didPushCharback to summary
private boolean didPushChar

Set to true if one character has been read ahead.

encounteredRuleSetback to summary
private boolean encounteredRuleSet

Set to true when the first non @ rule is encountered.

ENDback to summary
private static final int END
IDENTIFIERback to summary
private static final int IDENTIFIER
PAREN_CLOSEback to summary
private static final int PAREN_CLOSE
PAREN_OPENback to summary
private static final int PAREN_OPEN
pushedCharback to summary
private int pushedChar

The read ahead character.

readerback to summary
private Reader reader

Holds the incoming CSS rules.

readWSback to summary
private boolean readWS

Set to true if any whitespace is read.

stackCountback to summary
private int stackCount

Number of valid blocks.

tokenBufferback to summary
private char[] tokenBuffer

nextToken() inserts the string here.

tokenBufferLengthback to summary
private int tokenBufferLength

Current number of chars in tokenBufferLength.

unitBufferback to summary
private StringBuffer unitBuffer

Temporary place to hold identifiers.

unitStackback to summary
private int[] unitStack

Used to indicate blocks.

Constructor Detail

CSSParserback to summary
pack-priv CSSParser()

Method Detail

appendback to summary
private void append(char character)
endBlockback to summary
private void endBlock(int endToken)

Called when an end block is encountered )]}

getIdentifierback to summary
private boolean getIdentifier(char stopChar) throws IOException

Gets an identifier, returning true if the length of the string is greater than 0, stopping when stopChar, whitespace, or one of {}()[] is hit.

getNextStatementback to summary
private boolean getNextStatement() throws IOException

Gets the next statement, returning false if the end is reached. A statement is either an @rule, or a ruleset.

inBlockback to summary
private boolean inBlock()
Returns:boolean

true if currently in a block.

nextTokenback to summary
private int nextToken(char idChar) throws IOException

Fetches the next token.

parseback to summary
pack-priv void parse(Reader reader, CSSParser.CSSParserCallback callback, boolean inRule) throws IOException
parseAtRuleback to summary
private void parseAtRule() throws IOException

Parses an @ rule, stopping at a matching brace pair, or ;.

parseDeclarationback to summary
private int parseDeclaration() throws IOException

Parses a single declaration, which is an identifier a : and another identifier. This returns the last token seen.

parseDeclarationBlockback to summary
private void parseDeclarationBlock() throws IOException

Parses a declaration block. Which a number of declarations followed by a })].

parseIdentifiersback to summary
private int parseIdentifiers(char extraChar, boolean wantsBlocks) throws IOException

Parses identifiers until extraChar is encountered, returning the ending token, which will be IDENTIFIER if extraChar is found.

parseRuleSetback to summary
private void parseRuleSet() throws IOException

Parses the next rule set, which is a selector followed by a declaration block.

parseSelectorsback to summary
private boolean parseSelectors() throws IOException

Parses a set of selectors, returning false if the end of the stream is reached.

parseTillClosedback to summary
private void parseTillClosed(int openToken) throws IOException

Parses till a matching block close is encountered. This is only appropriate to be called at the top level (no nesting).

pushCharback to summary
private void pushChar(int tempChar)

Supports one character look ahead, this will throw if called twice in a row.

readCharback to summary
private int readChar() throws IOException

Reads a character from the stream.

readCommentback to summary
private void readComment() throws IOException

Parses a comment block.

readTillback to summary
private void readTill(char stopChar) throws IOException

Reads till a stopChar is encountered, escaping characters as necessary.

readWSback to summary
private int readWS() throws IOException

Skips any white space, returning the character after the white space.

startBlockback to summary
private void startBlock(int startToken)

Called when a block start is encountered ({[.

javax.swing.text.html back to summary

pack-priv Interface CSSParser.CSSParserCallback

Known Direct Implementers
javax.swing.text.html.StyleSheet.CssParser

Method Summary

Modifier and TypeMethod and Description
public void
public void
handleImport(String importString)

Called when an @import is encountered.

public void
public void
public void
public void

Method Detail

endRuleback to summary
public void endRule()
handleImportback to summary
public void handleImport(String importString)

Called when an @import is encountered.

handlePropertyback to summary
public void handleProperty(String property)
handleSelectorback to summary
public void handleSelector(String selector)
handleValueback to summary
public void handleValue(String value)
startRuleback to summary
public void startRule()