Package com.topologi.diffx.load
Class DOMRecorder
java.lang.Object
com.topologi.diffx.load.DOMRecorder
- All Implemented Interfaces:
Recorder,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 Summary
FieldsModifier and TypeFieldDescriptionprivate DiffXConfigThe DiffX configuration to useprivate intThe weight of the current element.private EventFactoryThe factory that will produce events according to the configuration.private booleanIndicates whether the given document is a fragment.private PrefixMappingThe sequence of event for this recorder.private EventSequenceThe sequence of event for this recorder.private TextTokenizerThe text tokenizer used by this recorder.The stack of events' weight, should only containInteger. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the configuration used by this recorder.private voidhandlePrefixMapping(String uri, String prefix) Handles the prefix mapping.private voidLoads the given attribute in the current sequence.private voidLoads the given attribute in the current sequence.private voidLoads the given document in the current sequence.private voidLoads the given element in the current sequence.private voidLoads the given processing instruction in the current sequence.private voidLoads the given text in the current sequence depending on the configuration.private voidLoads the given node in the current sequence.private intReturns the last weight and remove it from the stack.Runs the recorder on the specified file.Runs the recorder on the specified string.Processes the given node and returns the corresponding event sequence.Processes the given node list and returns the corresponding event sequence.process(InputSource is) Runs the recorder on the specified input source.voidsetConfig(DiffXConfig config) Sets the configuration used by this recorder.
-
Field Details
-
config
The DiffX configuration to use -
efactory
The factory that will produce events according to the configuration. -
tokenizer
The text tokenizer used by this recorder. -
sequence
The sequence of event for this recorder. -
mapping
The sequence of event for this recorder. -
currentWeight
private transient int currentWeightThe weight of the current element. -
weights
The stack of events' weight, should only containInteger. -
isFragment
private transient boolean isFragmentIndicates 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
Returns the configuration used by this recorder.- Returns:
- the configuration used by this recorder.
-
setConfig
Sets the configuration used by this recorder.- Parameters:
config- The configuration used by this recorder.
-
process
Runs the recorder on the specified file.- Specified by:
processin interfaceRecorder- 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
Runs the recorder on the specified string.- Specified by:
processin interfaceRecorder- Parameters:
xml- The string to process.- Returns:
- The recorded sequence of events.
- Throws:
LoadingException- If thrown while parsing.
-
process
Runs the recorder on the specified input source.- Specified by:
processin interfaceXMLRecorder- Parameters:
is- The input source.- Returns:
- The recorded sequence of events.
- Throws:
LoadingException- If thrown while parsing.
-
process
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
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
Loads the given node in the current sequence.- Parameters:
node- The W3C DOM node to load.- Throws:
LoadingException- If thrown while parsing.
-
load
Loads the given document in the current sequence.- Parameters:
document- The W3C DOM document node to load.- Throws:
LoadingException- If thrown while parsing.
-
load
Loads the given element in the current sequence.- Parameters:
element- The W3C DOM element node to load.- Throws:
LoadingException- If thrown while parsing.
-
load
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
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
Loads the given attribute in the current sequence.- Parameters:
attr- The W3C DOM attribute node to load.
-
load
Loads the given attribute in the current sequence.- Parameters:
e- An attribute event.
-
handlePrefixMapping
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.
-