AdventNet Web NMS 4 DMS API Specification

com.adventnet.nms.extranet.utils.common
Class XmlParseUtil
java.lang.Object
  |
  +--com.adventnet.nms.extranet.utils.common.XmlParseUtil

public class XmlParseUtil
extends java.lang.Object

Utility class providing basic methods for XML customization. Provides methods for creating node from the properties, retrieving the properties from the element node etc.


Constructor Summary
XmlParseUtil()
           
 
Method Summary
static org.w3c.dom.Element createDocElement(org.w3c.dom.Element elt)
          Creates a new Document and appends the given element to the document.
static org.w3c.dom.Document createNewDocument()
          Creates a new Document from the DocBuilder and Factory
static org.w3c.dom.Element createNode(org.w3c.dom.Document doc, java.util.Properties prop, java.lang.String name)
          Creates the XML Element with the given tag name and the properties as attributes of the node with doc as additional property.
static org.w3c.dom.Element createNode(java.util.Properties prop, java.lang.String name)
          Creates the XML Element with the given tag name and the properties as attributes of the node.
static org.w3c.dom.Element createNodeFromProperties(org.w3c.dom.Document doc, java.util.Properties prop, java.lang.String tag)
          Creates the XML sub-elements with the given properties under the tag name as that of the given name.
static org.w3c.dom.Element createNodeFromProperties(java.util.Properties prop, java.lang.String tag)
          Creates the XML Element with the given properties under the tag name as that of the given name.
static byte[] getBytes(org.w3c.dom.Element root)
          This method will return a byte array for the given XML element.
static java.lang.String getDTDName(java.io.File file)
           
static org.w3c.dom.Element getElement(byte[] b)
          This method will return a XML element for the given byte array.
static org.w3c.dom.Element getFirstChild(org.w3c.dom.Element elt)
          For a given Element node this method will return the first Element child node
static org.w3c.dom.Element getLastChild(org.w3c.dom.Element elt)
          For a given Element node this method will return the last Element child node
static java.util.Properties getProperties(org.w3c.dom.Element resultNode)
          Provided an Element node which is having its attributes set,this method will return the attributes in Properties.
static org.w3c.dom.Element getXmlDocument(java.io.File file)
          For the given XML file,the Root Element node is returned
static org.w3c.dom.Element getXmlDocument(java.io.File file, boolean validating)
          For the given XML file,the Root Element node is returned
static java.util.Properties loadAttributes(org.w3c.dom.Element currNode)
          This method will return a Properties object formed from the attributes of the given XML element.
static void saveDocument(org.apache.crimson.tree.XmlDocument doc, java.io.File f, java.lang.String encoding, java.lang.String dtdName)
          This method will save the given file, with the given encoding, dtd name and the XmlDocument with proper indentation.
static void saveDocument(org.apache.crimson.tree.XmlDocument doc, java.lang.String fileName)
          This method will save the XmlDocument in a file with the name, as that of the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlParseUtil

public XmlParseUtil()
Method Detail

loadAttributes

public static java.util.Properties loadAttributes(org.w3c.dom.Element currNode)
This method will return a Properties object formed from the attributes of the given XML element. For example, if the given XML element is as follows: <Topology implClassName="com.adventnet.nms.topodb.SnmpInterface" requestID="Added" region="tom" notificationType="1"/> Then, the returned properties will have the following key-value pairs: "implClassName","com.adventnet.nms.topodb.SnmpInterface" "requestID","Added" "region", "tom" "notificationType","1"
Parameters:
currNode - XML element whose attributes are used to construct the Properties
Returns:
Properties constructed from the attributes of the given XML element

createNode

public static org.w3c.dom.Element createNode(java.util.Properties prop,
                                             java.lang.String name)
Creates the XML Element with the given tag name and the properties as attributes of the node. For example if the tag name is Topology with some properties, the Element retuned will be as follows: <Topology implClassName="com.adventnet.nms.topodb.SnmpInterface" requestID="Added" region="tom" notificationType="1"/>
Parameters:
prop - Properties to be set as attributes for the XML node
name - Name of the tag for the Element Node created
Returns:
XML element constructed from Properties of the tag

createNode

public static org.w3c.dom.Element createNode(org.w3c.dom.Document doc,
                                             java.util.Properties prop,
                                             java.lang.String name)
Creates the XML Element with the given tag name and the properties as attributes of the node with doc as additional property. For example if the tag name is Topology with some properties the element retuned will be as follows: <Topology implClassName="com.adventnet.nms.topodb.SnmpInterface" requestID="Added" region="tom" notificationType="1"/>
Parameters:
doc - XML Document from which the Element is created
prop - Properties to be set as attributes for the XML node
name - Name of the tag for the Element node created
Returns:
XML element constructed from Properties of the tag

getProperties

public static java.util.Properties getProperties(org.w3c.dom.Element resultNode)
Provided an Element node which is having its attributes set,this method will return the attributes in Properties. For example if the element node is Topology with some properties set as attributes, <Topology implClassName="com.adventnet.nms.topodb.SnmpInterface" requestID="Added" region="tom" notificationType="1"/> The returned properties will have the name-value as follows: PropertyName="implClassName" and PropertyValue="com.adventnet.nms.topodb.SnmpInterface" PropertyName="region" and PropertyValue="tom" PropertyName="requestID" and PropertyValue="Added" PropertyName="notificationType" and PropertyValue="1" If the given Element node has children nodes, then the attributes of the children node will also be available in the returned properties.
Parameters:
resultNode - the element node from which properties need to be extracted
Returns:
attributes as Properties which are retrieved from the XML elemet

createNodeFromProperties

public static org.w3c.dom.Element createNodeFromProperties(java.util.Properties prop,
                                                           java.lang.String tag)
Creates the XML Element with the given properties under the tag name as that of the given name. For example, if the tag name is Topology with some properties, then the retuned Element will be as follows: <Topology> <Property name="pollInterval" value="1800"/> <Property name="statusChangeTime" value="1049813671082"/> <Property name="groupMembers" value=""/> </Topology>
Parameters:
prop - Properties for forming the XML node
name - Name of the tag for Element node created
Returns:
XML element which is constructed from Properties

createNodeFromProperties

public static org.w3c.dom.Element createNodeFromProperties(org.w3c.dom.Document doc,
                                                           java.util.Properties prop,
                                                           java.lang.String tag)
Creates the XML sub-elements with the given properties under the tag name as that of the given name. For example, if the tag name is Topology with some properties, the retuned Element will be as follows: <Topology> <Property name="pollInterval" value="1800"/> <Property name="statusChangeTime" value="1049813671082"/> <Property name="groupMembers" value=""/> </Topology>
Parameters:
doc - Document from which Element can be created
prop - Properties for forming the XML node
name - Name of the tag for the Element node created
Returns:
XML element which is constructed from Properties

createNewDocument

public static org.w3c.dom.Document createNewDocument()
Creates a new Document from the DocBuilder and Factory
Returns:
Document, if any exception occurs it will return null

createDocElement

public static org.w3c.dom.Element createDocElement(org.w3c.dom.Element elt)
Creates a new Document and appends the given element to the document. Returns element which is retrieved from the Document.
Parameters:
elt - XML element which needs to be appended to the document
Returns:
element which is retrieved from the XML Document

getBytes

public static byte[] getBytes(org.w3c.dom.Element root)
                       throws java.lang.Exception
This method will return a byte array for the given XML element. NOTE: This is strictly for internal usage.

getXmlDocument

public static org.w3c.dom.Element getXmlDocument(java.io.File file)
                                          throws java.lang.Exception
For the given XML file,the Root Element node is returned
Parameters:
file, - the XML file for which the root element node is required
Returns:
root, the Root Element node of the XML file.
Throws:
java.lang.Exception -  

getXmlDocument

public static org.w3c.dom.Element getXmlDocument(java.io.File file,
                                                 boolean validating)
                                          throws java.lang.Exception
For the given XML file,the Root Element node is returned
Parameters:
file, - the XML file for which the root element node is required
validating - a boolean to specify whether the DTD validation is required or not
Returns:
root, the Root Element node of the XML file.
Throws:
java.lang.Exception -  

getFirstChild

public static org.w3c.dom.Element getFirstChild(org.w3c.dom.Element elt)
For a given Element node this method will return the first Element child node
Parameters:
elt - Element for which first Childnode is required
Returns:
First Element Child node of the given Element node

getLastChild

public static org.w3c.dom.Element getLastChild(org.w3c.dom.Element elt)
For a given Element node this method will return the last Element child node
Parameters:
elt - Element for which last Childnode is required
Returns:
Last Element Child node of the given Element node

getElement

public static org.w3c.dom.Element getElement(byte[] b)
This method will return a XML element for the given byte array. NOTE: This is strictly for internal usage.

saveDocument

public static void saveDocument(org.apache.crimson.tree.XmlDocument doc,
                                java.io.File f,
                                java.lang.String encoding,
                                java.lang.String dtdName)
This method will save the given file, with the given encoding, dtd name and the XmlDocument with proper indentation.
Parameters:
doc - XmlDocument which is to be written in a file.
file - File in which the XmlDocument, encoding, dtd need to be written.
encoding - a String value representing the encoding format such as "UTF-8".
dtdName - a String value representing the dtdName, which contains the validation for this XML file.

saveDocument

public static void saveDocument(org.apache.crimson.tree.XmlDocument doc,
                                java.lang.String fileName)
This method will save the XmlDocument in a file with the name, as that of the given name.
Parameters:
doc - XmlDocument which is to be written in a file.
fileName - a String specifying the name of the file. NOTE: This method is only for internal usage

getDTDName

public static java.lang.String getDTDName(java.io.File file)
                                   throws java.lang.Exception

AdventNet Web NMS 4 DMS API Specification