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 int
LINE_UNIX
static int
LINE_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 boolean
abbreviationDefined(String abbreviation)
void
anchor(String name)
void
attribute(String name, String value)
void
attribute(String name, String value, boolean onlyIfNotEmpty)
void
attribute(String namespace, String name, String value)
void
attribute(String namespace, String name, String value, boolean onlyIfNotEmpty)
void
attributeNoLines(String name, String value)
void
cData(String text)
void
close()
void
comment(String comment, boolean doPretty)
protected void
commitAttributes()
protected boolean
condition(boolean bTest, String message)
void
decorate(ElementDecoration element)
void
element(String name)
void
element(String name, String content)
void
element(String name, String content, boolean onlyIfNotEmpty)
void
element(String namespace, String name, String content)
void
element(String namespace, String name, String content, boolean onlyIfNotEmpty)
void
element(String namespace, String name, String content, String comment)
void
end()
void
endCommentBlock()
void
enter(String name)
void
enter(String namespace, String name)
void
enter(String namespace, String name, String comment)
void
escapedText(String content)
void
exit()
void
exit(String name)
void
exit(String namespace, String name)
void
exitToLevel(int count)
XMLNamespace
findByAbbreviation(String abbreviation)
XMLNamespace
findByNamespace(String namespace)
protected XMLNamespace
findDefaultNamespace()
protected String
getAttribute(String name)
int
getAttributeLineWrap()
String
getDefaultNamespace()
int
getLineType()
String[]
getSpecialAttributeNames()
static String
getXMLCharsetName(String charset)
Returns the encoding.boolean
isPretty()
boolean
isPrettyHeader()
boolean
isSortAttributes()
boolean
isXmlHeader()
void
link(String href)
void
namespace(String namespace)
void
namespace(String namespace, String abbreviation)
boolean
namespaceDefined(String namespace)
void
processingInstruction(String value)
protected void
setAttribute(String name, String value)
void
setAttributeLineWrap(int attributeLineWrap)
void
setDefaultNamespace(String namespace)
void
setLineType(int lineType)
void
setPretty(boolean pretty)
void
setPrettyHeader(boolean pretty)
void
setSchemaLocation(String ns, String loc)
void
setSortAttributes(boolean sortAttributes)
void
setSpecialAttributeNames(String[] specialAttributeNames)
void
setXmlHeader(boolean xmlHeader)
void
start()
void
startCommentBlock()
Start comment inserts a so the comment doesn't close prematurely.void
text(String content)
void
text(String content, boolean dontEscape)
void
writeBytes(byte[] bytes)
int
writePretty()
int
writePretty(boolean eoln)
protected String
xmlEscape(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:
start
in 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:
attribute
in interfaceIXMLWriter
- Throws:
IOException
-
attribute
public void attribute(String namespace, String name, String value) throws IOException
- Specified by:
attribute
in interfaceIXMLWriter
- Throws:
IOException
-
attribute
public void attribute(String name, String value, boolean onlyIfNotEmpty) throws IOException
- Specified by:
attribute
in interfaceIXMLWriter
- Throws:
IOException
-
attribute
public void attribute(String name, String value) throws IOException
- Specified by:
attribute
in interfaceIXMLWriter
- Throws:
IOException
-
attributeNoLines
public void attributeNoLines(String name, String value) throws IOException
- Specified by:
attributeNoLines
in interfaceIXMLWriter
- Throws:
IOException
-
findByNamespace
public XMLNamespace findByNamespace(String namespace)
-
namespaceDefined
public boolean namespaceDefined(String namespace)
- Specified by:
namespaceDefined
in interfaceIXMLWriter
-
findByAbbreviation
public XMLNamespace findByAbbreviation(String abbreviation)
-
abbreviationDefined
public boolean abbreviationDefined(String abbreviation)
- Specified by:
abbreviationDefined
in interfaceIXMLWriter
-
findDefaultNamespace
protected XMLNamespace findDefaultNamespace()
-
getDefaultNamespace
public String getDefaultNamespace()
- Specified by:
getDefaultNamespace
in interfaceIXMLWriter
-
namespace
public void namespace(String namespace) throws IOException
- Specified by:
namespace
in interfaceIXMLWriter
- Throws:
IOException
-
setDefaultNamespace
public void setDefaultNamespace(String namespace) throws IOException
- Specified by:
setDefaultNamespace
in interfaceIXMLWriter
- Throws:
IOException
-
namespace
public void namespace(String namespace, String abbreviation) throws IOException
- Specified by:
namespace
in interfaceIXMLWriter
- Throws:
IOException
-
comment
public void comment(String comment, boolean doPretty) throws IOException
- Specified by:
comment
in interfaceIXMLWriter
- Throws:
IOException
-
enter
public void enter(String namespace, String name) throws IOException
- Specified by:
enter
in interfaceIXMLWriter
- Throws:
IOException
-
enter
public void enter(String namespace, String name, String comment) throws IOException
- Specified by:
enter
in interfaceIXMLWriter
- Throws:
IOException
-
exit
public void exit(String name) throws IOException
- Specified by:
exit
in interfaceIXMLWriter
- Throws:
IOException
-
exit
public void exit(String namespace, String name) throws IOException
- Specified by:
exit
in interfaceIXMLWriter
- Throws:
IOException
-
exitToLevel
public void exitToLevel(int count) throws IOException
- Specified by:
exitToLevel
in interfaceIXMLWriter
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStreamWriter
- Throws:
IOException
-
end
public void end() throws IOException
- Specified by:
end
in interfaceIXMLWriter
- Throws:
IOException
-
exit
public void exit() throws IOException
- Specified by:
exit
in interfaceIXMLWriter
- Throws:
IOException
-
enter
public void enter(String name) throws IOException
- Specified by:
enter
in interfaceIXMLWriter
- Throws:
IOException
-
element
public void element(String namespace, String name, String content, boolean onlyIfNotEmpty) throws IOException
- Specified by:
element
in interfaceIXMLWriter
- Throws:
IOException
-
element
public void element(String namespace, String name, String content, String comment) throws IOException
- Specified by:
element
in interfaceIXMLWriter
- Throws:
IOException
-
element
public void element(String namespace, String name, String content) throws IOException
- Specified by:
element
in interfaceIXMLWriter
- Throws:
IOException
-
element
public void element(String name, String content, boolean onlyIfNotEmpty) throws IOException
- Specified by:
element
in interfaceIXMLWriter
- Throws:
IOException
-
element
public void element(String name, String content) throws IOException
- Specified by:
element
in interfaceIXMLWriter
- Throws:
IOException
-
element
public void element(String name) throws IOException
- Specified by:
element
in interfaceIXMLWriter
- Throws:
IOException
-
text
public void text(String content) throws IOException
- Specified by:
text
in interfaceIXMLWriter
- Throws:
IOException
-
text
public void text(String content, boolean dontEscape) throws IOException
- Specified by:
text
in interfaceIXMLWriter
- Throws:
IOException
-
cData
public void cData(String text) throws IOException
- Specified by:
cData
in interfaceIXMLWriter
- Throws:
IOException
-
writeBytes
public void writeBytes(byte[] bytes) throws IOException
- Specified by:
writeBytes
in interfaceIXMLWriter
- Throws:
IOException
-
isPretty
public boolean isPretty() throws IOException
- Specified by:
isPretty
in interfaceIXMLWriter
- Throws:
IOException
-
setPretty
public void setPretty(boolean pretty) throws IOException
- Specified by:
setPretty
in interfaceIXMLWriter
- Throws:
IOException
-
startCommentBlock
public void startCommentBlock() throws IOException
Description copied from interface:IXMLWriter
Start comment inserts a so the comment doesn't close prematurely.- Specified by:
startCommentBlock
in interfaceIXMLWriter
- Throws:
IOException
-
endCommentBlock
public void endCommentBlock() throws IOException
- Specified by:
endCommentBlock
in 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:
escapedText
in interfaceIXMLWriter
- Throws:
IOException
-
processingInstruction
public void processingInstruction(String value) throws IOException
- Throws:
IOException
-
link
public void link(String href)
- Specified by:
link
in interfaceIXMLWriter
-
anchor
public void anchor(String name)
- Specified by:
anchor
in interfaceIXMLWriter
-
decorate
public void decorate(ElementDecoration element) throws IOException
- Specified by:
decorate
in interfaceIXMLWriter
- Throws:
IOException
-
setSchemaLocation
public void setSchemaLocation(String ns, String loc) throws IOException
- Specified by:
setSchemaLocation
in interfaceIXMLWriter
- Throws:
IOException
-
-