org.pdfsam.guiclient.utils
Class XmlUtility

java.lang.Object
  extended by org.pdfsam.guiclient.utils.XmlUtility

public final class XmlUtility
extends java.lang.Object

Utility class to deal with xml

Author:
Andrea Vacondio

Method Summary
static org.dom4j.Element addXmlNodeAndAttribute(org.dom4j.Element rootElement, java.lang.String nodeXPath, java.lang.String attributeName, java.lang.String attributeValue)
          Adds to the rootElement the nodes specified by nodeXPath.
static void addXmlNodesAndAttribute(org.dom4j.Element parentElement, java.lang.String nodeName, java.lang.String attributeName, java.util.Collection<java.lang.String> attributeValues)
          Adds multiple nodes to the parent element, one for each attributeValues and each of them with an attribute with the given name and value.
static DocumentPage getDocumentPage(org.dom4j.Node pageNode)
           
static java.lang.String getXmlValue(org.dom4j.Document document, java.lang.String xpath)
           
static java.util.Set<java.lang.String> getXmlValues(org.dom4j.Document document, java.lang.String xpath)
           
static org.dom4j.Document parseXmlFile(java.io.File inputFile)
          parse the xml input file
static org.dom4j.Document parseXmlFile(java.lang.String fullPath)
          Parse the xml file converting the given path
static org.dom4j.Document parseXmlFile(java.net.URL url)
          Parse the url
static org.dom4j.Element processXPath(org.dom4j.Element rootElement, java.lang.String xpath, java.lang.String attributeValue)
          Adds the to rootElement the given xpath and, if the xpath contains an attribute, sets the attribute value.
static void writeXmlFile(org.dom4j.Document domDoc, java.io.File outFile)
          Write the DOM to the xml file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDocumentPage

public static DocumentPage getDocumentPage(org.dom4j.Node pageNode)
Parameters:
pageNode -
Returns:
given a page dom4j node it returns a DocumentPage object

writeXmlFile

public static void writeXmlFile(org.dom4j.Document domDoc,
                                java.io.File outFile)
                         throws java.io.IOException
Write the DOM to the xml file

Parameters:
domDoc - Document to write
outFile - xml File to write
Throws:
java.io.IOException

getXmlValue

public static java.lang.String getXmlValue(org.dom4j.Document document,
                                           java.lang.String xpath)
Parameters:
document -
xpath -
Returns:
The xml tag values for the given xpath
Throws:
java.lang.Exception

getXmlValues

public static java.util.Set<java.lang.String> getXmlValues(org.dom4j.Document document,
                                                           java.lang.String xpath)
Parameters:
document -
xpath -
Returns:
a list of values for the given xpath
Throws:
java.lang.Exception

parseXmlFile

public static org.dom4j.Document parseXmlFile(java.lang.String fullPath)
                                       throws org.dom4j.DocumentException
Parse the xml file converting the given path

Parameters:
fullPath -
Returns:
parsed Document
Throws:
org.dom4j.DocumentException

parseXmlFile

public static org.dom4j.Document parseXmlFile(java.io.File inputFile)
                                       throws org.dom4j.DocumentException
parse the xml input file

Parameters:
inputFile -
Returns:
parsed Document
Throws:
org.dom4j.DocumentException

parseXmlFile

public static org.dom4j.Document parseXmlFile(java.net.URL url)
                                       throws org.dom4j.DocumentException
Parse the url

Returns:
The DOM object
Throws:
org.dom4j.DocumentException

processXPath

public static org.dom4j.Element processXPath(org.dom4j.Element rootElement,
                                             java.lang.String xpath,
                                             java.lang.String attributeValue)
Adds the to rootElement the given xpath and, if the xpath contains an attribute, sets the attribute value.

Parameters:
rootElement -
xpath -
attributeValue -
Returns:
the added element

addXmlNodeAndAttribute

public static org.dom4j.Element addXmlNodeAndAttribute(org.dom4j.Element rootElement,
                                                       java.lang.String nodeXPath,
                                                       java.lang.String attributeName,
                                                       java.lang.String attributeValue)
Adds to the rootElement the nodes specified by nodeXPath. If not null it adds the attibuteName with the give Attribute Value

Parameters:
rootElement -
nodeXPath -
attributeName -
AttributeValue -
Returns:
the added element

addXmlNodesAndAttribute

public static void addXmlNodesAndAttribute(org.dom4j.Element parentElement,
                                           java.lang.String nodeName,
                                           java.lang.String attributeName,
                                           java.util.Collection<java.lang.String> attributeValues)
Adds multiple nodes to the parent element, one for each attributeValues and each of them with an attribute with the given name and value.

Parameters:
parentElement -
nodeName -
attributeName -
attributeValues -