|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sk.uniba.euromath.document.IDManager
public final class IDManager
Provides support for mapping between ID and nodes. The class relies mainly on
value of the attribute Const.EM_ATTRIBUTE_ID
, its internal
list is used only for fast execution of getNode
. Non-element
nodes, such as text, cdata etc, are addressed by their parent element's id,
thus they don't have ID themselves.
Every element has an ID: an integer number. Every non-element non-atribute
node has two-part ID, split by a ;
: first part is ID of their
parent element, and second part is their position in this element (the
numbering starts from 0). Warning: this numbering is consistent with the
'normalized document' (the document that is source for the transformation
process) rather than the original document. Use the getID()
function rather than computing the ID yourself. Every attribute has an ID
split by @
: first part is the ID of their owner element
and second part is the prefixed name of the attribute.
If the node is a root node (the parent is the document) and it is not an
element then the ID is in format ";[number]
" - it does not
have an ID of parent element.
Prior to each transformation the document is normalized: entity references are resolved and all adjacent text and cdata nodes are merged into one text node. Hence one text node can be backwards-identified as a set of 'adjacent' nodes (adjacent when the entity references are resolved). No ID may reference an entity reference node.
Nodes belonging to contents of EntityReference
node are not
modifiable however they do have an ID - if they contain namespace cross
boundary then we need this ID for emp:mark
element.
FOP requires that each ID is unique. However we may want to identify same element from different places. We must ensure that two different ID strings denote the same element. Hence, we define the ID structure as follows:
[parent-id]{; or @} position or attribute-name [:any_string]
where [] denotes the optional part and {} represents choice between two or more strings. No whitespaces are allowed. Two IDs are equal if and only if their parent-id are equal or both are missing and position or attribute-name are equal.
Constructor Summary | |
---|---|
IDManager(DomCore document)
Constructs an IDManager instance bound to specified document . |
Method Summary | |
---|---|
String |
addElement(Element element)
Links given element with unique ID. |
String |
addElement(Element element,
boolean fail)
Links given element with unique ID. |
String |
addTree(Node node)
Adds all element nodes in the descendant-or-self axis of given node to the id list. |
String |
addTree(Node node,
boolean fail)
Adds all element nodes in the descendant-or-self axis of given node to the id list. |
boolean |
areIdEqual(String id1,
String id2)
Tests if the two IDs denote the same nodeset. |
static boolean |
canHaveId(Node node)
Checks if the node can have an id. |
static boolean |
canHaveId(short nodeType)
Checks if the node can have an id. |
void |
checkNode(Node node)
Checks if given node is from this document. |
int |
compareIds(String id1,
String id2)
Compares two IDs by their document order and returns result similar to Comparable.compareTo(Object) method. |
String |
getID(Node node)
Gets ID value from the node. |
static String |
getIDNull(Node node)
Gets ID value from the node. |
NodeListID |
getNode(String id)
Gets node identified by ID. |
NodeListID |
getNodeNull(String id)
Gets node identified by ID. |
short |
getNodeType(String id)
Returns the type of node, denoted by given ID. |
boolean |
hasID(Element element)
Examines if the node has ID (contains the emp:id
attribute). |
boolean |
inEntity(String id)
Checks if node with given ID is in an entity, therefore unmodifiable. |
static boolean |
isEmpId(Node node)
Checks if given node is the emp:id attribute. |
boolean |
isValid(String id)
Checks whether given ID is valid. |
static boolean |
isWellFormed(String id)
Checks whether given ID is well-formed (but the presence of the node with this id in the document is not checked). |
void |
remove(Element element)
Removes element from list. |
(package private) void |
remove(String id)
Removes element with given id from our list. |
(package private) static void |
removeIdAttr(Element element)
Removes the id attribute from the element. |
void |
removeTree(Node node)
Removes all element nodes in the descendant-or-self axis of given node from the id list. |
(package private) void |
removeTreeIdOnly(Node node)
Strips all element nodes in the descendant-or-self axis from the emp:id attribute but does not unregister them from the ID
manager. |
void |
sortByDocumentOrder(List<String> list)
Sorts list of IDs: node denoted by first ID precedes node denoted by second ID etc. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
IDManager(DomCore document) throws DocumentException
document
.
Instance created with reference to document will not accept nodes from
another document. Upon creating, IDs for all elements are generated,
except for elements, that are descendants of EntityReference
nodes, because they are not modifiable.
document
- the document.
DocumentException
- when some elements already contains
emp:id
.Method Detail |
---|
public String addElement(Element element)
emp:id
attribute. If the node already has an
id then its present id is returned instead.
element
- Element, that has been added to the document.
public String addElement(Element element, boolean fail) throws DocumentException
emp:id
attribute. If the node already has an
id then its present id is returned instead.
element
- Element, that has been added to the document.fail
- if true
then the function will fail when
element already has id.
DocumentException
- if element already contains id.public void checkNode(Node node)
node
- node to check
IllegalArgumentException
- if node is not from our document.public String addTree(Node node)
null
.
node
- the root of the tree to register.
null
only if the
node is not an element and parent element has no id.public String addTree(Node node, boolean fail) throws DocumentException
null
.
node
- the root of the tree to register.fail
- if true
then the function will fail when at
least one element contains the emp:id
attribute. In this
case some elements may already have received an id.
null
only if the
node is not an element and parent element has no id.
DocumentException
- if an element already contains
emp:id
and fail
is true
.public void remove(Element element)
element
- element, which is being removed from the manager.static void removeIdAttr(Element element)
element
- element, which shall have emp:id
attribute
stripped.public void removeTree(Node node)
null
.
node
- the root of the tree to remove from registry.void removeTreeIdOnly(Node node)
emp:id
attribute but does not unregister them from the ID
manager. Useful when making clone of element etc.
node
- the root of the tree.void remove(String id)
id
- id of the node, that will be removed.
AssertionError
- if the id is not an element id.public static boolean canHaveId(Node node)
node
- the node to check
public static boolean canHaveId(short nodeType)
nodeType
- the node type to check
public static boolean isWellFormed(String id)
id
- the ID to check.
true
if the ID is well-formed, false
otherwise.public boolean isValid(String id)
id
- the ID to check.
true
if id is valid, false
otherwise.public boolean inEntity(String id) throws DocumentException
id
- ID of the node
true
if the node is not modifiable,
false
if node is not in an entity (in case of element, PI,
comment, attribute) or some text parts may be modifiable (in case of
textual node).
DocumentException
- if id doesn't exist.public short getNodeType(String id) throws DocumentException
id
- id of the node.
Node
type constants.
DocumentException
- if given ID does not exist.public static String getIDNull(Node node)
null
. This method works also with nodes, which
doesn't belong to our document. If the ID spans over multiple nodes then
given node is amongst these nodes.
node
- Element, whose ID has to be returned.
null
if the node doesn't have
an ID. It will not have the trailing third (:) part.public String getID(Node node)
IllegalStateException
. It works with all types
of nodes, even not from our document.
node
- node, whose ID has to be returned.
public boolean areIdEqual(String id1, String id2)
id1
- first IDid2
- second ID
true
if the IDs are same.public NodeListID getNode(String id) throws DocumentException
id
- id of the desired node.
null
nor empty.
DocumentException
- if id doesn't exist.public NodeListID getNodeNull(String id)
id
- id of the desired node.
null
if the id
is not valid.public boolean hasID(Element element)
emp:id
attribute).
element
- the element to be examined.
public static boolean isEmpId(Node node)
emp:id
attribute.
node
- node to check.
true
if node is emp:id
attribute,
false
otherwise.public int compareIds(String id1, String id2) throws DocumentException
Comparable.compareTo(Object)
method.
id1
- first IDid2
- second ID
areIdEqual(String, String)
method, or 1 if
node denoted by first id follows node denoted by second id.
DocumentException
- if id doesn't exist.public void sortByDocumentOrder(List<String> list)
list
- list to sort.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |