org.apache.commons.modeler.util
Class DomUtil

java.lang.Object
  extended by org.apache.commons.modeler.util.DomUtil

public class DomUtil
extends java.lang.Object

Few simple utils to read DOM

Author:
Costin Manolache

Nested Class Summary
static class DomUtil.NullResolver
           
 
Constructor Summary
DomUtil()
           
 
Method Summary
static org.w3c.dom.Node findChildWithAtt(org.w3c.dom.Node parent, java.lang.String elemName, java.lang.String attName, java.lang.String attVal)
          Find the first direct child with a given attribute.
static java.lang.String getAttribute(org.w3c.dom.Node element, java.lang.String attName)
           
static org.w3c.dom.Node getChild(org.w3c.dom.Node parent, int type)
          Get the first direct child with a given type
static org.w3c.dom.Node getChild(org.w3c.dom.Node parent, java.lang.String name)
          Get the first element child.
static java.lang.String getChildContent(org.w3c.dom.Node parent, java.lang.String name)
          Get the first child's content ( ie it's included TEXT node ).
static java.lang.String getContent(org.w3c.dom.Node n)
          Get the trimed text content of a node or null if there is no text
static org.w3c.dom.Node getNext(org.w3c.dom.Node current)
          Get the next sibling with the same name and type
static org.w3c.dom.Node getNext(org.w3c.dom.Node current, java.lang.String name, int type)
          Return the next sibling with a given name and type
static org.w3c.dom.Document readXml(java.io.InputStream is)
          Read XML as DOM.
static void removeAttribute(org.w3c.dom.Node node, java.lang.String attName)
           
static void setAttribute(org.w3c.dom.Node node, java.lang.String attName, java.lang.String val)
           
static void setAttributes(java.lang.Object o, org.w3c.dom.Node parent)
           
static void setText(org.w3c.dom.Node node, java.lang.String val)
          Set or replace the text value
static void writeXml(org.w3c.dom.Node n, java.io.OutputStream os)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DomUtil

public DomUtil()
Method Detail

getContent

public static java.lang.String getContent(org.w3c.dom.Node n)
Get the trimed text content of a node or null if there is no text


getChild

public static org.w3c.dom.Node getChild(org.w3c.dom.Node parent,
                                        java.lang.String name)
Get the first element child.

Parameters:
parent - lookup direct childs
name - name of the element. If null return the first element.

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Node element,
                                            java.lang.String attName)

setAttribute

public static void setAttribute(org.w3c.dom.Node node,
                                java.lang.String attName,
                                java.lang.String val)

removeAttribute

public static void removeAttribute(org.w3c.dom.Node node,
                                   java.lang.String attName)

setText

public static void setText(org.w3c.dom.Node node,
                           java.lang.String val)
Set or replace the text value


findChildWithAtt

public static org.w3c.dom.Node findChildWithAtt(org.w3c.dom.Node parent,
                                                java.lang.String elemName,
                                                java.lang.String attName,
                                                java.lang.String attVal)
Find the first direct child with a given attribute.

Parameters:
parent -
elemName - name of the element, or null for any
attName - attribute we're looking for
attVal - attribute value or null if we just want any

getChildContent

public static java.lang.String getChildContent(org.w3c.dom.Node parent,
                                               java.lang.String name)
Get the first child's content ( ie it's included TEXT node ).


getChild

public static org.w3c.dom.Node getChild(org.w3c.dom.Node parent,
                                        int type)
Get the first direct child with a given type


getNext

public static org.w3c.dom.Node getNext(org.w3c.dom.Node current)
Get the next sibling with the same name and type


getNext

public static org.w3c.dom.Node getNext(org.w3c.dom.Node current,
                                       java.lang.String name,
                                       int type)
Return the next sibling with a given name and type


setAttributes

public static void setAttributes(java.lang.Object o,
                                 org.w3c.dom.Node parent)

readXml

public static org.w3c.dom.Document readXml(java.io.InputStream is)
                                    throws org.xml.sax.SAXException,
                                           java.io.IOException,
                                           javax.xml.parsers.ParserConfigurationException
Read XML as DOM.

Throws:
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException

writeXml

public static void writeXml(org.w3c.dom.Node n,
                            java.io.OutputStream os)
                     throws javax.xml.transform.TransformerException
Throws:
javax.xml.transform.TransformerException


Copyright 2002-2008 The Apache Software Foundation. All Rights Reserved.