The idea is to just build up a string of what was written. When
the close() method is called the added string is parsed into a DOM
document and then the individual nodes of the document (Document.getBody().getChildNodes()) are
appended one-by-one to the Document.
private PrintWriter m_printWriter;
private StringWriter m_stringWriter;
public void open()
{
if( m_printWriter ==
null )
{
m_stringWriter = new StringWriter();
m_printWriter = new PrintWriter( m_stringWriter );
}
}
public void close()
{
if( m_stringWriter !=
null )
{
// this call does most of the work but is simple - it just
// parses the string into a new DOM document and returns the child
// elements of the body
NodeList newNodes = DOMStuff.createElementsFromText( m_stringWriter.toString()
);
for( int i=0; i<newNodes.getLength(); i++ )
{
getBody().appendChild( newNodes.item( i ) );
}
m_stringWriter = null;
m_printWriter = null;
}
}
public void write( String p_text )
{
m_printWriter.print(
p_text );
}
public void writeln( String p_text )
{
m_printWriter.println(
p_text );
}
Comments?
court
