com.ibm.wbi.markuplanguage.html
Class HtmlEditor

java.lang.Object
  |
  +--com.ibm.wbi.markuplanguage.html.HtmlEditor

public class HtmlEditor
extends java.lang.Object

Class to edit HTML sources.


Field Summary
protected  boolean eofp
           
protected  HtmlTokenizer in
           
protected  HtmlItem item
           
protected  boolean needsFlushing
          This one is a little sketchy.
protected  java.io.Writer out
           
 
Constructor Summary
HtmlEditor(java.io.InputStream is, java.io.OutputStream os)
          Deprecated. Use HtmlEditor(Reader, Writer) instead
HtmlEditor(java.io.Reader r, java.io.Writer w)
          Creates a new HtmlEditor on a Reader and a Writer.
 
Method Summary
 boolean atEOF()
          Indicates whether editor has gone past the end of the stream.
 HtmlItem copyUntil(java.lang.String tagId)
          Reads from the input stream until the specified tag was found.
 HtmlItem copyUntil(java.lang.String[] tagId)
          Reads from the stream until any one of a set of tag types is found.
static void main(java.lang.String[] args)
          Main method to test HtmlEditor.
 HtmlItem nextToken()
          Get the next token from the input stream (HtmlItem).
 HtmlItem readUntil(java.lang.String tagId)
          Reads from the input stream until the specified tag was found.
 HtmlItem readUntil(java.lang.String[] tagId)
          Reads from the stream until any one of a set of tag types is found.
 HtmlItem readUntil(java.lang.String[] tagId, boolean copy)
          Reads from the stream until any one of a set of tag types is found.
 HtmlItem readUntil(java.lang.String tagId, boolean copy)
          Reads from the stream until a particular tag (HTML Element) type is found.
 HtmlItem readUntil(java.lang.String tagId, java.lang.StringBuffer textUpTo)
          Reads from the stream until a particular tag (HTML Element) type is found.
 void write(byte[] b)
          Deprecated. You shouldn't be dealing with bytes!!!! Use write(char[]) instead.
 void write(char[] ch)
           
 void write(HtmlItem item)
          Writes an HtmlItem to the output stream.
 void write(java.lang.String s)
          Write string to the output stream.
 void writeLastToken()
          Write the last token that was read from the inputstream.
 void writeRemaining()
          Writes the remaining data from the input stream to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.Writer out

item

protected HtmlItem item

in

protected HtmlTokenizer in

eofp

protected boolean eofp

needsFlushing

protected boolean needsFlushing
This one is a little sketchy. When the deprecated InputStream/OutputStream constructor is used, we construct a InputStreamReader and an OutputStreamWriter around the args. Since HtmlEditor has no flush() method and is intended to be backwards-compatible, we must flush after every write to avoid breaking old code. This may incur a small performance penalty, but only for those who use the deprecated constructor. One might wonder, "A MegWriter is just a wrapper around an OutputStreamWriter; why won't the same problem occur if the user passes a MegWriter in to the Reader/Writer constructor?" The answer is that the infrastructure knows about MegWriters and they are tracked externally. When a Meg's handleRequest() method exits, if a MegWriter was created, it is automatically flushed and closed before the MegOutputStream. Everything works fine.
Constructor Detail

HtmlEditor

public HtmlEditor(java.io.Reader r,
                  java.io.Writer w)
Creates a new HtmlEditor on a Reader and a Writer.
Parameters:
r - Reader containing the HTML source to edit.
w - Writer that will be used to write the edited HTML source.

HtmlEditor

public HtmlEditor(java.io.InputStream is,
                  java.io.OutputStream os)
Deprecated. Use HtmlEditor(Reader, Writer) instead

Creates a new HtmlEditor on an input stream.
Parameters:
is - Input stream containing the HTML source to edit.
os - Ouput stream that will be used to write the edited HTML source.
Method Detail

atEOF

public boolean atEOF()
Indicates whether editor has gone past the end of the stream.
Returns:
true if editor has gone past end of input stream (has already returned last token), false otherwise. Note: true will be returned by this method only after nextToken() has been called on an empty editor stream.

nextToken

public HtmlItem nextToken()
Get the next token from the input stream (HtmlItem).
Returns:
The next token.

writeLastToken

public void writeLastToken()
                    throws java.io.IOException
Write the last token that was read from the inputstream.

write

public void write(java.lang.String s)
           throws java.io.IOException
Write string to the output stream.
Parameters:
s - String to write to the output stream.

write

public void write(byte[] b)
           throws java.io.IOException
Deprecated. You shouldn't be dealing with bytes!!!! Use write(char[]) instead.

Write a byte array to the output stream.
Parameters:
b[] - Byte buffer to write to the output stream.

write

public void write(char[] ch)
           throws java.io.IOException

write

public void write(HtmlItem item)
           throws java.io.IOException
Writes an HtmlItem to the output stream.
Parameters:
The - HtmlItem.

readUntil

public HtmlItem readUntil(java.lang.String tagId,
                          boolean copy)
                   throws java.io.IOException
Reads from the stream until a particular tag (HTML Element) type is found.
Parameters:
tagId - String representation of the HTML element this function is looking for.
If - true, all the data read from the stream will be written to the output stream.
Returns:
The first HTML element that matches tagId if available, null otherwise.

readUntil

public HtmlItem readUntil(java.lang.String tagId,
                          java.lang.StringBuffer textUpTo)
                   throws java.io.IOException
Reads from the stream until a particular tag (HTML Element) type is found.
Parameters:
tagId - String representation of the HTML element this function is looking for.
textUpTo - StringBuffer. All the data read from the stream will be written to this buffer until tag was found.
Returns:
The first HTML element that matches tagId if available, null otherwise.

writeRemaining

public void writeRemaining()
                    throws java.io.IOException
Writes the remaining data from the input stream to the output stream. The editor will be at EOF after a call to this method.

readUntil

public HtmlItem readUntil(java.lang.String tagId)
                   throws java.io.IOException
Reads from the input stream until the specified tag was found. No data will be copied to the output stream.
Parameters:
tagId - String representation of the HTML element this function is looking for.
Returns:
The first HTML element that matches tagId if available, null otherwise.

copyUntil

public HtmlItem copyUntil(java.lang.String tagId)
                   throws java.io.IOException
Reads from the input stream until the specified tag was found. All data read from the input stream is copied to the output stream.
Parameters:
tagId - String representation of the HTML element this function is looking for.
Returns:
The first HTML element that matches tagId if available, null otherwise.

readUntil

public HtmlItem readUntil(java.lang.String[] tagId,
                          boolean copy)
                   throws java.io.IOException
Reads from the stream until any one of a set of tag types is found.
Parameters:
tagId[] - String representation of the HTML element this function is looking for.
If - true, all the data read from the stream will be written to the output stream.
Returns:
The first HTML element that matches any one of the tags if available, null otherwise.

readUntil

public HtmlItem readUntil(java.lang.String[] tagId)
                   throws java.io.IOException
Reads from the stream until any one of a set of tag types is found. No data will be written to the ouput stream.
Parameters:
tagId[] - String representation of the HTML element this function is looking for.
Returns:
The first HTML element that matches any one of the tags if available, null otherwise.

copyUntil

public HtmlItem copyUntil(java.lang.String[] tagId)
                   throws java.io.IOException
Reads from the stream until any one of a set of tag types is found. All data read from the input stream is written to the ouput stream.
Parameters:
tagId[] - String representation of the HTML element this function is looking for.
Returns:
The first HTML element that matches any one of the tags if available, null otherwise.

main

public static void main(java.lang.String[] args)
Main method to test HtmlEditor. Does not require any arguments.