sk.uniba.euromath.document
Class NodeListID

java.lang.Object
  extended by sk.uniba.euromath.document.NodeListID
All Implemented Interfaces:
NodeList

public final class NodeListID
extends Object
implements NodeList

Represents the nodelist that can be identified by some ID. The list can have more than one node only if:

The node returned by the item() function may be only one of the following: element, attribute, text, cdata, comment, processing instruction. This list shall always contain at least one node.

WARNING! If you add some nodes between the nodes that this list is holding, these changes are NOT reflected in this object! In such case you have to re-query the id to get new instance of nodelist, or use the recover method. equals() returns true when all nodes they represent are same. Two nodelists may differ when they represent one ID: if one is queried, the node is inserted and the second is queried.

Author:
Martin Vysny

Nested Class Summary
 class NodeListID.NodePtr
          Points into contents of text/cdata/comment/pi node.
 
Field Summary
(package private)  DomCore doc
          The document.
 boolean inEntity
          If true then all nodes represented by this nodelist are in some entity.
 Element parentElement
          'Parent' element of all nodes represented by this list.
 boolean parentElementInEntity
          If true then parent element itself is in some entity.
 
Constructor Summary
NodeListID(DomPointer start, DomPointer end, DomCore doc)
          The constructor.
NodeListID(Node node, DomCore doc)
          Contructs the instance that shall contain only given node.
 
Method Summary
(package private)  void checkDocument(DomCore doc)
          Checks if this nodelist points into nodes belonging to given doc.
 boolean contains(DomPointer ptr)
          Checks if given pointer points inside this nodelist.
 boolean equals(Object obj)
           
 DomPointer getEnd()
          Returns the ending pointer marking the end of this nodelist.
 int getLength()
          Returns number of nodes represented by this nodelist.
 int getMaxPos()
          Determines the maximum position that can be given as argument to functions.
 int getNearestInsertablePos(int pos, boolean forward)
          Computes nearest pos to given pos, that does not point into an entity.
 int getNodeIndex(Node node)
          Determines the index of the node in the 'item' array.
 NodeListID.NodePtr getNodePtr(int pos, boolean preferNext)
          Converts the position in the textValue into node, that holds specified piece.
 int getNodeTextEnd(Node node)
          Determines the end index of node text in global text value.
static int getNodeTextLength(Node node)
          Determines the length of the node text.
 int getNodeTextStart(Node node)
          Determines the start index of node text in global text value.
 DomPointer getPointer(int pos, boolean preferNext, boolean preferModifiable)
          Converts the position in the textValue into a DOM pointer instance.
 int getPos(DomPointer ptr)
          From given nodeindex and text position computes the global position (position in the text value).
 int getPos(int nodeIndex, int pos)
          From given nodeindex and text position computes the global position (position in the text value).
 EntityReference getPrimaryEntity(int index)
          Returns primary entity, where the node with given index is positioned.
 EntityReference getPrimaryEntity(Node node)
          Returns primary entity, where the node is positioned.
 DomPointer getStart()
          Returns the starting pointer marking the start of this nodelist.
 String getTextValue()
          Returns the textual value of the node.
 InsertPoint getTopLevelIP(int pos)
          Computes and returns the toplevel insertpoint (pointing into children of the context element), pointing onto given position in text value.
 int hashCode()
           
 boolean inEntity(int nodeIndex)
          Checks if the node with given index is contained in some entity, hence unmodifiable.
 boolean isDeletable(int start, int end)
          Checks if text between start and end indexes can be removed.
 boolean isPartiallySelectable()
          Determines if this nodelist denotes one or more text/cdata nodes, or a single comment node.
 boolean isTextual()
          Determines if this nodelist denotes one or more text/cdata nodes.
 Node item(int index)
          Returns node with given index.
(package private) static NodeListID newInstance(Node node, DomCore doc)
          Creates new instance of the nodelist.
 NodeListID recover()
          Tries to recover from modification of underlying nodes.
 int resolveIndex(String transformResult, int transformIndex)
          Tries to resolve the index from given string back to the original string.
 DOMInterval toInterval()
          Returns this node list as an interval.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

parentElement

public final Element parentElement
'Parent' element of all nodes represented by this list. 'Parent' means parent when all entity references are resolved. If the list denotes root element then this is null.


doc

final DomCore doc
The document.


inEntity

public final boolean inEntity
If true then all nodes represented by this nodelist are in some entity. If false then some nodes may not be in an entity, however there is a possibility that all nodes are in some entity(ies).


parentElementInEntity

public final boolean parentElementInEntity
If true then parent element itself is in some entity. If true then inEntity is true aswell. If there is no parent element then this value is false.

Constructor Detail

NodeListID

NodeListID(Node node,
           DomCore doc)
Contructs the instance that shall contain only given node.

Parameters:
node - the node.
doc - reference to the document.

NodeListID

NodeListID(DomPointer start,
           DomPointer end,
           DomCore doc)
The constructor.

Parameters:
start - the start of the range. The node where start points is included in result set.
end - the end of the range. The node where end points is excluded.
doc - the instance of the document.
Method Detail

newInstance

static NodeListID newInstance(Node node,
                              DomCore doc)
Creates new instance of the nodelist.

Parameters:
node - the node
doc - the instance of the document.
Returns:
a nodelist containing given node (and adjacent text/cdata nodes in case of text/cdata node)

getLength

public int getLength()
Returns number of nodes represented by this nodelist.

Specified by:
getLength in interface NodeList
Returns:
node count

item

public Node item(int index)
Returns node with given index.

Specified by:
item in interface NodeList
Returns:
node with given index or null if index is outside valid range.

isTextual

public boolean isTextual()
Determines if this nodelist denotes one or more text/cdata nodes.

Returns:
true if the list consists of text/cdata nodes, false otherwise.

isPartiallySelectable

public boolean isPartiallySelectable()
Determines if this nodelist denotes one or more text/cdata nodes, or a single comment node.

Returns:
true if the list consists of text/cdata nodes/comment node, false otherwise.

getTextValue

public String getTextValue()
Returns the textual value of the node. If there are more text/cdata nodes then the concatenation of their textual values is returned. This string is computed when the object is created hence it does not reflect the changes in the nodes.

Returns:
the textual value of the node(s), or null in case of element.

getPointer

public DomPointer getPointer(int pos,
                             boolean preferNext,
                             boolean preferModifiable)
Converts the position in the textValue into a DOM pointer instance. Applicable only to textual list.

Parameters:
pos - the position in the textValue string.
preferNext - if true and the pos points between adjacent text nodes, then prefer next node.
preferModifiable - if pos points between adjacent text nodes then prefer the one that is modifiable. It has higher priority than preferNext and it may even find a pointer that does not point to none of these two nodes - it is the case when there are two adjacent text entities, in such case the pointer shall point between these two entities. However, if no place is suitable for inserting text then this parameter has no meaning and will be ignored - the pointer shall always point into one of the text nodes picked by the preferNext argument.
Returns:
DOM pointer pointing at given pos.

getStart

public DomPointer getStart()
Returns the starting pointer marking the start of this nodelist.

Returns:
pointer, pointing on the first node in the list.

getEnd

public DomPointer getEnd()
Returns the ending pointer marking the end of this nodelist.

Returns:
pointer, pointing after the last node in the list.

contains

public boolean contains(DomPointer ptr)
Checks if given pointer points inside this nodelist.

Parameters:
ptr - pointer to check
Returns:
true if the pointer points inside this nodelist, false otherwise.

toInterval

public DOMInterval toInterval()
Returns this node list as an interval.

Returns:
the node interval

getTopLevelIP

public InsertPoint getTopLevelIP(int pos)
Computes and returns the toplevel insertpoint (pointing into children of the context element), pointing onto given position in text value. If no such insertpoint exists (for example if pos points into an entity), function returns null. Applicable only to textual list.

Parameters:
pos - the position in the textValue string.
Returns:
top-level insertpoint or null if no such insertpoint exists.

getNodePtr

public NodeListID.NodePtr getNodePtr(int pos,
                                     boolean preferNext)
Converts the position in the textValue into node, that holds specified piece. Applicable only to textual list.

Parameters:
pos - the position in the textValue string.
preferNext - if pos points into the boundary between two text nodes, then prefer the next one.
Returns:
node which contain text, where the pos points.

getMaxPos

public int getMaxPos()
Determines the maximum position that can be given as argument to functions.

Returns:
the maximum position. Always zero if list does not point onto a text.

getPos

public int getPos(int nodeIndex,
                  int pos)
From given nodeindex and text position computes the global position (position in the text value). Applicable to textual list only.

Parameters:
nodeIndex - the index of the ID-level node (into the 'item' getfunction).
pos - position in the text of the node
Returns:
global position

getPos

public int getPos(DomPointer ptr)
From given nodeindex and text position computes the global position (position in the text value). Applicable to selectable list only.

Parameters:
ptr - pointer to check
Returns:
the global position, or -1 if the pointer does not point inside the node list.

getNodeTextStart

public int getNodeTextStart(Node node)
Determines the start index of node text in global text value. Works with text/cdata nodes.

Parameters:
node - the node to check.
Returns:
index into getTextValue where the text contained in given node starts.

getNodeTextEnd

public int getNodeTextEnd(Node node)
Determines the end index of node text in global text value. Works with text/cdata nodes.

Parameters:
node - the node to check.
Returns:
index into getTextValue where the text contained in given node starts.

getNodeTextLength

public static int getNodeTextLength(Node node)
Determines the length of the node text.

Parameters:
node - the node to check.
Returns:
length of the node text. Works with text, cdata, attribute, ip and comment nodes.

getNodeIndex

public int getNodeIndex(Node node)
Determines the index of the node in the 'item' array.

Parameters:
node - the node.
Returns:
the index of the node in 'item' array or -1 if node haven't been found.

isDeletable

public boolean isDeletable(int start,
                           int end)
Checks if text between start and end indexes can be removed. Text cannot be removed for example if it would modify part of entity, etc. This function does not perform validation hence the text may not be deletable even when this function returns true. Applicable only to textual list.

Parameters:
start - start index
end - end index
Returns:
true if such interval is deletable, false otherwise.

inEntity

public boolean inEntity(int nodeIndex)
Checks if the node with given index is contained in some entity, hence unmodifiable.

Parameters:
nodeIndex - the node index
Returns:
true if the node is a descendant of some entity reference node, false otherwise.

getNearestInsertablePos

public int getNearestInsertablePos(int pos,
                                   boolean forward)
Computes nearest pos to given pos, that does not point into an entity. Applicable to textual list only.

Parameters:
pos - the starting position in global text.
forward - if true then scan goes forward.
Returns:
first position where the text can be inserted. It may return given pos. If -1 then no such position is found.

getPrimaryEntity

public EntityReference getPrimaryEntity(int index)
Returns primary entity, where the node with given index is positioned. If entities are nested then it shall be the 'lowest' entity - the entity whose parent is the context element. Applicable to textual list only.

Parameters:
index - index of the node
Returns:
primary entity, or null if the node is not in an entity or the context element is itself in an entity.

getPrimaryEntity

public EntityReference getPrimaryEntity(Node node)
Returns primary entity, where the node is positioned. If entities are nested then it shall be the 'lowest' entity - the entity whose parent is the context element. Applicable to textual list only.

Parameters:
node - the node
Returns:
primary entity, or null if the node is not in an entity or the context element is itself in an entity.

toString

public String toString()
Overrides:
toString in class Object

recover

public NodeListID recover()
Tries to recover from modification of underlying nodes. Returns new instance of the list that reflects the changes. Applicable only to the textual list.

Returns:
new nodelist instance reflecting the changes, or null if recovery was unsuccesfull (all old nodes are removed from the document).

resolveIndex

public int resolveIndex(String transformResult,
                        int transformIndex)
Tries to resolve the index from given string back to the original string. This method expects that transformed result may differ from our string only by whitespaces.

Parameters:
transformResult - the result of the transformation
transformIndex - index into the transformResult string.
Returns:
index into the textValue, always within the range of the textValue.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

checkDocument

void checkDocument(DomCore doc)
Checks if this nodelist points into nodes belonging to given doc.

Parameters:
doc - the document.


Copyright 2003-2003-2006 null. All Rights Reserved.