lumis.util
Class XmlUtil

Package class diagram package XmlUtil
java.lang.Object
  extended by lumis.util.XmlUtil

@StableMinor(version="4.1",
             sinceVersion="4.0")
public class XmlUtil
extends Object

Utility file for xml

Since:
4.0.0

Field Summary
static String XML_HEADER
           
 
Constructor Summary
XmlUtil()
           
 
Method Summary
static Node addNode(Node xmlParentNode, String newNodeName)
           
static Node addNode(Node xmlParentNode, String xpathExpressionParentNode, String newNodeName)
           
static Attr addNodeAttr(Node xmlParentNode, String attributeName)
           
static Attr addNodeAttr(Node xmlParentNode, String attributeName, String value)
           
static Node addNodeFromXmlString(Node node, String xmlString)
           
static Element addTextNode(Node xmlParentNode, String newNodeName, String newNodeText)
           
static Element addTextNode(Node xmlParentNode, String xpathExpressionParentNode, String newNodeName, String newNodeText)
           
static Node[] addTextNodes(Node xmlParentNode, String newNodesName, String[] newNodesValue)
           
static Node[] addTextNodes(Node xmlParentNode, String xpathExpressionParentNode, String newNodesName, String[] newNodesValue)
           
static boolean checkCondition(Node conditionNode, String condition)
           
protected static boolean checkCondition(String leftValue, String rightValue, String conditionOperator)
           
static boolean checkSingleCondition(Node conditionNode, String condition)
           
static byte[] convertToUTFBytes(byte[] content)
           
static Node copyNode(Node xmlNodeFrom, Node xmlNodeTo)
           
static Node copyNode(Node xmlNodeFrom, Node xmlNodeTo, String xpathExpressionTo)
           
static Node copyNode(Node xmlNodeFrom, String xpathExpressionFrom, Node xmlNodeTo)
           
static Node copyNode(Node xmlNodeFrom, String xpathExpressionFrom, Node xmlNodeTo, String xpathExpressionTo)
           
static PortalException createPortalException(SAXException e)
          Creates a PortalException based on the given SAXException.
static String encodeXml(String pStr)
          Encodes a string to be used inside a XML document.
static Document getDocument(File xmlFile)
           
static Document getDocument(HttpServletRequest request)
           
static Document getDocument(String xmlString)
           
static Document getDocumentFromFile(String filePath)
           
static Node getOrCreateNode(String path, Node parentNode)
           
static String getTextContent(Node node)
           
static DocumentBuilder getXmlDocumentBuilder()
           
static Document getXMLDocumentFromString(String xml)
           
static String getXmlEncoding(String xmlString)
          Returns the XML encoding for the xml with the given String.
static String getXmlString(Document document)
           
static String getXmlString(Element element)
           
static Node importIntoNewDocument(Node originalNode)
          Clones a node, and adopts it into a new document.
static boolean isValidXmlString(String xml)
           
static void mergeAttributes(Node destinationNode, Node sourceNode, boolean replace)
           
static void mergeElements(Node destinationNode, Node sourceNode, boolean replace)
          Merges the children elements from a node to another.
static boolean nodeExists(String xpathExpression, Node sourceNode)
           
static boolean readAttributeBoolean(String attributeName, Node node)
           
static boolean readAttributeBoolean(String attributeName, Node node, boolean valueForNull)
           
static int readAttributeInt(String attributeName, Node node, int valueForNull)
          Returns the attribute integer value in the given node.
static String readAttributeOrNodeString(Node node, String fieldName)
           
static String readAttributeOrNodeString(Node node, String fieldName, String valueForNull)
           
static String readAttributeString(String attributeName, Node node)
           
static String readAttributeString(String attributeName, Node node, String valueForNull)
           
static boolean readNodeBoolean(String xpathExpression, Node sourceNode, boolean valueForNull)
           
static int readNodeInt(String xpathExpression, Node sourceNode, int valueForNull)
           
static Integer readNodeInteger(String xpathExpression, Node sourceNode, Integer valueForNull)
           
static String[] readNodesString(String xpathExpression, Node sourceNode)
           
static String readNodeString(String xpathExpression, Node sourceNode)
           
static String readNodeString(String xpathExpression, Node sourceNode, String valueForNull)
           
static void replaceChildNode(Node parentNode, Node newChildNode)
           
static void replaceChildNode(String childNodeName, Node node, String xmlString)
           
static Node[] selectAncestorNodes(String ancestorNameQuery, Node childNode)
           
static Node[] selectNodes(String childNameQuery, Node parentNode)
           
static Node selectSingleAncestorNode(String ancestorNameQuery, Node childNode)
           
static Node selectSingleNode(String childNameQuery, Node parentNode)
           
protected static Node selectSingleNodeRecursiveByName(String nodeName, Node parentNode)
           
static void setTextContent(Node parentNode, String textValue)
           
static Node writeNodeString(String xpathExpression, Node sourceNode, String nodeValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_HEADER

public static final String XML_HEADER
See Also:
Constant Field Values
Constructor Detail

XmlUtil

public XmlUtil()
Method Detail

getXmlDocumentBuilder

public static DocumentBuilder getXmlDocumentBuilder()
                                             throws PortalException
Throws:
PortalException

getDocument

public static Document getDocument(File xmlFile)
                            throws PortalException
Throws:
PortalException

getDocument

public static Document getDocument(HttpServletRequest request)
                            throws Exception
Throws:
Exception

getDocument

public static Document getDocument(String xmlString)
                            throws PortalException
Throws:
PortalException

createPortalException

public static PortalException createPortalException(SAXException e)
Creates a PortalException based on the given SAXException. The PortalException created contains a message describing the error, according to the information in the SAXException.

Parameters:
e - the SAXException
Returns:
the PortalException created.
Since:
4.0.8

getXmlString

public static String getXmlString(Element element)
                           throws PortalException
Throws:
PortalException

getXmlString

public static String getXmlString(Document document)
                           throws Exception
Throws:
Exception

readNodeBoolean

public static boolean readNodeBoolean(String xpathExpression,
                                      Node sourceNode,
                                      boolean valueForNull)
                               throws PortalException
Throws:
PortalException

readAttributeBoolean

public static boolean readAttributeBoolean(String attributeName,
                                           Node node)
                                    throws PortalException
Throws:
PortalException

readAttributeBoolean

public static boolean readAttributeBoolean(String attributeName,
                                           Node node,
                                           boolean valueForNull)
                                    throws PortalException
Throws:
PortalException

readNodeInt

public static int readNodeInt(String xpathExpression,
                              Node sourceNode,
                              int valueForNull)
                       throws PortalException
Throws:
PortalException

readNodeInteger

public static Integer readNodeInteger(String xpathExpression,
                                      Node sourceNode,
                                      Integer valueForNull)
                               throws PortalException
Throws:
PortalException

readAttributeString

public static String readAttributeString(String attributeName,
                                         Node node)
                                  throws PortalException
Throws:
PortalException

readAttributeInt

public static int readAttributeInt(String attributeName,
                                   Node node,
                                   int valueForNull)
                            throws PortalException
Returns the attribute integer value in the given node.

Parameters:
attributeName -
node -
valueForNull -
Returns:
Throws:
PortalException

readAttributeString

public static String readAttributeString(String attributeName,
                                         Node node,
                                         String valueForNull)
                                  throws PortalException
Throws:
PortalException

getTextContent

public static String getTextContent(Node node)

setTextContent

public static void setTextContent(Node parentNode,
                                  String textValue)

readNodeString

public static String readNodeString(String xpathExpression,
                                    Node sourceNode)
                             throws PortalException
Throws:
PortalException

readNodeString

public static String readNodeString(String xpathExpression,
                                    Node sourceNode,
                                    String valueForNull)
                             throws PortalException
Throws:
PortalException

readNodesString

public static String[] readNodesString(String xpathExpression,
                                       Node sourceNode)
                                throws PortalException
Throws:
PortalException

nodeExists

public static boolean nodeExists(String xpathExpression,
                                 Node sourceNode)
                          throws PortalException
Throws:
PortalException

addTextNode

public static Element addTextNode(Node xmlParentNode,
                                  String newNodeName,
                                  String newNodeText)
                           throws PortalException
Throws:
PortalException

addTextNode

public static Element addTextNode(Node xmlParentNode,
                                  String xpathExpressionParentNode,
                                  String newNodeName,
                                  String newNodeText)
                           throws PortalException
Throws:
PortalException

addTextNodes

public static Node[] addTextNodes(Node xmlParentNode,
                                  String newNodesName,
                                  String[] newNodesValue)
                           throws PortalException
Throws:
PortalException

addTextNodes

public static Node[] addTextNodes(Node xmlParentNode,
                                  String xpathExpressionParentNode,
                                  String newNodesName,
                                  String[] newNodesValue)
                           throws Exception
Throws:
Exception

addNode

public static Node addNode(Node xmlParentNode,
                           String newNodeName)

addNode

public static Node addNode(Node xmlParentNode,
                           String xpathExpressionParentNode,
                           String newNodeName)
                    throws PortalException
Throws:
PortalException

addNodeAttr

public static Attr addNodeAttr(Node xmlParentNode,
                               String attributeName)

addNodeAttr

public static Attr addNodeAttr(Node xmlParentNode,
                               String attributeName,
                               String value)

copyNode

public static Node copyNode(Node xmlNodeFrom,
                            Node xmlNodeTo)

copyNode

public static Node copyNode(Node xmlNodeFrom,
                            String xpathExpressionFrom,
                            Node xmlNodeTo)
                     throws Exception
Throws:
Exception

copyNode

public static Node copyNode(Node xmlNodeFrom,
                            Node xmlNodeTo,
                            String xpathExpressionTo)
                     throws Exception
Throws:
Exception

copyNode

public static Node copyNode(Node xmlNodeFrom,
                            String xpathExpressionFrom,
                            Node xmlNodeTo,
                            String xpathExpressionTo)
                     throws Exception
Throws:
Exception

getDocumentFromFile

public static Document getDocumentFromFile(String filePath)
                                    throws Exception
Throws:
Exception

selectSingleAncestorNode

public static Node selectSingleAncestorNode(String ancestorNameQuery,
                                            Node childNode)
                                     throws Exception
Throws:
Exception

selectAncestorNodes

public static Node[] selectAncestorNodes(String ancestorNameQuery,
                                         Node childNode)
                                  throws Exception
Throws:
Exception

importIntoNewDocument

public static Node importIntoNewDocument(Node originalNode)
                                  throws PortalException
Clones a node, and adopts it into a new document.

Parameters:
originalNode -
Returns:
Throws:
PortalException
Since:
4.0.6

selectSingleNode

public static Node selectSingleNode(String childNameQuery,
                                    Node parentNode)
                             throws PortalException
Throws:
PortalException

selectNodes

public static Node[] selectNodes(String childNameQuery,
                                 Node parentNode)
                          throws PortalException
Throws:
PortalException

checkCondition

public static boolean checkCondition(Node conditionNode,
                                     String condition)
                              throws Exception
Throws:
Exception

checkSingleCondition

public static boolean checkSingleCondition(Node conditionNode,
                                           String condition)
                                    throws Exception
Throws:
Exception

checkCondition

protected static boolean checkCondition(String leftValue,
                                        String rightValue,
                                        String conditionOperator)

selectSingleNodeRecursiveByName

protected static Node selectSingleNodeRecursiveByName(String nodeName,
                                                      Node parentNode)
                                               throws Exception
Throws:
Exception

getXMLDocumentFromString

public static Document getXMLDocumentFromString(String xml)
                                         throws PortalException
Throws:
PortalException

convertToUTFBytes

public static byte[] convertToUTFBytes(byte[] content)

getOrCreateNode

public static Node getOrCreateNode(String path,
                                   Node parentNode)
                            throws PortalException
Throws:
PortalException

writeNodeString

public static Node writeNodeString(String xpathExpression,
                                   Node sourceNode,
                                   String nodeValue)
                            throws PortalException
Throws:
PortalException

readAttributeOrNodeString

public static String readAttributeOrNodeString(Node node,
                                               String fieldName)
                                        throws PortalException
Throws:
PortalException

readAttributeOrNodeString

public static String readAttributeOrNodeString(Node node,
                                               String fieldName,
                                               String valueForNull)
                                        throws PortalException
Throws:
PortalException

replaceChildNode

public static void replaceChildNode(Node parentNode,
                                    Node newChildNode)
                             throws Exception
Throws:
Exception

replaceChildNode

public static void replaceChildNode(String childNodeName,
                                    Node node,
                                    String xmlString)
                             throws PortalException
Throws:
PortalException

addNodeFromXmlString

public static Node addNodeFromXmlString(Node node,
                                        String xmlString)
                                 throws PortalException
Throws:
PortalException

mergeAttributes

public static void mergeAttributes(Node destinationNode,
                                   Node sourceNode,
                                   boolean replace)
                            throws PortalException
Throws:
PortalException

mergeElements

public static void mergeElements(Node destinationNode,
                                 Node sourceNode,
                                 boolean replace)
                          throws PortalException
Merges the children elements from a node to another.

Parameters:
destinationNode - the destination node, where the elements will be appended or replaced.
sourceNode - the source node, where the elements will be copied from.
replace - if true, elements with the same name will be replaced; if false they will not be copied if an element in the destinationNode with the same name already exists.
Throws:
PortalException
Since:
4.0.10

encodeXml

public static String encodeXml(String pStr)
Encodes a string to be used inside a XML document. Special XML characters are converted to their corresponding entities.

Returns:
the encoded string, or an empty string if pStr is null.

getXmlEncoding

public static String getXmlEncoding(String xmlString)
Returns the XML encoding for the xml with the given String.

The encoding is read from the XML declaration.

Parameters:
xmlString - the xml.
Returns:
the encoding or null if it was not found.

isValidXmlString

public static boolean isValidXmlString(String xml)


Lumisportal  4.1.0.071221 - Copyright © 2001-2007, Lumis. All Rights Reserved.