org.eclipse.emf.codegen.jet
Class JETReader

java.lang.Object
  extended by org.eclipse.emf.codegen.jet.JETReader

public class JETReader
extends java.lang.Object

JETReader is an input buffer for the JSP parser. It should allow unlimited lookahead and push-back. It also has a bunch of parsing utility methods for understanding html-style things.


Field Summary
protected  java.util.List<java.lang.String> baseURIs
           
protected  JETMark current
           
protected  char endTagFinalChar
           
protected  char endTagInitialChar
           
protected  java.lang.String master
           
protected  int size
           
protected  java.util.List<java.lang.String> sourceFiles
           
protected  char startTagInitialChar
           
protected  boolean trimExtraNewLine
           
 
Constructor Summary
JETReader(java.lang.String locationURI, java.io.InputStream inputStream, java.lang.String encoding)
           
JETReader(java.lang.String baseURI, java.lang.String locationURI, java.io.InputStream inputStream, java.lang.String encoding)
           
 
Method Summary
 void advance(int n)
           
 java.lang.String getBaseURI(int fileid)
           
 char[] getChars(JETMark start, JETMark stop)
           
 java.lang.String getFile(int fileid)
           
 boolean hasMoreInput()
          Returns whether more input is available.
protected  boolean hasTrailingNewLine()
          Tests whether the current stream has at least one trailing newline, optionally followed by spaces.
protected  boolean isDelimiter()
          Parse utilities - Is current character a token delimiter ?
protected  boolean isSpace()
           
 JETMark mark()
           
 boolean matches(java.lang.String string)
           
 boolean matchesIgnoreCase(java.lang.String string)
           
 int nextChar()
           
 java.lang.String nextContent()
          Gets Content until the next potential JSP element.
protected  void parseAttributeValue(java.util.HashMap<java.lang.String,java.lang.String> into)
          Parse an attribute/value pair, and store it in provided hash table.
 java.util.HashMap<java.lang.String,java.lang.String> parseTagAttributes()
          Parse some tag attributes.
 java.util.HashMap<java.lang.String,java.lang.String> parseTagAttributesBean()
          Parse some tag attributes for Beans.
 java.lang.String parseToken(boolean quoted)
          Parse a space delimited token.
 int peekChar()
           
 boolean popFile()
           
protected  void registerBaseURI(java.lang.String baseURI)
          Register a new baseURI.
protected  int registerSourceFile(java.lang.String file)
          Register a new source file.
 void reset(JETMark mark)
           
 void setEndTag(java.lang.String endTag)
           
 void setStartTag(java.lang.String startTag)
           
protected  void skipNewLine()
          If the next character would be a line break, moves the cursor past it.
 int skipSpaces()
           
 JETMark skipUntil(java.lang.String limit)
          Skip until the given string is matched in the stream.
 void stackStream(java.lang.String locationURI, java.io.InputStream iStream, java.lang.String encoding)
           
 void stackStream(java.lang.String baseURI, java.lang.String locationURI, java.io.InputStream iStream, java.lang.String encoding)
          Stack a stream for parsing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startTagInitialChar

protected char startTagInitialChar

endTagInitialChar

protected char endTagInitialChar

endTagFinalChar

protected char endTagFinalChar

current

protected JETMark current

master

protected java.lang.String master

sourceFiles

protected java.util.List<java.lang.String> sourceFiles

baseURIs

protected java.util.List<java.lang.String> baseURIs

size

protected int size

trimExtraNewLine

protected boolean trimExtraNewLine
Constructor Detail

JETReader

public JETReader(java.lang.String baseURI,
                 java.lang.String locationURI,
                 java.io.InputStream inputStream,
                 java.lang.String encoding)
          throws JETException
Throws:
JETException

JETReader

public JETReader(java.lang.String locationURI,
                 java.io.InputStream inputStream,
                 java.lang.String encoding)
          throws JETException
Throws:
JETException
Method Detail

getFile

public java.lang.String getFile(int fileid)

getBaseURI

public java.lang.String getBaseURI(int fileid)

stackStream

public void stackStream(java.lang.String locationURI,
                        java.io.InputStream iStream,
                        java.lang.String encoding)
                 throws JETException
Throws:
JETException

stackStream

public void stackStream(java.lang.String baseURI,
                        java.lang.String locationURI,
                        java.io.InputStream iStream,
                        java.lang.String encoding)
                 throws JETException
Stack a stream for parsing

Parameters:
iStream - Stream ready to parse
encoding - Optional encoding to read the file.
Throws:
JETException

popFile

public boolean popFile()

registerSourceFile

protected int registerSourceFile(java.lang.String file)
Register a new source file. This method is used to implement file inclusion. Each included file gets a unique identifier (which is the index in the array of source files).

Returns:
The index of the now registered file.

registerBaseURI

protected void registerBaseURI(java.lang.String baseURI)
Register a new baseURI. This method is used to implement file inclusion. Each included file gets a unique identifier (which is the index in the array of base URIs).


hasMoreInput

public boolean hasMoreInput()
Returns whether more input is available. If the end of the buffer for an included file is reached, it will return to the context of the previous file, and return whether more input is available from there. In this case, if trimExtraNewLine is true, then an unwanted extra newline character will be suppressed. We consider the first newline in the buffer we are returning to be unwanted if the ending buffer already has at least one trailing newline.


hasTrailingNewLine

protected boolean hasTrailingNewLine()
Tests whether the current stream has at least one trailing newline, optionally followed by spaces.


skipNewLine

protected void skipNewLine()
If the next character would be a line break, moves the cursor past it.


nextChar

public int nextChar()

nextContent

public java.lang.String nextContent()
Gets Content until the next potential JSP element. Because all elements begin with a '<' we can just move until we see the next one.


getChars

public char[] getChars(JETMark start,
                       JETMark stop)

peekChar

public int peekChar()

mark

public JETMark mark()

reset

public void reset(JETMark mark)

matchesIgnoreCase

public boolean matchesIgnoreCase(java.lang.String string)

matches

public boolean matches(java.lang.String string)

advance

public void advance(int n)

skipSpaces

public int skipSpaces()

skipUntil

public JETMark skipUntil(java.lang.String limit)
Skip until the given string is matched in the stream. When returned, the context is positioned past the end of the match.

Parameters:
limit - The String to match.
Returns:
A non-null JETMark instance if found, null otherwise.

isSpace

protected boolean isSpace()

parseToken

public java.lang.String parseToken(boolean quoted)
                            throws JETException
Parse a space delimited token. If quoted the token will consume all characters up to a matching quote, otherwise, it consumes up to the first delimiter character.

Parameters:
quoted - If true accept quoted strings.
Throws:
JETException

parseAttributeValue

protected void parseAttributeValue(java.util.HashMap<java.lang.String,java.lang.String> into)
                            throws JETException
Parse an attribute/value pair, and store it in provided hash table. The attribute/value pair is defined by:
 av := spaces token spaces '=' spaces token spaces
 
Where token is defined by parseToken and spaces is defined by skipSpaces. The name is always considered case insensitive, hence stored in its lower case version.

Parameters:
into - The HashMap instance to save the result to.
Throws:
JETException

parseTagAttributesBean

public java.util.HashMap<java.lang.String,java.lang.String> parseTagAttributesBean()
                                                                            throws JETException
Parse some tag attributes for Beans. The stream is assumed to be positioned right after the tag name. The syntax recognized is:
 tag-attrs := empty | attr-list (">" | "-->" | %>)
 attr-list := empty | av spaces attr-list
 empty     := spaces
 
Where av is defined by parseAttributeValue.

Returns:
A HashMap mapping String instances (variable names) into String instances (variable values).
Throws:
JETException

parseTagAttributes

public java.util.HashMap<java.lang.String,java.lang.String> parseTagAttributes()
                                                                        throws JETException
Parse some tag attributes. The stream is assumed to be positioned right after the tag name. The syntax recognized is:
 tag-attributes := empty | attribute-list (">" | "-->" | %>)
 attribute-list := empty | attribute-value spaces attribute-list
 empty     := spaces
 
Where attribute-value is defined by parseAttributeValue.

Returns:
A HashMap mapping String instances (variable names) into String instances (variable values).
Throws:
JETException

isDelimiter

protected boolean isDelimiter()
Parse utilities - Is current character a token delimiter ? Delimiters are currently defined to be =, >, <, ", and ' or any any space character as defined by isSpace.

Returns:
A boolean.

setStartTag

public void setStartTag(java.lang.String startTag)

setEndTag

public void setEndTag(java.lang.String endTag)

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.