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.ephesoft.dcma.util.OCREngineUtil.java

private static void setWordNodeTextContent(XPathExpression xOcrWordExpr, XPathExpression ocrXWordExpr,
        NodeList wordList, int wordNodeIndex) throws XPathExpressionException {
    Node wordNode = wordList.item(wordNodeIndex);
    if (wordNode != null) {
        Node word = (Node) xOcrWordExpr.evaluate(wordNode, XPathConstants.NODE);
        if (word != null) {
            wordNode.setTextContent(word.getTextContent());
        } else {//from   w  w w  .j  a v a 2  s .c om
            word = (Node) ocrXWordExpr.evaluate(wordNode, XPathConstants.NODE);
            if (word != null) {
                wordNode.setTextContent(word.getTextContent());
            }
        }
    }
}

From source file:cz.incad.kramerius.rest.api.k5.client.utils.SOLRUtils.java

public static <T> List<T> narray(final Element doc, final String attributeName, Class<T> clz) {
    synchronized (doc.getOwnerDocument()) {
        List<T> ret = new ArrayList<T>();
        List<Element> elms = XMLUtils.getElements(doc, new XMLUtils.ElementsFilter() {
            @Override/*from   w  w  w  .  j  a v a2s. c o  m*/
            public boolean acceptElement(Element element) {
                return (element.getNodeName().equals("arr") && element.hasAttribute("name")
                        && element.getAttribute("name").equals(attributeName));
            }
        });

        if (elms.size() >= 1) {
            Element parentE = elms.get(0);
            NodeList chnds = parentE.getChildNodes();
            for (int i = 0, ll = chnds.getLength(); i < ll; i++) {
                Node n = chnds.item(i);
                if (n.getNodeType() == Node.ELEMENT_NODE) {
                    ret.add(value(n.getTextContent(), clz));
                }
            }
        }
        return ret;
    }
}

From source file:kevin.gvmsgarch.App.java

static String extractInboxJson(String authToken, Worker.ListLocation location, int page)
        throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
    String pageData = "";
    try {/*  w w w.  j  a v a  2 s  . c  o  m*/
        pageData = App.getInboxPage(authToken, location, page);
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new ByteArrayInputStream(pageData.getBytes()));
        XPathExpression xpr = XPathFactory.newInstance().newXPath().compile("/response/json");
        NodeList nl = (NodeList) xpr.evaluate(doc, XPathConstants.NODESET);
        Node n = nl.item(0);
        return n.getTextContent();
    } catch (Exception ex) {
        throw new RuntimeException("Page data for error:\n\n" + pageData + "\n\n", ex);
    }
}

From source file:Main.java

public static Node SearchNode(NodeList listNode, ArrayList<String> arrStrCompare) {
    ArrayList<String> arrTempList = arrStrCompare;
    Iterator<String> iterator = arrTempList.iterator();

    while (iterator.hasNext()) {
        String strCompare = (String) iterator.next();
        iterator.remove();//w  w w .j  av  a  2 s  . co m

        for (int i = 0; i < listNode.getLength(); i++) {
            Node node = listNode.item(i);

            if (strCompare.equals(node.getNodeName())) {
                if (iterator.hasNext()) {
                    return SearchNode(node.getChildNodes(), arrTempList);
                }
                String strResp = node.getTextContent();
                System.out.println("Found DATA [" + strCompare + "]: " + strResp);
                return node;
            }
        }
    }

    return null;
}

From source file:Main.java

public static String FindNode(NodeList listNode, ArrayList<String> arrStrCompare, String strData) {
    ArrayList<String> arrTempList = arrStrCompare;
    Iterator<String> iterator = arrTempList.iterator();

    while (iterator.hasNext()) {
        String strCompare = (String) iterator.next();
        iterator.remove();// w  w w  .  j a v a 2  s  . c o m

        for (int i = 0; i < listNode.getLength(); i++) {
            Node node = listNode.item(i);

            if (strCompare.equals(node.getNodeName())) {
                if (iterator.hasNext()) {
                    return FindNode(node.getChildNodes(), arrTempList, strData);
                }
                String strResp = node.getTextContent();
                System.out.println("Found NODE [" + strCompare + "]: " + strResp);
                return strResp;
            }
        }
    }

    return null;
}

From source file:com.buzzdavidson.spork.util.OWAUtils.java

private static String fetchText(Node mailNode, Pattern[] path, boolean decode) {
    String retval = null;/*from w  w w . jav a  2 s.  c o m*/
    Node node = XmlUtils.getChild(mailNode, path);
    if (node != null) {
        retval = node.getTextContent();
    }
    if (retval != null && decode) {
        try {
            logger.info("-->decoding: " + retval);
            retval = URLDecoder.decode(retval, "UTF-8"); // TODO: determine charset? Headers should be all UTF-8
        } catch (UnsupportedEncodingException ex) {
            logger.error("Unsupported Encoding Exception", ex);
        }
    }
    return retval;
}

From source file:com.jaeksoft.searchlib.util.XPathParser.java

private final static String getAttributeString(Node node, String attributeName, boolean unescapeXml) {
    NamedNodeMap attr = node.getAttributes();
    if (attr == null)
        return null;
    Node n = attr.getNamedItem(attributeName);
    if (n == null)
        return null;
    String t = n.getTextContent();
    if (t == null)
        return null;
    return unescapeXml ? StringEscapeUtils.unescapeXml(t) : t;
}

From source file:de.jaetzold.philips.hue.HueBridgeComm.java

static List<HueBridge> discover() {
    final Logger log = Logger.getLogger(HueBridge.class.getName());
    final SimpleServiceDiscovery serviceDiscovery = new SimpleServiceDiscovery();
    int attempted = 0;
    int maxAttempts = Math.min(4, Math.max(1, HueBridge.discoveryAttempts));
    Map<String, URL> foundBriges = new HashMap<>();
    // if nothing is found the first time try up to maxAttempts times with increasing timeouts
    while (foundBriges.isEmpty() && attempted < maxAttempts) {
        serviceDiscovery.setSearchMx(1 + attempted);
        serviceDiscovery.setSocketTimeout(500 + attempted * 1500);
        final List<? extends SimpleServiceDiscovery.Response> responses = serviceDiscovery
                .discover(SimpleServiceDiscovery.SEARCH_TARGET_ROOTDEVICE);
        try {// ww w . j  a v  a2  s . c  o  m
            for (SimpleServiceDiscovery.Response response : responses) {
                String urlBase = null;
                final String usn = response.getHeader("USN");
                if (usn != null && usn.matches("uuid:[-\\w]+")) {
                    if (!foundBriges.containsKey(usn)) {
                        final String server = response.getHeader("SERVER");
                        if (server != null && server.contains("IpBridge")) {
                            final String location = response.getHeader("LOCATION");
                            if (location != null && location.endsWith(".xml")) {
                                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                                DocumentBuilder db = dbf.newDocumentBuilder();
                                Document doc = db.parse(new URL(location).openStream());
                                final NodeList modelNames = doc.getElementsByTagName("modelName");
                                for (int i = 0; i < modelNames.getLength(); i++) {
                                    final Node item = modelNames.item(i);
                                    if (item.getParentNode().getNodeName().equals("device") && item
                                            .getTextContent().matches("(?i).*philips\\s+hue\\s+bridge.*")) {
                                        final NodeList urlBases = doc.getElementsByTagName("URLBase");
                                        if (urlBases.getLength() > 0) {
                                            urlBase = urlBases.item(0).getTextContent();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (urlBase != null) {
                    foundBriges.put(usn, new URL(urlBase));
                }
            }
        } catch (Exception e) {
            HueBridge.lastDiscoveryException = e;
            log.log(Level.INFO, "Exception when dicovering devices", e);
        }
        attempted++;
    }
    List<HueBridge> result = new ArrayList<>();
    for (Map.Entry<String, URL> entry : foundBriges.entrySet()) {
        final HueBridge bridge = new HueBridge(entry.getValue(), null);
        bridge.UDN = entry.getKey();
        result.add(bridge);
    }
    return result;
}

From source file:com.cisco.dvbu.ps.common.adapters.util.XmlUtils.java

public static String getNodeIterationValue(String tagName, String doc) throws Exception {

    String value = null;// ww w.j  a v  a  2s .c  o  m

    try {
        // Convert string to a DOM object
        Document docXML = stringToDocument(doc);
        NodeList node1 = docXML.getElementsByTagName(tagName);
        if (node1 != null && node1.item(0) != null) {
            for (int i = 0; i < node1.getLength(); i++) {
                NodeList node2 = node1.item(i).getChildNodes();
                if (node2 != null && node2.item(0) != null) {
                    for (int j = 0; j < node2.getLength(); j++) {
                        Node n = node2.item(j);
                        System.out.println("name=" + n.getNodeName() + "  value=" + n.getTextContent());
                    }
                }
            }
        }

    } catch (Exception e) {
        throw e;
    }
    return value;
}

From source file:com.google.wave.api.AbstractRobotServlet.java

/**
 * Parse version identifier from the capabilities.xml file, and set it to
 * {@code version} static variable.//from   w w  w  .jav  a2  s . c  o  m
 */
private static void parseVersionIdentifier() {
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse(new FileInputStream(WAVE_CAPABILITIES_XML_FILE_PATH));
        NodeList elements = document.getElementsByTagName(CAPABILITIES_XML_VERSION_TAG_NAME);
        if (elements.getLength() >= 1) {
            Node versionNode = elements.item(0);
            version = versionNode.getTextContent();
        }
    } catch (IOException e) {
        log.warning("Problem opening capabilities.xml file. Cause: " + e.getMessage());
    } catch (SAXException e) {
        log.warning("Problem parsing capabilities.xml file. Cause: " + e.getMessage());
    } catch (ParserConfigurationException e) {
        log.warning("Problem setting up XML parser. Cause: " + e.getMessage());
    }
}