Top Description Fields Constructors Methods
org.testng.reporters

public Class XMLStringBuffer

Additional top-level class in compilation unit: Tag.

extends Object
Class Inheritance
Imports
java.io.Writer, java.util.Properties, .Stack, java.util.regex.Pattern, javax.annotation.Nullable

This class allows you to generate an XML text document by pushing and popping tags from a stack maintained internally.
Author
Cedric Beust Jul 21, 2003

Field Summary

Modifier and TypeField and Description
private static final String
DEFAULT_INDENT_INCREMENT

Tab space indent for XML document

private String
public static final String
EOL

End of line, value of 'line.separator' system property or '\n'

private static final Pattern
private IBuffer
m_buffer

The buffer to hold the xml document

private String
m_currentIndent

A string of space character representing the current indentation.

private final Stack<Tag>
m_tagStack

The stack of tags to make sure XML document is well formed.

Constructor Summary

AccessConstructor and Description
public
public
XMLStringBuffer(String
A string of spaces indicating the indentation at which to start the generation. This constructor will not insert an <?xml prologue.
start
)

public
XMLStringBuffer(IBuffer
The StringBuffer to use internally to represent the document.
buffer
,
String
A string of spaces indicating the indentation at which to start the generation.
start
)

Method Summary

Modifier and TypeMethod and Description
public void
addCDATA(String content)

public void
addComment(String comment)

public void
addEmptyElement(String
The name of the tag
tagName
)

Add an empty element tag (e.g. <foo/>)

public void
addEmptyElement(String
The name of the tag
tagName
,
Properties
A Properties file containing the attributes (or null)
attributes
)

Add an empty element tag (e.g. >foo/<)

public void
addEmptyElement(String tagName, String... attributes)

public void
addOptional(String
The name of the tag
tagName
,
String
The value for this tag
value
,
Properties
A Properties file containing the attributes (or null)
attributes
)

Add an optional String element to the current tag.

public void
addOptional(String tagName, String value, String... attributes)

public void
addOptional(String
The name of the tag
tagName
,
String
The value for this tag
value
)

Add an optional String element to the current tag.

public void
addOptional(String
The name of the tag
tagName
,
Boolean
The value for this tag
value
,
Properties
A Properties file containing the attributes (or null)
attributes
)

Add an optional Boolean element to the current tag.

public void
addOptional(String
The name of the tag
tagName
,
Boolean
The value for this tag
value
)

Add an optional Boolean element to the current tag.

public void
addRequired(String
The name of the tag
tagName
,
String
The value for this tag
value
)

Add a required element to the current tag.

public void
addRequired(String
The name of the tag
tagName
,
String
The value for this tag
value
,
Properties
A Properties file containing the attributes (or null)
attributes
)

Add a required element to the current tag.

public void
addRequired(String tagName, String value, String... attributes)

public void
private Properties
createProperties(String[] attributes)

public String
public IBuffer

Returns:

The StringBuffer used to create the document.
getStringBuffer
()

private void
init(IBuffer buffer, String start)

private void
init(IBuffer buffer, String
A string of spaces indicating the indentation at which to start the generation.
start
,
String version, String encoding)

public void
pop()

Pop the last pushed element without verifying it if matches the previously pushed tag.

public void
pop(String
The name of the tag this pop() is supposed to match.
tagName
)

Pop the last pushed element and throws an AssertionError if it doesn't match the corresponding tag that was pushed earlier.

public void
push(String
The name of the tag.
tagName
,
String
The schema to use (can be null or an empty string).
schema
,
Properties
A Properties file representing the attributes (or null)
attributes
)

Push a new tag.

public void
push(String
The name of the tag.
tagName
,
String
The schema to use (can be null or an empty string).
schema
)

Push a new tag.

public void
push(String
The name of the tag.
tagName
,
Properties
A Properties file representing the attributes (or null)
attributes
)

Push a new tag.

public void
push(String tagName, String... attributes)

public void
push(String
The name of the tag.
tagName
)

Push a new tag.

public void
setDefaultComment(String defaultComment)

public void
setDocType(String
The DOCTYPE string, without the "<!DOCTYPE " ">"
docType
)

Set the doctype for this document.

public void
setXmlDetails(String
the XML version
v
,
String
the XML encoding
enc
)

Set the xml version and encoding for this document.

public void
public String

Returns:

The String representation of the XML for this XMLStringBuffer.
toXML
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_INDENT_INCREMENTback to summary
private static final String DEFAULT_INDENT_INCREMENT

Tab space indent for XML document

defaultCommentback to summary
private String defaultComment
EOLback to summary
public static final String EOL

End of line, value of 'line.separator' system property or '\n'

INVALID_XML_CHARSback to summary
private static final Pattern INVALID_XML_CHARS
m_bufferback to summary
private IBuffer m_buffer

The buffer to hold the xml document

m_currentIndentback to summary
private String m_currentIndent

A string of space character representing the current indentation.

m_tagStackback to summary
private final Stack<Tag> m_tagStack

The stack of tags to make sure XML document is well formed.

Constructor Detail

XMLStringBufferback to summary
public XMLStringBuffer()
XMLStringBufferback to summary
public XMLStringBuffer(String start)
Parameters
start:String

A string of spaces indicating the indentation at which to start the generation. This constructor will not insert an <?xml prologue.

XMLStringBufferback to summary
public XMLStringBuffer(IBuffer buffer, String start)
Parameters
buffer:IBuffer

The StringBuffer to use internally to represent the document.

start:String

A string of spaces indicating the indentation at which to start the generation.

Method Detail

addCDATAback to summary
public void addCDATA(String content)
addCommentback to summary
public void addComment(String comment)
addEmptyElementback to summary
public void addEmptyElement(String tagName)

Add an empty element tag (e.g. <foo/>)

Parameters
tagName:String

The name of the tag

addEmptyElementback to summary
public void addEmptyElement(String tagName, Properties attributes)

Add an empty element tag (e.g. >foo/<)

Parameters
tagName:String

The name of the tag

attributes:Properties

A Properties file containing the attributes (or null)

addEmptyElementback to summary
public void addEmptyElement(String tagName, String... attributes)
addOptionalback to summary
public void addOptional(String tagName, String value, Properties attributes)

Add an optional String element to the current tag. If value is null, nothing is added.

Parameters
tagName:String

The name of the tag

value:String

The value for this tag

attributes:Properties

A Properties file containing the attributes (or null)

addOptionalback to summary
public void addOptional(String tagName, String value, String... attributes)
addOptionalback to summary
public void addOptional(String tagName, String value)

Add an optional String element to the current tag. If value is null, nothing is added.

Parameters
tagName:String

The name of the tag

value:String

The value for this tag

addOptionalback to summary
public void addOptional(String tagName, Boolean value, Properties attributes)

Add an optional Boolean element to the current tag. If value is null, nothing is added.

Parameters
tagName:String

The name of the tag

value:Boolean

The value for this tag

attributes:Properties

A Properties file containing the attributes (or null)

addOptionalback to summary
public void addOptional(String tagName, Boolean value)

Add an optional Boolean element to the current tag. If value is null, nothing is added.

Parameters
tagName:String

The name of the tag

value:Boolean

The value for this tag

addRequiredback to summary
public void addRequired(String tagName, 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:String

The name of the tag

value:String

The value for this tag

addRequiredback to summary
public void addRequired(String tagName, String value, 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:String

The name of the tag

value:String

The value for this tag

attributes:Properties

A Properties file containing the attributes (or null)

addRequiredback to summary
public void addRequired(String tagName, String value, String... attributes)
addStringback to summary
public void addString(String s)
createPropertiesback to summary
private Properties createProperties(String[] attributes)
getCurrentIndentback to summary
public String getCurrentIndent()
getStringBufferback to summary
public IBuffer getStringBuffer()
Returns:IBuffer

The StringBuffer used to create the document.

initback to summary
private void init(IBuffer buffer, String start)
initback to summary
private void init(IBuffer buffer, String start, String version, String encoding)
Parameters
start:String

A string of spaces indicating the indentation at which to start the generation.

popback to summary
public void pop()

Pop the last pushed element without verifying it if matches the previously pushed tag.

popback to summary
public void pop(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:String

The name of the tag this pop() is supposed to match.

pushback to summary
public void push(String tagName, String schema, Properties attributes)

Push a new tag. Its value is stored and will be compared against the parameter passed to pop().

Parameters
tagName:String

The name of the tag.

schema:String

The schema to use (can be null or an empty string).

attributes:Properties

A Properties file representing the attributes (or null)

pushback to summary
public void push(String tagName, String schema)

Push a new tag. Its value is stored and will be compared against the parameter passed to pop().

Parameters
tagName:String

The name of the tag.

schema:String

The schema to use (can be null or an empty string).

pushback to summary
public void push(String tagName, Properties attributes)

Push a new tag. Its value is stored and will be compared against the parameter passed to pop().

Parameters
tagName:String

The name of the tag.

attributes:Properties

A Properties file representing the attributes (or null)

pushback to summary
public void push(String tagName, String... attributes)
pushback to summary
public void push(String tagName)

Push a new tag. Its value is stored and will be compared against the parameter passed to pop().

Parameters
tagName:String

The name of the tag.

setDefaultCommentback to summary
public void setDefaultComment(String defaultComment)
setDocTypeback to summary
public void setDocType(String docType)

Set the doctype for this document.

Parameters
docType:String

The DOCTYPE string, without the "<!DOCTYPE " ">"

setXmlDetailsback to summary
public void setXmlDetails(String v, String enc)

Set the xml version and encoding for this document.

Parameters
v:String

the XML version

enc:String

the XML encoding

toWriterback to summary
public void toWriter(Writer fw)
toXMLback to summary
public String toXML()
Returns:String

The String representation of the XML for this XMLStringBuffer.