Package org.hl7.fhir.utilities.xml
Class XMLWriter
- java.lang.Object
-
- java.io.Writer
-
- java.io.OutputStreamWriter
-
- org.hl7.fhir.utilities.xml.XMLWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable,IXMLWriter
public class XMLWriter extends OutputStreamWriter implements IXMLWriter
XML Writer class.
-
-
Field Summary
Fields Modifier and Type Field Description static intLINE_UNIXstatic intLINE_WINDOWS
-
Constructor Summary
Constructors Constructor Description XMLWriter(OutputStream stream, String charset)XMLWriter(OutputStream stream, String charset, boolean xml1_1)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanabbreviationDefined(String abbreviation)voidanchor(String name)voidattribute(String name, String value)voidattribute(String name, String value, boolean onlyIfNotEmpty)voidattribute(String namespace, String name, String value)voidattribute(String namespace, String name, String value, boolean onlyIfNotEmpty)voidattributeNoLines(String name, String value)voidcData(String text)voidclose()voidcomment(String comment, boolean doPretty)protected voidcommitAttributes()protected booleancondition(boolean bTest, String message)voiddecorate(ElementDecoration element)voidelement(String name)voidelement(String name, String content)voidelement(String name, String content, boolean onlyIfNotEmpty)voidelement(String namespace, String name, String content)voidelement(String namespace, String name, String content, boolean onlyIfNotEmpty)voidelement(String namespace, String name, String content, String comment)voidend()voidendCommentBlock()voidenter(String name)voidenter(String namespace, String name)voidenter(String namespace, String name, String comment)voidescapedText(String content)voidexit()voidexit(String name)voidexit(String namespace, String name)voidexitToLevel(int count)XMLNamespacefindByAbbreviation(String abbreviation)XMLNamespacefindByNamespace(String namespace)protected XMLNamespacefindDefaultNamespace()protected StringgetAttribute(String name)intgetAttributeLineWrap()StringgetDefaultNamespace()intgetLineType()String[]getSpecialAttributeNames()static StringgetXMLCharsetName(String charset)Returns the encoding.booleanisPretty()booleanisPrettyHeader()booleanisSortAttributes()booleanisXmlHeader()voidlink(String href)voidnamespace(String namespace)voidnamespace(String namespace, String abbreviation)booleannamespaceDefined(String namespace)voidprocessingInstruction(String value)protected voidsetAttribute(String name, String value)voidsetAttributeLineWrap(int attributeLineWrap)voidsetDefaultNamespace(String namespace)voidsetLineType(int lineType)voidsetPretty(boolean pretty)voidsetPrettyHeader(boolean pretty)voidsetSchemaLocation(String ns, String loc)voidsetSortAttributes(boolean sortAttributes)voidsetSpecialAttributeNames(String[] specialAttributeNames)voidsetXmlHeader(boolean xmlHeader)voidstart()voidstartCommentBlock()Start comment inserts a so the comment doesn't close prematurely.voidtext(String content)voidtext(String content, boolean dontEscape)voidwriteBytes(byte[] bytes)intwritePretty()intwritePretty(boolean eoln)protected StringxmlEscape(String s)-
Methods inherited from class java.io.OutputStreamWriter
append, append, flush, getEncoding, write, write, write
-
Methods inherited from class java.io.Writer
append, nullWriter, write, write
-
-
-
-
Field Detail
-
LINE_UNIX
public static final int LINE_UNIX
- See Also:
- Constant Field Values
-
LINE_WINDOWS
public static final int LINE_WINDOWS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XMLWriter
public XMLWriter(OutputStream stream, String charset, boolean xml1_1) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
XMLWriter
public XMLWriter(OutputStream stream, String charset) throws UnsupportedEncodingException
- Throws:
UnsupportedEncodingException
-
-
Method Detail
-
condition
protected boolean condition(boolean bTest, String message) throws IOException
- Throws:
IOException
-
getXMLCharsetName
public static String getXMLCharsetName(String charset) throws IOException
Returns the encoding.- Parameters:
charset-- Returns:
- encoding
- Throws:
IOException
-
start
public void start() throws IOException
- Specified by:
startin interfaceIXMLWriter- Throws:
IOException
-
getAttribute
protected String getAttribute(String name)
-
setAttribute
protected void setAttribute(String name, String value) throws IOException
- Throws:
IOException
-
commitAttributes
protected void commitAttributes() throws IOException
- Throws:
IOException
-
attribute
public void attribute(String namespace, String name, String value, boolean onlyIfNotEmpty) throws IOException
- Specified by:
attributein interfaceIXMLWriter- Throws:
IOException
-
attribute
public void attribute(String namespace, String name, String value) throws IOException
- Specified by:
attributein interfaceIXMLWriter- Throws:
IOException
-
attribute
public void attribute(String name, String value, boolean onlyIfNotEmpty) throws IOException
- Specified by:
attributein interfaceIXMLWriter- Throws:
IOException
-
attribute
public void attribute(String name, String value) throws IOException
- Specified by:
attributein interfaceIXMLWriter- Throws:
IOException
-
attributeNoLines
public void attributeNoLines(String name, String value) throws IOException
- Specified by:
attributeNoLinesin interfaceIXMLWriter- Throws:
IOException
-
findByNamespace
public XMLNamespace findByNamespace(String namespace)
-
namespaceDefined
public boolean namespaceDefined(String namespace)
- Specified by:
namespaceDefinedin interfaceIXMLWriter
-
findByAbbreviation
public XMLNamespace findByAbbreviation(String abbreviation)
-
abbreviationDefined
public boolean abbreviationDefined(String abbreviation)
- Specified by:
abbreviationDefinedin interfaceIXMLWriter
-
findDefaultNamespace
protected XMLNamespace findDefaultNamespace()
-
getDefaultNamespace
public String getDefaultNamespace()
- Specified by:
getDefaultNamespacein interfaceIXMLWriter
-
namespace
public void namespace(String namespace) throws IOException
- Specified by:
namespacein interfaceIXMLWriter- Throws:
IOException
-
setDefaultNamespace
public void setDefaultNamespace(String namespace) throws IOException
- Specified by:
setDefaultNamespacein interfaceIXMLWriter- Throws:
IOException
-
namespace
public void namespace(String namespace, String abbreviation) throws IOException
- Specified by:
namespacein interfaceIXMLWriter- Throws:
IOException
-
comment
public void comment(String comment, boolean doPretty) throws IOException
- Specified by:
commentin interfaceIXMLWriter- Throws:
IOException
-
enter
public void enter(String namespace, String name) throws IOException
- Specified by:
enterin interfaceIXMLWriter- Throws:
IOException
-
enter
public void enter(String namespace, String name, String comment) throws IOException
- Specified by:
enterin interfaceIXMLWriter- Throws:
IOException
-
exit
public void exit(String name) throws IOException
- Specified by:
exitin interfaceIXMLWriter- Throws:
IOException
-
exit
public void exit(String namespace, String name) throws IOException
- Specified by:
exitin interfaceIXMLWriter- Throws:
IOException
-
exitToLevel
public void exitToLevel(int count) throws IOException
- Specified by:
exitToLevelin interfaceIXMLWriter- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStreamWriter- Throws:
IOException
-
end
public void end() throws IOException
- Specified by:
endin interfaceIXMLWriter- Throws:
IOException
-
exit
public void exit() throws IOException
- Specified by:
exitin interfaceIXMLWriter- Throws:
IOException
-
enter
public void enter(String name) throws IOException
- Specified by:
enterin interfaceIXMLWriter- Throws:
IOException
-
element
public void element(String namespace, String name, String content, boolean onlyIfNotEmpty) throws IOException
- Specified by:
elementin interfaceIXMLWriter- Throws:
IOException
-
element
public void element(String namespace, String name, String content, String comment) throws IOException
- Specified by:
elementin interfaceIXMLWriter- Throws:
IOException
-
element
public void element(String namespace, String name, String content) throws IOException
- Specified by:
elementin interfaceIXMLWriter- Throws:
IOException
-
element
public void element(String name, String content, boolean onlyIfNotEmpty) throws IOException
- Specified by:
elementin interfaceIXMLWriter- Throws:
IOException
-
element
public void element(String name, String content) throws IOException
- Specified by:
elementin interfaceIXMLWriter- Throws:
IOException
-
element
public void element(String name) throws IOException
- Specified by:
elementin interfaceIXMLWriter- Throws:
IOException
-
text
public void text(String content) throws IOException
- Specified by:
textin interfaceIXMLWriter- Throws:
IOException
-
text
public void text(String content, boolean dontEscape) throws IOException
- Specified by:
textin interfaceIXMLWriter- Throws:
IOException
-
cData
public void cData(String text) throws IOException
- Specified by:
cDatain interfaceIXMLWriter- Throws:
IOException
-
writeBytes
public void writeBytes(byte[] bytes) throws IOException
- Specified by:
writeBytesin interfaceIXMLWriter- Throws:
IOException
-
isPretty
public boolean isPretty() throws IOException
- Specified by:
isPrettyin interfaceIXMLWriter- Throws:
IOException
-
setPretty
public void setPretty(boolean pretty) throws IOException
- Specified by:
setPrettyin interfaceIXMLWriter- Throws:
IOException
-
startCommentBlock
public void startCommentBlock() throws IOException
Description copied from interface:IXMLWriterStart comment inserts a so the comment doesn't close prematurely.- Specified by:
startCommentBlockin interfaceIXMLWriter- Throws:
IOException
-
endCommentBlock
public void endCommentBlock() throws IOException
- Specified by:
endCommentBlockin interfaceIXMLWriter- Throws:
IOException
-
isSortAttributes
public boolean isSortAttributes()
-
setSortAttributes
public void setSortAttributes(boolean sortAttributes)
-
isPrettyHeader
public boolean isPrettyHeader()
-
setPrettyHeader
public void setPrettyHeader(boolean pretty)
-
writePretty
public int writePretty() throws IOException
- Throws:
IOException
-
writePretty
public int writePretty(boolean eoln) throws IOException
- Throws:
IOException
-
getLineType
public int getLineType()
-
setLineType
public void setLineType(int lineType)
-
isXmlHeader
public boolean isXmlHeader()
-
setXmlHeader
public void setXmlHeader(boolean xmlHeader)
-
getSpecialAttributeNames
public String[] getSpecialAttributeNames()
-
setSpecialAttributeNames
public void setSpecialAttributeNames(String[] specialAttributeNames)
-
getAttributeLineWrap
public int getAttributeLineWrap()
-
setAttributeLineWrap
public void setAttributeLineWrap(int attributeLineWrap)
-
escapedText
public void escapedText(String content) throws IOException
- Specified by:
escapedTextin interfaceIXMLWriter- Throws:
IOException
-
processingInstruction
public void processingInstruction(String value) throws IOException
- Throws:
IOException
-
link
public void link(String href)
- Specified by:
linkin interfaceIXMLWriter
-
anchor
public void anchor(String name)
- Specified by:
anchorin interfaceIXMLWriter
-
decorate
public void decorate(ElementDecoration element) throws IOException
- Specified by:
decoratein interfaceIXMLWriter- Throws:
IOException
-
setSchemaLocation
public void setSchemaLocation(String ns, String loc) throws IOException
- Specified by:
setSchemaLocationin interfaceIXMLWriter- Throws:
IOException
-
-