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.amalto.core.initdb.InitDBUtil.java

private static void parseInitMap(InputStream in, DocumentBuilder builder, Map<String, List<String>> initMap)
        throws Exception {
    Document doc = builder.parse(in);
    NodeList nodelist = doc.getElementsByTagName("item"); //$NON-NLS-1$
    for (int i = 0; i < nodelist.getLength(); i++) {
        Node node = nodelist.item(i);
        NodeList list = node.getChildNodes();
        String name = null;// ww  w  .j  av  a  2s  .c  om
        for (int j = 0; j < list.getLength(); j++) {
            Node n = list.item(j);
            if (n instanceof Element) {
                if ("name".equals(n.getNodeName())) { //$NON-NLS-1$
                    name = n.getTextContent();
                    if (initMap.get(name) == null) {
                        initMap.put(name, new ArrayList<String>());
                    }
                }
                if ("list".equals(n.getNodeName())) { //$NON-NLS-1$
                    if (n.getTextContent() == null || n.getTextContent().trim().length() == 0) {
                        continue;
                    }
                    List<String> lists = initMap.get(name);
                    String[] arr = n.getTextContent().split(";"); //$NON-NLS-1$
                    lists.addAll(Arrays.asList(arr));
                }
            }
        }
    }
}

From source file:controllers.modules.cas.SecureCAS.java

public static void handleLogout(String body) throws Throwable {
    int i = StringUtils.indexOf(body, LOGOUT_REQ_PARAMETER);
    String postBody = URLDecoder.decode(body, "UTF-8");
    if (i == 0) {
        String logoutRequestMessage = StringUtils.substring(postBody, LOGOUT_REQ_PARAMETER.length() + 1);
        if (StringUtils.isNotEmpty(logoutRequestMessage)) {

            Document document = XML.getDocument(logoutRequestMessage);
            if (document != null) {
                NodeList nodeList = document.getElementsByTagName("samlp:SessionIndex");
                if (nodeList != null && nodeList.getLength() > 0) {
                    Node node = nodeList.item(0);
                    String ticket = node.getTextContent();
                    String stKey = ST + "_" + ticket;
                    String username = Cache.get(stKey, String.class);
                    if (username != null) {
                        Cache.delete(stKey);
                        Cache.set(LOGOUT_TAG + "_" + username, 1, TEN_YEARS_EXPIRATION);
                        Logger.debug("Mark that %s has been logout ", username);
                        return;
                    }//ww w . j a  va  2 s .c  o m
                }
            }
        }
    }
    Logger.warn("illegal logout message: %s", postBody);
}

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

public static String getMessageURL(Node mailNode) {
    String url = null;/*from   ww  w.  jav  a  2s.  c  o m*/
    Node urlNode = XmlUtils.getChild(mailNode, OWAConstants.OWA_FILTER_EMAIL_PATH);
    if (urlNode != null) {
        url = urlNode.getTextContent();
        // Exchange uses several characters in URL's which
        // httpclient (or standards) don't like so
        // we'll replace them with hex reference
        url = url.replaceAll("\\[", "%5B");
        url = url.replaceAll("\\]", "%5D");
        url = url.replaceAll("\\|", "%7C");
        url = url.replaceAll("\\^", "%5E");
        url = url.replaceAll("\\`", "%60");
        url = url.replaceAll("\\{", "%7B");
        url = url.replaceAll("\\}", "%7D");
    }
    return url;
}

From source file:com.twentyn.patentExtractor.PatentDocumentFeatures.java

private static List<String> appendTextContent(List<String> textList, Node n) {
    if (n.getNodeType() == Node.TEXT_NODE) {
        textList.add(n.getTextContent());
    } else {//from  w ww  .  j  a  va 2  s. c o  m
        NodeList childNodes = n.getChildNodes();
        for (int j = 0; j < childNodes.getLength(); j++) {
            Node childNode = childNodes.item(j);
            textList = appendTextContent(textList, childNode);
        }
    }
    return textList;
}

From source file:net.roboconf.agent.internal.misc.UserDataUtils.java

private static String getValueOfTagInXMLFile(String filePath, String tagName)
        throws ParserConfigurationException, SAXException, IOException {

    File fXmlFile = new File(filePath);
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);

    // Optional, but recommended
    // Read this: http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
    doc.getDocumentElement().normalize();

    NodeList nList = doc.getElementsByTagName(tagName);
    String valueOfTagName = "";

    for (int temp = 0; temp < nList.getLength(); temp++) {
        Node nNode = nList.item(temp);
        valueOfTagName = nNode.getTextContent();
    }//from w  w w  .java 2 s  .c om

    return valueOfTagName;
}

From source file:edu.mayo.cts2.framework.plugin.service.bioportal.transform.TransformUtils.java

/**
 * Gets the node text./*ww w.ja  v  a  2  s  .c  o  m*/
 *
 * @param node the node
 * @return the node text
 */
public static String getNodeText(Node node) {
    return StringUtils.trim(node.getTextContent()).replaceAll("[\\n\\t]", "");
}

From source file:Main.java

public static <T> T loadBean(Node node, Class<T> beanClass)
        throws IntrospectionException, InstantiationException, IllegalAccessException, IllegalArgumentException,
        DOMException, InvocationTargetException {
    T store = beanClass.newInstance();//from  ww  w.j  av a 2 s. c  o  m

    Map<String, PropertyDescriptor> properties = new HashMap<String, PropertyDescriptor>();
    BeanInfo beanInfo = Introspector.getBeanInfo(beanClass);
    for (PropertyDescriptor property : beanInfo.getPropertyDescriptors()) {
        properties.put(property.getName(), property);
    }

    NamedNodeMap attributes = node.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        PropertyDescriptor property = properties.get(attribute.getNodeName());
        if (property != null && property.getPropertyType().equals(String.class)
                && property.getWriteMethod() != null) {
            property.getWriteMethod().invoke(store, attribute.getNodeValue());
        }
    }

    NodeList childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        PropertyDescriptor property = properties.get(child.getNodeName());
        if (property != null && property.getPropertyType().equals(String.class)
                && property.getWriteMethod() != null) {
            property.getWriteMethod().invoke(store, child.getTextContent());
        }
    }

    return store;
}

From source file:com.adaptris.core.services.jdbc.StatementParameterImpl.java

private static String resolveXPath(AdaptrisMessage msg, String queryString) {
    // Might be null, if we're part of a RawJdbcDataCaptureService, but that
    // should be fine for XPath.newXPathInstance()
    DocumentBuilderFactoryBuilder builder = (DocumentBuilderFactoryBuilder) msg.getObjectHeaders()
            .get(JdbcDataQueryService.KEY_DOCBUILDER_FAC);
    NamespaceContext ctx = (NamespaceContext) msg.getObjectHeaders()
            .get(JdbcDataQueryService.KEY_NAMESPACE_CTX);
    try {//from   w  w w. ja  v a 2  s . c  o m
        Node node = XPath.newXPathInstance(builder, ctx)
                .selectSingleNode(XmlHelper.createDocument(msg, builder), queryString);
        return node != null ? node.getTextContent() : null;
    } catch (Exception e) {
        throw new IllegalArgumentException(queryString + " didn't work as an xpath");
    }
}

From source file:gov.nih.nci.cabig.caaers.utils.pdf.MedwatchUtils.java

public static String evalXPathOnXML(String xml, String xpathExpression) {
    try {// w ww .  j a va  2 s .  co m

        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new ByteArrayInputStream(xml.getBytes()));
        NodeList l = XPathAPI.selectNodeList(doc, xpathExpression);
        StringBuffer sb = new StringBuffer();
        if (l != null) {
            for (int i = 0; i < l.getLength(); i++) {
                Node n = l.item(i);
                sb.append(n.getTextContent());
            }
        }
        return sb.toString();
    } catch (Exception e) {
        log.debug(e);
    }
    return "";
}

From source file:org.ensembl.gti.seqstore.database.cramstore.EnaCramSubmitter.java

protected static String getElemAttrib(Document doc, String tag, String attr) {
    try {/*from  ww  w  .j av a2 s.c o  m*/
        XPathExpression acc = xpath.compile("//" + tag + "[@" + attr + "]");
        Node nl = (Node) acc.evaluate(doc, XPathConstants.NODE);
        if (nl == null) {
            return null;
        }
        Node attrN = nl.getAttributes().getNamedItem(attr);
        if (attrN == null) {
            return null;
        } else {
            return attrN.getTextContent();
        }
    } catch (XPathExpressionException e) {
        throw new EnaSubmissionException("Could not parse submission receipt", e);
    }
}