Class DOMRecorder

java.lang.Object
com.topologi.diffx.load.DOMRecorder
All Implemented Interfaces:
Recorder, XMLRecorder

public final class DOMRecorder extends Object implements XMLRecorder
Loads a DOM documents as a sequence of events.

This class implements the methods Recorder.process(File) and Recorder.process(String) for convenience, but is it much more efficient to feed this recorder directly with a DOM.

This class is not synchronised.

Since:
0.7
Version:
10 May 2010
  • Field Details

    • config

      private DiffXConfig config
      The DiffX configuration to use
    • efactory

      private transient EventFactory efactory
      The factory that will produce events according to the configuration.
    • tokenizer

      private transient TextTokenizer tokenizer
      The text tokenizer used by this recorder.
    • sequence

      private transient EventSequence sequence
      The sequence of event for this recorder.
    • mapping

      private transient PrefixMapping mapping
      The sequence of event for this recorder.
    • currentWeight

      private transient int currentWeight
      The weight of the current element.
    • weights

      private transient List<Integer> weights
      The stack of events' weight, should only contain Integer.
    • isFragment

      private transient boolean isFragment
      Indicates whether the given document is a fragment.

      An fragment is a portion of XML that is not necessarily well-formed by itself, because the namespace has been declared higher in the hierarchy, in which if the DOM tree was serialised it would not produce well-formed XML.

      This option indicates that the recorder should try to generate the prefix mapping without the declaration.

  • Constructor Details

    • DOMRecorder

      public DOMRecorder()
  • Method Details

    • getConfig

      public DiffXConfig getConfig()
      Returns the configuration used by this recorder.
      Returns:
      the configuration used by this recorder.
    • setConfig

      public void setConfig(DiffXConfig config)
      Sets the configuration used by this recorder.
      Parameters:
      config - The configuration used by this recorder.
    • process

      public EventSequence process(File file) throws LoadingException, IOException
      Runs the recorder on the specified file.
      Specified by:
      process in interface Recorder
      Parameters:
      file - The file to process.
      Returns:
      The recorded sequence of events.
      Throws:
      LoadingException - If thrown while parsing.
      IOException - Should I/O error occur.
    • process

      public EventSequence process(String xml) throws LoadingException
      Runs the recorder on the specified string.
      Specified by:
      process in interface Recorder
      Parameters:
      xml - The string to process.
      Returns:
      The recorded sequence of events.
      Throws:
      LoadingException - If thrown while parsing.
    • process

      public EventSequence process(InputSource is) throws LoadingException
      Runs the recorder on the specified input source.
      Specified by:
      process in interface XMLRecorder
      Parameters:
      is - The input source.
      Returns:
      The recorded sequence of events.
      Throws:
      LoadingException - If thrown while parsing.
    • process

      public EventSequence process(Node node) throws LoadingException
      Processes the given node and returns the corresponding event sequence.
      Parameters:
      node - The W3C DOM node to be processed.
      Returns:
      The recorded sequence of events.
      Throws:
      LoadingException - If thrown while parsing.
    • process

      public EventSequence process(NodeList node) throws LoadingException
      Processes the given node list and returns the corresponding event sequence.

      This method only returns the event sequence from the first node in the node list, if the node list is empty, this method returns an empty sequence.

      Parameters:
      node - The W3C DOM node to be processed.
      Returns:
      The recorded sequence of events.
      Throws:
      LoadingException - If thrown while parsing.
    • loadNode

      private void loadNode(Node node) throws LoadingException
      Loads the given node in the current sequence.
      Parameters:
      node - The W3C DOM node to load.
      Throws:
      LoadingException - If thrown while parsing.
    • load

      private void load(Document document) throws LoadingException
      Loads the given document in the current sequence.
      Parameters:
      document - The W3C DOM document node to load.
      Throws:
      LoadingException - If thrown while parsing.
    • load

      private void load(Element element) throws LoadingException
      Loads the given element in the current sequence.
      Parameters:
      element - The W3C DOM element node to load.
      Throws:
      LoadingException - If thrown while parsing.
    • load

      private void load(Text text) throws LoadingException
      Loads the given text in the current sequence depending on the configuration.
      Parameters:
      text - The W3C DOM text node to load.
      Throws:
      LoadingException - If thrown while parsing.
    • load

      private void load(ProcessingInstruction pi) throws LoadingException
      Loads the given processing instruction in the current sequence.
      Parameters:
      pi - The W3C DOM PI node to load.
      Throws:
      LoadingException - If thrown while parsing.
    • popWeight

      private int popWeight()
      Returns the last weight and remove it from the stack.
      Returns:
      The weight on top of the stack.
    • load

      private void load(Attr attr)
      Loads the given attribute in the current sequence.
      Parameters:
      attr - The W3C DOM attribute node to load.
    • load

      private void load(AttributeEvent e)
      Loads the given attribute in the current sequence.
      Parameters:
      e - An attribute event.
    • handlePrefixMapping

      private void handlePrefixMapping(String uri, String prefix)
      Handles the prefix mapping. If the current process is working on a fragment,
      Parameters:
      uri - The namespace URI.
      prefix - The prefix used for the namespace.