Top Description Inners Fields Constructors Methods
org.jboss.logmanager.formatters

public Class XmlFormatter

extends StructuredFormatter
Class Inheritance
Annotations
@SuppressWarnings:WeakerAccess, unused, SameParameterValue
Imports
java.io.Writer, java.util.Map, javax.xml.stream.XMLOutputFactory, .XMLStreamException, .XMLStreamWriter, org.jboss.logmanager.PropertyValues

A formatter that outputs the record in XML format.

The details include;

Author
James R. Perkins

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
public static final String
private final XMLOutputFactory
private volatile String
private volatile boolean
private volatile boolean

Constructor Summary

AccessConstructor and Description
public
XmlFormatter()

Creates a new XML formatter.

public
XmlFormatter(final String
a string representation of a map to override keys
keyOverrides
)

Creates a new XML formatter.

public
XmlFormatter(final Map<StructuredFormatter.Key, String>
a map of overrides for the default keys
keyOverrides
)

Creates a new XML formatter.

Method Summary

Modifier and TypeMethod and Description
protected StructuredFormatter.Generator
createGenerator(final Writer writer)

Implements abstract org.jboss.logmanager.formatters.StructuredFormatter.createGenerator.

Creates the generator used to create the structured data.

public String

Returns:

the namespace URI, may be null if explicitly set to null
getNamespaceUri
()

Returns the namespace URI used for each record if isPrintNamespace() is true.

public boolean

Returns:

true if pretty printing is enabled, otherwise false
isPrettyPrint
()

Indicates whether or not pretty printing is enabled.

public boolean

Returns:

true if the name space should be written for each record
isPrintNamespace
()

Indicates whether or not the name space should be written on the <record/>.

public void
setNamespaceUri(final String
the namespace to use or null if no namespace URI should be used regardless of the isPrintNamespace() value
namespaceUri
)

Sets the namespace URI used for each record if isPrintNamespace() is true.

public void
setPrettyPrint(final boolean
true to turn on pretty printing or false to turn it off
prettyPrint
)

Turns on or off pretty printing.

public void
setPrintNamespace(final boolean
true if the name space should be written for each record
printNamespace
)

Turns on or off the printing of the namespace for each <record/>.

Inherited from org.jboss.logmanager.formatters.StructuredFormatter:
afterbeforeformatgetDateTimeFormattergetExceptionOutputTypegetKeygetKeyOverridesgetMetaDatagetRecordDelimitergetZoneIdisCallerCalculationRequiredisDetailedExceptionOutputTypeisFormattedExceptionOutputTypeisPrintDetailssetDateFormatsetExceptionOutputTypesetMetaDatasetPrintDetailssetRecordDelimitersetZoneId

Field Detail

DEFAULT_NAMESPACEback to summary
public static final String DEFAULT_NAMESPACE
factoryback to summary
private final XMLOutputFactory factory
namespaceUriback to summary
private volatile String namespaceUri
prettyPrintback to summary
private volatile boolean prettyPrint
printNamespaceback to summary
private volatile boolean printNamespace

Constructor Detail

XmlFormatterback to summary
public XmlFormatter()

Creates a new XML formatter.

XmlFormatterback to summary
public XmlFormatter(final String keyOverrides)

Creates a new XML formatter.

If the keyOverrides is empty the default namespace will be used.

Parameters
keyOverrides:String

a string representation of a map to override keys

See Also
PropertyValues#stringToEnumMap(Class, String)
XmlFormatterback to summary
public XmlFormatter(final Map<StructuredFormatter.Key, String> keyOverrides)

Creates a new XML formatter.

If the keyOverrides is empty the default namespace will be used.

Parameters
keyOverrides:Map<StructuredFormatter.Key, String>

a map of overrides for the default keys

Method Detail

createGeneratorback to summary
protected StructuredFormatter.Generator createGenerator(final Writer writer) throws Exception

Implements abstract org.jboss.logmanager.formatters.StructuredFormatter.createGenerator.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.createGenerator.

Creates the generator used to create the structured data.

Returns:StructuredFormatter.Generator

the generator to use

Annotations
@Override
Exceptions
Exception:
if an error occurs creating the generator
getNamespaceUriback to summary
public String getNamespaceUri()

Returns the namespace URI used for each record if isPrintNamespace() is true.

Returns:String

the namespace URI, may be null if explicitly set to null

isPrettyPrintback to summary
public boolean isPrettyPrint()

Indicates whether or not pretty printing is enabled.

Returns:boolean

true if pretty printing is enabled, otherwise false

isPrintNamespaceback to summary
public boolean isPrintNamespace()

Indicates whether or not the name space should be written on the <record/>.

Returns:boolean

true if the name space should be written for each record

setNamespaceUriback to summary
public void setNamespaceUri(final String namespaceUri)

Sets the namespace URI used for each record if isPrintNamespace() is true.

Parameters
namespaceUri:String

the namespace to use or null if no namespace URI should be used regardless of the isPrintNamespace() value

setPrettyPrintback to summary
public void setPrettyPrint(final boolean prettyPrint)

Turns on or off pretty printing.

Parameters
prettyPrint:boolean

true to turn on pretty printing or false to turn it off

setPrintNamespaceback to summary
public void setPrintNamespace(final boolean printNamespace)

Turns on or off the printing of the namespace for each <record/>. This is set to false by default.

Parameters
printNamespace:boolean

true if the name space should be written for each record

org.jboss.logmanager.formatters back to summary

private Class XmlFormatter.XmlGenerator

extends Object
implements Generator
Class Inheritance
All Implemented Interfaces
org.jboss.logmanager.formatters.StructuredFormatter.Generator

Field Summary

Modifier and TypeField and Description
private final XMLStreamWriter

Constructor Summary

AccessConstructor and Description
private
XmlGenerator(final XMLStreamWriter xmlWriter)

Method Summary

Modifier and TypeMethod and Description
public StructuredFormatter.Generator
add(final String
the key for the map
key
,
final Map<String, ?>
the map
value
)

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a map value

public StructuredFormatter.Generator
add(final String
the key for the value
key
,
final String
the string value
value
)

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a string value.

public StructuredFormatter.Generator
addAttribute(final String
the name of the attribute
name
,
final int
the value of the attribute
value
)

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.addAttribute.

Writes an attribute.

public StructuredFormatter.Generator
addAttribute(final String
the name of the attribute
name
,
final String
the value of the attribute
value
)

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.addAttribute.

Writes an attribute.

public StructuredFormatter.Generator
addMetaData(final Map<String, String>
the map of the meta data, cannot be null
metaData
)

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.addMetaData.

Adds the meta data to the structured format.

public StructuredFormatter.Generator
begin()

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.begin.

Initial method invoked at the start of the generation.

public StructuredFormatter.Generator
end()

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.end.

Writes any trailing data that's needed.

public StructuredFormatter.Generator
private void
safeClose(final XMLStreamWriter closeable)

private void
safeFlush(final XMLStreamWriter flushable)

public StructuredFormatter.Generator
startObject(final String
they key for the object, or null if this object was started in an array and the wrapArrays() is false
key
)

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.startObject.

Writes the start of an object.

public boolean
wrapArrays()

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.wrapArrays.

Indicates whether or not elements in an array should be wrapped or not.

private void
writeEmpty(final String name)

private void
private void
writeStart(final String name)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

xmlWriterback to summary
private final XMLStreamWriter xmlWriter

Constructor Detail

XmlGeneratorback to summary
private XmlGenerator(final XMLStreamWriter xmlWriter)

Method Detail

addback to summary
public StructuredFormatter.Generator add(final String key, final Map<String, ?> value) throws Exception

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a map value

Parameters
key:String

the key for the map

value:Map<String, ?>

the map

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
addback to summary
public StructuredFormatter.Generator add(final String key, final String value) throws Exception

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.add.

Writes a string value.

Parameters
key:String

the key for the value

value:String

the string value

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
addAttributeback to summary
public StructuredFormatter.Generator addAttribute(final String name, final int value) throws Exception

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.addAttribute.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.addAttribute.

Writes an attribute.

By default this uses the add(String, int) method to add the attribute. If a formatter requires special handling for attributes, for example an attribute on an XML element, this method can be overridden.

Parameters
name:String

the name of the attribute

value:int

the value of the attribute

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
addAttributeback to summary
public StructuredFormatter.Generator addAttribute(final String name, final String value) throws Exception

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.addAttribute.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.addAttribute.

Writes an attribute.

By default this uses the add(String, String) method to add the attribute. If a formatter requires special handling for attributes, for example an attribute on an XML element, this method can be overridden.

Parameters
name:String

the name of the attribute

value:String

the value of the attribute

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
addMetaDataback to summary
public StructuredFormatter.Generator addMetaData(final Map<String, String> metaData) throws Exception

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.addMetaData.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.addMetaData.

Adds the meta data to the structured format.

By default this processes the map and uses add(String, String) to add entries.

Parameters
metaData:Map<String, String>

the map of the meta data, cannot be null

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
beginback to summary
public StructuredFormatter.Generator begin() throws Exception

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.begin.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.begin.

Initial method invoked at the start of the generation.

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
endback to summary
public StructuredFormatter.Generator end() throws Exception

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.end.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.end.

Writes any trailing data that's needed.

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data during the build
endObjectback to summary
public StructuredFormatter.Generator endObject() throws Exception

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.endObject.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.endObject.

Writes an end to the object.

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
safeCloseback to summary
private void safeClose(final XMLStreamWriter closeable)
safeFlushback to summary
private void safeFlush(final XMLStreamWriter flushable)
startObjectback to summary
public StructuredFormatter.Generator startObject(final String key) throws Exception

Implements org.jboss.logmanager.formatters.StructuredFormatter.Generator.startObject.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.startObject.

Writes the start of an object.

If the wrapArrays() returns false the key may be null and implementations should handle this.

Parameters
key:String

they key for the object, or null if this object was started in an array and the wrapArrays() is false

Returns:StructuredFormatter.Generator

the generator

Annotations
@Override
Exceptions
Exception:
if an error occurs while adding the data
wrapArraysback to summary
public boolean wrapArrays()

Overrides default org.jboss.logmanager.formatters.StructuredFormatter.Generator.wrapArrays.

Doc from org.jboss.logmanager.formatters.StructuredFormatter.Generator.wrapArrays.

Indicates whether or not elements in an array should be wrapped or not. The default is false.

Returns:boolean

true if elements should be wrapped, otherwise false

Annotations
@Override
writeEmptyback to summary
private void writeEmpty(final String name) throws XMLStreamException
writeEndback to summary
private void writeEnd() throws XMLStreamException
writeStartback to summary
private void writeStart(final String name) throws XMLStreamException