|
||||||||||
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 String |
NAME_COMMENT
Constant value for the name of comment nodes. |
static String |
NAME_DOCTYPE
Constant value the name of the doctype node ( <? |
static String |
NAME_TEXTPART
Constant value for the name of comment nodes. |
static 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_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,
String pName)
Creates a new instance of XmlNode without a parent. |
|
XmlNode(short pType,
String pName,
String pValue)
Creates a new instance of XmlNode without a parent. |
|
XmlNode(short pType,
String pName,
String pValue,
XmlNode pParentNode)
Creates a new instance of XmlNode . |
|
XmlNode(short pType,
String pName,
XmlNode pParentNode)
Creates a new instance of XmlNode with a parent. |
|
XmlNode(String pName)
Creates a new instance of XmlNode
without a parent. |
Method Summary | |
---|---|
void |
add(XmlNode xmnSub)
Adds a XmlNode as a known sub node, at the end of
the known sub nodes list. |
void |
clearSubNodes()
Clears the list of known sub elements. |
Object |
clone()
|
static XmlNode |
createDoctype(String pName,
String pPublicId,
String pSystemId)
Creates the xml doctype tag <! |
void |
createXml(OutputStream pOut,
int pIndent,
boolean pInsertNewLines)
Create the xml structure based on the current node. |
static XmlNode |
createXmlDeclaration()
Creates the xml declaration tag <? |
int |
getColumnNumber()
Gets the column number behind the start-tag tag. |
int |
getLineNumber()
Gets the line number of the tag occurence. |
String |
getName()
Gets the node name. |
XmlNode |
getNode(String pNodePath)
Gets a specific (sub) XmlNode based on the current
XmlNode . |
int |
getNodeCount(String pNodePath)
Count the elements of a node list. |
List<XmlNode> |
getNodes(String pNodePath)
Gets a list of XmlNode s based on the current
XmlNode . |
String |
getNodeValue(String pNodePath)
Gets the value of a specific (sub) XmlNode based on the current
XmlNode . |
XmlNode |
getParent()
Gets the parent XmlNode . |
List<XmlNode> |
getSubNodes()
Gets the list of sub XmlNode elements. |
short |
getType()
Gets the node type. |
String |
getValue()
Gets the node value. |
static String |
getXmlValue(String pValue)
Returns the given value as XML value. |
int |
indexOf(String pNodePath,
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(String pNodePath,
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 iPosition,
XmlNode xmnSub)
Inserts a XmlNode as a known sub node at a defined
position, in the sub node list. |
XmlNode |
insertNode(String pNodePath,
Object pValue)
Inserts a specific XmlNode at a defined position
based on the current XmlNode . |
boolean |
remove(XmlNode xmnSub)
Remove a sub XmlNode from the known sub nodes. |
XmlNode |
removeNode(String pNodePath)
Removes a specific (sub) XmlNode based on the current
XmlNode . |
XmlNode |
setNode(String pNodePath,
Object pValue)
Sets a specific (sub) XmlNode based on the current
XmlNode . |
void |
setValue(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. |
String |
toString()
|
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 String NAME_COMMENT
public static final String NAME_TEXTPART
public static final String NAME_XMLDECLARATION
<?xml?>
).
public static final String NAME_DOCTYPE
<?xml?>
).
Constructor Detail |
---|
public XmlNode(String pName)
XmlNode
without a parent. The node type is TYPE_TEXT
.
pName
- name of the nodepublic XmlNode(short pType, String pName)
XmlNode
without a parent.
pType
- node typepName
- name of the nodepublic XmlNode(short pType, String pName, String pValue)
XmlNode
without a parent.
pType
- node typepValue
- value of the nodepName
- name of the nodepublic XmlNode(short pType, String pName, XmlNode pParentNode)
XmlNode
with a parent.
pType
- node typepName
- name of the nodepParentNode
- parent XmlNode
or null
public XmlNode(short pType, String pName, String pValue, XmlNode pParentNode)
XmlNode
.
pType
- node typepName
- name of the nodepValue
- value of the nodepParentNode
- parent XmlNode
or null
Method Detail |
---|
public String toString()
toString
in class Object
public Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public void add(XmlNode xmnSub)
XmlNode
as a known sub node, at the end of
the known sub nodes list.
xmnSub
- instance of the sub nodepublic void insert(int iPosition, XmlNode xmnSub)
XmlNode
as a known sub node at a defined
position, in the sub node list.
iPosition
- position at which the specified element is to be insertedxmnSub
- instance of the sub nodepublic List<XmlNode> getSubNodes()
XmlNode
elements.
public boolean remove(XmlNode xmnSub)
XmlNode
from the known sub nodes.
xmnSub
- instance of the sub node
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_DECLARATION
), TYPE_DOCTYPE
)public String getName()
public void setValue(String pValue)
pValue
- node valuepublic String getValue()
public static String getXmlValue(String pValue)
pValue
- the value
public XmlNode getNode(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
IllegalArgumentException
- if the path contains an incomplete or an invalid index
IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthpublic String getNodeValue(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
IllegalArgumentException
- if the path contains an incomplete or an invalid index
IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthpublic List<XmlNode> getNodes(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
IllegalArgumentException
- if the path contains an incomplete or an invalid index
IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthgetSubNodes()
public int getNodeCount(String pNodePath)
pNodePath
- Node path e.g. /document/nodelist
IllegalArgumentException
- if the path contains an incomplete or an invalid index
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(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
IllegalArgumentException
- if the path contains an incomplete or an invalid index
IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthgetNode(String)
public XmlNode setNode(String pNodePath, 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
IllegalArgumentException
- if the path contains an incomplete or an invalid index
IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthpublic XmlNode insertNode(String pNodePath, 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
IllegalArgumentException
- if the path contains an incomplete or an invalid index
IndexOutOfBoundsException
- if the path contains an index which is smaller or
larger than the allowed lengthpublic void createXml(OutputStream pOut, int pIndent, boolean pInsertNewLines) throws IOException
pOut
- stream for writing the xml structurepIndent
- indentation for sub nodespInsertNewLines
- true
to insert new lines
IOException
- if the output operation to pOut
fails or
the encoding UTF-8 is not usablepublic static XmlNode createXmlDeclaration()
public static XmlNode createDoctype(String pName, String pPublicId, String pSystemId)
pName
- the doctype namepPublicId
- the public idpSystemId
- the system id
public int getLineNumber()
public int getColumnNumber()
public int indexOf(String pNodePath, 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
IndexOutOfBoundsException
- if the start position is invalidpublic int indexOf(String pNodePath, 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
IndexOutOfBoundsException
- if the start position is invalidpublic 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 |