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
Print an event stream in XML format on a PrintWriter.
-
Field Summary
FieldsModifier and TypeFieldDescriptionboolean
static final ThreadLocation
The system identifier emitted in a DOCTYPE declaration.static final ThreadLocation
Fluid parameter to control whether a DOCTYPE declaration is emitted.boolean
boolean
boolean
boolean
When indenting, should attributes be lined up?static final ThreadLocation
<String> protected int
int
Handling of empty elements.Fields inherited from class gnu.lists.PrintConsumer
base, skipping
Fields inherited from class java.io.PrintWriter
out
-
Constructor Summary
ConstructorsConstructorDescriptionXMLPrinter
(Consumer out) XMLPrinter
(PrintConsumer out) XMLPrinter
(OutputStream out) XMLPrinter
(Writer out) XMLPrinter
(Writer out, boolean autoFlush) -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
beginEntity
(Object base) void
closeTag()
void
End of an attribute or end of an actual parameter.void
void
void
void
protected void
void
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.protected String
getHtmlTag
(Object type) boolean
ignoring()
True if consumer is ignoring rest of element.static boolean
isHtmlEmptyElementTag
(String name) static XMLPrinter
void
void
setCanonicalizeCDATA
(boolean v) void
setEscapeNonAscii
(boolean v) void
setEscapeText
(boolean v) void
setExtended
(boolean v) void
setIndent
(int v) Controls whether to add extra indentation.void
setPrintXMLdecl
(boolean value) void
void
setUseEmptyElementTag
(int v) void
startAttribute
(Object attrType) Write a attribute for the current element.void
void
startElement
(Object type) protected void
static String
Convert argument to string in XML syntax.void
write
(char[] buf, int off, int len) void
write
(int v) void
void
writeBaseUri
(Object uri) void
writeBoolean
(boolean v) void
writeCDATA
(char[] chars, int offset, int length) void
writeComment
(char[] chars, int offset, int length) void
writeComment
(String chars) void
writeDoctype
(String tagname, String systemId, String publicId) void
writeDoctypeIfDefined
(String tagname) Write DOCTYPE using ThreadLocations doctypeSystem and doctypePublicvoid
writeDouble
(double d) void
writeFloat
(float f) void
void
writePosition
(AbstractSequence seq, int ipos) Consume a single position pair.void
writePosition
(SeqPosition position) Consume node at current position.void
writeProcessingInstruction
(String target, char[] content, int offset, int length) protected void
writeQName
(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 Details
-
printIndent
protected int printIndent -
indentAttributes
public boolean indentAttributesWhen indenting, should attributes be lined up? -
canonicalizeCDATA
public boolean canonicalizeCDATA -
useEmptyElementTag
public int useEmptyElementTagHandling 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
Fluid parameter to control whether a DOCTYPE declaration is emitted. If non-null, this is the the public identifier. -
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
-
-
Constructor Details
-
XMLPrinter
-
XMLPrinter
-
XMLPrinter
-
XMLPrinter
-
XMLPrinter
-
-
Method Details
-
setPrintXMLdecl
public void setPrintXMLdecl(boolean value) -
make
-
toString
Convert argument to string in XML syntax. -
setStyle
-
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:
write
in interfaceConsumer
- Overrides:
write
in classPrintWriter
-
writeBoolean
public void writeBoolean(boolean v) - Specified by:
writeBoolean
in interfaceConsumer
- Overrides:
writeBoolean
in classPrintConsumer
-
startNumber
protected void startNumber()- Overrides:
startNumber
in classPrintConsumer
-
endNumber
protected void endNumber()- Overrides:
endNumber
in classPrintConsumer
-
closeTag
public void closeTag() -
startDocument
public void startDocument()- Specified by:
startDocument
in interfaceConsumer
- Overrides:
startDocument
in classPrintConsumer
-
endDocument
public void endDocument()- Specified by:
endDocument
in interfaceConsumer
- Overrides:
endDocument
in classPrintConsumer
-
beginEntity
- Specified by:
beginEntity
in interfaceXConsumer
- Overrides:
beginEntity
in classPrintConsumer
-
endEntity
public void endEntity()- Specified by:
endEntity
in interfaceXConsumer
- Overrides:
endEntity
in classPrintConsumer
-
writeQName
-
writeDoctypeIfDefined
Write DOCTYPE using ThreadLocations doctypeSystem and doctypePublic -
writeDoctype
-
startElement
- Specified by:
startElement
in interfaceConsumer
- Overrides:
startElement
in classPrintConsumer
-
isHtmlEmptyElementTag
-
getHtmlTag
-
endElement
public void endElement()- Specified by:
endElement
in interfaceConsumer
- Overrides:
endElement
in classPrintConsumer
-
startAttribute
Write a attribute for the current element. This is only allowed immediately after a startElement.- Specified by:
startAttribute
in interfaceConsumer
- Overrides:
startAttribute
in classPrintConsumer
-
endAttribute
public void endAttribute()Description copied from interface:Consumer
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 interfaceConsumer
- Overrides:
endAttribute
in classPrintConsumer
-
writeDouble
public void writeDouble(double d) - Specified by:
writeDouble
in interfaceConsumer
- Overrides:
writeDouble
in classPrintConsumer
-
writeFloat
public void writeFloat(float f) - Specified by:
writeFloat
in interfaceConsumer
- Overrides:
writeFloat
in classPrintConsumer
-
formatDouble
Helper to format xs:double according to XPath/XQuery specification. -
formatFloat
Helper to format xs:float according to XPath/XQuery specification. -
formatDecimal
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
- Overrides:
print
in classPrintWriter
-
writeObject
- Specified by:
writeObject
in interfaceConsumer
- Overrides:
writeObject
in classPrintConsumer
-
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 interfaceConsumer
- Overrides:
ignoring
in classPrintConsumer
-
write
- Overrides:
write
in classPrintWriter
-
write
public void write(char[] buf, int off, int len) - Specified by:
write
in interfaceConsumer
- Overrides:
write
in classPrintWriter
-
writePosition
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 interfacePositionConsumer
-
writeBaseUri
-
beginComment
public void beginComment() -
endComment
public void endComment() -
writeComment
-
writeComment
public void writeComment(char[] chars, int offset, int length) - Specified by:
writeComment
in interfaceXConsumer
- Overrides:
writeComment
in classPrintConsumer
-
writeCDATA
public void writeCDATA(char[] chars, int offset, int length) - Specified by:
writeCDATA
in interfaceXConsumer
- Overrides:
writeCDATA
in classPrintConsumer
-
writeProcessingInstruction
- Specified by:
writeProcessingInstruction
in interfaceXConsumer
- Overrides:
writeProcessingInstruction
in classPrintConsumer
-
writePosition
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:
writePosition
in interfacePositionConsumer
-
error
-