org.w3c.mwi.mobileok.basic
Class DOMUtils

java.lang.Object
  extended by org.w3c.mwi.mobileok.basic.DOMUtils

public final class DOMUtils
extends java.lang.Object

Static helper class that defines useful constants and methods to build and parse DOM trees.

The methods are used throughout the mobileOK Checker library, and in particular to generate the intermediary moki representation of the resource under test (see PreprocessorResults, to parse the XML result returned by XSL stylesheets (see AbstractXSLTTestImplementation, and to generate the final XML report (see TestResults).

Version:
$Revision: 1.1 $
Author:
The W3C mobileOK Checker Task Force

Nested Class Summary
private static class DOMUtils.XSLTURIResolver
           
 
Field Summary
private static javax.xml.parsers.DocumentBuilderFactory docFactory
           
private static javax.xml.transform.sax.SAXTransformerFactory factory
           
(package private) static java.lang.String NAMESPACE_MOKI
           
private static java.lang.String XSLT_PATH
           
 
Constructor Summary
private DOMUtils()
           
 
Method Summary
(package private) static org.w3c.dom.Element addElement(org.w3c.dom.Document document, org.w3c.dom.Node parent, java.lang.String namespace, java.lang.String elementName)
           
(package private) static org.w3c.dom.Element addElementWithText(org.w3c.dom.Document document, org.w3c.dom.Node parent, java.lang.String namespace, java.lang.String elementName, java.lang.String value)
           
(package private) static void domToStream(org.w3c.dom.Document dom, javax.xml.transform.Result streamResult)
           
(package private) static java.lang.String domToString(org.w3c.dom.Document dom)
           
static java.lang.String getAttribute(org.w3c.dom.Node n, java.lang.String name)
          Returns the value of the attribute of the given Node that matches the given name.
static int getNodeLineNumber(org.w3c.dom.Node node)
           
(package private) static java.io.InputStream getResourceStream(java.lang.String href)
           
(package private) static javax.xml.parsers.DocumentBuilder newDocumentBuilder()
           
(package private) static org.w3c.dom.Document newDOM()
           
(package private) static javax.xml.transform.Transformer newTransformer()
           
(package private) static javax.xml.transform.Transformer newTransformer(javax.xml.transform.Source source)
           
(package private) static javax.xml.transform.sax.TransformerHandler newTransformerHandler()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACE_MOKI

static final java.lang.String NAMESPACE_MOKI
See Also:
Constant Field Values

XSLT_PATH

private static final java.lang.String XSLT_PATH
See Also:
Constant Field Values

docFactory

private static final javax.xml.parsers.DocumentBuilderFactory docFactory

factory

private static final javax.xml.transform.sax.SAXTransformerFactory factory
Constructor Detail

DOMUtils

private DOMUtils()
Method Detail

addElement

static org.w3c.dom.Element addElement(org.w3c.dom.Document document,
                                      org.w3c.dom.Node parent,
                                      java.lang.String namespace,
                                      java.lang.String elementName)

addElementWithText

static org.w3c.dom.Element addElementWithText(org.w3c.dom.Document document,
                                              org.w3c.dom.Node parent,
                                              java.lang.String namespace,
                                              java.lang.String elementName,
                                              java.lang.String value)

newDOM

static org.w3c.dom.Document newDOM()
                            throws TestException
Throws:
TestException

domToString

static java.lang.String domToString(org.w3c.dom.Document dom)
                             throws TestException
Throws:
TestException

domToStream

static void domToStream(org.w3c.dom.Document dom,
                        javax.xml.transform.Result streamResult)
                 throws TestException
Throws:
TestException

newTransformer

static javax.xml.transform.Transformer newTransformer()
                                               throws TestException
Throws:
TestException

newTransformer

static javax.xml.transform.Transformer newTransformer(javax.xml.transform.Source source)
                                               throws TestException
Throws:
TestException

newTransformerHandler

static javax.xml.transform.sax.TransformerHandler newTransformerHandler()
                                                                 throws TestException
Throws:
TestException

newDocumentBuilder

static javax.xml.parsers.DocumentBuilder newDocumentBuilder()
                                                     throws TestException
Throws:
TestException

getNodeLineNumber

public static int getNodeLineNumber(org.w3c.dom.Node node)

getResourceStream

static java.io.InputStream getResourceStream(java.lang.String href)
                                      throws TestException
Throws:
TestException

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Node n,
                                            java.lang.String name)
Returns the value of the attribute of the given Node that matches the given name.

Parameters:
n - the Node to parse.
name - the name of the attribute to retrieve.
Returns:
the value of the corresponding attribute, null if not found.