Package org.testng.reporters
Class XMLStringBuffer
- java.lang.Object
-
- org.testng.reporters.XMLStringBuffer
-
public class XMLStringBuffer extends java.lang.ObjectThis class allows you to generate an XML text document by pushing and popping tags from a stack maintained internally.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringDEFAULT_INDENT_INCREMENTTab space indent for XML documentprivate java.lang.StringdefaultCommentstatic java.lang.StringEOLEnd of line, value of 'line.separator' system property or '\n'private static java.util.regex.PatternINVALID_XML_CHARSprivate IBufferm_bufferThe buffer to hold the xml documentprivate java.lang.Stringm_currentIndentA string of space character representing the current indentation.private java.util.Stack<Tag>m_tagStackThe stack of tags to make sure XML document is well formed.
-
Constructor Summary
Constructors Constructor Description XMLStringBuffer()XMLStringBuffer(java.lang.String start)XMLStringBuffer(IBuffer buffer, java.lang.String start)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCDATA(java.lang.String content)voidaddComment(java.lang.String comment)voidaddEmptyElement(java.lang.String tagName)Add an empty element tag (e.g.voidaddEmptyElement(java.lang.String tagName, java.lang.String... attributes)voidaddEmptyElement(java.lang.String tagName, java.util.Properties attributes)Add an empty element tag (e.g.voidaddOptional(java.lang.String tagName, java.lang.Boolean value)Add an optional Boolean element to the current tag.voidaddOptional(java.lang.String tagName, java.lang.Boolean value, java.util.Properties attributes)Add an optional Boolean element to the current tag.voidaddOptional(java.lang.String tagName, java.lang.String value)Add an optional String element to the current tag.voidaddOptional(java.lang.String tagName, java.lang.String value, java.lang.String... attributes)voidaddOptional(java.lang.String tagName, java.lang.String value, java.util.Properties attributes)Add an optional String element to the current tag.voidaddRequired(java.lang.String tagName, java.lang.String value)Add a required element to the current tag.voidaddRequired(java.lang.String tagName, java.lang.String value, java.lang.String... attributes)voidaddRequired(java.lang.String tagName, java.lang.String value, java.util.Properties attributes)Add a required element to the current tag.voidaddString(java.lang.String s)private java.util.PropertiescreateProperties(java.lang.String[] attributes)java.lang.StringgetCurrentIndent()IBuffergetStringBuffer()private voidinit(IBuffer buffer, java.lang.String start)private voidinit(IBuffer buffer, java.lang.String start, java.lang.String version, java.lang.String encoding)voidpop()Pop the last pushed element without verifying it if matches the previously pushed tag.voidpop(java.lang.String tagName)Pop the last pushed element and throws an AssertionError if it doesn't match the corresponding tag that was pushed earlier.voidpush(java.lang.String tagName)Push a new tag.voidpush(java.lang.String tagName, java.lang.String schema)Push a new tag.voidpush(java.lang.String tagName, java.lang.String... attributes)voidpush(java.lang.String tagName, java.lang.String schema, java.util.Properties attributes)Push a new tag.voidpush(java.lang.String tagName, java.util.Properties attributes)Push a new tag.voidsetDefaultComment(java.lang.String defaultComment)voidsetDocType(java.lang.String docType)Set the doctype for this document.voidsetXmlDetails(java.lang.String v, java.lang.String enc)Set the xml version and encoding for this document.voidtoWriter(java.io.Writer fw)java.lang.StringtoXML()
-
-
-
Field Detail
-
EOL
public static final java.lang.String EOL
End of line, value of 'line.separator' system property or '\n'
-
DEFAULT_INDENT_INCREMENT
private static final java.lang.String DEFAULT_INDENT_INCREMENT
Tab space indent for XML document- See Also:
- Constant Field Values
-
m_buffer
private IBuffer m_buffer
The buffer to hold the xml document
-
m_tagStack
private final java.util.Stack<Tag> m_tagStack
The stack of tags to make sure XML document is well formed.
-
m_currentIndent
private java.lang.String m_currentIndent
A string of space character representing the current indentation.
-
defaultComment
private java.lang.String defaultComment
-
INVALID_XML_CHARS
private static final java.util.regex.Pattern INVALID_XML_CHARS
-
-
Constructor Detail
-
XMLStringBuffer
public XMLStringBuffer()
-
XMLStringBuffer
public XMLStringBuffer(java.lang.String start)
- Parameters:
start- A string of spaces indicating the indentation at which to start the generation. This constructor will not insert an<?xmlprologue.
-
XMLStringBuffer
public XMLStringBuffer(IBuffer buffer, java.lang.String start)
- Parameters:
buffer- The StringBuffer to use internally to represent the document.start- A string of spaces indicating the indentation at which to start the generation.
-
-
Method Detail
-
init
private void init(IBuffer buffer, java.lang.String start)
-
init
private void init(IBuffer buffer, java.lang.String start, @Nullable java.lang.String version, @Nullable java.lang.String encoding)
- Parameters:
start- A string of spaces indicating the indentation at which to start the generation.
-
setXmlDetails
public void setXmlDetails(java.lang.String v, java.lang.String enc)Set the xml version and encoding for this document.- Parameters:
v- the XML versionenc- the XML encoding
-
setDocType
public void setDocType(java.lang.String docType)
Set the doctype for this document.- Parameters:
docType- The DOCTYPE string, without the "<!DOCTYPE " ">"
-
push
public void push(java.lang.String tagName, @Nullable java.lang.String schema, @Nullable java.util.Properties attributes)Push a new tag. Its value is stored and will be compared against the parameter passed to pop().- Parameters:
tagName- The name of the tag.schema- The schema to use (can be null or an empty string).attributes- A Properties file representing the attributes (or null)
-
push
public void push(java.lang.String tagName, @Nullable java.lang.String schema)Push a new tag. Its value is stored and will be compared against the parameter passed to pop().- Parameters:
tagName- The name of the tag.schema- The schema to use (can be null or an empty string).
-
push
public void push(java.lang.String tagName, @Nullable java.util.Properties attributes)Push a new tag. Its value is stored and will be compared against the parameter passed to pop().- Parameters:
tagName- The name of the tag.attributes- A Properties file representing the attributes (or null)
-
push
public void push(java.lang.String tagName, java.lang.String... attributes)
-
createProperties
private java.util.Properties createProperties(java.lang.String[] attributes)
-
push
public void push(java.lang.String tagName)
Push a new tag. Its value is stored and will be compared against the parameter passed to pop().- Parameters:
tagName- The name of the tag.
-
pop
public void pop()
Pop the last pushed element without verifying it if matches the previously pushed tag.
-
pop
public void pop(java.lang.String tagName)
Pop the last pushed element and throws an AssertionError if it doesn't match the corresponding tag that was pushed earlier.- Parameters:
tagName- The name of the tag this pop() is supposed to match.
-
addRequired
public void addRequired(java.lang.String tagName, @Nullable java.lang.String value)Add a required element to the current tag. An opening and closing tag will be generated even if value is null.- Parameters:
tagName- The name of the tagvalue- The value for this tag
-
addRequired
public void addRequired(java.lang.String tagName, @Nullable java.lang.String value, @Nullable java.util.Properties attributes)Add a required element to the current tag. An opening and closing tag will be generated even if value is null.- Parameters:
tagName- The name of the tagvalue- The value for this tagattributes- A Properties file containing the attributes (or null)
-
addRequired
public void addRequired(java.lang.String tagName, @Nullable java.lang.String value, java.lang.String... attributes)
-
addOptional
public void addOptional(java.lang.String tagName, @Nullable java.lang.String value, @Nullable java.util.Properties attributes)Add an optional String element to the current tag. If value is null, nothing is added.- Parameters:
tagName- The name of the tagvalue- The value for this tagattributes- A Properties file containing the attributes (or null)
-
addOptional
public void addOptional(java.lang.String tagName, @Nullable java.lang.String value, java.lang.String... attributes)
-
addOptional
public void addOptional(java.lang.String tagName, @Nullable java.lang.String value)Add an optional String element to the current tag. If value is null, nothing is added.- Parameters:
tagName- The name of the tagvalue- The value for this tag
-
addOptional
public void addOptional(java.lang.String tagName, @Nullable java.lang.Boolean value, @Nullable java.util.Properties attributes)Add an optional Boolean element to the current tag. If value is null, nothing is added.- Parameters:
tagName- The name of the tagvalue- The value for this tagattributes- A Properties file containing the attributes (or null)
-
addOptional
public void addOptional(java.lang.String tagName, @Nullable java.lang.Boolean value)Add an optional Boolean element to the current tag. If value is null, nothing is added.- Parameters:
tagName- The name of the tagvalue- The value for this tag
-
addEmptyElement
public void addEmptyElement(java.lang.String tagName)
Add an empty element tag (e.g.<foo/>)- Parameters:
tagName- The name of the tag
-
addEmptyElement
public void addEmptyElement(java.lang.String tagName, @Nullable java.util.Properties attributes)Add an empty element tag (e.g.>foo/<)- Parameters:
tagName- The name of the tagattributes- A Properties file containing the attributes (or null)
-
addEmptyElement
public void addEmptyElement(java.lang.String tagName, java.lang.String... attributes)
-
addComment
public void addComment(java.lang.String comment)
-
addString
public void addString(java.lang.String s)
-
setDefaultComment
public void setDefaultComment(java.lang.String defaultComment)
-
addCDATA
public void addCDATA(java.lang.String content)
-
getStringBuffer
public IBuffer getStringBuffer()
- Returns:
- The StringBuffer used to create the document.
-
toXML
public java.lang.String toXML()
- Returns:
- The String representation of the XML for this XMLStringBuffer.
-
getCurrentIndent
public java.lang.String getCurrentIndent()
-
toWriter
public void toWriter(java.io.Writer fw)
-
-