org.codehaus.cargo.util
Class Dom4JUtil

java.lang.Object
  extended by org.codehaus.cargo.util.Dom4JUtil

public class Dom4JUtil
extends Object

This class offers utility methods not exposed in the current dom4j api.

Version:
$Id$

Constructor Summary
Dom4JUtil()
          default constructor will assign no namespaces and use a default file handler.
Dom4JUtil(FileHandler fileHandler)
          constructor will assign no namespaces.
 
Method Summary
 FileHandler getFileHandler()
           
 Map getNamespaces()
           
 org.dom4j.Document loadXmlFromFile(String sourceFile)
          read the specified file into a Document.
 org.dom4j.Element parseIntoElement(String elementToParse)
          parse the passed string into an Element object.
 void saveXml(org.dom4j.Document document, String filename)
          write the xml document to disk, rethrowing checked exceptions as runtime.
 org.dom4j.Element selectElementMatchingXPath(String xpath, org.dom4j.Element toSearch)
          The following will search the given element for the specified xpath and return any node that matches.
 List selectElementsMatchingXPath(String xpath, org.dom4j.Element toSearch)
          The following will search the given element for the specified xpath and return a list of nodes that match.
 void setFileHandler(FileHandler fileHandler)
           
 void setNamespaces(Map namespaces)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dom4JUtil

public Dom4JUtil()
default constructor will assign no namespaces and use a default file handler.


Dom4JUtil

public Dom4JUtil(FileHandler fileHandler)
constructor will assign no namespaces.

Parameters:
fileHandler - used to read and write xml files.
Method Detail

selectElementsMatchingXPath

public List selectElementsMatchingXPath(String xpath,
                                        org.dom4j.Element toSearch)
The following will search the given element for the specified xpath and return a list of nodes that match.

Parameters:
xpath - - selection criteria
toSearch - - element to start the search at
Returns:
List of matching elements

selectElementMatchingXPath

public org.dom4j.Element selectElementMatchingXPath(String xpath,
                                                    org.dom4j.Element toSearch)
The following will search the given element for the specified xpath and return any node that matches.

Parameters:
xpath - - selection criteria
toSearch - - element to start the search at
Returns:
a matching element

loadXmlFromFile

public org.dom4j.Document loadXmlFromFile(String sourceFile)
read the specified file into a Document.

Parameters:
sourceFile - file to read
Returns:
Document corresponding with sourceFile

saveXml

public void saveXml(org.dom4j.Document document,
                    String filename)
write the xml document to disk, rethrowing checked exceptions as runtime.

Parameters:
document - document to write to disk
filename - where to write the document

getFileHandler

public FileHandler getFileHandler()
Returns:
the Cargo file utility class

setFileHandler

public void setFileHandler(FileHandler fileHandler)
Parameters:
fileHandler - the Cargo file utility class to use. This method is useful for unit testing with Mock objects as it can be passed a test file handler that doesn't perform any real file action.

setNamespaces

public void setNamespaces(Map namespaces)
Parameters:
namespaces - the namespaces to set

getNamespaces

public Map getNamespaces()
Returns:
the namespaces

parseIntoElement

public org.dom4j.Element parseIntoElement(String elementToParse)
parse the passed string into an Element object.

Parameters:
elementToParse - string to parse
Returns:
result of parsing


Copyright © 2004-2012 Codehaus. All Rights Reserved.