Class StrictXMLFormatter

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

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

    Fields
    Modifier and Type
    Field
    Description
    private String
    The close 'del' tag, that is the element end tag that we put after test is being deleted.
    private String
    The close 'ins' tag, that is the element end tag that we put after test is being inserted.
    private DiffXConfig
    The DiffX configuration to use
    private boolean
    Set to false once the prefix mapping has been declared.
    private boolean
    Set to true to indicate that there is an open 'del' tag.
    private boolean
    Set to true to indicate that there is an open element tag that does not have its right angle bracket.
    private boolean
    Set to true to indicate that there is an open 'ins' tag.
    private String
    The open 'del' tag, that is the element start tag that we put before test is being deleted.
    private String
    The open 'ins' tag, that is the element start tag that we put before test is being inserted.
    private final PrintWriter
    Thw output goes here.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new formatter on the standard output.
    Creates a new formatter using the specified writer.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Closes the 'del' element, and update the state flags.
    private void
    Closes the 'ins' element, and update the state flags.
    void
    Adds the prefix mapping to this class.
    void
    Formats the specified deleted event.
    private void
    Closes the 'del' element, and update the state flags.
    void
    Formats the specified event.
    private void
    Writes the XML declaration.
    void
    Formats the specified inserted event.
    private void
    Opens the 'del' element, and update the state flags.
    private void
    Opens the 'ins' element, and update the state flags.
    void
    Sets the configuration to use with this formatter.
    void
    Sets the open and end tags for deleted text.
    void
    Sets the open and end tags for inserted text.
    void
    setWriteXMLDeclaration(boolean show)
    Set whether the formatter should include the XML declaration or not.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • xml

      private final PrintWriter xml
      Thw output goes here.
    • openDel

      private String openDel
      The open 'del' tag, that is the element start tag that we put before test is being deleted.
    • closeDel

      private String closeDel
      The close 'del' tag, that is the element end tag that we put after test is being deleted.
    • openIns

      private String openIns
      The open 'ins' tag, that is the element start tag that we put before test is being inserted.
    • closeIns

      private String closeIns
      The close 'ins' tag, that is the element end tag that we put after test is being inserted.
    • config

      private DiffXConfig config
      The DiffX configuration to use
    • declareNamespace

      private transient boolean declareNamespace
      Set to false once the prefix mapping has been declared.
         xmlns:dfx="http://www.allette.com.au/diffex"
       
    • isInserting

      private transient boolean isInserting
      Set to true to indicate that there is an open 'ins' tag.
    • isDeleting

      private transient boolean isDeleting
      Set to true to indicate that there is an open 'del' tag.
    • isElementNude

      private transient boolean isElementNude
      Set to true to 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

      public StrictXMLFormatter(Writer w)
      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

      public void format(DiffXEvent e) throws IOException
      Description copied from interface: DiffXFormatter
      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
      Description copied from interface: DiffXFormatter
      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, IllegalStateException
      Description copied from interface: DiffXFormatter
      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.
      IllegalStateException - If the formatter is not in a state to run this method.
    • setInsertTags

      public void setInsertTags(String start, String end) throws NullPointerException
      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 is null.
    • setDeleteTags

      public void setDeleteTags(String start, String end) throws NullPointerException
      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 is null.
    • 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.
    • 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.