Class BasicXMLFormatter

java.lang.Object
com.topologi.diffx.format.BasicXMLFormatter
All Implemented Interfaces:
DiffXFormatter, XMLDiffXFormatter

public final class BasicXMLFormatter extends Object implements 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 Details

    • xml

      private final XMLWriter xml
      The output goes here.
    • config

      private DiffXConfig config
      The DiffX configuration to use
    • writeXMLDeclaration

      private transient boolean writeXMLDeclaration
      Set to true to include the XML declaration. This attribute is set to false when the setWriteXMLDeclaration(boolean) is called with false or once the XML declaration has been written.
    • isSetup

      private transient boolean isSetup
      Indicates whether the XML writer has been setup already.
    • textFormat

      private transient short textFormat
      Indicates 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

      private transient Stack<AttributeEvent> insAttributes
      A stack of attributes to insert.
    • delAttributes

      private transient Stack<AttributeEvent> delAttributes
      A stack of attributes to delete.
  • Constructor Details

    • BasicXMLFormatter

      public BasicXMLFormatter(Writer w) throws NullPointerException
      Creates a new formatter using the specified writer.
      Parameters:
      w - The writer to use.
      Throws:
      NullPointerException - If the specified writer is null.
  • Method Details

    • format

      public void format(DiffXEvent e) throws IOException
      Formats the specified event.
      Specified by:
      format in interface DiffXFormatter
      Parameters:
      e - The event to format
      Throws:
      IOException - Should an I/O exception occurs while formatting.
    • insert

      public void insert(DiffXEvent e) throws IOException
      Formats the specified inserted event.
      Specified by:
      insert in interface DiffXFormatter
      Parameters:
      e - The event to format
      Throws:
      IOException - Should an I/O exception occurs while formatting.
    • delete

      public void delete(DiffXEvent e) throws IOException
      Formats the specified deleted event.
      Specified by:
      delete in interface DiffXFormatter
      Parameters:
      e - The event to format
      Throws:
      IOException - Should an I/O exception occurs while formatting.
    • change

      private void change(DiffXEvent e, int mod) throws IOException
      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

      public void setConfig(DiffXConfig config)
      Description copied from interface: DiffXFormatter
      Sets the configuration to use with this formatter.
      Specified by:
      setConfig in interface DiffXFormatter
      Parameters:
      config - The configuration to use.
    • setWriteXMLDeclaration

      public void setWriteXMLDeclaration(boolean show)
      Description copied from interface: XMLDiffXFormatter
      Set whether the formatter should include the XML declaration or not.
      Specified by:
      setWriteXMLDeclaration in interface XMLDiffXFormatter
      Parameters:
      show - true to get the formatter to write the XML declaration; false otherwise.
    • declarePrefixMapping

      public void declarePrefixMapping(PrefixMapping mapping)
      Adds the prefix mapping to this class.
      Specified by:
      declarePrefixMapping in interface XMLDiffXFormatter
      Parameters:
      mapping - The prefix mapping to add.
    • setUpXML

      private void setUpXML() throws IOException
      Set up the XML.
      Throws:
      IOException - an I/O exception if an error occurs.
    • endTextChange

      private void endTextChange() throws IOException
      Formats the end of a text change.
      Throws:
      IOException - If throws by XMl writer.
    • switchTextChange

      private void switchTextChange(int mod) throws IOException
      Switch between text changes.
      Parameters:
      mod - The modification flag (positive for inserts, negative for deletes).
      Throws:
      IOException - If throws by XMl writer.
    • flushAttributes

      private void flushAttributes() throws IOException
      Writes any attribute that has not be written.
      Throws:
      IOException - Should an I/O error occur.
    • flushAttributes

      private void flushAttributes(Stack<AttributeEvent> atts, String uri) throws IOException
      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.