|
||||||||||
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. |
DocumentFragment |
cut(sk.baka.ikslibs.ptr.DomPointer from,
sk.baka.ikslibs.ptr.DomPointer to)
Deprecated. |
sk.baka.ikslibs.levelmapper.NodeListID |
delete(sk.baka.ikslibs.levelmapper.NodeListID list,
int fromPos,
int toPos)
Deprecated. |
void |
endModify()
Ends modification of document. |
sk.baka.ikslibs.levelmapper.NodeListID |
insertEntity(sk.baka.ikslibs.levelmapper.NodeListID list,
int pos,
String entityName)
Deprecated. |
void |
insertFragment(DocumentFragment frag,
sk.baka.ikslibs.ptr.DomPointer ptr)
Deprecated. |
void |
insertNode(Node node,
sk.baka.ikslibs.ptr.DomPointer ptr,
boolean merge)
Deprecated. |
String |
insertText(sk.baka.ikslibs.ptr.DOMPoint ip,
Element contextElement,
String value,
short type)
Deprecated. |
String |
insertText(sk.baka.ikslibs.ptr.DomPointer point,
String value,
short type)
Deprecated. |
String |
insertText(sk.baka.ikslibs.ptr.DOMPoint ip,
String contextId,
String value,
short type)
Deprecated. |
sk.baka.ikslibs.levelmapper.NodeListID |
insertText(sk.baka.ikslibs.levelmapper.NodeListID list,
int pos,
String text,
short type)
Deprecated. |
boolean |
isModifying()
Returns true , if document is being modified by caller
thread. |
boolean |
isRemovable(sk.baka.ikslibs.ptr.DomPointer from,
sk.baka.ikslibs.ptr.DomPointer to)
Checks whether all nodes from specified range can be deleted - i.e. |
void |
remove(sk.baka.ikslibs.ptr.DomPointer from,
sk.baka.ikslibs.ptr.DomPointer to)
Deprecated. |
void |
remove(Node node)
Removes given node from the document. |
void |
remove(String id)
Deprecated. |
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 |
setText(String id,
String value)
Deprecated. |
Text |
splitText(sk.baka.ikslibs.ptr.DomPointer ptr)
Deprecated. |
Text |
splitText(String id,
int pos)
Deprecated. |
Text |
splitText(Text text,
int pos)
Deprecated. |
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 sk.baka.xml.gene.ExportException
sk.baka.xml.gene.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.@Deprecated public void setText(String id, String value)
id
- id of text node, that receives new value.value
- new text value. null
value is equivalent to
an empty string.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.@Deprecated public Text splitText(String id, int pos)
id
- the id of the text/cdata nodepos
- zero-based position where the text shall be splitted.
null
when no splitting occured.@Deprecated public Text splitText(Text text, int pos)
text
- the text/cdata nodepos
- zero-based position where the text shall be splitted.
null
when no splitting occured.@Deprecated public Text splitText(sk.baka.ikslibs.ptr.DomPointer ptr)
ptr
- the pointer pointing into the text/cdata node.
null
when no splitting occured.@Deprecated public String insertText(sk.baka.ikslibs.ptr.DOMPoint ip, String contextId, String value, short type) throws DocumentException
ip
- insert point, where to insert new text.contextId
- the context element, where new text must be inserted.value
- new text value. if null
or empty string ("")
is given, then nothing is created.type
- type of created node, one of Node.TEXT_NODE
or
Node.CDATA_SECTION_NODE
constants. When modifying text,
this parameter is ignored.
null
is returned.
DocumentException
- when element with given id doesn't exist or it
doesn't denote regular element.@Deprecated public String insertText(sk.baka.ikslibs.ptr.DomPointer point, String value, short type)
point
- insert point, where to insert new text. It must not point
into an entity.value
- new text value. if null
or empty string ("")
is given, then nothing is created.type
- type of created node, one of Node.TEXT_NODE
or
Node.CDATA_SECTION_NODE
constants. When modifying text,
this parameter is ignored.
null
is returned.@Deprecated public String insertText(sk.baka.ikslibs.ptr.DOMPoint ip, Element contextElement, String value, short type)
ip
- insert point, where to insert new text.contextElement
- the context element, where new text must be
inserted.value
- new text value. if null
or empty string ("")
is given, then nothing is created.type
- type of created node, one of Node.TEXT_NODE
or
Node.CDATA_SECTION_NODE
constants. When modifying text,
this parameter is ignored.
null
is returned.@Deprecated public void remove(String id)
id
- id of the node, that will be removed.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.
@Deprecated public void insertNode(Node node, sk.baka.ikslibs.ptr.DomPointer ptr, boolean merge)
node
- the node to insert, it must be element, comment, pi, text or
cdata only.ptr
- where to insert the node.merge
- if true
then if new node is a text node then
it will be merged with adjacent nodes if possible. If false
then no merging is performed.@Deprecated public void insertFragment(DocumentFragment frag, sk.baka.ikslibs.ptr.DomPointer ptr)
emp:id
attributes are ignored. All nodes are removed from the fragment in the
process and become part of the document.
frag
- the fragmentptr
- where to insert nodes from the fragment.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.public boolean isRemovable(sk.baka.ikslibs.ptr.DomPointer from, sk.baka.ikslibs.ptr.DomPointer to)
delete
with these parameters shall succeed.
from
- start of the removal interval. The node where this pointer
points shall be removed (an exception is if some contents of the node are
left after the operation).to
- end of the removal interval.
true
if the specified interval is removable,
false
otherwise.@Deprecated public void remove(sk.baka.ikslibs.ptr.DomPointer from, sk.baka.ikslibs.ptr.DomPointer to)
to
parameter is not removed). The function shall not
remove elements that shall not have all its children removed.
from
- start of the removal interval. The node where this pointer
points shall be removed (exception is a node which have some children
left after the operation).to
- end of the removal interval. It may be null
- in
such case the function shall remove all nodes to the end of the document.@Deprecated public DocumentFragment cut(sk.baka.ikslibs.ptr.DomPointer from, sk.baka.ikslibs.ptr.DomPointer to)
to
parameter is not removed). Removed nodes are returned
in a DocumentFragment
instance. Both pointers must have
the same parent element.
from
- start of the removal interval. The node where this pointer
points shall be removed.to
- end of the removal interval.
DocumentFragment
instance containing nodes that
have been cut from the document. Never null
. No element
in the target fragment will have emp:id
attribute.@Deprecated public sk.baka.ikslibs.levelmapper.NodeListID insertText(sk.baka.ikslibs.levelmapper.NodeListID list, int pos, String text, short type)
list
- current list of nodes, where to insert the text.pos
- the position in the textValue
string.type
- type of created node, one of Node.TEXT_NODE
or
Node.CDATA_SECTION_NODE
constants. When modifying text,
this parameter is ignored.text
- the text to be inserted
IllegalArgumentException
- if no text can be inserted at specified
position.@Deprecated public sk.baka.ikslibs.levelmapper.NodeListID insertEntity(sk.baka.ikslibs.levelmapper.NodeListID list, int pos, String entityName)
list
- current list of nodes, where to insert the entity.pos
- the position in the textValue
string.entityName
- the name of the entity.
@Deprecated public sk.baka.ikslibs.levelmapper.NodeListID delete(sk.baka.ikslibs.levelmapper.NodeListID list, int fromPos, int toPos)
list
- list of text/cdata nodes. If function finishes succesfully
and the document gets modified, this list is invalid and must not be
used.fromPos
- the starting positiontoPos
- the ending position - character at this position shall not
be deleted.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |