gnu.xml
Class XMLPrinter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.PrintWriter
          extended by gnu.lists.PrintConsumer
              extended by gnu.xml.XMLPrinter
All Implemented Interfaces:
Consumer, PositionConsumer, XConsumer, java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class XMLPrinter
extends PrintConsumer
implements PositionConsumer, XConsumer

Print an event stream in XML format on a PrintWriter.


Field Summary
static ThreadLocation doctypePublic
          The system identifier emitted in a DOCTYPE declaration.
static ThreadLocation doctypeSystem
          Fluid parameter to control whether a DOCTYPE declaration is emitted.
 boolean escapeText
           
static ThreadLocation indentLoc
           
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
XMLPrinter(Consumer out)
           
XMLPrinter(Consumer out, boolean autoFlush)
           
XMLPrinter(java.io.OutputStream out)
           
XMLPrinter(java.io.OutputStream out, boolean autoFlush)
           
XMLPrinter(PrintConsumer out)
           
XMLPrinter(PrintConsumer out, boolean autoFlush)
          To disambiguate between Writer and Consumer versions.
XMLPrinter(java.io.Writer out)
           
XMLPrinter(java.io.Writer out, boolean autoFlush)
           
 
Method Summary
 void beginAttribute(java.lang.String attrName, java.lang.Object attrType)
          Write a attribute for the current group.
 void beginDocument()
           
 void beginGroup(java.lang.String typeName, java.lang.Object type)
           
 void consume(SeqPosition position)
          Consume node at current position.
 void endAttribute()
           
 void endDocument()
           
 void endGroup(java.lang.String typeName)
           
 boolean ignoring()
          True if consumer is ignoring rest of group.
static boolean isHtmlEmptyElementTag(java.lang.String name)
           
protected static boolean isWordChar(char ch)
           
static XMLPrinter make(Consumer out, java.lang.Object style)
           
 void setStyle(java.lang.Object style)
           
protected  void startNumber()
           
static java.lang.String toString(java.lang.Object value)
          Convert argument to string in XML syntax.
 void write(char[] buf, int off, int len)
           
 void writeBaseUri(java.lang.Object uri)
          Write/set the base-uri property of the current element or document.
 void writeBoolean(boolean v)
           
 void writeCDATA(char[] chars, int offset, int length)
           
 void writeChar(int v)
           
 void writeChars(java.lang.String str)
           
 void writeComment(char[] chars, int offset, int length)
           
 void writeObject(java.lang.Object v)
           
 void writePosition(AbstractSequence seq, int ipos)
          Consume a single position pair.
 void writeProcessingInstruction(java.lang.String target, char[] content, int offset, int length)
           
 
Methods inherited from class gnu.lists.PrintConsumer
append, append, append, writeDouble, writeFloat, writeInt, writeLong
 
Methods inherited from class java.io.PrintWriter
checkError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gnu.lists.Consumer
append, append, append, writeDouble, writeFloat, writeInt, writeLong
 

Field Detail

escapeText

public boolean escapeText

doctypeSystem

public static final ThreadLocation doctypeSystem
Fluid parameter to control whether a DOCTYPE declaration is emitted. If non-null, this is the the public identifier.


doctypePublic

public static final ThreadLocation doctypePublic
The system identifier emitted in a DOCTYPE declaration. Has no effect if doctypeSystem returns null. If non-null, this is the the system identifier.


indentLoc

public static final ThreadLocation indentLoc
Constructor Detail

XMLPrinter

public XMLPrinter(java.io.Writer out,
                  boolean autoFlush)

XMLPrinter

public XMLPrinter(Consumer out,
                  boolean autoFlush)

XMLPrinter

public XMLPrinter(PrintConsumer out,
                  boolean autoFlush)
To disambiguate between Writer and Consumer versions.


XMLPrinter

public XMLPrinter(java.io.OutputStream out,
                  boolean autoFlush)

XMLPrinter

public XMLPrinter(Consumer out)

XMLPrinter

public XMLPrinter(java.io.Writer out)

XMLPrinter

public XMLPrinter(PrintConsumer out)

XMLPrinter

public XMLPrinter(java.io.OutputStream out)
Method Detail

make

public static XMLPrinter make(Consumer out,
                              java.lang.Object style)

toString

public static java.lang.String toString(java.lang.Object value)
Convert argument to string in XML syntax.


setStyle

public void setStyle(java.lang.Object style)

isWordChar

protected static final boolean isWordChar(char ch)

writeChar

public void writeChar(int v)
Specified by:
writeChar in interface Consumer
Overrides:
writeChar in class PrintConsumer

writeBoolean

public void writeBoolean(boolean v)
Specified by:
writeBoolean in interface Consumer
Overrides:
writeBoolean in class PrintConsumer

startNumber

protected void startNumber()
Overrides:
startNumber in class PrintConsumer

beginDocument

public void beginDocument()
Specified by:
beginDocument in interface Consumer
Overrides:
beginDocument in class PrintConsumer

endDocument

public void endDocument()
Specified by:
endDocument in interface Consumer
Overrides:
endDocument in class PrintConsumer

beginGroup

public void beginGroup(java.lang.String typeName,
                       java.lang.Object type)
Specified by:
beginGroup in interface Consumer
Overrides:
beginGroup in class PrintConsumer

isHtmlEmptyElementTag

public static boolean isHtmlEmptyElementTag(java.lang.String name)

endGroup

public void endGroup(java.lang.String typeName)
Specified by:
endGroup in interface Consumer
Overrides:
endGroup in class PrintConsumer

beginAttribute

public void beginAttribute(java.lang.String attrName,
                           java.lang.Object attrType)
Write a attribute for the current group. This is only allowed immediately after a beginGroup.

Specified by:
beginAttribute in interface Consumer
Overrides:
beginAttribute in class PrintConsumer

endAttribute

public void endAttribute()
Specified by:
endAttribute in interface Consumer
Overrides:
endAttribute in class PrintConsumer

writeObject

public void writeObject(java.lang.Object v)
Specified by:
writeObject in interface Consumer
Overrides:
writeObject in class PrintConsumer

ignoring

public boolean ignoring()
True if consumer is ignoring rest of group. The producer can use this information to skip ahead.

Specified by:
ignoring in interface Consumer
Overrides:
ignoring in class PrintConsumer

writeChars

public void writeChars(java.lang.String str)
Specified by:
writeChars in interface Consumer
Overrides:
writeChars in class PrintConsumer

write

public void write(char[] buf,
                  int off,
                  int len)
Specified by:
write in interface Consumer
Overrides:
write in class java.io.PrintWriter

writePosition

public void writePosition(AbstractSequence seq,
                          int ipos)
Description copied from interface: PositionConsumer
Consume a single position pair. This PositionConsumer may assume the sequence does no reference management; i.e. that copyPos is trivial and releasePos is a no-op. If that is not the case, use consume(TreePosition) instead.

Specified by:
writePosition in interface PositionConsumer

writeBaseUri

public void writeBaseUri(java.lang.Object uri)
Description copied from interface: XConsumer
Write/set the base-uri property of the current element or document. Only allowed immediately following beginDocument, beginGroup, or writeProcessingInstruction.

Specified by:
writeBaseUri in interface XConsumer

writeComment

public void writeComment(char[] chars,
                         int offset,
                         int length)
Specified by:
writeComment in interface XConsumer

writeCDATA

public void writeCDATA(char[] chars,
                       int offset,
                       int length)
Specified by:
writeCDATA in interface XConsumer

writeProcessingInstruction

public void writeProcessingInstruction(java.lang.String target,
                                       char[] content,
                                       int offset,
                                       int length)
Specified by:
writeProcessingInstruction in interface XConsumer

consume

public void consume(SeqPosition position)
Description copied from interface: PositionConsumer
Consume node at current position. The caller may invalidate or change the position after consume returns, so if the consumer wants to save it, it needs to copy it.

Specified by:
consume in interface PositionConsumer