com.wewebu.ow.server.util
Class OwXMLDOMUtil

java.lang.Object
  extended by com.wewebu.ow.server.util.OwXMLDOMUtil

public class OwXMLDOMUtil
extends Object

Implements DOM Node utility methods for XML access.
Please note: DOM is not thread safe.
To read the configuration for plugins and boot options use OwXMLUtil getters only.

Alfresco Workdesk
Copyright (c) Alfresco Software, Inc.
All rights reserved.

For licensing information read the license.txt file or
go to: http://wiki.alfresco.com


Constructor Summary
OwXMLDOMUtil(String strRootNodeName_p)
          construct an empty XML Dom node
 
Method Summary
 Node addNode(String strSubNodeName_p)
          add a subnode to the node wrapped by this object
 void addTextNode(String strNodeName_p, String strText_p)
          add a text node in the wrapped node
static String encodeSpecialCharactersForXML(String xmlString_p)
          encodes special XML characters from the given string
static Element getChildElement(Element parent_p, String childElementName_p)
          get the child element
static String getChildElementText(Element parent_p, String childElementName_p)
          get text element of a given child
static Node getChildNode(Node node_p, String childToFind_p)
          get a given child node
static Document getDocumentFromInputStream(InputStream inputStream_p)
          get a XML document from a given InputStream
static Document getDocumentFromString(String xml_p)
          get a XML document from a given String
static String getElementText(Element element_p)
          get the text of a node
 InputStream getInputStream()
          get an input stream for the XML content of the wrapped node
static InputStream getInputStream(Node node_p)
          get an input stream for the XML content of a given node
static Document getNewDocument()
          get a new XML document
static boolean getSafeBooleanAttributeValue(Node node_p, String strAttributeName_p, boolean fDefault_p)
          get the value of a boolean attribute [true | false], catch exception
static boolean getSafeBooleanValue(Node node_p, boolean fDefault_p)
          get the value of a boolean node [true | false], catch exception
static List getSafeCDATAList(Node node_p)
          retrieve a CDATA defined strings list from a node definition
static int getSafeIntegerAttributeValue(Node node_p, String strAttributeName_p, int iDefault_p)
          get the value of a string attribute, catch exception
static List getSafeNodeList(Node node_p)
          retrieve a node list in a subnode
static String getSafeStringAttributeValue(Node node_p, String strAttributeName_p, String strDefault_p)
          get the value of a string attribute, catch exception
static List getSafeStringList(Node node_p)
          retrieve a string list in a node
static Set getSafeStringSet(Node node_p)
          retrieve a string list in a node
static void initialize(Document document)
          Prepares the given DOM Document for concurrent access.
static void initialize(Node node)
          Prepares the given DOM Node for concurrent access.
static String makeXMLString(String sText_p)
          create a XML conform text representation
static void setNodeAttribute(Document document_p, Node node_p, String attrName_p, String attrValue_p)
          set a node attribute to the node of a given document
static boolean toFile(File file_p, Node node_p)
          write XML Node to file
 String toString()
           
static String toString(Node node_p)
          write XML Node to a String
static void writeHtmlDump(Writer w_p, Node node_p)
          write XML Node as HTML to a writer object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OwXMLDOMUtil

public OwXMLDOMUtil(String strRootNodeName_p)
             throws Exception
construct an empty XML Dom node

Parameters:
strRootNodeName_p - String Name of the root node
Throws:
Exception
Method Detail

addNode

public Node addNode(String strSubNodeName_p)
add a subnode to the node wrapped by this object

Parameters:
strSubNodeName_p - String name of the new node
Returns:
Node DOM Node

addTextNode

public void addTextNode(String strNodeName_p,
                        String strText_p)
add a text node in the wrapped node

Parameters:
strNodeName_p - String tag name of new node
strText_p - String text to set as new textnode

getInputStream

public InputStream getInputStream()
                           throws Exception
get an input stream for the XML content of the wrapped node

Returns:
InputStream
Throws:
Exception

writeHtmlDump

public static void writeHtmlDump(Writer w_p,
                                 Node node_p)
                          throws Exception
write XML Node as HTML to a writer object

Parameters:
w_p - a Writer
node_p - a Node
Throws:
Exception

getChildElement

public static Element getChildElement(Element parent_p,
                                      String childElementName_p)
get the child element

Parameters:
parent_p -
childElementName_p -
Returns:
an Element

getElementText

public static String getElementText(Element element_p)
get the text of a node

Parameters:
element_p -
Returns:
a String

getChildElementText

public static String getChildElementText(Element parent_p,
                                         String childElementName_p)
get text element of a given child

Parameters:
parent_p -
childElementName_p -
Returns:
a String

getChildNode

public static Node getChildNode(Node node_p,
                                String childToFind_p)
get a given child node

Parameters:
node_p -
childToFind_p -
Returns:
a Node

encodeSpecialCharactersForXML

public static String encodeSpecialCharactersForXML(String xmlString_p)
encodes special XML characters from the given string

Parameters:
xmlString_p -
Returns:
a String

makeXMLString

public static String makeXMLString(String sText_p)
create a XML conform text representation


toFile

public static boolean toFile(File file_p,
                             Node node_p)
write XML Node to file

Parameters:
file_p - File to write XML to.
node_p - Node
Returns:
true on success

toString

public static String toString(Node node_p)
                       throws TransformerException
write XML Node to a String

Parameters:
node_p - Node
Returns:
XML string
Throws:
TransformerException

getSafeNodeList

public static List getSafeNodeList(Node node_p)
retrieve a node list in a subnode

Parameters:
node_p - Node
Returns:
List of DOM Nodes

getInputStream

public static InputStream getInputStream(Node node_p)
                                  throws Exception
get an input stream for the XML content of a given node

Returns:
InputStream
Throws:
Exception

getSafeBooleanAttributeValue

public static boolean getSafeBooleanAttributeValue(Node node_p,
                                                   String strAttributeName_p,
                                                   boolean fDefault_p)
get the value of a boolean attribute [true | false], catch exception

Parameters:
node_p - Node to get the attribute from
strAttributeName_p - name of the String attribute
fDefault_p - Default string in case the attribute could not be found
Returns:
boolean value of attribute or fDefault_p on failure

getSafeBooleanValue

public static boolean getSafeBooleanValue(Node node_p,
                                          boolean fDefault_p)
get the value of a boolean node [true | false], catch exception

Parameters:
node_p - Node to get the attribute from
fDefault_p - Default value in case the node could not be found
Returns:
boolean value of node or fDefault_p on failure

getSafeStringAttributeValue

public static String getSafeStringAttributeValue(Node node_p,
                                                 String strAttributeName_p,
                                                 String strDefault_p)
get the value of a string attribute, catch exception

Parameters:
node_p - a Node to get the attribute from
strAttributeName_p - name of the String attribute
strDefault_p - Default string in case the attribute could not be found
Returns:
string value of attribute or strDefault_p on failure

getSafeIntegerAttributeValue

public static int getSafeIntegerAttributeValue(Node node_p,
                                               String strAttributeName_p,
                                               int iDefault_p)
get the value of a string attribute, catch exception

Parameters:
node_p - a Node to get the attribute from
strAttributeName_p - name of the String attribute
iDefault_p - Default int in case the attribute could not be found
Returns:
int value of attribute or iDefault_p on failure

getSafeStringSet

public static Set getSafeStringSet(Node node_p)
retrieve a string list in a node

Parameters:
node_p - Node
Returns:
List of Strings

getSafeStringList

public static List getSafeStringList(Node node_p)
retrieve a string list in a node

Parameters:
node_p - Node
Returns:
List of Strings

getSafeCDATAList

public static List getSafeCDATAList(Node node_p)
retrieve a CDATA defined strings list from a node definition

Parameters:
node_p - Node
Returns:
List of CDATA Strings

getDocumentFromInputStream

public static Document getDocumentFromInputStream(InputStream inputStream_p)
                                           throws IOException,
                                                  SAXException,
                                                  ParserConfigurationException
get a XML document from a given InputStream

Parameters:
inputStream_p -
Returns:
a Document
Throws:
IOException
SAXException
ParserConfigurationException

getNewDocument

public static Document getNewDocument()
                               throws ParserConfigurationException
get a new XML document

Returns:
a Document
Throws:
ParserConfigurationException

getDocumentFromString

public static Document getDocumentFromString(String xml_p)
                                      throws IOException,
                                             SAXException,
                                             ParserConfigurationException
get a XML document from a given String

Parameters:
xml_p -
Returns:
a Document
Throws:
IOException
SAXException
ParserConfigurationException

setNodeAttribute

public static void setNodeAttribute(Document document_p,
                                    Node node_p,
                                    String attrName_p,
                                    String attrValue_p)
set a node attribute to the node of a given document

Parameters:
document_p -
node_p -
attrName_p -
attrValue_p -

initialize

public static void initialize(Node node)
Prepares the given DOM Node for concurrent access.

Parameters:
node - Node the initialized DOM node
Since:
2.5.3.2

initialize

public static void initialize(Document document)
Prepares the given DOM Document for concurrent access.

Parameters:
document - Document the initialized document
Since:
2.5.3.2

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 Alfresco Business Solutions. All Rights Reserved.