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:edu.lternet.pasta.portal.HarvesterServlet.java

private ArrayList<String> parseDocumentURLsFromHarvestList(String harvestListURL) throws Exception {
    ArrayList<String> urlList = new ArrayList<String>();

    if (harvestListURL != null) {
        DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        CachedXPathAPI xpathapi = new CachedXPathAPI();
        Document document = documentBuilder.parse(harvestListURL);

        if (document != null) {
            NodeList documentURLNodeList = xpathapi.selectNodeList(document, "//documentURL");
            for (int i = 0; i < documentURLNodeList.getLength(); i++) {
                Node aNode = documentURLNodeList.item(i);
                String url = aNode.getTextContent();
                urlList.add(url);//from w  w w.  j a  va2  s  . c  o m
            }
        }
    }

    return urlList;
}

From source file:com.nirima.jenkins.SimpleArtifactCopier.java

private List<String> getEntries(byte[] string)
        throws ParserConfigurationException, IOException, SAXException, TransformerException {

    List<String> items = new ArrayList<String>();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);//from  w  w w  .j ava 2s . c  om
    DocumentBuilder db = dbf.newDocumentBuilder();

    //parse using builder to get DOM representation of the XML file
    Document dom = db.parse(new ByteArrayInputStream(string));

    NodeList l = XPathAPI.selectNodeList(dom, "//a:response");

    for (int i = 0; i < l.getLength(); i++) {
        Node n = l.item(i);

        Node ref = XPathAPI.selectSingleNode(n, "a:href");
        Node type = XPathAPI.selectSingleNode(n, "a:propstat/a:prop/a:resourcetype").getFirstChild();
        //System.out.println(ref.getTextContent());
        //
        //            System.out.println(type);

        // Just add files
        if (type == null)
            items.add(ref.getTextContent());
    }

    return items;
}

From source file:io.wallfly.lockdapp.weatherutils.YahooWeather.java

private WeatherInfo parseWeatherInfo(Context context, Document doc, WOEIDInfo woeidInfo) {
    WeatherInfo weatherInfo = new WeatherInfo();
    try {//from www  .  ja v a2  s. c  o  m

        Node titleNode = doc.getElementsByTagName("title").item(0);

        if (titleNode.getTextContent().equals(YAHOO_WEATHER_ERROR)) {
            return null;
        }

        weatherInfo.setTitle(titleNode.getTextContent());
        weatherInfo.setDescription(doc.getElementsByTagName("description").item(0).getTextContent());
        weatherInfo.setLanguage(doc.getElementsByTagName("language").item(0).getTextContent());
        weatherInfo.setLastBuildDate(doc.getElementsByTagName("lastBuildDate").item(0).getTextContent());

        Node locationNode = doc.getElementsByTagName("yweather:location").item(0);
        weatherInfo.setLocationCity(locationNode.getAttributes().getNamedItem("city").getNodeValue());
        weatherInfo.setLocationRegion(locationNode.getAttributes().getNamedItem("region").getNodeValue());
        weatherInfo.setLocationCountry(locationNode.getAttributes().getNamedItem("country").getNodeValue());

        Node windNode = doc.getElementsByTagName("yweather:wind").item(0);
        weatherInfo.setWindChill(windNode.getAttributes().getNamedItem("chill").getNodeValue());
        weatherInfo.setWindDirection(windNode.getAttributes().getNamedItem("direction").getNodeValue());
        weatherInfo.setWindSpeed(windNode.getAttributes().getNamedItem("speed").getNodeValue());

        Node atmosphereNode = doc.getElementsByTagName("yweather:atmosphere").item(0);
        weatherInfo
                .setAtmosphereHumidity(atmosphereNode.getAttributes().getNamedItem("humidity").getNodeValue());
        weatherInfo.setAtmosphereVisibility(
                atmosphereNode.getAttributes().getNamedItem("visibility").getNodeValue());
        weatherInfo
                .setAtmospherePressure(atmosphereNode.getAttributes().getNamedItem("pressure").getNodeValue());
        weatherInfo.setAtmosphereRising(atmosphereNode.getAttributes().getNamedItem("rising").getNodeValue());

        Node astronomyNode = doc.getElementsByTagName("yweather:astronomy").item(0);
        weatherInfo.setAstronomySunrise(astronomyNode.getAttributes().getNamedItem("sunrise").getNodeValue());
        weatherInfo.setAstronomySunset(astronomyNode.getAttributes().getNamedItem("sunset").getNodeValue());

        weatherInfo.setConditionTitle(doc.getElementsByTagName("title").item(2).getTextContent());
        weatherInfo.setConditionLat(doc.getElementsByTagName("geo:lat").item(0).getTextContent());
        weatherInfo.setConditionLon(doc.getElementsByTagName("geo:long").item(0).getTextContent());

        Node currentConditionNode = doc.getElementsByTagName("yweather:condition").item(0);
        weatherInfo.setCurrentCode(
                Integer.parseInt(currentConditionNode.getAttributes().getNamedItem("code").getNodeValue()));
        weatherInfo.setCurrentText(currentConditionNode.getAttributes().getNamedItem("text").getNodeValue());
        weatherInfo.setCurrentTemp(
                Integer.parseInt(currentConditionNode.getAttributes().getNamedItem("temp").getNodeValue()));
        weatherInfo.setCurrentConditionDate(
                currentConditionNode.getAttributes().getNamedItem("date").getNodeValue());

        if (mNeedDownloadIcons) {
            /*
            weatherInfo.setCurrentConditionIcon(ImageUtils.getBitmapFromWeb(
                  weatherInfo.getCurrentConditionIconURL()));
                  */
        }

        for (int i = 0; i < FORECAST_INFO_MAX_SIZE; i++) {
            this.parseForecastInfo(weatherInfo.getForecastInfoList().get(i), doc, i);
        }

        /*
         * pass some woied info
         */
        weatherInfo.mWOEIDneighborhood = woeidInfo.mNeighborhood;
        weatherInfo.mWOEIDCounty = woeidInfo.mCounty;
        weatherInfo.mWOEIDState = woeidInfo.mState;
        weatherInfo.mWOEIDCountry = woeidInfo.mCountry;

    } catch (NullPointerException e) {
        YahooWeatherLog.printStack(e);
        if (mExceptionListener != null)
            mExceptionListener.onFailParsing(e);
        weatherInfo = null;
    }

    return weatherInfo;
}

From source file:com.apatar.buzzsaw.BuzzsawNode.java

private void putPropertyValueToTable(Node node, KeyInsensitiveMap datas) {
    String fieldNameSpace = node.getNamespaceURI();
    String fieldName = node.getLocalName();
    String fieldValue = node.getTextContent();

    // does node have children or not
    if (node.hasChildNodes()) {
        for (int i = 0; i < node.getChildNodes().getLength(); i++) {
            if (1 == node.getChildNodes().item(i).getNodeType()) {
                putPropertyValueToTable(node.getChildNodes().item(i), datas);
            }/*w  w  w . j a v  a  2s .  co  m*/
        }
    }

    // is this bazzsaw property or not
    if ("http://www.buzzsaw.com/projectpoint".equalsIgnoreCase(fieldNameSpace)) {
        fieldName = "Buzzsaw_" + fieldName;
    }

    List<Record> recs = getTiForConnection(OUT_CONN_POINT_NAME).getRecords();
    Record rec = Record.getRecordByFieldName(recs, fieldName);
    if (rec != null) {
        datas.put(fieldName, new JdbcObject(fieldValue, rec.getSqlType()));
    }
}

From source file:com.hyunnyapp.yahooweathergatter.YahooWeather.java

private WeatherInfo parseWeatherInfo(Context context, Document doc, WOEIDInfo woeidInfo) {
    WeatherInfo weatherInfo = new WeatherInfo();
    try {// w  ww .j a va 2 s .c o m

        Node titleNode = doc.getElementsByTagName("title").item(0);

        if (titleNode.getTextContent().equals(YAHOO_WEATHER_ERROR)) {
            return null;
        }

        weatherInfo.setTitle(titleNode.getTextContent());
        weatherInfo.setDescription(doc.getElementsByTagName("description").item(0).getTextContent());
        weatherInfo.setLanguage(doc.getElementsByTagName("language").item(0).getTextContent());
        weatherInfo.setLastBuildDate(doc.getElementsByTagName("lastBuildDate").item(0).getTextContent());

        Node locationNode = doc.getElementsByTagName("yweather:location").item(0);
        weatherInfo.setLocationCity(locationNode.getAttributes().getNamedItem("city").getNodeValue());
        weatherInfo.setLocationRegion(locationNode.getAttributes().getNamedItem("region").getNodeValue());
        weatherInfo.setLocationCountry(locationNode.getAttributes().getNamedItem("country").getNodeValue());

        Node windNode = doc.getElementsByTagName("yweather:wind").item(0);
        weatherInfo.setWindChill(windNode.getAttributes().getNamedItem("chill").getNodeValue());
        weatherInfo.setWindDirection(windNode.getAttributes().getNamedItem("direction").getNodeValue());
        weatherInfo.setWindSpeed(windNode.getAttributes().getNamedItem("speed").getNodeValue());

        Node atmosphereNode = doc.getElementsByTagName("yweather:atmosphere").item(0);
        weatherInfo
                .setAtmosphereHumidity(atmosphereNode.getAttributes().getNamedItem("humidity").getNodeValue());
        weatherInfo.setAtmosphereVisibility(
                atmosphereNode.getAttributes().getNamedItem("visibility").getNodeValue());
        weatherInfo
                .setAtmospherePressure(atmosphereNode.getAttributes().getNamedItem("pressure").getNodeValue());
        weatherInfo.setAtmosphereRising(atmosphereNode.getAttributes().getNamedItem("rising").getNodeValue());

        Node astronomyNode = doc.getElementsByTagName("yweather:astronomy").item(0);
        weatherInfo.setAstronomySunrise(astronomyNode.getAttributes().getNamedItem("sunrise").getNodeValue());
        weatherInfo.setAstronomySunset(astronomyNode.getAttributes().getNamedItem("sunset").getNodeValue());

        weatherInfo.setConditionTitle(doc.getElementsByTagName("title").item(2).getTextContent());
        weatherInfo.setConditionLat(doc.getElementsByTagName("geo:lat").item(0).getTextContent());
        weatherInfo.setConditionLon(doc.getElementsByTagName("geo:long").item(0).getTextContent());

        Node currentConditionNode = doc.getElementsByTagName("yweather:condition").item(0);
        weatherInfo.setCurrentCode(
                Integer.parseInt(currentConditionNode.getAttributes().getNamedItem("code").getNodeValue()));
        weatherInfo.setCurrentText(currentConditionNode.getAttributes().getNamedItem("text").getNodeValue());
        weatherInfo.setCurrentTemp(
                Integer.parseInt(currentConditionNode.getAttributes().getNamedItem("temp").getNodeValue()));
        weatherInfo.setCurrentConditionDate(
                currentConditionNode.getAttributes().getNamedItem("date").getNodeValue());

        if (mNeedDownloadIcons) {
            weatherInfo.setCurrentConditionIcon(
                    ImageUtils.getBitmapFromWeb(weatherInfo.getCurrentConditionIconURL()));
        }

        for (int i = 0; i < FORECAST_INFO_MAX_SIZE; i++) {
            this.parseForecastInfo(weatherInfo.getForecastInfoList().get(i), doc, i);
        }

        /*
         * pass some woied info
         */
        weatherInfo.mWOEIDneighborhood = woeidInfo.mNeighborhood;
        weatherInfo.mWOEIDCounty = woeidInfo.mCounty;
        weatherInfo.mWOEIDState = woeidInfo.mState;
        weatherInfo.mWOEIDCountry = woeidInfo.mCountry;

    } catch (NullPointerException e) {
        YahooWeatherLog.printStack(e);
        if (mExceptionListener != null)
            mExceptionListener.onFailParsing(e);
        weatherInfo = null;
    }

    return weatherInfo;
}

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

public void checkLessThanProperty(NodeList resultList, String queryProperty, String qVal, Document doc) {
    String queryPropertyNS = "*";
    String queryPropertyName = queryProperty;
    if (queryProperty.contains(":")) {
        queryPropertyNS = queryProperty.substring(0, queryProperty.indexOf(':'));
        queryPropertyName = queryProperty.substring(queryProperty.indexOf(':') + 1);
    }/*from ww  w . j  av a  2s  . c  o m*/
    for (int i = 0; i < resultList.getLength(); i++) {
        NodeList elements = resultList.item(i).getChildNodes();
        for (int j = 0; j < elements.getLength(); j++) {
            Node element = elements.item(j);
            if (element.getLocalName() != null && element.getLocalName().equals(queryPropertyName)
                    && (element.getNamespaceURI().equals(doc.lookupNamespaceURI(queryPropertyNS))
                            || queryPropertyNS.equals("*"))) {
                assertTrue(element.getTextContent().compareTo(qVal) < 0);
            }
        }
    }
}

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

public void checkGreaterThanProperty(NodeList resultList, String queryProperty, String qVal, Document doc) {
    String queryPropertyNS = "*";
    String queryPropertyName = queryProperty;
    if (queryProperty.contains(":")) {
        queryPropertyNS = queryProperty.substring(0, queryProperty.indexOf(':'));
        queryPropertyName = queryProperty.substring(queryProperty.indexOf(':') + 1);
    }//from w  w w  .  java  2 s. c  o  m
    for (int i = 0; i < resultList.getLength(); i++) {
        NodeList elements = resultList.item(i).getChildNodes();
        for (int j = 0; j < elements.getLength(); j++) {
            Node element = elements.item(j);
            if (element.getLocalName() != null && element.getLocalName().equals(queryPropertyName)
                    && (element.getNamespaceURI().equals(doc.lookupNamespaceURI(queryPropertyNS))
                            || queryPropertyNS.equals("*"))) {
                assertTrue(element.getTextContent().compareTo(qVal) >= 0);
            }
        }
    }
}

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

public void checkInequalityProperty(NodeList resultList, String queryProperty, String qVal, Document doc) {
    String queryPropertyNS = "*";
    String queryPropertyName = queryProperty;
    if (queryProperty.contains(":")) {
        queryPropertyNS = queryProperty.substring(0, queryProperty.indexOf(':'));
        queryPropertyName = queryProperty.substring(queryProperty.indexOf(':') + 1);
    }//from  ww w .  j a  v  a2  s.  c o  m
    for (int i = 0; i < resultList.getLength(); i++) {
        NodeList elements = resultList.item(i).getChildNodes();
        for (int j = 0; j < elements.getLength(); j++) {
            Node element = elements.item(j);
            if (element.getLocalName() != null && element.getLocalName().equals(queryPropertyName)
                    && (element.getNamespaceURI().equals(doc.lookupNamespaceURI(queryPropertyNS))
                            || queryPropertyNS.equals("*"))) {
                assertTrue(!element.getTextContent().equals(qVal));
            }
        }
    }
}

From source file:edu.lternet.pasta.portal.HarvestReport.java

private int[] getStatusCounts(File qualityReportFile) {
    int[] statusCounts = new int[5];
    int total = 0;
    int valid = 0;
    int info = 0;
    int warn = 0;
    int error = 0;

    try {/*  www  .j  a va 2 s .  co  m*/
        if (qualityReportFile != null && qualityReportFile.exists()) {
            FileInputStream fis = new FileInputStream(qualityReportFile);

            DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document document = documentBuilder.parse(fis);
            NodeList nodeList = document.getElementsByTagName("status");
            for (int i = 0; i < nodeList.getLength(); i++) {
                Node node = nodeList.item(i);
                String status = node.getTextContent();
                if (status != null && status.length() > 0) {
                    if (status.equals("valid")) {
                        valid++;
                        total++;
                    }
                    if (status.equals("info")) {
                        info++;
                        total++;
                    }
                    if (status.equals("warn")) {
                        warn++;
                        total++;
                    }
                    if (status.equals("error")) {
                        error++;
                        total++;
                    }
                }
            }
            statusCounts[0] = total;
            statusCounts[1] = valid;
            statusCounts[2] = info;
            statusCounts[3] = warn;
            statusCounts[4] = error;
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(e.getMessage());
    }

    return statusCounts;
}

From source file:com.marklogic.dom.NodeImpl.java

private void getTextContent(StringBuilder sb) throws DOMException {
    NodeList children = getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (hasTextContent(child)) {
            sb.append(child.getTextContent());
        }//  ww w . jav  a 2s  .co m
    }
}