Package com.topologi.diffx.format
Class StrictXMLFormatter
java.lang.Object
com.topologi.diffx.format.StrictXMLFormatter
- All Implemented Interfaces:
DiffXFormatter,XMLDiffXFormatter
A simple XML formatter that writes strictly what it is given.
This formatter will write the events exactly in the order in which they are given,
in other words, there is no way to prevent this class from writing malformed XML.
On other hand, the SmartXMLFormatter will close
XML elements automatically, therefore rectifying a lot of the errors that lead to
malformed XML.
- Version:
- 3 April 2005
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringThe close 'del' tag, that is the element end tag that we put after test is being deleted.private StringThe close 'ins' tag, that is the element end tag that we put after test is being inserted.private DiffXConfigThe DiffX configuration to useprivate booleanSet tofalseonce the prefix mapping has been declared.private booleanSet totrueto indicate that there is an open 'del' tag.private booleanSet totrueto indicate that there is an open element tag that does not have its right angle bracket.private booleanSet totrueto indicate that there is an open 'ins' tag.private StringThe open 'del' tag, that is the element start tag that we put before test is being deleted.private StringThe open 'ins' tag, that is the element start tag that we put before test is being inserted.private final PrintWriterThw 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 TypeMethodDescriptionprivate voidcloseDel()Closes the 'del' element, and update the state flags.private voidcloseIns()Closes the 'ins' element, and update the state flags.voiddeclarePrefixMapping(PrefixMapping mapping) Adds the prefix mapping to this class.voiddelete(DiffXEvent e) Formats the specified deleted event.private voidCloses the 'del' element, and update the state flags.voidformat(DiffXEvent e) Formats the specified event.private voidinit()Writes the XML declaration.voidinsert(DiffXEvent e) Formats the specified inserted event.private voidopenDel()Opens the 'del' element, and update the state flags.private voidopenIns()Opens the 'ins' element, and update the state flags.voidsetConfig(DiffXConfig config) Sets the configuration to use with this formatter.voidsetDeleteTags(String start, String end) Sets the open and end tags for deleted text.voidsetInsertTags(String start, String end) Sets the open and end tags for inserted text.voidsetWriteXMLDeclaration(boolean show) Set whether the formatter should include the XML declaration or not.
-
Field Details
-
xml
Thw output goes here. -
openDel
The open 'del' tag, that is the element start tag that we put before test is being deleted. -
closeDel
The close 'del' tag, that is the element end tag that we put after test is being deleted. -
openIns
The open 'ins' tag, that is the element start tag that we put before test is being inserted. -
closeIns
The close 'ins' tag, that is the element end tag that we put after test is being inserted. -
config
The DiffX configuration to use -
declareNamespace
private transient boolean declareNamespaceSet tofalseonce the prefix mapping has been declared.xmlns:dfx="http://www.allette.com.au/diffex"
-
isInserting
private transient boolean isInsertingSet totrueto indicate that there is an open 'ins' tag. -
isDeleting
private transient boolean isDeletingSet totrueto indicate that there is an open 'del' tag. -
isElementNude
private transient boolean isElementNudeSet totrueto indicate that there is an open element tag that does not have its right angle bracket.
-
-
Constructor Details
-
StrictXMLFormatter
public StrictXMLFormatter()Creates a new formatter on the standard output. -
StrictXMLFormatter
Creates a new formatter using the specified writer.- Parameters:
w- The writer to use.
-
-
Method Details
-
init
private void init()Writes the XML declaration. -
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.IllegalStateException- If the formatter is not in a state to run this method.
-
setInsertTags
Sets the open and end tags for inserted text.The default values are "<ins:>" and "</ins:>" respectively.
- Parameters:
start- The open tag for inserts.end- The close tag for inserts.- Throws:
NullPointerException- If any of the tags isnull.
-
setDeleteTags
Sets the open and end tags for deleted text.The default values are "<del:>" and "</del:>" respectively.
- Parameters:
start- The open tag for deletions.end- The close tag for deletions.- Throws:
NullPointerException- If any of the tags isnull.
-
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.
-
openIns
private void openIns()Opens the 'ins' element, and update the state flags. -
openDel
private void openDel()Opens the 'del' element, and update the state flags. -
closeIns
private void closeIns()Closes the 'ins' element, and update the state flags. -
closeDel
private void closeDel()Closes the 'del' element, and update the state flags. -
denudeElement
private void denudeElement()Closes the 'del' element, and update the state flags.
-