Package com.topologi.diffx.format
Class SafeXMLFormatter
java.lang.Object
com.topologi.diffx.format.SafeXMLFormatter
- All Implemented Interfaces:
DiffXFormatter,XMLDiffXFormatter
An XML formatter that tries to ensure that the output XML will be well-formed.
This class will always close the elements correctly by maintaining a stack of parent elements.
Implementation note: this classes uses the namespace prefixes 'dfx' and 'del', in the future it should be possible to configure which prefixes to use for each namespace, but in this version the namespace prefix mapping is hard-coded.
- Version:
- 11 May 2010
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DiffXConfigThe DiffX configuration to useprivate static final booleanSet totrueto show debug info.private booleanSet totrueto include the XML declaration.private final XMLWriterThe output goes here. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new formatter on the standard output.Creates a new formatter using the specified writer. -
Method Summary
Modifier and TypeMethodDescriptionvoiddeclarePrefixMapping(PrefixMapping mapping) Adds the prefix mapping to this class.voiddelete(DiffXEvent e) Formats the specified deleted event.voidformat(DiffXEvent e) Formats the specified event.voidinsert(DiffXEvent e) Formats the specified inserted event.voidsetConfig(DiffXConfig config) Sets the configuration to use with this formatter.voidsetWriteXMLDeclaration(boolean show) Set whether the formatter should include the XML declaration or not.
-
Field Details
-
DEBUG
private static final boolean DEBUGSet totrueto show debug info.- See Also:
-
xml
The output goes here. -
config
The DiffX configuration to use -
writeXMLDeclaration
private transient boolean writeXMLDeclarationSet totrueto include the XML declaration.This attribute is set to
falsewhen thesetWriteXMLDeclaration(boolean)is called withfalseor once the XML declaration has been written.
-
-
Constructor Details
-
SafeXMLFormatter
Creates a new formatter on the standard output.This constructor is equivalent to:
new SmartXMLFormatter(new PrintWriter(System.out));
.- Throws:
IOException- should an I/O exception occurs.- See Also:
-
SafeXMLFormatter
Creates a new formatter using the specified writer.- Parameters:
w- The writer to use.- Throws:
IOException- should an I/O exception occurs.
-
-
Method Details
-
format
Description copied from interface:DiffXFormatterFormats the specified event.- Specified by:
formatin interfaceDiffXFormatter- Parameters:
e- The event to format- Throws:
IOException- Should an I/O exception occurs while formatting.
-
insert
Description copied from interface:DiffXFormatterFormats the specified inserted event.- Specified by:
insertin interfaceDiffXFormatter- Parameters:
e- The event to format- Throws:
IOException- Should an I/O exception occurs while formatting.
-
delete
Description copied from interface:DiffXFormatterFormats the specified deleted event.- Specified by:
deletein interfaceDiffXFormatter- Parameters:
e- The event to format- Throws:
IOException- Should an I/O exception occurs while formatting.
-
setConfig
Description copied from interface:DiffXFormatterSets the configuration to use with this formatter.- Specified by:
setConfigin interfaceDiffXFormatter- Parameters:
config- The configuration to use.
-
setWriteXMLDeclaration
public void setWriteXMLDeclaration(boolean show) Description copied from interface:XMLDiffXFormatterSet whether the formatter should include the XML declaration or not.- Specified by:
setWriteXMLDeclarationin interfaceXMLDiffXFormatter- Parameters:
show-trueto get the formatter to write the XML declaration;falseotherwise.
-
declarePrefixMapping
Adds the prefix mapping to this class.- Specified by:
declarePrefixMappingin interfaceXMLDiffXFormatter- Parameters:
mapping- The prefix mapping to add.
-