gnu.xml

Class XMLPrinter

Implemented Interfaces:
Consumer, PositionConsumer, Printable, XConsumer

public class XMLPrinter
extends OutPort
implements PositionConsumer, XConsumer

Print an event stream in XML format on a PrintWriter.

Field Summary

boolean
canonicalizeCDATA
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
escapeNonAscii
boolean
escapeText
boolean
indentAttributes
When indentating, should attributes be lined up?
static ThreadLocation
indentLoc
int
printIndent
Controls whether to add extra indentation.
boolean
strict
int
useEmptyElementTag
Handling of empty elements.

Fields inherited from class gnu.mapping.OutPort

bout, errLocation, objectFormat, outLocation, printReadable, unregisterRef

Constructor Summary

XMLPrinter(OutputStream out)
XMLPrinter(OutputStream out, boolean autoFlush)
XMLPrinter(OutputStream out, Path path)
XMLPrinter(Writer out)
XMLPrinter(Writer out, boolean autoFlush)
XMLPrinter(OutPort out, boolean autoFlush)

Method Summary

void
beginComment()
void
beginEntity(Object base)
void
closeTag()
void
consume(SeqPosition position)
Consume node at current position.
void
endAttribute()
End of an attribute or end of an actual parameter.
void
endComment()
void
endDocument()
void
endElement()
void
endEntity()
protected void
endNumber()
void
error(String msg, String code)
static String
formatDecimal(BigDecimal dec)
Format java.math.BigDecimal as needed for XPath/XQuery's xs:decimal.
static String
formatDouble(double d)
Helper to format xs:double according to XPath/XQuery specification.
static String
formatFloat(float f)
Helper to format xs:float according to XPath/XQuery specification.
boolean
ignoring()
True if consumer is ignoring rest of element.
static boolean
isHtmlEmptyElementTag(String name)
static XMLPrinter
make(OutPort out, Object style)
void
print(Object v)
void
setPrintXMLdecl(boolean value)
void
setStyle(Object style)
void
startAttribute(Object attrType)
Write a attribute for the current element.
void
startDocument()
void
startElement(Object type)
protected void
startNumber()
static String
toString(Object value)
Convert argument to string in XML syntax.
void
write(String str, int start, int length)
void
write(char[] buf, int off, int len)
void
write(int v)
void
writeBaseUri(Object uri)
void
writeBoolean(boolean v)
void
writeCDATA(char[] chars, int offset, int length)
void
writeComment(String chars)
void
writeComment(char[] chars, int offset, int length)
void
writeDouble(double d)
void
writeFloat(float f)
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)
protected void
writeQName(Object name)

Methods inherited from class gnu.mapping.OutPort

clearBuffer, close, closeLogFile, closeOnExit, echo, endAttribute, endElement, endLogicalBlock, errDefault, freshLine, getColumnNumber, isWordChar, openFile, outDefault, print, print, print, print, print, print, print, runCleanups, setColumnNumber, setErrDefault, setIndentation, setLogFile, setOutDefault, startAttribute, startElement, startLogicalBlock, startLogicalBlock, writeBreak, writeBreakFill, writeBreakLinear, writeSpaceFill, writeSpaceLinear, writeWordEnd, writeWordStart

Methods inherited from class gnu.lists.PrintConsumer

endAttribute, endDocument, endElement, endNumber, ignoring, startAttribute, startDocument, startElement, startNumber, write, writeBoolean, writeDouble, writeFloat, writeInt, writeLong, writeObject

Field Details

canonicalizeCDATA

public boolean canonicalizeCDATA

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.

escapeNonAscii

public boolean escapeNonAscii

escapeText

public boolean escapeText

indentAttributes

public boolean indentAttributes
When indentating, should attributes be lined up?

indentLoc

public static final ThreadLocation indentLoc

printIndent

public int printIndent
Controls whether to add extra indentation. -1: don't add indentation; 0: pretty-print (avoid needless newlines); 1: indent (force).

strict

public boolean strict

useEmptyElementTag

public int useEmptyElementTag
Handling of empty elements. 0: No element element tags, as required for canonical XML:

. 1: Use XML-style empty element tags:
2: Use HTML-compatible empty element tags:

Constructor Details

XMLPrinter

public XMLPrinter(OutputStream out)

XMLPrinter

public XMLPrinter(OutputStream out,
                  boolean autoFlush)

XMLPrinter

public XMLPrinter(OutputStream out,
                  Path path)

XMLPrinter

public XMLPrinter(Writer out)

XMLPrinter

public XMLPrinter(Writer out,
                  boolean autoFlush)

XMLPrinter

public XMLPrinter(OutPort out,
                  boolean autoFlush)

Method Details

beginComment

public void beginComment()

beginEntity

public void beginEntity(Object base)
Specified by:
beginEntity in interface XConsumer

closeTag

public void closeTag()

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()
End of an attribute or end of an actual parameter. The former use matches a startAttribute; the latter may not, and can be used to separate parameters in a parameter list. This double duty suggsts the method should at least be re-named.
Specified by:
endAttribute in interface Consumer
Overrides:
endAttribute in interface OutPort

endComment

public void endComment()

endDocument

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

endElement

public void endElement()
Specified by:
endElement in interface Consumer
Overrides:
endElement in interface OutPort

endEntity

public void endEntity()
Specified by:
endEntity in interface XConsumer

endNumber

protected void endNumber()
Overrides:
endNumber in interface PrintConsumer

error

public void error(String msg,
                  String code)

formatDecimal

public static String formatDecimal(BigDecimal dec)
Format java.math.BigDecimal as needed for XPath/XQuery's xs:decimal. Specifically this means removing trailing fractional zeros, and a trailing decimal point. However, note that the XML Schema canonical representation does require a decimal point and at least one fractional digit.

formatDouble

public static String formatDouble(double d)
Helper to format xs:double according to XPath/XQuery specification.

formatFloat

public static String formatFloat(float f)
Helper to format xs:float according to XPath/XQuery specification.

ignoring

public boolean ignoring()
True if consumer is ignoring rest of element. 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)

make

public static XMLPrinter make(OutPort out,
                              Object style)

print

public void print(Object v)
Overrides:
print in interface OutPort

setPrintXMLdecl

public void setPrintXMLdecl(boolean value)

setStyle

public void setStyle(Object style)

startAttribute

public void startAttribute(Object attrType)
Write a attribute for the current element. This is only allowed immediately after a startElement.
Specified by:
startAttribute in interface Consumer
Overrides:
startAttribute in interface OutPort

startDocument

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

startElement

public void startElement(Object type)
Specified by:
startElement in interface Consumer
Overrides:
startElement in interface OutPort

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(String str,
                  int start,
                  int length)

write

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

write

public void write(int v)
Specified by:
write in interface Consumer

writeBaseUri

public void writeBaseUri(Object uri)

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

writeComment

public void writeComment(String chars)

writeComment

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

writeDouble

public void writeDouble(double d)
Specified by:
writeDouble in interface Consumer
Overrides:
writeDouble in interface PrintConsumer

writeFloat

public void writeFloat(float f)
Specified by:
writeFloat in interface Consumer
Overrides:
writeFloat in interface PrintConsumer

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

writeQName

protected void writeQName(Object name)