Package com.topologi.diffx.format
Class ConvenientXMLFormatter
java.lang.Object
com.topologi.diffx.format.ConvenientXMLFormatter
- All Implemented Interfaces:
DiffXFormatter,XMLDiffXFormatter
A XML formatter that provides a convenient XML formatting.
Nodes that have not changed are kept the way they are.
Elements that have been modified
- Version:
- 17 May 2005
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DiffXConfigThe DiffX configuration to useprivate Stack<AttributeEvent>A stack of attributes to delete.private Stack<AttributeEvent>A stack of attributes to insert.private booleanIndicates whether the XML writer has been setup already.private shortIndicates whether some text is being inserted or removed.private booleanSet totrueto include the XML declaration.private final XMLWriterThe output goes here. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new formatter using the specified writer. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidchange(DiffXEvent e, int mod) Reports a change in XML.voiddeclarePrefixMapping(PrefixMapping mapping) Adds the prefix mapping to this class.voiddelete(DiffXEvent e) Formats the specified deleted event.private voidFormats the end of a text change.private voidWrites any attribute that has not be written.private voidflushAttributes(Stack<AttributeEvent> atts, int mod) Writes any attribute that has not be written.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.private voidsetUpXML()Set up the XML.voidsetWriteXMLDeclaration(boolean show) Set whether the formatter should include the XML declaration or not.private voidswitchTextChange(int mod) Switch between text changes.
-
Field Details
-
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 tofalsewhen thesetWriteXMLDeclaration(boolean)is called withfalseor once the XML declaration has been written. -
isSetup
private transient boolean isSetupIndicates whether the XML writer has been setup already. -
textFormat
private transient short textFormatIndicates whether some text is being inserted or removed. 0 = indicate format or no open text element. +1 = indicates an insert open text element. -1 = indicates an delete open text element. -
insAttributes
A stack of attributes to insert. -
delAttributes
A stack of attributes to delete.
-
-
Constructor Details
-
ConvenientXMLFormatter
Creates a new formatter using the specified writer.- Parameters:
w- The writer to use.- Throws:
NullPointerException- If the specified writer isnull.
-
-
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.
-
change
Reports a change in XML.- Parameters:
e- The diff-x event that has been inserted or deleted.mod- The modification flag (positive for inserts, negative for deletes).- Throws:
IOException- an I/O exception if an error occurs.
-
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.
-
setUpXML
Set up the XML.- Throws:
IOException- an I/O exception if an error occurs.
-
endTextChange
Formats the end of a text change.- Throws:
IOException- If throws by XMl writer.
-
switchTextChange
Switch between text changes.- Parameters:
mod- The modification flag (positive for inserts, negative for deletes).- Throws:
IOException- If throws by XMl writer.
-
flushAttributes
Writes any attribute that has not be written.- Throws:
IOException- Should an I/O error occur.
-
flushAttributes
Writes any attribute that has not be written.- Parameters:
atts- The attribute stack.mod- The modification flag (positive for inserts, negative for deletes).- Throws:
IOException- Should an I/O error occur.
-