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.espertech.esper.client.ConfigurationParser.java

private static String getOptionalAttribute(Node node, String key) {
    Node valueNode = node.getAttributes().getNamedItem(key);
    if (valueNode != null) {
        return valueNode.getTextContent();
    }/* www. j a  v  a  2s . c  om*/
    return null;
}

From source file:io.selendroid.server.model.internal.AbstractNativeElementContext.java

public List<AndroidElement> findElementsByXPath(String expression) {
    JSONObject root = null;/*from  w ww . j a v  a2s  .  c o  m*/
    try {
        root = getElementTree();
    } catch (JSONException e1) {
        SelendroidLogger.error("Could not getElementTree", e1);
    }

    Document xmlDocument = JsonXmlUtil.buildXmlDocument(root);
    XPath xPath = XPathFactory.newInstance().newXPath();

    List<AndroidElement> elements = new ArrayList<AndroidElement>();
    NodeList nodeList;
    try {
        // read a nodelist using xpath
        nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        SelendroidLogger.error("Failed to get NodeList for XPath", e);
        return elements;
    }
    if (nodeList != null && nodeList.getLength() > 0) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getAttributes() == null) {
                continue;
            }
            Node namedItem = node.getAttributes().getNamedItem("ref");
            if (namedItem != null) {
                elements.add(knownElements.get(namedItem.getTextContent()));
            }
        }
    }

    return elements;
}

From source file:at.ait.dme.yuma.suite.apps.map.server.geo.GeocoderServiceImpl.java

private List<SemanticTag> getCountries(List<String> countries) throws GeocoderException {
    try {//  w w  w.  j  a  va2s  .c  o m
        ArrayList<SemanticTag> tags = new ArrayList<SemanticTag>();
        for (String country : countries) {
            // Query Geonames 'search' service
            URL url = new URL(GEONAMES_SEARCH_QUERY + "q=" + URLEncoder.encode(country, "UTF-8"));

            // Parse response
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
            StringBuffer s = new StringBuffer();
            String line = null;
            while ((line = br.readLine()) != null) {
                s.append(line + "\n");
            }

            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.parse(new ByteArrayInputStream(s.toString().getBytes("UTF-8")));
            NodeList nodes = doc.getElementsByTagName("geoname");

            NodeList children;

            if (nodes.getLength() > 0) {
                String toponymName = null;
                String geonameId = null;
                children = nodes.item(0).getChildNodes();
                for (int j = 0; j < children.getLength(); j++) {
                    Node child = children.item(j);
                    if (child.getNodeName().equals("toponymName")) {
                        toponymName = child.getTextContent();
                    } else if (child.getNodeName().equals("geonameId")) {
                        geonameId = child.getTextContent();
                    }
                }

                if (toponymName != null && geonameId != null)
                    tags.add(new SemanticTag(country, getAlternativePlacenames(toponymName), "Place", "en",
                            toponymName + " (country)", GEONAMES_URI_TEMPLATE.replace("@id@", geonameId)));
            }
        }
        return tags;
    } catch (Exception e) {
        throw new GeocoderException(e);
    }
}

From source file:de.ingrid.interfaces.csw.domain.encoding.impl.XMLEncoding.java

@Override
public List<String> getAcceptVersions() {
    this.checkInitialized();

    if (this.acceptVersions == null) {
        this.acceptVersions = new ArrayList<String>();

        NodeList versionNodes = this.xpath.getNodeList(this.getRequestBody(), GETCAP_VERSION_PARAM_XPATH);
        int length = versionNodes.getLength();
        for (int i = 0; i < length; i++) {
            Node curVersionNode = versionNodes.item(i);
            if (curVersionNode != null) {
                this.acceptVersions.add(curVersionNode.getTextContent());
            }/*w w w .  ja v  a2s.com*/
        }
        this.acceptVersions = Collections.unmodifiableList(this.acceptVersions);
    }
    return this.acceptVersions;
}

From source file:de.ingrid.iplug.opensearch.converter.IngridRSSConverter.java

private void setPartnerAndProvider(IngridHitDetail hitDetail, Node item) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    Node node = (Node) xpath.evaluate("provider", item, XPathConstants.NODE);
    if (node != null) {
        hitDetail.put("provider", new String[] { node.getTextContent() });
    }/*from  w w w  . j  ava2s .c om*/
    node = (Node) xpath.evaluate("partner", item, XPathConstants.NODE);
    if (node != null) {
        hitDetail.put("partner", new String[] { node.getTextContent() });
    }
}

From source file:org.eclipse.lyo.testsuite.oslcv2.FetchResourceTests.java

/**
 * Assume that nodeList.getLength()==1//www  .ja  v  a2s . c  om
 */
protected void validateCompactPreview(NodeList nodeList) throws IOException, XPathExpressionException {
    Node node = (Node) OSLCUtils.getXPath().evaluate("./oslc_v2:Preview/oslc_v2:document/@rdf:resource",
            nodeList.item(0), XPathConstants.NODE);
    assertNotNull("Expected number of oslc:Preview/oslc:document/@rdf:resource", node);
    String previewUrl = node.getTextContent();
    HttpResponse response = OSLCUtils.getResponseFromUrl(previewUrl, previewUrl, creds, "*/*", headers);

    int statusCode = response.getStatusLine().getStatusCode();
    String contentType = response.getEntity().getContentType().getValue();
    EntityUtils.consume(response.getEntity());
    assertTrue("Fetching document preview from " + previewUrl + " did not respond with expected code, received "
            + statusCode, 200 <= statusCode && statusCode < 400);
    assertTrue("Expected HTML content type from preview document but received " + contentType,
            contentType.startsWith("text/html"));
}

From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.ServiceDescriptionTests.java

@Test
public void changeManagementServiceDescriptionHasValidSimpleQuery() throws XPathException {
    //If ServiceDescription is oslc_cm, make sure it has a valid simple query child element
    Node cmRequest = (Node) OSLCUtils.getXPath().evaluate("//oslc_cm:changeRequests", doc, XPathConstants.NODE);
    if (cmRequest != null) {
        NodeList sQ = (NodeList) OSLCUtils.getXPath().evaluate("//oslc_cm:changeRequests/oslc_cm:simpleQuery",
                doc, XPathConstants.NODESET);
        assertTrue(sQ.getLength() == 1);
        Node url = (Node) OSLCUtils.getXPath()
                .evaluate("//oslc_cm:changeRequests/oslc_cm:simpleQuery/oslc_cm:url", doc, XPathConstants.NODE);
        assertNotNull(url);/*from   www.  ja  v a  2s  . c o  m*/
        Node title = (Node) OSLCUtils.getXPath()
                .evaluate("//oslc_cm:changeRequests/oslc_cm:simpleQuery/dc:title", doc, XPathConstants.NODE);
        assertNotNull(title);
        assertFalse(title.getTextContent().isEmpty());
    }
}

From source file:edu.toronto.cs.cidb.ncbieutils.NCBIEUtilsAccessService.java

protected List<String> getMatches(final String query, final int rows, final int start) {
    // response example at http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=omim&term=down
    // response type: XML
    // get corrected query from /eSearchResult/IdList/Id (multiple elements)
    String url = composeURL(TERM_SEARCH_QUERY_SCRIPT, TERM_SEARCH_PARAM_NAME, query, rows, start);
    List<String> result = new ArrayList<String>();
    try {/*from   www . j  ava  2  s  .  c  o  m*/
        Document response = readXML(url);
        NodeList nodes = response.getElementsByTagName("IdList");
        if (nodes.getLength() > 0) {
            nodes = nodes.item(0).getChildNodes();
            for (int i = 0; i < nodes.getLength(); ++i) {
                Node n = nodes.item(i);
                if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals("Id")) {
                    result.add(n.getTextContent());
                }
            }
        }

    } catch (Exception ex) {
        this.logger.error("Error while trying to retrieve matches for " + query + " " + ex.getClass().getName()
                + " " + ex.getMessage(), ex);
    }
    return result;
}

From source file:org.eclipse.lyo.testsuite.server.oslcv1tests.ServiceDescriptionTests.java

@Test
public void changeManagementServiceDescriptionHasValidFactory() throws XPathException {
    //If ServiceDescription is oslc_cm, make sure it has a valid factory child element
    Node cmRequest = (Node) OSLCUtils.getXPath().evaluate("//oslc_cm:changeRequests", doc, XPathConstants.NODE);
    if (cmRequest != null) {
        Node fac = (Node) OSLCUtils.getXPath().evaluate("//oslc_cm:changeRequests/oslc_cm:factory", doc,
                XPathConstants.NODE);
        assertNotNull(fac);//w w w .j  a  va 2 s.c  om
        Node facUrl = (Node) OSLCUtils.getXPath()
                .evaluate("//oslc_cm:changeRequests/oslc_cm:factory/oslc_cm:url", doc, XPathConstants.NODE);
        assertNotNull(facUrl);
        Node facTitle = (Node) OSLCUtils.getXPath()
                .evaluate("//oslc_cm:changeRequests/oslc_cm:factory/dc:title", doc, XPathConstants.NODE);
        assertNotNull(facTitle);
        assertFalse(facTitle.getTextContent().isEmpty());
    }
}

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

public static CustomForm processForm(Node formNode) {
    // Each table in the form node is a "Group"
    Element formElement = (Element) formNode;
    // Populate the form object
    CustomForm form = new CustomForm();
    form.setName(formElement.getAttribute("name"));
    // Parse the tables which represent a group of fields
    NodeList tableNodes = formNode.getChildNodes();
    for (int tableI = 0; tableI < tableNodes.getLength(); tableI++) {
        // For each table, parse the rows
        Node tableNode = tableNodes.item(tableI);
        // There will be 1 group per table
        CustomFormGroup group = null;/*from   ww w  . j  a va2 s .  c  o m*/
        // Split the rows into groups and fields...
        NodeList rowNodes = tableNode.getChildNodes();
        for (int rowI = 0; rowI < rowNodes.getLength(); rowI++) {
            // For each row, parse the groups and fields
            Node rowNode = rowNodes.item(rowI);
            NodeList cellNodes = rowNode.getChildNodes();
            // Any number of fields should be found...
            CustomFormField field = null;
            for (int cellI = 0; cellI < cellNodes.getLength(); cellI++) {
                Node cellNode = cellNodes.item(cellI);
                Element cellElement = (Element) cellNode;
                String tag = cellElement.getTagName();
                // Check to see if there is a group row, represented by th
                if ("th".equals(tag)) {
                    group = new CustomFormGroup();
                    group.setName(cellNode.getTextContent());
                }
                // Construct a field object from each row's tds
                if ("td".equals(tag)) {
                    if (field == null) {
                        field = new CustomFormField();
                        field.setLabel(cellNode.getTextContent());
                    } else {
                        // TODO: parse the td
                        /*
                        field.setName();
                        field.setType();
                        field.setRequired();
                        field.setParameters();
                        field.setAdditionalText();
                        */
                    }
                }
            }
            if (field != null) {
                if (group == null) {
                    group = new CustomFormGroup();
                }
                group.add(field);
            }
        }
        if (group != null) {
            form.add(group);
        }
    }
    return form;
}