Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

javax.swing.text.html
Class CSSParser  view CSSParser download CSSParser.java

java.lang.Object
  extended byjavax.swing.text.html.CSSParser

class CSSParser
extends java.lang.Object

Parses a CSS document. This works by way of a delegate that implements the CSSParserCallback interface. The delegate is notified of the following events: - Import statement: handleImport - Selectors 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'. - When a rule starts, startRule - Properties in the rule via the 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'. - Values in the rule via the handleValue, this is notified for the total value. - When a rule ends, endRule


Nested Class Summary
(package private) static interface CSSParser.CSSParserCallback
          Receives all information about the CSS document structure while parsing it.
 
Field Summary
private static int BRACE_CLOSE
          The close brace.
private static int BRACE_OPEN
          The open brace.
private static int BRACKET_CLOSE
          The close bracket.
private static int BRACKET_OPEN
          The open bracket.
private  CSSParser.CSSParserCallback callback
          The call back used to parse.
private static char[] charMapping
          The character mapping in the document.
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
          The end of the document.
private static int IDENTIFIER
          The identifier of the rule.
private static int PAREN_CLOSE
          The close parentheses.
private static int PAREN_OPEN
          The open parentheses.
private  int pushedChar
          The read ahead character.
private  java.io.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  java.lang.StringBuffer unitBuffer
          Temporary place to hold identifiers.
private  int[] unitStack
          Used to indicate blocks.
 
Constructor Summary
(package private) CSSParser()
          Constructor
 
Method Summary
private  void append(char c)
          Appends a character to the token buffer.
private  void endBlock(int end)
          Called when an end block is encountered )]}
private  boolean getIdentifier(char c)
          Gets an identifier, returning true if the length of the string is greater than 0, stopping when c, whitespace, or one of {}()[] is hit.
private  boolean getNextStatement()
          Gets the next statement, returning false if the end is reached.
private  boolean inBlock()
          Checks if currently in a block.
private  int nextToken(char c)
          Fetches the next token.
(package private)  void parse(java.io.Reader reader, CSSParser.CSSParserCallback callback, boolean parsingDeclaration)
          Parses the the contents of the reader using the callback.
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 c, boolean wantsBlocks)
          Parses identifiers until c is encountered, returning the ending token, which will be IDENTIFIER if c 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 i)
          Parses till a matching block close is encountered.
private  void pushChar(int c)
          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 c)
          Reads till c is encountered, escaping characters as necessary.
private  int readWS()
          Skips any white space, returning the character after the white space.
private  void startBlock(int start)
          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

IDENTIFIER

private static final int IDENTIFIER
The identifier of the rule.

See Also:
Constant Field Values

BRACKET_OPEN

private static final int BRACKET_OPEN
The open bracket.

See Also:
Constant Field Values

BRACKET_CLOSE

private static final int BRACKET_CLOSE
The close bracket.

See Also:
Constant Field Values

BRACE_OPEN

private static final int BRACE_OPEN
The open brace.

See Also:
Constant Field Values

BRACE_CLOSE

private static final int BRACE_CLOSE
The close brace.

See Also:
Constant Field Values

PAREN_OPEN

private static final int PAREN_OPEN
The open parentheses.

See Also:
Constant Field Values

PAREN_CLOSE

private static final int PAREN_CLOSE
The close parentheses.

See Also:
Constant Field Values

END

private static final int END
The end of the document.

See Also:
Constant Field Values

charMapping

private static final char[] charMapping
The character mapping in the document.


didPushChar

private boolean didPushChar
Set to true if one character has been read ahead.


pushedChar

private int pushedChar
The read ahead character.


unitBuffer

private java.lang.StringBuffer unitBuffer
Temporary place to hold identifiers.


unitStack

private int[] unitStack
Used to indicate blocks.


stackCount

private int stackCount
Number of valid blocks.


reader

private java.io.Reader reader
Holds the incoming CSS rules.


encounteredRuleSet

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


callback

private CSSParser.CSSParserCallback callback
The call back used to parse.


tokenBuffer

private char[] tokenBuffer
nextToken() inserts the string here.


tokenBufferLength

private int tokenBufferLength
Current number of chars in tokenBufferLength.


readWS

private boolean readWS
Set to true if any whitespace is read.

Constructor Detail

CSSParser

CSSParser()
Constructor

Method Detail

append

private void append(char c)
Appends a character to the token buffer.


nextToken

private int nextToken(char c)
               throws java.io.IOException
Fetches the next token.


readChar

private int readChar()
              throws java.io.IOException
Reads a character from the stream.


parse

void parse(java.io.Reader reader,
           CSSParser.CSSParserCallback callback,
           boolean parsingDeclaration)
     throws java.io.IOException
Parses the the contents of the reader using the callback.


readWS

private int readWS()
            throws java.io.IOException
Skips any white space, returning the character after the white space.


getNextStatement

private boolean getNextStatement()
                          throws java.io.IOException
Gets the next statement, returning false if the end is reached. A statement is either an At-rule, or a ruleset.


parseAtRule

private void parseAtRule()
                  throws java.io.IOException
Parses an @ rule, stopping at a matching brace pair, or ;.


parseRuleSet

private void parseRuleSet()
                   throws java.io.IOException
Parses the next rule set, which is a selector followed by a declaration block.


parseSelectors

private boolean parseSelectors()
                        throws java.io.IOException
Parses a set of selectors, returning false if the end of the stream is reached.


parseDeclarationBlock

private void parseDeclarationBlock()
                            throws java.io.IOException
Parses a declaration block. Which a number of declarations followed by a })].


parseDeclaration

private int parseDeclaration()
                      throws java.io.IOException
Parses a single declaration, which is an identifier a : and another identifier. This returns the last token seen.


parseIdentifiers

private int parseIdentifiers(char c,
                             boolean wantsBlocks)
                      throws java.io.IOException
Parses identifiers until c is encountered, returning the ending token, which will be IDENTIFIER if c is found.


parseTillClosed

private void parseTillClosed(int i)
                      throws java.io.IOException
Parses till a matching block close is encountered. This is only appropriate to be called at the top level (no nesting).


getIdentifier

private boolean getIdentifier(char c)
                       throws java.io.IOException
Gets an identifier, returning true if the length of the string is greater than 0, stopping when c, whitespace, or one of {}()[] is hit.


readTill

private void readTill(char c)
               throws java.io.IOException
Reads till c is encountered, escaping characters as necessary.


readComment

private void readComment()
                  throws java.io.IOException
Parses a comment block.


startBlock

private void startBlock(int start)
Called when a block start is encountered ({[.


endBlock

private void endBlock(int end)
Called when an end block is encountered )]}


inBlock

private boolean inBlock()
Checks if currently in a block.


pushChar

private void pushChar(int c)
               throws java.io.IOException
Supports one character look ahead, this will throw if called twice in a row.