|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sibvisions.util.xml.XmlNode
public final class XmlNode
The XmlNode
encapsulates the information of a xml tag.
A node can be a comment, tag or xml. The xml type is the first
node of a xml file. The xml node contains all other sub xml nodes.
Field Summary | |
---|---|
static java.lang.String |
NAME_COMMENT
Constant value for the name of comment nodes. |
static java.lang.String |
NAME_DOCTYPE
Constant value the name of the doctype node ( <? |
static java.lang.String |
NAME_TEXTPART
Constant value for the name of comment nodes. |
static java.lang.String |
NAME_XMLDECLARATION
Constant value the name of the declaration node ( <? |
static short |
TYPE_ATTRIBUTE
Constant value for the type of attributes. |
static short |
TYPE_CDATA
Constant value for the type of standard nodes. |
static short |
TYPE_COMMENT
Constant value for the type of comment nodes. |
static short |
TYPE_DECLARATION
Constant value for the type of declaration elements. |
static short |
TYPE_DOCTYPE
Constant value for the doctype. |
static short |
TYPE_TEXT
Constant value for the type of standard nodes. |
static short |
TYPE_TEXTPART
Constant value for the type of standard nodes. |
Constructor Summary | |
---|---|
XmlNode(short pType,
java.lang.String pName)
Creates a new instance of XmlNode without a parent. |
|
XmlNode(short pType,
java.lang.String pName,
java.lang.String pValue)
Creates a new instance of XmlNode without a parent. |
|
XmlNode(short pType,
java.lang.String pName,
java.lang.String pValue,
XmlNode pParentNode)
Creates a new instance of XmlNode . |
|
XmlNode(short pType,
java.lang.String pName,
XmlNode pParentNode)
Creates a new instance of XmlNode with a parent. |
|
XmlNode(java.lang.String pName)
Creates a new instance of XmlNode
without a parent. |
Method Summary | |
---|---|
void |
add(XmlNode pNode)
Adds a XmlNode as a known sub node, at the end of
the known sub nodes list. |
void |
addAll(java.util.Collection<XmlNode> pNodes)
Adds all the nodes as a known sub node, at the end of the known sub nodes list. |
void |
clearSubNodes()
Clears the list of known sub elements. |
java.lang.Object |
clone()
|
static XmlNode |
createDoctype(java.lang.String pName,
java.lang.String pPublicId,
java.lang.String pSystemId)
Creates the xml doctype tag <! |
void |
createXml(java.io.OutputStream pOut,
int pIndent,
boolean pInsertNewLines)
Create the xml structure based on the current node. |
static XmlNode |
createXmlDeclaration()
Creates the xml declaration tag <? |
XmlNode |
get(int pIndex)
Gets the node from the given index. |
int |
getColumnNumber()
Gets the column number behind the start-tag tag. |
XmlNode |
getFirstTextNode()
Gets the first text node. |
int |
getLineNumber()
Gets the line number of the tag occurence. |
java.lang.String |
getName()
Gets the node name. |
XmlNode |
getNode(java.lang.String pNodePath)
Gets a specific (sub) XmlNode based on the current
XmlNode . |
int |
getNodeCount(java.lang.String pNodePath)
Count the elements of a node list. |
java.util.List<XmlNode> |
getNodes()
Gets the list of sub XmlNode elements. |
java.util.List<XmlNode> |
getNodes(short pType)
Gets the list of sub XmlNode elements of the given type. |
java.util.List<XmlNode> |
getNodes(java.lang.String pNodePath)
Gets a list of XmlNode s based on the current
XmlNode . |
java.lang.String |
getNodeValue(java.lang.String pNodePath)
Gets the value of a specific (sub) XmlNode based on the current
XmlNode . |
XmlNode |
getParent()
Gets the parent XmlNode . |
java.util.List<XmlNode> |
getSubNodes()
Deprecated. since 2.6 use getNodes() instead. |
short |
getType()
Gets the node type. |
java.lang.String |
getValue()
Gets the node value. |
static java.lang.String |
getXmlValue(java.lang.String pValue)
Returns the given value as XML value. |
int |
indexOf(java.lang.String pNodePath,
java.lang.String pValue)
Returns the index of the first occurrence of the specified node with the given value, or -1
if this node does not contain the specified node with the given value. |
int |
indexOf(java.lang.String pNodePath,
java.lang.String pValue,
int pStartPos)
Returns the index of the first occurrence of the specified node with the given value, or -1
if this node does not contain the specified node with the given value. |
void |
insert(int pPosition,
XmlNode pNode)
Inserts a XmlNode as a known sub node at a defined
position, in the sub node list. |
void |
insertAll(int pIndex,
java.util.Collection<XmlNode> pNodes)
Adds all the nodes as a known sub node, at the end of the known sub nodes list. |
XmlNode |
insertNode(java.lang.String pNodePath,
java.lang.Object pValue)
Inserts a specific XmlNode at a defined position
based on the current XmlNode . |
XmlNode |
remove(int pIndex)
Remove a sub XmlNode from the known sub nodes. |
boolean |
remove(XmlNode xmnSub)
Remove a sub XmlNode from the known sub nodes. |
XmlNode |
removeNode(java.lang.String pNodePath)
Removes a specific (sub) XmlNode based on the current
XmlNode . |
XmlNode |
setNode(java.lang.String pNodePath,
java.lang.Object pValue)
Sets a specific (sub) XmlNode based on the current
XmlNode . |
void |
setNodes(java.util.List<XmlNode> pNodes)
Sets the list of sub XmlNode elements. |
void |
setSubNodes(java.util.List<XmlNode> pSubNodes)
Deprecated. since 2.6 use setNodes(List) instead. |
void |
setValue(java.lang.String pValue)
Sets the node value. |
int |
size()
Returns the number of sub elements. |
int |
size(short pType)
Returns the number of sub elements of the defined type. |
java.lang.String |
toString()
|
java.lang.String |
toString(boolean pInsertNewLines)
Returns the string representation of this node. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final short TYPE_DECLARATION
public static final short TYPE_DOCTYPE
public static final short TYPE_COMMENT
public static final short TYPE_TEXT
public static final short TYPE_ATTRIBUTE
public static final short TYPE_TEXTPART
public static final short TYPE_CDATA
public static final java.lang.String NAME_COMMENT
public static final java.lang.String NAME_TEXTPART
public static final java.lang.String NAME_XMLDECLARATION
<?xml?>
).
public static final java.lang.String NAME_DOCTYPE
<?xml?>
).
Constructor Detail |
---|
public XmlNode(java.lang.String pName)
XmlNode
without a parent. The node type is TYPE_TEXT
.
pName
- name of the nodepublic XmlNode(short pType, java.lang.String pName)
XmlNode
without a parent.
pType
- node typepName
- name of the nodepublic XmlNode(short pType, java.lang.String pName, java.lang.String pValue)
XmlNode
without a parent.
pType
- node typepValue
- value of the nodepName
- name of the nodepublic XmlNode(short pType, java.lang.String pName, XmlNode pParentNode)
XmlNode
with a parent.
pType
- node typepName
- name of the nodepParentNode
- parent XmlNode
or null
public XmlNode(short pType, java.lang.String pName, java.lang.String pValue, XmlNode pParentNode)
XmlNode
.
pType
- node typepName
- name of the nodepValue
- value of the nodepParentNode
- parent XmlNode
or null
Method Detail |
---|
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public XmlNode get(int pIndex)
pIndex
- the index.
public XmlNode getFirstTextNode()
public void add(XmlNode pNode)
XmlNode
as a known sub node, at the end of
the known sub nodes list.
pNode
- instance of the sub nodepublic void insert(int pPosition, XmlNode pNode)
XmlNode
as a known sub node at a defined
position, in the sub node list.
pPosition
- position at which the specified element is to be insertedpNode
- instance of the sub nodepublic void addAll(java.util.Collection<XmlNode> pNodes)
pNodes
- the list of nodespublic void insertAll(int pIndex, java.util.Collection<XmlNode> pNodes)
pIndex
- the index where to insertpNodes
- the list of nodes@Deprecated public java.util.List<XmlNode> getSubNodes()
getNodes()
instead.
XmlNode
elements.
null if there are no sub nodes.
@Deprecated public void setSubNodes(java.util.List<XmlNode> pSubNodes)
setNodes(List)
instead.
XmlNode
elements.
pSubNodes
- list of sub elementspublic void setNodes(java.util.List<XmlNode> pNodes)
XmlNode
elements.
if the given list is an ArrayUtil, it is not cloned and used
directly. This is for memory and performance reasons.
pNodes
- list of sub elementspublic java.util.List<XmlNode> getNodes()
XmlNode
elements.
The result is an empty or unmodifiable list of sub nodes.
This is for memory and performance reasons using big xml files.
public java.util.List<XmlNode> getNodes(short pType)
XmlNode
elements of the given type.
The result is an empty list, if no sub nodes with the type exists.
pType
- the type
public boolean remove(XmlNode xmnSub)
XmlNode
from the known sub nodes.
xmnSub
- instance of the sub node
public XmlNode remove(int pIndex)
XmlNode
from the known sub nodes.
pIndex
- the index
XmlNode
public void clearSubNodes()
public XmlNode getParent()
XmlNode
.
XmlNode
or null
if the
node has no parentpublic short getType()
TYPE_ATTRIBUTE
, TYPE_COMMENT
, TYPE_TEXT
,
TYPE_CDATA
, TYPE_DECLARATION
), TYPE_DOCTYPE
)public java.lang.String getName()
public void setValue(java.lang.String pValue)
pValue
- node valuepublic java.lang.String getValue()
public static java.lang.String getXmlValue(java.lang.String pValue)
pValue
- the value
public XmlNode getNode(java.lang.String pNodePath)
XmlNode
based on the current
XmlNode
. To get a special element of a node list, use
brackets to define the element position e.g. /document/nodes(2)
pNodePath
- Node path e.g. /document/singlenode
XmlNode
is not present or the position is invalid,
otherwise the XmlNode
java.lang.IllegalArgumentException
- if the path contains an incomplete or an invalid index
java.lang.IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthpublic java.lang.String getNodeValue(java.lang.String pNodePath)
XmlNode
based on the current
XmlNode
. To get a special element of a node list, use
brackets to define the element position e.g. /document/nodes(2)
pNodePath
- Node path e.g. /document/singlenode
XmlNode
is not present or the position is invalid,
otherwise the value of the XmlNode
java.lang.IllegalArgumentException
- if the path contains an incomplete or an invalid index
java.lang.IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthpublic java.util.List<XmlNode> getNodes(java.lang.String pNodePath)
XmlNode
s based on the current
XmlNode
. If you define a special list element,
you will get a list with only one element instead of all
list elements.
pNodePath
- Node path e.g. /document/nodelist or null
to get all sub nodes
XmlNode
is not present or the position is invalid,
otherwise the list with XmlNode
s
java.lang.IllegalArgumentException
- if the path contains an incomplete or an invalid index
java.lang.IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthgetNodes()
public int getNodeCount(java.lang.String pNodePath)
pNodePath
- Node path e.g. /document/nodelist
java.lang.IllegalArgumentException
- if the path contains an incomplete or an invalid index
java.lang.IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthpublic int size()
size()
includes
all element types (comment, attribute, ...).
public int size(short pType)
pType
- type of sub elements to count
public XmlNode removeNode(java.lang.String pNodePath)
XmlNode
based on the current
XmlNode
.
pNodePath
- Node path e.g. /document/singlenode
XmlNode
is not present or the position is invalid,
otherwise the removed XmlNode
java.lang.IllegalArgumentException
- if the path contains an incomplete or an invalid index
java.lang.IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthgetNode(String)
public XmlNode setNode(java.lang.String pNodePath, java.lang.Object pValue)
XmlNode
based on the current
XmlNode
. If the hierarchy is not present, this method
will create the necessary elements.
pNodePath
- Node path e.g. /document/singlenodepValue
- the pValue
can be an instance of XmlNode
or any other object. If
the pValue
is not an instance of XmlNode
then the node value will
be set to pValue.toString()
. Otherwise, if pValue
is
an instance of XmlNode
, the pValue
will be used as replacement
for the specified node (the name of the node will be used instead of the name defined in the path).
The node value will be set to null
if pValue == null
.
XmlNode
is not present or the position is invalid,
otherwise the new XmlNode
java.lang.IllegalArgumentException
- if the path contains an incomplete or an invalid index
java.lang.IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthpublic XmlNode insertNode(java.lang.String pNodePath, java.lang.Object pValue)
XmlNode
at a defined position
based on the current XmlNode
. If the hierarchy is not present, this method
will create the necessary elements.
pNodePath
- Node path with or without position e.g. /document/singlenode(2). The
pValue
will be inserted before the found node or after
the last occurence of the pNodePath
, if the position is size()
+ 1
or not defined.pValue
- the value can be an instance of XmlNode
or any other object. If
pValue
is not an instance of XmlNode
, the node
value will be pValue.toString()
. If it is an instance of
XmlNode
then the pValue
will be used as node (the name of the node
will be used instead of the name defined in the path).
The node value will be set to null
if pValue == null
.
pValue
is null,
otherwise the inserted XmlNode
java.lang.IllegalArgumentException
- if the path contains an incomplete or an invalid index
java.lang.IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthpublic void createXml(java.io.OutputStream pOut, int pIndent, boolean pInsertNewLines) throws java.io.IOException
pOut
- stream for writing the xml structurepIndent
- indentation for sub nodespInsertNewLines
- true
to insert new lines
java.io.IOException
- if the output operation to pOut
fails or
the encoding UTF-8 is not usablepublic static XmlNode createXmlDeclaration()
public static XmlNode createDoctype(java.lang.String pName, java.lang.String pPublicId, java.lang.String pSystemId)
pName
- the doctype namepPublicId
- the public idpSystemId
- the system id
public int getLineNumber()
public int getColumnNumber()
public int indexOf(java.lang.String pNodePath, java.lang.String pValue)
-1
if this node does not contain the specified node with the given value.
pNodePath
- the node pathpValue
- the search value
-1
if the node was not found
java.lang.IndexOutOfBoundsException
- if the start position is invalidpublic int indexOf(java.lang.String pNodePath, java.lang.String pValue, int pStartPos)
-1
if this node does not contain the specified node with the given value.
pNodePath
- the node pathpValue
- the search valuepStartPos
- the start position of the search
-1
if the node was not found
java.lang.IndexOutOfBoundsException
- if the start position is invalidpublic java.lang.String toString(boolean pInsertNewLines)
pInsertNewLines
- true
to insert new lines
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |