bruno 2003/07/15 07:13:00
Modified: src/blocks/woody/java/org/apache/cocoon/woody/util DomHelper.java Log: Added getElementText method. Revision Changes Path 1.4 +13 -4 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/util/DomHelper.java Index: DomHelper.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/util/DomHelper.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- DomHelper.java 26 Jun 2003 09:12:12 -0000 1.3 +++ DomHelper.java 15 Jul 2003 14:12:59 -0000 1.4 @@ -55,10 +55,7 @@ import org.apache.xerces.dom.NodeImpl; import org.apache.cocoon.components.sax.XMLByteStreamCompiler; import org.apache.cocoon.xml.dom.DOMStreamer; -import org.w3c.dom.Element; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.w3c.dom.Node; +import org.w3c.dom.*; import org.xml.sax.InputSource; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.SAXException; @@ -179,6 +176,18 @@ return false; else throw new Exception("Cannot parse the value \"" + attrValue + "\" as a boolean in the attribute \"" + attributeName + "\" on the element \"" + element.getTagName() + "\" at " + getLocation(element)); + } + + public static String getElementText(Element element) { + StringBuffer value = new StringBuffer(); + NodeList nodeList = element.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + if (node instanceof Text || node instanceof CDATASection) { + value.append(node.getNodeValue()); + } + } + return value.toString(); } /**