edu.internet2.middleware.grouper.ui.util
Class DOMHelper

java.lang.Object
  extended by edu.internet2.middleware.grouper.ui.util.DOMHelper

public class DOMHelper
extends Object

Utility class to provide common functions useful when working with DOM.

Version:
$Id: DOMHelper.java,v 1.2 2008-01-31 16:16:35 mchyzer Exp $
Author:
Gary Brown.

Constructor Summary
DOMHelper()
           
 
Method Summary
static String domToString(Document document)
          Serializes a Document to a String - without an Xml declaration
static String domToString(Document document, boolean withDeclaration)
          Serializes a Document to a String - with/without an Xml declaration
static String elementToString(Element element)
          Serializes an Element to a String - without an Xml declaration
static String elementToString(Element element, boolean withDeclaration)
          Serializes an Element to a String - with/without an Xml declaration
static Document getDomFromResourceOnClassPath(String resource)
          looks for file on classpath and parses it into a Document
static Element getImmediateElement(Element element, String elementName)
          Returns immediate child element with given name - first only if > 1
static Collection getImmediateElements(Element element, String elementName)
          Returns immediate child elements with given name
static String getText(Element element, String elementName, boolean nullable)
          Assumes tag only occurs once and contains only text / CDATA If tag does not exist 'nullable' determines if an Exception is thrown
static String getText(String elementName, Document doc, boolean nullable)
          Assumes tag only occurs once and contains only text / CDATA If tag does not exist 'nullable' determines if an Exception is thrown
static Document newDocument()
          Convenience method so you can forget about DocumentBuilderFactory etc
static Document newDocument(File file)
          Convenience method so you can forget about DocumentBuilderFactory etc
static Document newDocument(String str)
          Convenience method so you can forget about DocumentBuilderFactory etc
static String nodeToString(Node node)
          Somewhat old method to turn org.w3c.dom.Node into a String
static Document transform(Document doc, String xsl)
           
static Document transform(Document doc, String xsl, Map parameters)
           
static void transform(String data, File out, String xsl)
          Convenience method for transformations
static void transform(String data, File out, String xsl, Map parameters)
          Convenience method for transformations
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMHelper

public DOMHelper()
Method Detail

nodeToString

public static String nodeToString(Node node)
                           throws Exception
Somewhat old method to turn org.w3c.dom.Node into a String

Throws:
Exception

domToString

public static String domToString(Document document)
                          throws Exception
Serializes a Document to a String - without an Xml declaration

Throws:
Exception

domToString

public static String domToString(Document document,
                                 boolean withDeclaration)
                          throws Exception
Serializes a Document to a String - with/without an Xml declaration

Throws:
Exception

elementToString

public static String elementToString(Element element)
                              throws Exception
Serializes an Element to a String - without an Xml declaration

Throws:
Exception

elementToString

public static String elementToString(Element element,
                                     boolean withDeclaration)
                              throws Exception
Serializes an Element to a String - with/without an Xml declaration

Throws:
Exception

getDomFromResourceOnClassPath

public static Document getDomFromResourceOnClassPath(String resource)
                                              throws Exception
looks for file on classpath and parses it into a Document

Throws:
Exception

getText

public static String getText(String elementName,
                             Document doc,
                             boolean nullable)
                      throws Exception
Assumes tag only occurs once and contains only text / CDATA If tag does not exist 'nullable' determines if an Exception is thrown

Throws:
Exception

getText

public static String getText(Element element,
                             String elementName,
                             boolean nullable)
                      throws Exception
Assumes tag only occurs once and contains only text / CDATA If tag does not exist 'nullable' determines if an Exception is thrown

Throws:
Exception

getImmediateElements

public static Collection getImmediateElements(Element element,
                                              String elementName)
                                       throws Exception
Returns immediate child elements with given name

Throws:
Exception

getImmediateElement

public static Element getImmediateElement(Element element,
                                          String elementName)
                                   throws Exception
Returns immediate child element with given name - first only if > 1

Throws:
Exception

newDocument

public static Document newDocument()
                            throws Exception
Convenience method so you can forget about DocumentBuilderFactory etc

Throws:
Exception

newDocument

public static Document newDocument(String str)
                            throws Exception
Convenience method so you can forget about DocumentBuilderFactory etc

Throws:
Exception

newDocument

public static Document newDocument(File file)
                            throws Exception
Convenience method so you can forget about DocumentBuilderFactory etc

Throws:
Exception

transform

public static void transform(String data,
                             File out,
                             String xsl)
                      throws Exception
Convenience method for transformations

Throws:
Exception

transform

public static void transform(String data,
                             File out,
                             String xsl,
                             Map parameters)
                      throws Exception
Convenience method for transformations

Throws:
Exception

transform

public static Document transform(Document doc,
                                 String xsl)
                          throws Exception
Throws:
Exception

transform

public static Document transform(Document doc,
                                 String xsl,
                                 Map parameters)
                          throws Exception
Throws:
Exception