Package gnu.xml
Class XMLPrinter
- java.lang.Object
-
- java.io.Writer
-
- java.io.PrintWriter
-
- gnu.lists.PrintConsumer
-
- gnu.xml.XMLPrinter
-
- All Implemented Interfaces:
Consumer,PositionConsumer,XConsumer,Closeable,Flushable,Appendable,AutoCloseable,Consumer<Object>,DoubleConsumer,IntConsumer,LongConsumer
public class XMLPrinter extends PrintConsumer implements PositionConsumer, XConsumer
Print an event stream in XML format on a PrintWriter.
-
-
Field Summary
Fields Modifier and Type Field Description booleancanonicalizeCDATAstatic ThreadLocationdoctypePublicThe system identifier emitted in a DOCTYPE declaration.static ThreadLocationdoctypeSystemFluid parameter to control whether a DOCTYPE declaration is emitted.booleanescapeNonAsciibooleanescapeTextbooleanextendedbooleanindentAttributesWhen indenting, should attributes be lined up?static ThreadLocation<String>indentLocprotected intprintIndentintuseEmptyElementTagHandling of empty elements.-
Fields inherited from class gnu.lists.PrintConsumer
base, skipping
-
Fields inherited from class java.io.PrintWriter
out
-
-
Constructor Summary
Constructors Constructor Description XMLPrinter(Consumer out)XMLPrinter(PrintConsumer out)XMLPrinter(OutputStream out)XMLPrinter(Writer out)XMLPrinter(Writer out, boolean autoFlush)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginComment()voidbeginEntity(Object base)voidcloseTag()voidendAttribute()End of an attribute or end of an actual parameter.voidendComment()voidendDocument()voidendElement()voidendEntity()protected voidendNumber()voiderror(String msg, String code)static StringformatDecimal(BigDecimal dec)Format java.math.BigDecimal as needed for XPath/XQuery's xs:decimal.static StringformatDouble(double d)Helper to format xs:double according to XPath/XQuery specification.static StringformatFloat(float f)Helper to format xs:float according to XPath/XQuery specification.protected StringgetHtmlTag(Object type)booleanignoring()True if consumer is ignoring rest of element.static booleanisHtmlEmptyElementTag(String name)static XMLPrintermake(Consumer out, Object style)voidprint(Object v)voidsetCanonicalizeCDATA(boolean v)voidsetEscapeNonAscii(boolean v)voidsetEscapeText(boolean v)voidsetExtended(boolean v)voidsetIndent(int v)Controls whether to add extra indentation.voidsetPrintXMLdecl(boolean value)voidsetStyle(Object style)voidsetUseEmptyElementTag(int v)voidstartAttribute(Object attrType)Write a attribute for the current element.voidstartDocument()voidstartElement(Object type)protected voidstartNumber()static StringtoString(Object value)Convert argument to string in XML syntax.voidwrite(char[] buf, int off, int len)voidwrite(int v)voidwrite(String str, int start, int length)voidwriteBaseUri(Object uri)voidwriteBoolean(boolean v)voidwriteCDATA(char[] chars, int offset, int length)voidwriteComment(char[] chars, int offset, int length)voidwriteComment(String chars)voidwriteDoctype(String tagname, String systemId, String publicId)voidwriteDoctypeIfDefined(String tagname)Write DOCTYPE using ThreadLocations doctypeSystem and doctypePublicvoidwriteDouble(double d)voidwriteFloat(float f)voidwriteObject(Object v)voidwritePosition(AbstractSequence seq, int ipos)Consume a single position pair.voidwritePosition(SeqPosition position)Consume node at current position.voidwriteProcessingInstruction(String target, char[] content, int offset, int length)protected voidwriteQName(Object name)-
Methods inherited from class gnu.lists.PrintConsumer
append, append, append, beforeContent, beforeNode, clearWordEnd, endHiderSection, endLogicalBlock, endLogicalBlock, freshLine, getPrettyWriter, isDomTerm, setIndentation, startHiderSection, startLogicalBlock, startLogicalBlock, startLogicalBlock, write, writeBreak, writeBreakFill, writeBreakFill, writeBreakLinear, writeInt, writeLong, writeRaw, writeRaw, writeRaw, writeRaw, writeShowHideButton, writeSpace, writeSpaceFill, writeSpaceFill, writeSpaceLinear, writeWordEnd, writeWordStart
-
Methods inherited from class java.io.PrintWriter
checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write
-
Methods inherited from class java.io.Writer
nullWriter
-
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
accept, accept, accept, accept, append, append, append, write, write, writeInt, writeLong
-
Methods inherited from interface java.util.function.DoubleConsumer
andThen
-
Methods inherited from interface java.util.function.IntConsumer
andThen
-
Methods inherited from interface java.util.function.LongConsumer
andThen
-
-
-
-
Field Detail
-
printIndent
protected int printIndent
-
indentAttributes
public boolean indentAttributes
When indenting, should attributes be lined up?
-
canonicalizeCDATA
public boolean canonicalizeCDATA
-
useEmptyElementTag
public int useEmptyElementTag
Handling of empty elements. 0: No element element tags, as required for canonical XML:<br></br>. 1: Use XML-style empty element tags:<br/>2: Use HTML-compatible empty element tags:<br />but<p></p>.
-
escapeText
public boolean escapeText
-
escapeNonAscii
public boolean escapeNonAscii
-
extended
public boolean extended
-
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<String> indentLoc
-
-
Constructor Detail
-
XMLPrinter
public XMLPrinter(Writer out, boolean autoFlush)
-
XMLPrinter
public XMLPrinter(Writer out)
-
XMLPrinter
public XMLPrinter(Consumer out)
-
XMLPrinter
public XMLPrinter(PrintConsumer out)
-
XMLPrinter
public XMLPrinter(OutputStream out)
-
-
Method Detail
-
setPrintXMLdecl
public void setPrintXMLdecl(boolean value)
-
make
public static XMLPrinter make(Consumer out, Object style)
-
setStyle
public void setStyle(Object style)
-
setEscapeText
public void setEscapeText(boolean v)
-
setEscapeNonAscii
public void setEscapeNonAscii(boolean v)
-
setCanonicalizeCDATA
public void setCanonicalizeCDATA(boolean v)
-
setUseEmptyElementTag
public void setUseEmptyElementTag(int v)
-
setExtended
public void setExtended(boolean v)
-
setIndent
public void setIndent(int v)
Controls whether to add extra indentation. -1: don't add indentation; 0: pretty-print (avoid needless newlines); 1: indent (force).
-
write
public void write(int v)
- Specified by:
writein interfaceConsumer- Overrides:
writein classPrintWriter
-
writeBoolean
public void writeBoolean(boolean v)
- Specified by:
writeBooleanin interfaceConsumer- Overrides:
writeBooleanin classPrintConsumer
-
startNumber
protected void startNumber()
- Overrides:
startNumberin classPrintConsumer
-
endNumber
protected void endNumber()
- Overrides:
endNumberin classPrintConsumer
-
closeTag
public void closeTag()
-
startDocument
public void startDocument()
- Specified by:
startDocumentin interfaceConsumer- Overrides:
startDocumentin classPrintConsumer
-
endDocument
public void endDocument()
- Specified by:
endDocumentin interfaceConsumer- Overrides:
endDocumentin classPrintConsumer
-
beginEntity
public void beginEntity(Object base)
- Specified by:
beginEntityin interfaceXConsumer- Overrides:
beginEntityin classPrintConsumer
-
endEntity
public void endEntity()
- Specified by:
endEntityin interfaceXConsumer- Overrides:
endEntityin classPrintConsumer
-
writeQName
protected void writeQName(Object name)
-
writeDoctypeIfDefined
public void writeDoctypeIfDefined(String tagname)
Write DOCTYPE using ThreadLocations doctypeSystem and doctypePublic
-
startElement
public void startElement(Object type)
- Specified by:
startElementin interfaceConsumer- Overrides:
startElementin classPrintConsumer
-
isHtmlEmptyElementTag
public static boolean isHtmlEmptyElementTag(String name)
-
endElement
public void endElement()
- Specified by:
endElementin interfaceConsumer- Overrides:
endElementin classPrintConsumer
-
startAttribute
public void startAttribute(Object attrType)
Write a attribute for the current element. This is only allowed immediately after a startElement.- Specified by:
startAttributein interfaceConsumer- Overrides:
startAttributein classPrintConsumer
-
endAttribute
public void endAttribute()
Description copied from interface:ConsumerEnd 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:
endAttributein interfaceConsumer- Overrides:
endAttributein classPrintConsumer
-
writeDouble
public void writeDouble(double d)
- Specified by:
writeDoublein interfaceConsumer- Overrides:
writeDoublein classPrintConsumer
-
writeFloat
public void writeFloat(float f)
- Specified by:
writeFloatin interfaceConsumer- Overrides:
writeFloatin classPrintConsumer
-
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.
-
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.
-
print
public void print(Object v)
- Overrides:
printin classPrintWriter
-
writeObject
public void writeObject(Object v)
- Specified by:
writeObjectin interfaceConsumer- Overrides:
writeObjectin classPrintConsumer
-
ignoring
public boolean ignoring()
True if consumer is ignoring rest of element. The producer can use this information to skip ahead.- Specified by:
ignoringin interfaceConsumer- Overrides:
ignoringin classPrintConsumer
-
write
public void write(String str, int start, int length)
- Overrides:
writein classPrintWriter
-
write
public void write(char[] buf, int off, int len)- Specified by:
writein interfaceConsumer- Overrides:
writein classPrintWriter
-
writePosition
public void writePosition(AbstractSequence seq, int ipos)
Description copied from interface:PositionConsumerConsume 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:
writePositionin interfacePositionConsumer
-
writeBaseUri
public void writeBaseUri(Object uri)
-
beginComment
public void beginComment()
-
endComment
public void endComment()
-
writeComment
public void writeComment(String chars)
-
writeComment
public void writeComment(char[] chars, int offset, int length)- Specified by:
writeCommentin interfaceXConsumer- Overrides:
writeCommentin classPrintConsumer
-
writeCDATA
public void writeCDATA(char[] chars, int offset, int length)- Specified by:
writeCDATAin interfaceXConsumer- Overrides:
writeCDATAin classPrintConsumer
-
writeProcessingInstruction
public void writeProcessingInstruction(String target, char[] content, int offset, int length)
- Specified by:
writeProcessingInstructionin interfaceXConsumer- Overrides:
writeProcessingInstructionin classPrintConsumer
-
writePosition
public void writePosition(SeqPosition position)
Description copied from interface:PositionConsumerConsume 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:
writePositionin interfacePositionConsumer
-
-