Example usage for org.w3c.dom Node CDATA_SECTION_NODE

List of usage examples for org.w3c.dom Node CDATA_SECTION_NODE

Introduction

In this page you can find the example usage for org.w3c.dom Node CDATA_SECTION_NODE.

Prototype

short CDATA_SECTION_NODE

To view the source code for org.w3c.dom Node CDATA_SECTION_NODE.

Click Source Link

Document

The node is a CDATASection.

Usage

From source file:org.exist.storage.dom.DOMFile.java

public String debugPageContents(DOMPage page) {
    final StringBuilder buf = new StringBuilder();
    buf.append("Page " + page.getPageNum() + ": ");
    short count = 0;
    final int dataLength = page.getPageHeader().getDataLength();
    for (int pos = 0; pos < dataLength; count++) {
        buf.append(pos + "/");
        final short tupleID = ByteConversion.byteToShort(page.data, pos);
        pos += LENGTH_TID;//from   ww  w . j a  va  2s  .  co  m
        buf.append(ItemId.getId(tupleID));
        if (ItemId.isLink(tupleID)) {
            buf.append("L");
        } else if (ItemId.isRelocated(tupleID)) {
            buf.append("R");
        }
        if (ItemId.isLink(tupleID)) {
            final long forwardLink = ByteConversion.byteToLong(page.data, pos);
            buf.append(':').append(forwardLink).append(" ");
            pos += LENGTH_FORWARD_LOCATION;
        } else {
            final short valueLength = ByteConversion.byteToShort(page.data, pos);
            pos += LENGTH_DATA_LENGTH;
            if (valueLength < 0) {
                LOG.warn("Illegal length: " + valueLength);
                return buf.append("[Illegal length : " + valueLength + "] ").toString();
                //Probably unable to continue...
            } else if (ItemId.isRelocated(tupleID)) {
                //TODO : output to buffer ?
                pos += LENGTH_ORIGINAL_LOCATION;
            } else {
                buf.append("[");
                switch (Signatures.getType(page.data[pos])) {
                case Node.ELEMENT_NODE: {
                    buf.append("element ");
                    int readOffset = pos;
                    readOffset += 1;
                    final int children = ByteConversion.byteToInt(page.data, readOffset);
                    readOffset += ElementImpl.LENGTH_ELEMENT_CHILD_COUNT;
                    final int dlnLen = ByteConversion.byteToShort(page.data, readOffset);
                    readOffset += NodeId.LENGTH_NODE_ID_UNITS;
                    //That might happen during recovery runs : TODO, investigate
                    if (owner == null) {
                        buf.append("(Can't read data, owner is null)");
                    } else {
                        try {
                            final NodeId nodeId = ((NativeBroker) owner).getBrokerPool().getNodeFactory()
                                    .createFromData(dlnLen, page.data, readOffset);
                            readOffset += nodeId.size();
                            buf.append("(" + nodeId.toString() + ")");
                            final short attributes = ByteConversion.byteToShort(page.data, readOffset);
                            buf.append(" children: " + children);
                            buf.append(" attributes: " + attributes);
                        } catch (final Exception e) {
                            //TODO : more friendly message. Provide the array of bytes ?
                            buf.append("(Unable to read the node ID at: " + readOffset);
                            buf.append(" children : " + children);
                            //Probably a wrong offset so... don't read it
                            buf.append(" attributes : unknown");
                        }
                    }
                    break;
                }
                case Node.TEXT_NODE:
                case Node.CDATA_SECTION_NODE: {
                    if (Signatures.getType(page.data[pos]) == Node.TEXT_NODE) {
                        buf.append("text ");
                    } else {
                        buf.append("CDATA ");
                    }
                    int readOffset = pos;
                    readOffset += 1;
                    final int dlnLen = ByteConversion.byteToShort(page.data, readOffset);
                    readOffset += NodeId.LENGTH_NODE_ID_UNITS;
                    //That might happen during recovery runs : TODO, investigate
                    if (owner == null) {
                        buf.append("(Can't read data, owner is null)");
                    } else {
                        try {
                            final NodeId nodeId = ((NativeBroker) owner).getBrokerPool().getNodeFactory()
                                    .createFromData(dlnLen, page.data, readOffset);
                            readOffset += nodeId.size();
                            buf.append("(" + nodeId.toString() + ")");
                            final ByteArrayOutputStream os = new ByteArrayOutputStream();
                            os.write(page.data, readOffset, valueLength - (readOffset - pos));

                            String value = new String(os.toByteArray(), UTF_8);
                            if (value.length() > 15) {
                                value = value.substring(0, 8) + "..." + value.substring(value.length() - 8);
                            }

                            buf.append(":'" + value + "'");
                        } catch (final Exception e) {
                            //TODO : more friendly message. Provide the array of bytes ?
                            buf.append("(unable to read the node ID at : " + readOffset);
                        }
                    }
                    break;
                }
                case Node.ATTRIBUTE_NODE: {
                    buf.append("[");
                    buf.append("attribute ");
                    int readOffset = pos;
                    final byte idSizeType = (byte) (page.data[readOffset] & 0x3);
                    final boolean hasNamespace = (page.data[readOffset] & 0x10) == 0x10;
                    readOffset += 1;
                    final int dlnLen = ByteConversion.byteToShort(page.data, readOffset);
                    readOffset += NodeId.LENGTH_NODE_ID_UNITS;
                    //That might happen during recovery runs : TODO, investigate
                    if (owner == null) {
                        buf.append("(can't read data, owner is null)");
                    } else {
                        try {
                            final NodeId nodeId = ((NativeBroker) owner).getBrokerPool().getNodeFactory()
                                    .createFromData(dlnLen, page.data, readOffset);
                            readOffset += nodeId.size();
                            buf.append("(" + nodeId.toString() + ")");
                            readOffset += Signatures.getLength(idSizeType);
                            if (hasNamespace) {
                                //Untested
                                final short NSId = ByteConversion.byteToShort(page.data, readOffset);
                                readOffset += AttrImpl.LENGTH_NS_ID;
                                final short prefixLen = ByteConversion.byteToShort(page.data, readOffset);
                                readOffset += AttrImpl.LENGTH_PREFIX_LENGTH + prefixLen;
                                final ByteArrayOutputStream os = new ByteArrayOutputStream();
                                os.write(page.data, readOffset, valueLength - (readOffset - prefixLen));
                                String prefix = new String(os.toByteArray(), UTF_8);

                                final String NsURI = ((NativeBroker) owner).getBrokerPool().getSymbols()
                                        .getNamespace(NSId);
                                buf.append(prefix + "{" + NsURI + "}");
                            }
                            final ByteArrayOutputStream os = new ByteArrayOutputStream();
                            os.write(page.data, readOffset, valueLength - (readOffset - pos));

                            String value = new String(os.toByteArray(), UTF_8);
                            if (value.length() > 15) {
                                value = value.substring(0, 8) + "..." + value.substring(value.length() - 8);
                            }

                            buf.append(":'" + value + "'");
                        } catch (final Exception e) {
                            //TODO : more friendly message. Provide the array of bytes ?
                            buf.append("(unable to read the node ID at : " + readOffset);
                        }
                    }
                    buf.append("] ");
                    break;
                }
                default:
                    buf.append("Unknown node type !");
                }
                buf.append("] ");
            }
            pos += valueLength;
        }
    }
    buf.append("; records in page: " + count + " (header says: " + page.getPageHeader().getRecordCount() + ")");
    buf.append("; currentTupleID: " + page.getPageHeader().getCurrentTupleID());
    buf.append("; data length: " + page.getPageHeader().getDataLength());
    for (int i = page.data.length; i > 0; i--) {
        if (page.data[i - 1] != 0) {
            buf.append(" (last non-zero byte: " + i + ")");
            break;
        }
    }
    return buf.toString();
}

From source file:org.exist.storage.dom.DOMFile.java

/**
 * Recursive method to retrieve the string values of the root node
 * and all its descendants./*from  w  w w . ja v a2 s  . c  o  m*/
 */
private void getNodeValue(BrokerPool pool, DocumentImpl doc, ByteArrayOutputStream os, RecordPos rec,
        boolean isTopNode, boolean addWhitespace) {
    if (!lock.hasLock()) {
        LOG.warn("The file doesn't own a lock");
    }
    //Locate the next real node, skipping relocated nodes
    boolean foundNext = false;
    do {
        final DOMFilePageHeader pageHeader = rec.getPage().getPageHeader();
        if (rec.offset > pageHeader.getDataLength()) {
            // end of page reached, proceed to the next page
            final long nextPage = pageHeader.getNextDataPage();
            if (nextPage == Page.NO_PAGE) {
                SanityCheck.TRACE("Bad link to next page! " + "Offset: " + rec.offset + ", Len: "
                        + pageHeader.getDataLength() + ", Page info : " + rec.getPage().page.getPageInfo());
                //TODO : throw exception ? -pb
                return;
            }
            rec.setPage(getDOMPage(nextPage));
            dataCache.add(rec.getPage());
            rec.offset = LENGTH_TID;
        }
        //Position the stream at the very beginning of the record
        final short tupleID = ByteConversion.byteToShort(rec.getPage().data, rec.offset - LENGTH_TID);
        rec.setTupleID(tupleID);
        if (ItemId.isLink(rec.getTupleID())) {
            //This is a link: skip it
            //We position the offset *after* the next TupleID
            rec.offset += (LENGTH_FORWARD_LOCATION + LENGTH_TID);
        } else {
            //OK: node found
            foundNext = true;
        }
    } while (!foundNext);
    final short valueLength = ByteConversion.byteToShort(rec.getPage().data, rec.offset);
    int realLen = valueLength;
    rec.offset += LENGTH_DATA_LENGTH;
    //Check if the node was relocated
    if (ItemId.isRelocated(rec.getTupleID())) {
        rec.offset += LENGTH_ORIGINAL_LOCATION;
    }
    byte[] data = rec.getPage().data;
    int readOffset = rec.offset;
    boolean inOverflow = false;
    if (valueLength == OVERFLOW) {
        //If we have an overflow value, load it from the overflow page
        final long p = ByteConversion.byteToLong(data, rec.offset);
        data = getOverflowValue(p);
        //We position the offset *after* the next TID
        rec.offset += LENGTH_OVERFLOW_LOCATION + LENGTH_TID;
        realLen = data.length;
        readOffset = 0;
        inOverflow = true;
    }
    // check the type of the node
    final short type = Signatures.getType(data[readOffset]);
    readOffset += StoredNode.LENGTH_SIGNATURE_LENGTH;
    //Switch on the node type
    switch (type) {
    case Node.ELEMENT_NODE: {
        final int children = ByteConversion.byteToInt(data, readOffset);
        readOffset += ElementImpl.LENGTH_ELEMENT_CHILD_COUNT;
        final int dlnLen = ByteConversion.byteToShort(data, readOffset);
        readOffset += NodeId.LENGTH_NODE_ID_UNITS;
        final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset);
        readOffset += nodeIdLen;
        final short attributes = ByteConversion.byteToShort(data, readOffset);
        //Ignore the following NS data which are of no use
        //We position the offset *after* the next TID
        rec.offset += realLen + LENGTH_TID;
        final boolean extraWhitespace = addWhitespace && (children - attributes) > 1;
        for (int i = 0; i < children; i++) {
            //recursive call : we ignore attributes children
            getNodeValue(pool, doc, os, rec, false, addWhitespace);
            if (extraWhitespace) {
                os.write((byte) ' ');
            }
        }
        return;
    }
    case Node.TEXT_NODE:
    case Node.CDATA_SECTION_NODE: {
        final int dlnLen = ByteConversion.byteToShort(data, readOffset);
        readOffset += NodeId.LENGTH_NODE_ID_UNITS;
        final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset);
        readOffset += nodeIdLen;
        os.write(data, readOffset,
                realLen - (StoredNode.LENGTH_SIGNATURE_LENGTH + NodeId.LENGTH_NODE_ID_UNITS + nodeIdLen));
        break;
    }
    case Node.PROCESSING_INSTRUCTION_NODE: {
        final int dlnLen = ByteConversion.byteToShort(data, readOffset);
        readOffset += NodeId.LENGTH_NODE_ID_UNITS;
        final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset);
        readOffset += nodeIdLen;
        final int targetLen = ByteConversion.byteToInt(data, readOffset);
        readOffset += 4 + targetLen;
        os.write(data, readOffset, realLen - (StoredNode.LENGTH_SIGNATURE_LENGTH + NodeId.LENGTH_NODE_ID_UNITS
                + nodeIdLen + targetLen + 4));
        break;
    }
    case Node.ATTRIBUTE_NODE: {
        if (isTopNode) {
            final int start = readOffset - StoredNode.LENGTH_SIGNATURE_LENGTH;
            final byte idSizeType = (byte) (data[start] & 0x3);
            final boolean hasNamespace = (data[start] & 0x10) == 0x10;
            final int dlnLen = ByteConversion.byteToShort(data, readOffset);
            readOffset += NodeId.LENGTH_NODE_ID_UNITS;
            final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset);
            readOffset += nodeIdLen;
            readOffset += Signatures.getLength(idSizeType);
            if (hasNamespace) {
                readOffset += AttrImpl.LENGTH_NS_ID; // skip namespace id
                final short prefixLen = ByteConversion.byteToShort(data, readOffset);
                readOffset += AttrImpl.LENGTH_PREFIX_LENGTH;
                readOffset += prefixLen; // skip prefix
            }
            os.write(data, readOffset, realLen - (readOffset - start));
        }
        break;
    }
    case Node.COMMENT_NODE: {
        if (isTopNode) {
            final int dlnLen = ByteConversion.byteToShort(data, readOffset);
            readOffset += NodeId.LENGTH_NODE_ID_UNITS;
            final int nodeIdLen = pool.getNodeFactory().lengthInBytes(dlnLen, data, readOffset);
            readOffset += nodeIdLen;
            os.write(data, readOffset,
                    realLen - (StoredNode.LENGTH_SIGNATURE_LENGTH + NodeId.LENGTH_NODE_ID_UNITS + nodeIdLen));
        }
        break;
    }
    }
    if (!inOverflow) {
        //If it isn't an overflow value, add the value length to the current offset
        //We position the offset *after* the next TID
        rec.offset += realLen + LENGTH_TID;
    }
}

From source file:org.getobjects.appserver.templates.WOxElemBuilder.java

public WOElement buildNode(Node _node, WOxElemBuilder _builder) {
    if (_node == null)
        return null;

    switch (_node.getNodeType()) {
    case Node.ELEMENT_NODE:
        return this.buildElement((Element) _node, _builder);
    case Node.TEXT_NODE:
        return this.buildText((Text) _node, _builder);
    case Node.CDATA_SECTION_NODE:
        return this.buildCDATASection((CDATASection) _node, _builder);
    case Node.COMMENT_NODE:
        return this.buildComment((Comment) _node, _builder);
    case Node.DOCUMENT_NODE:
        return this.buildDocument((Document) _node, _builder);

    default: {// ww  w. java2  s  . c om
        if (this.nextBuilder != null)
            return this.nextBuilder.buildNode(_node, _builder);

        this.log.error("unsupported node type: " + _node);
    }
    }
    return null;
}

From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java

/**
 * Compares and updates script blocks in the MXML document if necessary.
 * Assumes that there is only a single script block.
 * //from   w w w. ja v  a2s.  c o m
 * @param original
 * @param proposed
 * @param originalDocumentAdjusted
 * @return the new document if changes are necessary, null if no changes are
 *         necessary
 */
private static boolean updateScriptBlock(Element original, Element proposed, boolean originalDocumentAdjusted) {
    Element originalScriptBlock = XmlUtils.findFirstElementByName("fx:Script", original);
    Element proposedScriptBlock = XmlUtils.findFirstElementByName("fx:Script", proposed);
    if (originalScriptBlock != null && proposedScriptBlock != null) {
        if (originalScriptBlock.getTextContent() != null
                && !originalScriptBlock.getTextContent().equals(proposedScriptBlock.getTextContent())) {
            originalScriptBlock.setTextContent(proposedScriptBlock.getTextContent());
            originalDocumentAdjusted = true;
        } else if (originalScriptBlock.getChildNodes().getLength() > 0
                && proposedScriptBlock.getChildNodes().getLength() > 0) {
            CDATASection originalCDATA = null;
            CDATASection proposedCDATA = null;
            for (int i = 0; i < originalScriptBlock.getChildNodes().getLength(); i++) {
                if (originalScriptBlock.getChildNodes().item(i).getNodeType() == Node.CDATA_SECTION_NODE) {
                    originalCDATA = (CDATASection) originalScriptBlock.getChildNodes().item(i);
                    break;
                }
            }
            for (int i = 0; i < proposedScriptBlock.getChildNodes().getLength(); i++) {
                if (proposedScriptBlock.getChildNodes().item(i).getNodeType() == Node.CDATA_SECTION_NODE) {
                    proposedCDATA = (CDATASection) proposedScriptBlock.getChildNodes().item(i);
                    break;
                }
            }

            if (originalCDATA == null || proposedCDATA == null) {
                return originalDocumentAdjusted;
            }

            if (originalCDATA.getData() != null && !originalCDATA.getData().equals(proposedCDATA.getData())) {
                originalCDATA.setData(proposedCDATA.getData());
                originalDocumentAdjusted = true;
            }
        }
    }
    return originalDocumentAdjusted;
}

From source file:org.infoscoop.util.Xml2Json.java

private void nodelist2json(Map map, NodeList nodes) throws Exception {
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        switch (node.getNodeType()) {
        case Node.TEXT_NODE:
        case Node.CDATA_SECTION_NODE:
            String text = node.getNodeValue().trim();
            if (text.length() > 0)
                map.put("content", listner.text(node.getNodeValue()));
            break;
        case Node.ELEMENT_NODE:
            Element childElm = (Element) node;
            String childXPath = getXPath(childElm);
            if (skips.contains(childXPath)) {
                nodelist2json(map, childElm.getChildNodes());
            } else if (arrays.contains(childXPath)) {
                JSONArray obj = (JSONArray) map.get(childElm.getNodeName());
                if (obj == null) {
                    obj = new JSONArray();
                    map.put(childElm.getNodeName(), obj);
                }/*from   w w w  .  ja  v a2s. c om*/
                JSONArray array = new JSONArray();
                NodeList childNodes = childElm.getChildNodes();
                for (int j = 0; j < childNodes.getLength(); j++) {
                    Node child = childNodes.item(j);
                    //TODO need to support the other node types.
                    if (child.getNodeType() != Node.ELEMENT_NODE)
                        continue;
                    array.put(node2json((Element) child));
                }
                obj.put(array);
            } else {
                String childName = childElm.getNodeName();
                boolean isRepeatable = repeatables.contains(childXPath);
                boolean hasKey = keyPaths.contains(childXPath);
                if (isRepeatable && hasKey) {
                    JSONObject obj = (JSONObject) map.get(childName);
                    if (obj == null) {
                        obj = new JSONObject();
                        map.put(childName, obj);
                    }
                    String attrName = (String) pathMaps.get(childXPath);
                    String attrValue = childElm.getAttribute(attrName);
                    obj.put(attrValue, node2json(childElm));
                } else if (isRepeatable && !hasKey) {
                    JSONArray obj = (JSONArray) map.get(childName);
                    if (obj == null) {
                        obj = new JSONArray();
                        map.put(childName, obj);
                    }
                    obj.put(node2json(childElm));
                } else if (hasKey) {
                    String attrName = (String) pathMaps.get(childXPath);
                    String attrValue = childElm.getAttribute(attrName);
                    map.put(attrValue, node2json(childElm));
                } else {
                    map.put(childName, node2json(childElm));
                }
            }
            break;
        default:
            break;
        }
    }
}

From source file:org.infoscoop.web.CustomizationServlet.java

private String getCustomizationFtl(Map<String, Object> root) throws ParserConfigurationException, Exception {
    JSONObject layoutJson = new JSONObject();
    Map<String, TabLayout> CustomizationMap = TabLayoutService.getHandle().getMyTabLayoutHTML();

    //int staticPanelCount = 0;
    for (Iterator<Map.Entry<String, TabLayout>> ite = CustomizationMap.entrySet().iterator(); ite.hasNext();) {
        Map.Entry<String, TabLayout> entry = ite.next();
        String key = (String) entry.getKey();
        TabLayout tabLayout = (TabLayout) entry.getValue();
        JSONObject value = new JSONObject();

        String layout = tabLayout.getLayout();
        if (layout == null)
            layout = "";
        value.put("layout", layout);
        value.put("adjustToWindowHeight", tabLayout.isAdjustToWindowHeight());

        if ("commandbar".equals(key.toLowerCase())) {
            layoutJson.put("commandbar", applyFreemakerTemplate(root, layout));
        } else {//from ww  w .j  a  va  2s  .com
            layoutJson.put("staticPanel" + key, value);
        }
    }

    // get the information of static layout.
    PortalLayoutService service = (PortalLayoutService) SpringUtil.getBean("PortalLayoutService");
    List<Portallayout> layoutList = service.getPortalLayoutList();
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();

    for (Iterator<Portallayout> layoutIt = layoutList.iterator(); layoutIt.hasNext();) {
        Portallayout portalLayout = layoutIt.next();

        String name = portalLayout.getName();
        if (name.equals("javascript"))
            continue;

        String layout;
        boolean isIframeToolBar = name.toLowerCase().equals("contentfooter");
        if (isIframeToolBar) {
            String tempLayout = "<temp>" + portalLayout.getLayout() + "</temp>";
            Document ifdoc = db.parse(new ByteArrayInputStream(tempLayout.getBytes("UTF-8")));
            Element ifroot = ifdoc.getDocumentElement();
            NodeList icons = ifroot.getElementsByTagName("icon");

            JSONArray iconsJson = new JSONArray();
            for (int i = 0; i < icons.getLength(); i++) {
                Element icon = (Element) icons.item(i);

                JSONObject iconJson = new JSONObject();
                if (icon.hasAttribute("type"))
                    iconJson.put("type", icon.getAttribute("type"));

                NodeList nodeList = icon.getChildNodes();
                for (int j = 0; j < nodeList.getLength(); j++) {
                    if (nodeList.item(j).getNodeType() == Node.CDATA_SECTION_NODE) {
                        iconJson.put("html", nodeList.item(j).getNodeValue());
                        break;
                    }
                }

                iconsJson.put(iconJson);
            }
            layout = iconsJson.toString();
        } else {
            layout = portalLayout.getLayout();
            if (layout == null)
                layout = "";
        }

        layout = applyFreemakerTemplate(root, layout);
        layoutJson.put(name, (isIframeToolBar) ? new JSONArray(layout) : layout);
    }

    return "IS_Customization = " + layoutJson.toString() + ";";
}

From source file:org.jbpm.bpel.integration.soap.SoapUtil.java

public static void copyChildNodes(SOAPElement target, Element source) throws SOAPException {
    // easy way out: no child nodes
    if (!source.hasChildNodes())
        return;//from  w  w  w. ja  va  2  s . c  o m
    // traverse child nodes
    for (Node child = source.getFirstChild(); child != null; child = child.getNextSibling()) {
        switch (child.getNodeType()) {
        case Node.ELEMENT_NODE: {
            copyChildElement(target, (Element) child);
            break;
        }
        case Node.TEXT_NODE:
        case Node.CDATA_SECTION_NODE: {
            String text = child.getNodeValue();
            // drop whitespace-only text nodes
            if (!StringUtils.isWhitespace(text)) {
                target.addTextNode(text);
                if (traceEnabled)
                    log.trace("appended text: " + text);
            }
            break;
        }
        default:
            log.debug("discarding child: " + child);
        }
    }
}

From source file:org.jbpm.bpel.xml.util.XmlUtil.java

public static void copyChildNodes(Element target, Element source) {
    Document targetDoc = target.getOwnerDocument();
    for (Node child = source.getFirstChild(); child != null; child = child.getNextSibling()) {
        switch (child.getNodeType()) {
        case Node.ELEMENT_NODE:
            copyChildElement(target, (Element) child);
            break;
        case Node.TEXT_NODE:
        case Node.CDATA_SECTION_NODE:
            target.appendChild(targetDoc.createTextNode(child.getNodeValue()));
            if (traceEnabled)
                log.trace("appended text: " + child.getNodeValue());
            break;
        default://from   w  w  w  .j  ava2s.c o m
            log.debug("discarding child: " + child);
        }
    }
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Returns the text contained in the specified element. The returned value is trimmed by calling the trim() method of
 * java.lang.String/*w w w  .j a v  a 2 s  .  c o m*/
 * <p>
 * 
 * @param node
 *          current element
 * @return the textual contents of the element or null, if it is missing
 */
public static String getStringValue(final Node node) {
    if (node.getNodeType() == Node.TEXT_NODE)
        return node.getNodeValue();
    final NodeList children = node.getChildNodes();
    final StringBuffer sb = new StringBuffer(children.getLength() * 500);

    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i).getNodeType() == Node.TEXT_NODE
                || children.item(i).getNodeType() == Node.CDATA_SECTION_NODE) {
            sb.append(children.item(i).getNodeValue());
        }
    }

    return sb.toString().trim();
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Returns the concatenated Strings of all direct children that are TEXT_NODEs.
 *//*from   w ww .j  a v a2 s . c  o  m*/
public static String getValue(final Node node) {
    final NodeList children = node.getChildNodes();
    final StringBuffer sb = new StringBuffer(children.getLength() * 500);

    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i).getNodeType() == Node.TEXT_NODE
                || children.item(i).getNodeType() == Node.CDATA_SECTION_NODE) {
            sb.append(children.item(i).getNodeValue());
        }
    }

    return sb.toString().trim();
}