sk.baka.ikslibs.modify
Class DOMChangeCollector

java.lang.Object
  extended by sk.baka.ikslibs.modify.DOMChangeCollector
All Implemented Interfaces:
EventListener, INodeObserver, IChangeCollector

public class DOMChangeCollector
extends Object
implements IChangeCollector, EventListener, INodeObserver

Collects changes to DOM document. To start collecting changes simply register it as a listener to a node with some raw mutation event type.

Author:
Martin Vysny

Constructor Summary
DOMChangeCollector()
           
 
Method Summary
 void clearChanges()
          Clears the change tracer.
 List<? extends Node> getModifiedNodes()
          Returns unmodifiable list of modified nodes.
 DOMSource getSource()
           Returns a source that contains whole document.
 void handleEvent(Event evt)
           
 void init(Source source)
           Initializes the collector with given source.
 boolean isChanged()
          Checks if this collector has captured at least one change.
 boolean isCompletelyChanged()
           Checks if the source object has changed completely since last call to IChangeCollector.clearChanges().
protected  void nodeModified(Node node)
          Informs the collector that the node has been modified (this applies only to non-element nodes when changing their textual value).
 void observe(Node node)
          Starts to observe given node and its descendants.
 void reinit(Source source)
           Reinitializes the collector.
 void stopObservation(Node node)
           Finishes observation of given node and its descendants.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMChangeCollector

public DOMChangeCollector()
Method Detail

init

public void init(Source source)
Description copied from interface: IChangeCollector

Initializes the collector with given source. Implementors must act as if whole document was changed. Implementor should clone the source object if it intends to keep it.

Must be called exactly once as the first method.

Specified by:
init in interface IChangeCollector
Parameters:
source - the source to reinit.

getSource

public DOMSource getSource()
Description copied from interface: IChangeCollector

Returns a source that contains whole document.

Specified by:
getSource in interface IChangeCollector
Returns:
source containing the document.

clearChanges

public void clearChanges()
Description copied from interface: IChangeCollector
Clears the change tracer.

Specified by:
clearChanges in interface IChangeCollector

isChanged

public boolean isChanged()
Description copied from interface: IChangeCollector
Checks if this collector has captured at least one change.

Specified by:
isChanged in interface IChangeCollector
Returns:
true if some changes occured, false otherwise.

isCompletelyChanged

public boolean isCompletelyChanged()
Description copied from interface: IChangeCollector

Checks if the source object has changed completely since last call to IChangeCollector.clearChanges().

Specified by:
isCompletelyChanged in interface IChangeCollector
Returns:
true if the source changed as a whole, false if it changed only partially or no change occured at all.

reinit

public void reinit(Source source)
Description copied from interface: IChangeCollector

Reinitializes the collector. The collector may act as if whole source was changed, or it may compare new source to previous source and reinitialize the list of changes.

May be called multiple times.

Specified by:
reinit in interface IChangeCollector

getModifiedNodes

public List<? extends Node> getModifiedNodes()
Returns unmodifiable list of modified nodes. This list contains nodes that were changed (inserted, deleted or modified). In case of elements, it should be taken that all descendant nodes have changed aswell. Therefore, no node from this list is descendant of another node from the list.

Returns:
list of nodes that were reported as modified.

handleEvent

public void handleEvent(Event evt)
Specified by:
handleEvent in interface EventListener

nodeModified

protected void nodeModified(Node node)
Informs the collector that the node has been modified (this applies only to non-element nodes when changing their textual value).

Parameters:
node - the node from the splitted document, that was modified.

observe

public void observe(Node node)
Description copied from interface: INodeObserver
Starts to observe given node and its descendants.

Specified by:
observe in interface INodeObserver
Parameters:
node - node to observe

stopObservation

public void stopObservation(Node node)
Description copied from interface: INodeObserver

Finishes observation of given node and its descendants.

Warning: the method simply deregisters from given node. It does NOT deregister from any descendants of given node hence the observation of some descendants may continue.

Specified by:
stopObservation in interface INodeObserver
Parameters:
node - stops observing this node.


Copyright © 2006 Martin Vysny - baka. All Rights Reserved.