Warning
this utility currently does not declare XML Namespaces.
Utility class used by XmlLogger and
org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter
XMLJUnitResultFormatter}.
| Modifier and Type | Class and Description |
|---|---|
| public static class | DOMElementWriter.
Whether namespaces should be ignored for elements and attributes. |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| protected String[] | knownEntities
Don't try to be too smart but at least recognize the predefined entities. |
| private DOMElementWriter. | namespacePolicy
XML Namespaces are ignored by default. |
| private int | nextPrefix
Number of generated prefix to use next. |
| private static final String | NS
prefix for generated prefixes |
| private Map | nsPrefixMap
Map (URI to prefix) of known namespaces. |
| private Map | nsURIByElement
Map (Element to URI) of namespaces defined on a given element. |
| private static final String[] | |
| private boolean | xmlDeclaration
xml declaration is on by default |
| Access | Constructor and Description |
|---|---|
| public | |
| public | DOMElementWriter(boolean
flag to indicate whether the ?xml? declaration
should be included. xmlDeclaration)Create an element writer XML namespaces will be ignored. |
| public | DOMElementWriter(boolean
flag to indicate whether the ?xml? declaration
should be included. xmlDeclaration, DOMElementWriter.the policy to use. namespacePolicyCreate an element writer XML namespaces will be ignored. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | closeElement(Element
the Root DOM element of the tree element, Writer where to send the output out, int number of indent, String string that should be used to indent the
corresponding tag. indentWith, boolean if true indent. hasChildren)Writes a DOM tree to a stream. |
| public String | |
| private String | |
| public String | Returns: the encoded string.the string to encode. value)Escape <, >, &, ', " as their entities, \n, \r and \t as numeric entities and drop characters that are illegal in XML documents. |
| public String | Returns: the encoded value.the value to be encoded. value)Drop characters that are illegal in XML documents. |
| public void | encodedata(final Writer
where to write the encoded data to. out, final String the value to be encoded. value)Drop characters that are illegal in XML documents and write the rest to the given writer. |
| private static String | |
| public boolean | Returns: true if the character is allowed.the character to test. c)Is the given character allowed inside an XML document? |
| public static boolean | Returns: true if the character is allowed.the character to test. c)Is the given character allowed inside an XML document? |
| public boolean | Returns: true if it is an entity.the value to be checked. ent)Is the given argument a character or entity reference? |
| public void | openElement(Element
the DOM element to write element, Writer where to send the output out, int number of indent, String string that should be used to indent the
corresponding tag. indentWith)Writes the opening tag - including all attributes - corresponding to a DOM element. |
| public void | openElement(Element
the DOM element to write element, Writer where to send the output out, int number of indent, String string that should be used to indent the
corresponding tag. indentWith, boolean whether this element has children. hasChildren)Writes the opening tag - including all attributes - corresponding to a DOM element. |
| private void | |
| public void | write(Element
the root element of the DOM tree. root, OutputStream the outputstream to write to. out)Writes a DOM tree to a stream in UTF8 encoding. |
| public void | |
| public void | writeXMLDeclaration(Writer
the writer to write to. wri)Writes the XML declaration if xmlDeclaration is true. |
| HEX | back to summary |
|---|---|
| private static final int HEX | |
| knownEntities | back to summary |
|---|---|
| protected String[] knownEntities Don't try to be too smart but at least recognize the predefined entities. | |
| namespacePolicy | back to summary |
|---|---|
| private DOMElementWriter. XML Namespaces are ignored by default. | |
| nextPrefix | back to summary |
|---|---|
| private int nextPrefix Number of generated prefix to use next. | |
| NS | back to summary |
|---|---|
| private static final String NS prefix for generated prefixes | |
| nsPrefixMap | back to summary |
|---|---|
| private Map<String, String> nsPrefixMap Map (URI to prefix) of known namespaces. | |
| nsURIByElement | back to summary |
|---|---|
| private Map<Element, List<String>> nsURIByElement Map (Element to URI) of namespaces defined on a given element. | |
| WS_ENTITIES | back to summary |
|---|---|
| private static final String[] WS_ENTITIES | |
| xmlDeclaration | back to summary |
|---|---|
| private boolean xmlDeclaration xml declaration is on by default | |
| DOMElementWriter | back to summary |
|---|---|
| public DOMElementWriter() Create an element writer. The ?xml? declaration will be included, namespaces ignored. | |
| DOMElementWriter | back to summary |
|---|---|
| public DOMElementWriter(boolean xmlDeclaration) Create an element writer XML namespaces will be ignored.
| |
| DOMElementWriter | back to summary |
|---|---|
| public DOMElementWriter(boolean xmlDeclaration, DOMElementWriter. Create an element writer XML namespaces will be ignored.
| |
| addNSDefinition | back to summary |
|---|---|
| private void addNSDefinition(Element element, String uri) | |
| closeElement | back to summary |
|---|---|
| public void closeElement(Element element, Writer out, int indent, String indentWith, boolean hasChildren) throws IOException Writes a DOM tree to a stream.
| |
| encode | back to summary |
|---|---|
| public String encode(String value) Escape <, >, &, ', " as their entities and drop characters that are illegal in XML documents. | |
| encode | back to summary |
|---|---|
| private String encode(final String value, final boolean encodeWhitespace) | |
| encodeAttributeValue | back to summary |
|---|---|
| public String encodeAttributeValue(String value) Escape <, >, &, ', " as their entities, \n, \r and \t as numeric entities and drop characters that are illegal in XML documents. | |
| encodedata | back to summary |
|---|---|
| public String encodedata(final String value) Drop characters that are illegal in XML documents. Also ensure that we are not including an See XML 1.0 2.2 https://www.w3.org/TR/1998/REC-xml-19980210#charsets and 2.7 https://www.w3.org/TR/1998/REC-xml-19980210#sec-cdata-sect. | |
| encodedata | back to summary |
|---|---|
| public void encodedata(final Writer out, final String value) throws IOException Drop characters that are illegal in XML documents and write the rest to the given writer. Also ensure that we are not including an See XML 1.0 2.2 https://www.w3.org/TR/1998/REC-xml-19980210#charsets and 2.7 https://www.w3.org/TR/1998/REC-xml-19980210#sec-cdata-sect.
| |
| getNamespaceURI | back to summary |
|---|---|
| private static String getNamespaceURI(Node n) | |
| isLegalCharacter | back to summary |
|---|---|
| public boolean isLegalCharacter(final char c) Is the given character allowed inside an XML document? See XML 1.0 2.2 https://www.w3.org/TR/1998/REC-xml-19980210#charsets.
| |
| isLegalXmlCharacter | back to summary |
|---|---|
| public static boolean isLegalXmlCharacter(final char c) Is the given character allowed inside an XML document? See XML 1.0 2.2 https://www.w3.org/TR/1998/REC-xml-19980210#charsets.
| |
| isReference | back to summary |
|---|---|
| public boolean isReference(String ent) Is the given argument a character or entity reference?
| |
| openElement | back to summary |
|---|---|
| public void openElement(Element element, Writer out, int indent, String indentWith) throws IOException Writes the opening tag - including all attributes - corresponding to a DOM element.
| |
| openElement | back to summary |
|---|---|
| public void openElement(Element element, Writer out, int indent, String indentWith, boolean hasChildren) throws IOException Writes the opening tag - including all attributes - corresponding to a DOM element.
| |
| removeNSDefinitions | back to summary |
|---|---|
| private void removeNSDefinitions(Element element) | |
| write | back to summary |
|---|---|
| public void write(Element root, OutputStream out) throws IOException Writes a DOM tree to a stream in UTF8 encoding. Note that it prepends the <?xml version='1.0' encoding='UTF-8'?> if the xmlDeclaration field is true. The indent number is set to 0 and a 2-space indent.
| |
| write | back to summary |
|---|---|
| public void write(Element element, Writer out, int indent, String indentWith) throws IOException Writes a DOM tree to a stream.
| |
| writeXMLDeclaration | back to summary |
|---|---|
| public void writeXMLDeclaration(Writer wri) throws IOException Writes the XML declaration if xmlDeclaration is true.
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final DOMElementWriter. | IGNORE
Ignores namespaces for elements and attributes, the default. |
| public static final DOMElementWriter. | ONLY_QUALIFY_ELEMENTS
Ignores namespaces for attributes. |
| public static final DOMElementWriter. | QUALIFY_ALL
Qualifies namespaces for elements and attributes. |
| private boolean | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | XmlNamespacePolicy(boolean
whether to qualify elements qualifyElements, boolean whether to qualify elements qualifyAttributes)
|
| IGNORE | back to summary |
|---|---|
| public static final DOMElementWriter. Ignores namespaces for elements and attributes, the default. | |
| ONLY_QUALIFY_ELEMENTS | back to summary |
|---|---|
| public static final DOMElementWriter. Ignores namespaces for attributes. | |
| QUALIFY_ALL | back to summary |
|---|---|
| public static final DOMElementWriter. Qualifies namespaces for elements and attributes. | |
| qualifyAttributes | back to summary |
|---|---|
| private boolean qualifyAttributes | |
| qualifyElements | back to summary |
|---|---|
| private boolean qualifyElements | |
| XmlNamespacePolicy | back to summary |
|---|---|
public XmlNamespacePolicy(boolean qualifyElements, boolean qualifyAttributes)
| |