Example usage for org.w3c.dom Node getTextContent

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

Introduction

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

Prototype

public String getTextContent() throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:com.concursive.connect.web.modules.wiki.utils.HTMLToWikiUtils.java

private static boolean hasTextContent(Node n) {
    return (!"".equals(n.getTextContent().trim()) && !" ".equals(n.getTextContent().trim()));
}

From source file:com.puppycrawl.tools.checkstyle.internal.XdocsPagesTest.java

private static void validatePackageSection(String fileName, String sectionName, Node subSection,
        Object instance) {// w w w .  j  ava 2  s .c  o m
    Assert.assertEquals(fileName + " section '" + sectionName + "' should have matching package",
            instance.getClass().getPackage().getName(), subSection.getTextContent().trim());
}

From source file:com.jkoolcloud.tnt4j.streams.transform.FuncGetFileName.java

/**
 * Resolves file name from provided file path. File path can be provided as {@link String}, {@link Node} or
 * {@link NodeList} (first node item containing file path).
 *
 * @param args/*from ww w.java  2 s. c o m*/
 *            arguments list containing file path as first item
 * @return file name resolved from provided path
 *
 * @see Node
 * @see NodeList
 */
@Override
@SuppressWarnings("rawtypes")
public Object evaluate(List args) {
    Object param = CollectionUtils.isEmpty(args) ? null : args.get(0);

    if (param == null) {
        return param;
    }

    String filePath = null;
    if (param instanceof String) {
        filePath = (String) param;
    } else if (param instanceof Node) {
        filePath = ((Node) param).getTextContent();
    } else if (param instanceof NodeList) {
        NodeList nodes = (NodeList) param;

        if (nodes.getLength() > 0) {
            Node node = nodes.item(0);
            filePath = node.getTextContent();
        }
    }

    if (StringUtils.isEmpty(filePath)) {
        return filePath;
    }

    return filePath.substring(filePath.lastIndexOf(UNIX_PATH_SEPARATOR) + 1)
            .substring(filePath.lastIndexOf(WIN_PATH_SEPARATOR) + 1);
}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.BCRXMLFileReader.java

public Set<String> getBCRIDs() {
    //BCRSAMPLEBARCODE is BCRID
    if (bcrIDs == null) {
        bcrIDs = new HashSet<String>();
        final NodeList nl = document.getElementsByTagName("BCRSAMPLEBARCODE");
        for (int i = 0; i < nl.getLength(); i++) {
            final Node n = nl.item(i);
            bcrIDs.add(n.getTextContent());
        }//from  w w w .  j a  va  2 s .  c om
    }
    return bcrIDs;
}

From source file:fr.redteam.dressyourself.plugins.weather.yahooWeather.WOEIDUtils.java

private String getFirstMatchingWOEID(Document srcDoc) {
    Log.d(TAG, "parserWOEID");

    try {// ww w  .j a va2  s  .c  o m
        NodeList nodeListDescription = srcDoc.getElementsByTagName("woeid");
        if (nodeListDescription.getLength() > 0) {
            Node node = nodeListDescription.item(0);
            return node.getTextContent();
        } else {
            return WOEID_NOT_FOUND;
        }
    } catch (Exception e) {
        return WOEID_NOT_FOUND;
    }

}

From source file:com.digitalpebble.storm.crawler.parse.filter.ContentFilter.java

@Override
public void filter(String URL, byte[] content, DocumentFragment doc, ParseResult parse) {

    ParseData pd = parse.get(URL);

    // TODO determine how to restrict the expressions e.g. regexp on URL
    // or value in metadata

    // iterates on the expressions - stops at the first that matches
    for (XPathExpression expression : expressions) {
        try {/*from ww  w . j a v a2 s.c  om*/
            NodeList evalResults = (NodeList) expression.evaluate(doc, XPathConstants.NODESET);
            if (evalResults.getLength() == 0) {
                continue;
            }
            StringBuilder newText = new StringBuilder();
            for (int i = 0; i < evalResults.getLength(); i++) {
                Node node = evalResults.item(i);
                newText.append(node.getTextContent()).append("\n");
            }

            // ignore if no text captured
            if (StringUtils.isBlank(newText.toString())) {
                LOG.debug("Found match for doc {} but empty text extracted - skipping", URL);
                continue;
            }

            // give the doc its new text value
            LOG.debug("Restricted text for doc {}. Text size was {} and is now {}", URL, pd.getText().length(),
                    newText.length());

            pd.setText(newText.toString());

            return;
        } catch (XPathExpressionException e) {
            LOG.error("Caught XPath expression", e);
        }
    }

}

From source file:eu.europa.esig.dss.DSSXMLUtils.java

/**
 * If this method finds an attribute with names ID (case-insensitive) then it is returned. If there is more than one ID attributes then the first one is returned.
 *
 * @param element to be checked/*from   w w w  .j  av a  2 s  .  c  o m*/
 * @return the ID attribute value or null
 */
public static String getIDIdentifier(final Element element) {

    final NamedNodeMap attributes = element.getAttributes();
    for (int jj = 0; jj < attributes.getLength(); jj++) {

        final Node item = attributes.item(jj);
        final String localName = item.getNodeName();
        if (localName != null) {
            final String id = localName.toLowerCase();
            if (ID_ATTRIBUTE_NAME.equals(id)) {

                return item.getTextContent();
            }
        }
    }
    return null;
}

From source file:com.intel.podm.redfish.resources.MetadataResourceProvider.java

private void updateUris(Document xmlDocument) {
    NodeList list = xmlDocument.getElementsByTagName("edmx:Reference");
    for (int i = 0; i < list.getLength(); i++) {
        Node item = list.item(i);
        Node uri = item.getAttributes().getNamedItem("Uri");
        uri.setTextContent("/redfish/v1/metadata/" + uri.getTextContent());
    }/*w  w w  . j a v a2  s.co m*/
}

From source file:com.michael.feng.utils.YahooWeather4a.WOEIDUtils.java

private String getFirstMatchingWOEID(Document srcDoc) {
    Log.d("tag", "parserWOEID");

    try {//from  w w  w  . j a v  a 2  s.  co m
        NodeList nodeListDescription = srcDoc.getElementsByTagName("woeid");
        if (nodeListDescription.getLength() > 0) {
            Node node = nodeListDescription.item(0);
            return node.getTextContent();
        } else {
            return WOEID_NOT_FOUND;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return WOEID_NOT_FOUND;
    }

}

From source file:com.swetha.easypark.GetDirections.java

public String getDurationText(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("duration");
    Node node1 = nl1.item(nl1.getLength() - 1);
    NodeList nl2 = node1.getChildNodes();
    Node node2 = nl2.item(getNodeIndex(nl2, "text"));
    Log.i("DurationText", node2.getTextContent());
    return node2.getTextContent();
}