org.dspace.app.webui.util
Class XMLUtil

java.lang.Object
  extended by org.dspace.app.webui.util.XMLUtil

public class XMLUtil
extends Object

This class provides a set of static methods to load and transform XML documents. It supports parameter-aware stylesheets (XSLT).

Author:
Miguel Ferreira

Constructor Summary
XMLUtil()
           
 
Method Summary
static Document loadXML(String filename)
          Loads a W3C XML document from a file.
static Document transformDocument(Document xmlDocument, Map<String,String> parameters, String xsltFilename)
          Applies a stylesheet (that receives parameters) to a given xml document.
static Document transformDocument(Document xmlDocument, String xsltFilename)
          Applies a stylesheet to a given xml document.
static String transformDocumentAsString(Document xmlDocument, Map<String,String> parameters, String xsltFilename)
          Applies a stylesheet (that receives parameters) to a given xml document.
static String transformDocumentAsString(Document xmlDocument, String xsltFilename)
          Applies a stylesheet to a given xml document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtil

public XMLUtil()
Method Detail

loadXML

public static Document loadXML(String filename)
                        throws IOException,
                               ParserConfigurationException,
                               SAXException
Loads a W3C XML document from a file.

Parameters:
filename - The name of the file to be loaded
Returns:
a document object model object representing the XML file
Throws:
IOException
ParserConfigurationException
SAXException

transformDocument

public static Document transformDocument(Document xmlDocument,
                                         String xsltFilename)
                                  throws Exception
Applies a stylesheet to a given xml document.

Parameters:
xmlDocument - the xml document to be transformed
xsltFilename - the filename of the stylesheet
Returns:
the transformed xml document
Throws:
Exception

transformDocument

public static Document transformDocument(Document xmlDocument,
                                         Map<String,String> parameters,
                                         String xsltFilename)
                                  throws Exception
Applies a stylesheet (that receives parameters) to a given xml document.

Parameters:
xmlDocument - the xml document to be transformed
parameters - the hashtable with the parameters to be passed to the stylesheet
xsltFilename - the filename of the stylesheet
Returns:
the transformed xml document
Throws:
Exception

transformDocumentAsString

public static String transformDocumentAsString(Document xmlDocument,
                                               Map<String,String> parameters,
                                               String xsltFilename)
                                        throws Exception
Applies a stylesheet (that receives parameters) to a given xml document. The resulting XML document is converted to a string after transformation.

Parameters:
xmlDocument - the xml document to be transformed
parameters - the hashtable with the parameters to be passed to the stylesheet
xsltFilename - the filename of the stylesheet
Returns:
the transformed xml document as a string
Throws:
Exception

transformDocumentAsString

public static String transformDocumentAsString(Document xmlDocument,
                                               String xsltFilename)
                                        throws Exception
Applies a stylesheet to a given xml document.

Parameters:
xmlDocument - the xml document to be transformed
xsltFilename - the filename of the stylesheet
Returns:
the transformed xml document
Throws:
Exception


Copyright © 2013 DuraSpace. All Rights Reserved.