com.levigo.jadice.document.metadata
Interface MutableMetadataNode

All Superinterfaces:
MetadataNode

public interface MutableMetadataNode
extends MetadataNode

Enables the creation, parsing, navigation, and modification of XML-based meta-data-documents through a simple and intuitive fluent interface.


Method Summary
 MutableMetadataNode add(Document doc)
          Inserts another Document instance under the current tag
 MutableMetadataNode add(Element tag)
          Inserts a Element instance and its hierarchy under the current tag
 MutableMetadataNode add(Metadata metadata)
          Insert another Metadata tree into the hierarchy under the current tag
 MutableMetadataNode addAttribute(String name, Object value)
          Create a new attribute for the current node.
 MutableMetadataNode addAttributeInDefaultNamespace(String name, String value)
          Create a new attribute for the current node.
 MutableMetadataNode addCDATA(String data)
          Add a data node under the current node, and jump to the parent node.
 MutableMetadataNode addDocument(MetadataNode tag)
          Inserts another MutableMetadataNode instance under the current tag.
 MutableMetadataNode addNamespace(String prefix, String namespaceURI)
          Add a namespace to the document
 MutableMetadataNode addNode(MetadataNode tag)
          Inserts another MutableMetadataNode tag hierarchy under the current tag.
 MutableMetadataNode addNode(String name)
          Create a tag under the current location and use it as the current node
 MutableMetadataNode addText(String text)
          Add a text node under the current node, and jump to the parent node.
 MutableMetadataNode addText(Text text)
          Add a text note to the current tag
 MutableMetadataNode clone()
           
 MutableMetadataNode createNamespaceContext()
          Create a wrapper node which allows a new mapping of namespace prefixes to be used to navigate and query nodes without changing the base document.
 MutableMetadataNode delete()
          Delete current tag and its children.
 MutableMetadataNode deleteAttribute(String name)
          Delete an attribute of the current node.
 MutableMetadataNode deleteAttributeIfExists(String name)
          Delete an attribute of the current node, if it exists
 MutableMetadataNode deleteAttributes()
          Delete all existing attributes of current node
 MutableMetadataNode deleteChildren()
          Delete all existing elements of this node
 MutableMetadataNode deletePrefixes()
          Remove any prefix and name-spaces contained in the tag name, children and attributes, thus changing name-space and tag name.
 List<MutableMetadataNode> getChildren()
          Return a list of all child nodes.
 List<MutableMetadataNode> getChildren(String relativeXpath, Object... arguments)
          Return a list of all nodes selected by the XPath expression.
 MutableMetadataNode getInnerDocument()
           
 MutableMetadataNode gotoChild()
          Go to the only child element of the current node.
 MutableMetadataNode gotoChild(int i)
          Go to the Nth child of the curent node.
 MutableMetadataNode gotoChild(String nodeName)
          Go to the child found with given node name
 MutableMetadataNode gotoFirstChild()
          Go to the first child element of the current node.
 MutableMetadataNode gotoFirstChild(String name)
          Go to the first child with the given name
 MutableMetadataNode gotoLastChild()
          Go to the last child element of the current node.
 MutableMetadataNode gotoLastChild(String name)
          Go to the last child with the given name
 MutableMetadataNode gotoParent()
          Go to parent tag.
 MutableMetadataNode gotoRoot()
          Go to document root tag
 MutableMetadataNode gotoTag(String relativeXpath, Object... arguments)
          Go to a specific node
 MutableMetadataNode renameTo(String newTagName)
          Replace current element name by another name
 MutableMetadataNode setAttribute(String name, String value)
          Sets the new value on an existing attribute, and remains on the current tag.
 MutableMetadataNode setAttribute(String name, String value, String relativeXpath, Object... arguments)
          Sets the new value on a targeted node's attribute, and remains on the current tag.
 MutableMetadataNode setAttributeIfExist(String name, String value)
          Sets the new value on an attribute, and remains on the current tag.
 MutableMetadataNode setAttributeIfExist(String name, String value, String relativeXpath, Object... arguments)
          Sets the new value on a targeted node's attribute, and remains on the current tag.
 MutableMetadataNode setCDATA(String data)
          Set the cdata in the current node.
 MutableMetadataNode setText(String text)
          Set the text in the current node.
 MutableMetadataNode setText(String text, String relativeXpath, Object... arguments)
          Set the text in the targeted node.
 MutableMetadataNode setTextIfExist(String text, String relativeXpath, Object... arguments)
          Set the text in the targeted node.
 
Methods inherited from interface com.levigo.jadice.document.metadata.MetadataNode
evalToBoolean, evalToNode, evalToNodeSet, evalToNumber, evalToString, findAttribute, findAttribute, getAttribute, getAttribute, getAttributeNames, getCDATA, getChildCount, getDocument, getElement, getEncoding, getInnerText, getLocation, getName, getPrefix, getPrefixes, getText, getText, getTextOrCDATA, getTextOrCDATA, hasAttribute, hasAttribute, hasNode
 

Method Detail

addAttribute

MutableMetadataNode addAttribute(String name,
                                 Object value)
Create a new attribute for the current node. If the name doesn't contain a prefix, the attribute is put into the null namespace.

Example:
addDefaultNamespace("http://foo").addNode("foo").addAttribute("bar", "baz");
yields
<foo xmlns="http://foo" bar="baz"/>

Parameters:
name - Name of the attribute to add
value - value of the attribute to add. If the value isn't a string, it is converted into one using Object.toString(). If the value is null, the attribute is omitted.
Returns:
this

addAttributeInDefaultNamespace

MutableMetadataNode addAttributeInDefaultNamespace(String name,
                                                   String value)
Create a new attribute for the current node. If the name doesn't contain a prefix, the attribute is put into the default name space.

Example:
addDefaultNamespace("http://foo").addNode("foo").addAttribute("bar", "baz");
yields
<foo xmlns="http://foo" xmlns:ns0="http://foo" ns0:bar="baz"/>

Parameters:
name - Name of the attribute to add
value - value of the attribute to add
Returns:
this

addCDATA

MutableMetadataNode addCDATA(String data)
Add a data node under the current node, and jump to the parent node. This enables the create or quick documents like this:

addTag("name").addCDATA("Bob")addTag("sex").addCDATA("M")addTag("age").addCDATA("30")

<name><![CDATA[Bob]]></name><sex><![CDATA[M]]></sex><age><![CDATA[30]]></ age>

Parameters:
data - the data to add
Returns:
this

addDocument

MutableMetadataNode addDocument(MetadataNode tag)
Inserts another MutableMetadataNode instance under the current tag. The whole document will be inserted.

Parameters:
tag - The MutableMetadataNode instance to insert
Returns:
this

add

MutableMetadataNode add(Document doc)
Inserts another Document instance under the current tag

Parameters:
doc - The Document instance to insert
Returns:
this

addNamespace

MutableMetadataNode addNamespace(String prefix,
                                 String namespaceURI)
Add a namespace to the document

Parameters:
prefix - The prefix of the namespace
namespaceURI - The URI of the namespace
Returns:
this

addNode

MutableMetadataNode addNode(MetadataNode tag)
Inserts another MutableMetadataNode tag hierarchy under the current tag. Only the current tag of the given document will be inserted with its hierarchy, not the whole document.

Parameters:
tag - The MutableMetadataNode current tag hierarchy to insert
Returns:
this

add

MutableMetadataNode add(Element tag)
Inserts a Element instance and its hierarchy under the current tag

Parameters:
tag - The Element instance to insert
Returns:
this

add

MutableMetadataNode add(Metadata metadata)
Insert another Metadata tree into the hierarchy under the current tag

Parameters:
metadata - the metadata tree to add
Returns:
this

addNode

MutableMetadataNode addNode(String name)
Create a tag under the current location and use it as the current node

Parameters:
name - Name of the element to add
Returns:
this

addText

MutableMetadataNode addText(String text)
Add a text node under the current node, and jump to the parent node. This enables the create or quick documents like this:

addTag("name").addText("Bob")addTag("sex").addText("M")addTag("age").addText("30")

<name>Bob</name><sex>M</sex><age>30</age>

Parameters:
text - the text to add
Returns:
this

addText

MutableMetadataNode addText(Text text)
Add a text note to the current tag

Parameters:
text - The node to insert
Returns:
this

delete

MutableMetadataNode delete()
                           throws MetadataException
Delete current tag and its children. If the current tag is the root tag of XML document, it cannot be delete. It can just be replaced. In this case, an exception is thrown

Returns:
this
Throws:
MetadataException - if the current node is the root node

deleteAttribute

MutableMetadataNode deleteAttribute(String name)
                                    throws MetadataException
Delete an attribute of the current node.

Parameters:
name - attribute name
Returns:
this
Throws:
MetadataException - if the attribute does not exist

deleteAttributeIfExists

MutableMetadataNode deleteAttributeIfExists(String name)
Delete an attribute of the current node, if it exists

Parameters:
name - attribute name
Returns:
this

deleteAttributes

MutableMetadataNode deleteAttributes()
Delete all existing attributes of current node

Returns:
this

deleteChildren

MutableMetadataNode deleteChildren()
Delete all existing elements of this node

Returns:
this

deletePrefixes

MutableMetadataNode deletePrefixes()
Remove any prefix and name-spaces contained in the tag name, children and attributes, thus changing name-space and tag name. This can be very useful if you are working in a document when you want to ignore name-spaces, if you don't know the tag prefix

Returns:
this

clone

MutableMetadataNode clone()
Returns:
A new com.mycila.xmltool.XMLTag instance having the same properties and documents of the current instance. The current tag will also remain the same (this.getCurrentTagName().equals(this.duplicate(). getCurrentTagName()))

gotoChild

MutableMetadataNode gotoChild()
                              throws MetadataException
Go to the only child element of the current node.

Specified by:
gotoChild in interface MetadataNode
Returns:
this
Throws:
MetadataException - If the current node has several childs or no child at all

gotoChild

MutableMetadataNode gotoChild(int i)
                              throws MetadataException
Go to the Nth child of the curent node.

Specified by:
gotoChild in interface MetadataNode
Parameters:
i - index of the child, from 1 to child element number
Returns:
this
Throws:
MetadataException - If the child node does not exist

gotoChild

MutableMetadataNode gotoChild(String nodeName)
                              throws MetadataException
Go to the child found with given node name

Specified by:
gotoChild in interface MetadataNode
Parameters:
nodeName - name of the child to find.
Returns:
this
Throws:
MetadataException - If the element with this name has not been found or if there are too many elements

gotoFirstChild

MutableMetadataNode gotoFirstChild()
                                   throws MetadataException
Go to the first child element of the current node.

Specified by:
gotoFirstChild in interface MetadataNode
Returns:
this
Throws:
MetadataException - If the current node has no child at all

gotoFirstChild

MutableMetadataNode gotoFirstChild(String name)
                                   throws MetadataException
Go to the first child with the given name

Specified by:
gotoFirstChild in interface MetadataNode
Parameters:
name - Name of the child to go at
Returns:
this
Throws:
MetadataException - If the current node has no child at all

gotoLastChild

MutableMetadataNode gotoLastChild()
                                  throws MetadataException
Go to the last child element of the current node.

Specified by:
gotoLastChild in interface MetadataNode
Returns:
this
Throws:
MetadataException - If the current node has no child at all

gotoLastChild

MutableMetadataNode gotoLastChild(String name)
                                  throws MetadataException
Go to the last child with the given name

Specified by:
gotoLastChild in interface MetadataNode
Parameters:
name - Name of the child to go at
Returns:
this
Throws:
MetadataException - If the current node has no child at all

gotoParent

MutableMetadataNode gotoParent()
Go to parent tag. Do nothing if we are already at root

Specified by:
gotoParent in interface MetadataNode
Returns:
this

gotoRoot

MutableMetadataNode gotoRoot()
Go to document root tag

Specified by:
gotoRoot in interface MetadataNode
Returns:
this

gotoTag

MutableMetadataNode gotoTag(String relativeXpath,
                            Object... arguments)
                            throws MetadataException
Go to a specific node

Specified by:
gotoTag in interface MetadataNode
Parameters:
relativeXpath - XPath expression
arguments - to be replaced in XPath expression before compiling. Uses String.format() to build XPath expression.
Returns:
this
Throws:
MetadataException - if the node does not exist or if the XPath expression is invalid

renameTo

MutableMetadataNode renameTo(String newTagName)
Replace current element name by another name

Parameters:
newTagName - New name of the tag
Returns:
this

setAttribute

MutableMetadataNode setAttribute(String name,
                                 String value)
                                 throws MetadataException
Sets the new value on an existing attribute, and remains on the current tag.

Parameters:
name - attribute name
value - new attribute'svalue
Returns:
attribute value
Throws:
MetadataException - If the attribute does not exist

setAttribute

MutableMetadataNode setAttribute(String name,
                                 String value,
                                 String relativeXpath,
                                 Object... arguments)
                                 throws MetadataException
Sets the new value on a targeted node's attribute, and remains on the current tag.

Parameters:
name - attribute name
value - new attribute's value
relativeXpath - XPath expression
arguments - optional XPath expression arguments. Uses String.format() to build XPath expression.
Returns:
attribute value
Throws:
MetadataException - Attribute does not exist, targeted node does not exit, or XPath expression is invalid

setAttributeIfExist

MutableMetadataNode setAttributeIfExist(String name,
                                        String value)
Sets the new value on an attribute, and remains on the current tag. If it does not exist, do nothing.

Parameters:
name - attribute name
value - new attribute value
Returns:
attribute value

setAttributeIfExist

MutableMetadataNode setAttributeIfExist(String name,
                                        String value,
                                        String relativeXpath,
                                        Object... arguments)
                                        throws MetadataException
Sets the new value on a targeted node's attribute, and remains on the current tag. If the attribute does not exist, do nothing.

Parameters:
name - attribute name
value - new attribute's value
relativeXpath - XPath expression
arguments - optional XPath expression arguments. Uses String.format() to build XPath expression.
Returns:
attribute value
Throws:
MetadataException - XPath expression is invalid or targeted node does not exist

setCDATA

MutableMetadataNode setCDATA(String data)
Set the cdata in the current node. This method will replace all existing text and CDATA by the given cdata Also Jump after to the parent node. This enables the quickly replace test on several nodes like this:

gotoChild("name").setText("Bob").gotoChild("sex").setText("M").gotoChild("age").setText("30")

<name>Bob</name><sex>M</sex><age>30</age>

Parameters:
data - text to put under this node in a CDATA section
Returns:
this

setText

MutableMetadataNode setText(String text)
Set the text in the current node. This method will replace all existing text and CDATA by the given text. Also Jump after to the parent node. This enables the quickly replace test on several nodes like this:

gotoChild("name").setText("Bob").gotoChild("sex").setText("M").gotoChild("age").setText("30")

<name>Bob</name><sex>M</sex><age>30</age>

Parameters:
text - text to put under this node
Returns:
this

setText

MutableMetadataNode setText(String text,
                            String relativeXpath,
                            Object... arguments)
                            throws MetadataException
Set the text in the targeted node. This method will replace all existing text and cdata by the given text, but remains on the current tag.

Parameters:
text - text to put under this node
relativeXpath - XPath expression that select the node
arguments - optional XPath expression arguments. Uses String.format() to build XPath expression.
Returns:
this
Throws:
MetadataException - If the XPath expression is invalid or if the node does not exist

setTextIfExist

MutableMetadataNode setTextIfExist(String text,
                                   String relativeXpath,
                                   Object... arguments)
                                   throws MetadataException
Set the text in the targeted node. This method will replace all existing text and cdata by the given text, but remains on the current tag. If the targeted node does not exist, do nothing.

Parameters:
text - text to put under this node
relativeXpath - XPath expression that select the node
arguments - optional XPath expression arguments. Uses String.format() to build XPath expression.
Returns:
this
Throws:
MetadataException - If the XPath expression is invalid

getInnerDocument

MutableMetadataNode getInnerDocument()
Specified by:
getInnerDocument in interface MetadataNode
Returns:
Another XMLTag instance in which the current tag becomes de root element of the new document, and it contains all inner elements as in the previous document.

getChildren

List<MutableMetadataNode> getChildren()
Return a list of all child nodes.

Specified by:
getChildren in interface MetadataNode
Returns:
The list

getChildren

List<MutableMetadataNode> getChildren(String relativeXpath,
                                      Object... arguments)
Return a list of all nodes selected by the XPath expression.

Specified by:
getChildren in interface MetadataNode
Parameters:
relativeXpath - XPath to select tags
arguments - XPath arguments
Returns:
The list

createNamespaceContext

MutableMetadataNode createNamespaceContext()
Create a wrapper node which allows a new mapping of namespace prefixes to be used to navigate and query nodes without changing the base document.

Specified by:
createNamespaceContext in interface MetadataNode
Returns:
Throws:
MetadataException - If the namespace handling has been disabled on the Metadata containing this node.


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.