|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sk.uniba.euromath.document.DocumentModifier
public final class DocumentModifier
Serves for modifying document. Tracks changes in document, and makes them consistent with 'splitted' images of document. Accessible from out of document package. All functions work on DOM-level nodes. Thread safe.
This class is unchecked - it allows to set given text or modify document structure even if the change violates the grammar rules. Caller should make sure that the document is valid before the transformation execution.
WARNING: when modifying the document, then IDs pointing to nodes after node
being modified can become invalid (may denote a wrong node) - this happens
for example when the text/cdata/comment/pi node is deleted (for example, when
null
value is given to a setText()
function).
Method Summary | |
---|---|
String |
createAttribute(Element e,
QName qname,
String value)
Creates an attribute. |
String |
createAttribute(Element e,
String prefix,
String localName,
String namespace,
String value)
Creates an attribute. |
String |
createAttribute(String id,
QName qname,
String value)
Creates an attribute. |
String |
createAttribute(String id,
String prefix,
String localName,
String namespace,
String value)
Creates an attribute. |
void |
endModify()
Ends modification of document. |
boolean |
isModifying()
Returns true , if document is being modified by caller
thread. |
void |
remove(Node node)
Removes given node from the document. |
void |
replaceNode(Node node,
Node newNode)
Replaces the node with another node. |
void |
setText(Node node,
String value)
Sets text of given node to given value. |
void |
startModify()
Begins modification sequence. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public void startModify()
Begins modification sequence. All modifications to document must be
enclosed with startModify() .. endModify()
sequence. In
other words, modifying document when isModifying()==false
will result in IllegalStateException
.
startModify()
calls can be nested, i.e. it is possible to
call startModify()
when isModifying()
, but
every call to startModify()
should be closed with
endModify()
, otherwise document won't be never
transformed, and other threads will block forever.
Two threads cannot modify one document concurrently. If one thread is
currently modifying a document and second thread calls
startModify()
, the function will block until current
thread finishes the modification.
public void endModify() throws ExportException
ExportException
- when something goes wrong in the process of
transformation.public boolean isModifying()
true
, if document is being modified by caller
thread.
true
, if document is being modified,
false
otherwise.public void setText(Node node, String value)
node
- the text node, that receives new value.value
- new text value. null
value is equivalent to
an empty string.public void remove(Node node)
node
- the node, that will be removed. Its id is removed aswell, but
the id of descendants is not removed.public String createAttribute(String id, String prefix, String localName, String namespace, String value)
id
- id of element, that contains the attribute.prefix
- prefix of qname of attribute. See
NamespaceManager
for details.localName
- local name of attribute.namespace
- namespace of attribute.value
- new value for attribute.
public String createAttribute(String id, QName qname, String value)
id
- id of element, that contains the attribute.qname
- qualified name of the attributevalue
- new value for attribute.
public String createAttribute(Element e, QName qname, String value)
e
- element, that contains the attribute.qname
- qualified name of the attributevalue
- new value for attribute.
public String createAttribute(Element e, String prefix, String localName, String namespace, String value)
e
- element, that contains the attribute.prefix
- prefix of qname of attribute. See
NamespaceManager
for details.localName
- local name of attribute.namespace
- namespace of attribute.value
- new value for attribute.
public void replaceNode(Node node, Node newNode)
newNode
must have
null
parent or it must be from another document.
node
- the node to be replaced.newNode
- the node will be replaced with this node. If
null
then given node is removed. If not from our document
then it is automatically imported.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |