gnu.xml

Class XMLPrinter

Implemented Interfaces:
Consumer, PositionConsumer, XConsumer

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

Constructor Summary

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

Method Summary

void
beginAttribute(String attrName, Object attrType)
Write a attribute for the current group.
void
beginDocument()
void
beginGroup(String typeName, Object type)
void
consume(SeqPosition position)
Consume node at current position.
void
endAttribute()
void
endDocument()
void
endGroup(String typeName)
boolean
ignoring()
True if consumer is ignoring rest of group.
static boolean
isHtmlEmptyElementTag(String name)
protected static boolean
isWordChar(char ch)
static XMLPrinter
make(Consumer out, Object style)
void
setStyle(Object style)
protected void
startNumber()
static String
toString(Object value)
Convert argument to string in XML syntax.
void
write(char[] buf, int off, int len)
void
writeBaseUri(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(String str)
void
writeComment(char[] chars, int offset, int length)
void
writeObject(Object v)
void
writePosition(AbstractSequence seq, int ipos)
Consume a single position pair.
void
writeProcessingInstruction(String target, char[] content, int offset, int length)

Methods inherited from class gnu.lists.PrintConsumer

beginAttribute, beginDocument, beginGroup, endAttribute, endDocument, endGroup, ignoring, startNumber, writeBoolean, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeObject

Field Details

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.

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.

escapeText

public boolean escapeText

indentLoc

public static final ThreadLocation indentLoc

Constructor Details

XMLPrinter

public XMLPrinter(OutputStream out)

XMLPrinter

public XMLPrinter(OutputStream out,
                  boolean autoFlush)

XMLPrinter

public XMLPrinter(Writer out)

XMLPrinter

public XMLPrinter(Writer out,
                  boolean autoFlush)

XMLPrinter

public XMLPrinter(Consumer out)

XMLPrinter

public XMLPrinter(Consumer out,
                  boolean autoFlush)

XMLPrinter

public XMLPrinter(PrintConsumer out)

XMLPrinter

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

Method Details

beginAttribute

public void beginAttribute(String attrName,
                           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 interface PrintConsumer

beginDocument

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

beginGroup

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

consume

public void consume(SeqPosition position)
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

endAttribute

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

endDocument

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

endGroup

public void endGroup(String typeName)
Specified by:
endGroup in interface Consumer
Overrides:
endGroup in interface 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 interface PrintConsumer

isHtmlEmptyElementTag

public static boolean isHtmlEmptyElementTag(String name)

isWordChar

protected static final boolean isWordChar(char ch)

make

public static XMLPrinter make(Consumer out,
                              Object style)

setStyle

public void setStyle(Object style)

startNumber

protected void startNumber()
Overrides:
startNumber in interface PrintConsumer

toString

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

write

public void write(char[] buf,
                  int off,
                  int len)
Specified by:
write in interface Consumer

writeBaseUri

public void writeBaseUri(Object uri)
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

writeBoolean

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

writeCDATA

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

writeChar

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

writeChars

public void writeChars(String str)
Specified by:
writeChars in interface Consumer
Overrides:
writeChars in interface PrintConsumer

writeComment

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

writeObject

public void writeObject(Object v)
Specified by:
writeObject in interface Consumer
Overrides:
writeObject in interface PrintConsumer

writePosition

public void writePosition(AbstractSequence seq,
                          int ipos)
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

writeProcessingInstruction

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