Class SafeXMLFormatter

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

public final class SafeXMLFormatter extends Object implements XMLDiffXFormatter
An XML formatter that tries to ensure that the output XML will be well-formed.

This class will always close the elements correctly by maintaining a stack of parent elements.

Implementation note: this classes uses the namespace prefixes 'dfx' and 'del', in the future it should be possible to configure which prefixes to use for each namespace, but in this version the namespace prefix mapping is hard-coded.

Version:
11 May 2010
  • Field Details

    • DEBUG

      private static final boolean DEBUG
      Set to true to show debug info.
      See Also:
    • 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.

  • Constructor Details

    • SafeXMLFormatter

      public SafeXMLFormatter() throws IOException
      Creates a new formatter on the standard output.

      This constructor is equivalent to:

      new SmartXMLFormatter(new PrintWriter(System.out));
      .
      Throws:
      IOException - should an I/O exception occurs.
      See Also:
    • SafeXMLFormatter

      public SafeXMLFormatter(Writer w) throws IOException
      Creates a new formatter using the specified writer.
      Parameters:
      w - The writer to use.
      Throws:
      IOException - should an I/O exception occurs.
  • Method Details

    • 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
      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.
    • 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.