Package com.topologi.diffx.format
Class BasicXMLFormatter
java.lang.Object
com.topologi.diffx.format.BasicXMLFormatter
- All Implemented Interfaces:
DiffXFormatter,XMLDiffXFormatter
A XML formatter that simply uses a different namespace for any inserted or modified
node.
Nodes that have not changed are kept the way they are.
Nodes that have been modified will always be in a different namespace and will be reported as follows:
Elements:
<mod:element name="elt.getName()" uri="elt.getURI()">
...
</mod:element>
Attributes:
<mod:attribute name="att.getName()" uri="att.getURI()" value="att.getValue()"/>
Texts:
<mod:text>text.getCharacters()</mod:text>
- 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, String uri) 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
-
BasicXMLFormatter
Creates a new formatter using the specified writer.- Parameters:
w- The writer to use.- Throws:
NullPointerException- If the specified writer isnull.
-
-
Method Details
-
format
Formats the specified event.- Specified by:
formatin interfaceDiffXFormatter- Parameters:
e- The event to format- Throws:
IOException- Should an I/O exception occurs while formatting.
-
insert
Formats 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
Formats 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.uri- The Namespace URI required- Throws:
IOException- Should an I/O error occur.
-