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

Quick Search    Search Deep

org.enhydra.xml.xmlc.misc
Class SSIParsedStream  view SSIParsedStream download SSIParsedStream.java

java.lang.Object
  extended byorg.enhydra.xml.xmlc.misc.SSIParsedStream

final class SSIParsedStream
extends java.lang.Object

Implements the reading and parsing of an SSI stream. When a SSI directive is encountered, a new instance of this class is created and pushed on a stack.

To simplified the implementation, the entire file is read into a buffer. A previous version attempted to buffer less, but this ended up being a bit tricky due to the need to scan while reading and still maintain the block read() method.


Field Summary
static int AT_EOF
          Character returned to indicate EOF.
static int AT_SSI
          Character returned to indicate the beginning of an SSI directive.
private  char[] fBuffer
          Buffer for input, contains the entire file.
private  int fDepth
          Nesting depth.
private  int fLastCharIdx
          Index of the last valid character in the buffer.
private  LineNumberRecorder fLineNumbers
          Map of stream position to source file and line number.
private  int fNextCharIdx
          Index of the next character in the buffer.
private  SSIParsedStream fPrevStream
          Next stream in the stack.
private  org.xml.sax.InputSource fSource
          Input source that was used.
private  int fSSIStartIdx
          Index of the start of the next SSI directive in the buffer.
private static int INIT_BUFFER_SIZE
          Initial buffer size to use.
private static int MAX_NESTING_DEPTH
          Maximum nesting depth of SSIs.
private static int SSI_INIT_ARG_STRING_SIZE
          Initial StringBuffer size for a SSI directive argument
private static char[] SSI_PREFIX
           
private static int SSI_PREFIX_LEN
           
private static java.lang.String SSI_PREFIX_STR
          SSI directive prefix definitions.
private static char[] SSI_SUFFIX
           
private static int SSI_SUFFIX_LEN
           
private static java.lang.String SSI_SUFFIX_STR
          SSI directive suffix definitions.
 
Constructor Summary
SSIParsedStream(org.xml.sax.InputSource source, LineNumberRecorder lineNumbers)
          Constructor.
SSIParsedStream(org.xml.sax.InputSource source, LineNumberRecorder lineNumbers, SSIParsedStream prevStream)
          Constructor.
 
Method Summary
private  void expandBuffer()
          Expand the buffer for the next read.
 java.lang.String getSystemId()
          Get the system id of the associated file.
private  boolean isSSIPrefix(int idx)
          Check for SSI prefix at specified offset in buffer, reading more into the buffer if necessary to hold an entire prefix.
private  boolean isSSISuffix(int idx)
          Check for the SSI suffix (comment close) at specified offset in buffer.
 SSIDirective parseSSIDirective()
          Parse the SSI directive that starts at the next available character in the buffer.
 SSIParsedStream pop()
          Close this input stream, returning the previous stream.
 int read()
          Read a character.
 int read(char[] cbuf, int off, int len)
          Read characters into a portion of an array.
private  void readIntoBuffer(org.xml.sax.InputSource source)
          Open the file and read it into the buffer.
private  void readIntoBuffer(java.io.Reader in)
          Read the file into the buffer.
private  int scanForSSIStart(int startIdx)
          Scan for the start of an SSI directive in the buffer.
private  void ssiAdvanceChar()
          Advance the next character index while parsing an SSI directive, checking for hitting eof.
private  void ssiNonSkipWhiteSpace()
          Skip zero or more non-whitespace characters, stopping at the next whitespace character.
private  void ssiParseArg(SSIDirective directive)
          Parse an argument name and value.
private  java.lang.String ssiParseArgName()
          Parse an argument name.
private  java.lang.String ssiParseArgValue()
          Parse an argument value, handling quoting
private  java.lang.String ssiParseCmd()
          Parse the command name from the buffer.
private  void ssiSkipWhiteSpace()
          Skip zero or more whitespace characters, stopping at the next non-whitespace character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AT_EOF

public static final int AT_EOF
Character returned to indicate EOF.

See Also:
Constant Field Values

AT_SSI

public static final int AT_SSI
Character returned to indicate the beginning of an SSI directive.

See Also:
Constant Field Values

SSI_PREFIX_STR

private static final java.lang.String SSI_PREFIX_STR
SSI directive prefix definitions.

See Also:
Constant Field Values

SSI_PREFIX_LEN

private static final int SSI_PREFIX_LEN

SSI_PREFIX

private static final char[] SSI_PREFIX

SSI_SUFFIX_STR

private static final java.lang.String SSI_SUFFIX_STR
SSI directive suffix definitions.

See Also:
Constant Field Values

SSI_SUFFIX_LEN

private static final int SSI_SUFFIX_LEN

SSI_SUFFIX

private static final char[] SSI_SUFFIX

INIT_BUFFER_SIZE

private static final int INIT_BUFFER_SIZE
Initial buffer size to use. May grow as needed.

See Also:
Constant Field Values

MAX_NESTING_DEPTH

private static final int MAX_NESTING_DEPTH
Maximum nesting depth of SSIs.

See Also:
Constant Field Values

SSI_INIT_ARG_STRING_SIZE

private static final int SSI_INIT_ARG_STRING_SIZE
Initial StringBuffer size for a SSI directive argument

See Also:
Constant Field Values

fSource

private org.xml.sax.InputSource fSource
Input source that was used.


fPrevStream

private SSIParsedStream fPrevStream
Next stream in the stack. This was the one that included this file.


fDepth

private int fDepth
Nesting depth.


fBuffer

private char[] fBuffer
Buffer for input, contains the entire file.


fNextCharIdx

private int fNextCharIdx
Index of the next character in the buffer.


fLastCharIdx

private int fLastCharIdx
Index of the last valid character in the buffer.


fSSIStartIdx

private int fSSIStartIdx
Index of the start of the next SSI directive in the buffer. Set to fLastCharIdx+1 if no SSI directive is contained.


fLineNumbers

private LineNumberRecorder fLineNumbers
Map of stream position to source file and line number. Shared by all SSIParsedStream.

Constructor Detail

SSIParsedStream

public SSIParsedStream(org.xml.sax.InputSource source,
                       LineNumberRecorder lineNumbers)
                throws java.io.IOException
Constructor. Open the named file.


SSIParsedStream

public SSIParsedStream(org.xml.sax.InputSource source,
                       LineNumberRecorder lineNumbers,
                       SSIParsedStream prevStream)
                throws java.io.IOException
Constructor. Open the named file.

Method Detail

expandBuffer

private void expandBuffer()
Expand the buffer for the next read.


readIntoBuffer

private void readIntoBuffer(java.io.Reader in)
                     throws java.io.IOException
Read the file into the buffer.


readIntoBuffer

private void readIntoBuffer(org.xml.sax.InputSource source)
                     throws java.io.IOException
Open the file and read it into the buffer.


getSystemId

public java.lang.String getSystemId()
Get the system id of the associated file.


pop

public SSIParsedStream pop()
                    throws java.io.IOException
Close this input stream, returning the previous stream.


isSSIPrefix

private boolean isSSIPrefix(int idx)
                     throws java.io.IOException
Check for SSI prefix at specified offset in buffer, reading more into the buffer if necessary to hold an entire prefix.


isSSISuffix

private boolean isSSISuffix(int idx)
                     throws java.io.IOException
Check for the SSI suffix (comment close) at specified offset in buffer.


scanForSSIStart

private int scanForSSIStart(int startIdx)
                     throws java.io.IOException
Scan for the start of an SSI directive in the buffer. This checks for the `

read

public int read()
         throws java.io.IOException
Read a character.


read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Read characters into a portion of an array.


ssiAdvanceChar

private void ssiAdvanceChar()
                     throws java.io.IOException
Advance the next character index while parsing an SSI directive, checking for hitting eof.


ssiSkipWhiteSpace

private void ssiSkipWhiteSpace()
                        throws java.io.IOException
Skip zero or more whitespace characters, stopping at the next non-whitespace character. If current character is not a whitespace, do nothing.


ssiNonSkipWhiteSpace

private void ssiNonSkipWhiteSpace()
                           throws java.io.IOException
Skip zero or more non-whitespace characters, stopping at the next whitespace character. If current character is a whitespace, do nothing.


ssiParseCmd

private java.lang.String ssiParseCmd()
                              throws java.io.IOException
Parse the command name from the buffer.


ssiParseArgName

private java.lang.String ssiParseArgName()
                                  throws java.io.IOException
Parse an argument name.


ssiParseArgValue

private java.lang.String ssiParseArgValue()
                                   throws java.io.IOException
Parse an argument value, handling quoting


ssiParseArg

private void ssiParseArg(SSIDirective directive)
                  throws java.io.IOException
Parse an argument name and value.


parseSSIDirective

public SSIDirective parseSSIDirective()
                               throws java.io.IOException
Parse the SSI directive that starts at the next available character in the buffer.