dk.netarkivet.common.utils
Class XmlUtils

java.lang.Object
  extended by dk.netarkivet.common.utils.XmlUtils

public class XmlUtils
extends java.lang.Object

Utilities for handling XML-files.


Constructor Summary
XmlUtils()
           
 
Method Summary
static org.dom4j.Document documentFromString(java.lang.String xml)
          Parses a given string to produce a Document instance.
static org.dom4j.Document getXmlDoc(java.io.File f)
          Read and parse an XML-file, and return a Document object representing this object.
static org.dom4j.Document getXmlDoc(java.io.InputStream resourceAsStream)
          Read and parse an XML stream, and return a Document object representing this object.
static void setNode(org.dom4j.Document doc, java.lang.String xpath, java.lang.String value)
          Set a XmlNode defined by the given XPath to the given value.
static void validateWithXSD(java.io.File xsdFile)
          Validate that the settings xml files conforms to the XSD.
static void writeXmlToFile(org.dom4j.Document doc, java.io.File f)
          Write document tree to file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtils

public XmlUtils()
Method Detail

getXmlDoc

public static org.dom4j.Document getXmlDoc(java.io.File f)
                                    throws IOFailure
Read and parse an XML-file, and return a Document object representing this object.

Parameters:
f - a given xml file
Returns:
a Document representing the xml file
Throws:
IOFailure - if unable to read the xml file or unable to parse the file as XML

getXmlDoc

public static org.dom4j.Document getXmlDoc(java.io.InputStream resourceAsStream)
Read and parse an XML stream, and return a Document object representing this object.

Parameters:
resourceAsStream - a given xml document
Returns:
a Document representing the xml document
Throws:
IOFailure - if unable to read the xml document or unable to parse the document as XML

setNode

public static void setNode(org.dom4j.Document doc,
                           java.lang.String xpath,
                           java.lang.String value)
Set a XmlNode defined by the given XPath to the given value.

Parameters:
doc - the Document, which is being modified
xpath - the given XPath
value - the given value
Throws:
IOFailure - If the given XPath was not found in the document

validateWithXSD

public static void validateWithXSD(java.io.File xsdFile)
Validate that the settings xml files conforms to the XSD.

Parameters:
xsdFile - Schema to check settings against.
Throws:
ArgumentNotValid - if unable to validate the settings files
IOFailure - If unable to read the settings files and/or the xsd file.

writeXmlToFile

public static void writeXmlToFile(org.dom4j.Document doc,
                                  java.io.File f)
                           throws IOFailure
Write document tree to file.

Parameters:
doc - the document tree to save.
f - the file to write the document to.
Throws:
IOFailure - On trouble writing XML file to disk.

documentFromString

public static org.dom4j.Document documentFromString(java.lang.String xml)
                                             throws org.dom4j.DocumentException
Parses a given string to produce a Document instance.

Parameters:
xml - Some XML text.
Returns:
a Document parsed from the given xml.
Throws:
org.dom4j.DocumentException - If unable to parse the given text as XML.