Example usage for org.dom4j Node getText

List of usage examples for org.dom4j Node getText

Introduction

In this page you can find the example usage for org.dom4j Node getText.

Prototype

String getText();

Source Link

Document

Returns the text of this node.

Usage

From source file:com.flaptor.hounder.util.HtmlParser.java

License:Apache License

private void extractTitle(Document htmlDoc, Output out) {
    Node titleNode = htmlDoc.selectSingleNode("//TITLE");
    if (null != titleNode) {
        out.setTitle(titleNode.getText());
    }/* w ww . j a v a 2s. co m*/
}

From source file:com.flaptor.hounder.util.HtmlParser.java

License:Apache License

/**
 * Simple method to concatenate all readable text in the document and get the outlinks.
 * /*  w w  w  .jav  a2 s  .  c  om*/
 * @param e
 *            the element in where to look for readable text and outlinks.
 * @param out
 *            the parse output so far. For any caller except the getText itself,
 *            should be empty. After return, it contains the readable text
 *            of the html and the outlinks.
 */
protected void extractText(final Element e, final Output out, final String fieldName) {
    //String nodeName = e.getName();
    if (!(e.getNodeType() == Node.COMMENT_NODE)) {
        int size = e.nodeCount();
        for (int i = 0; i < size; i++) {
            Node node = e.node(i);
            if (node instanceof Element) {
                extractText((Element) node, out, fieldName);
            } else if (node instanceof Text) {
                String t = node.getText();
                out.addFieldString(fieldName, t);
            }
        }
    }
}

From source file:com.flaptor.util.DomUtil.java

License:Apache License

/**
 * Gets the entire text of an element an all its children
 * /*from   w  w w .j a  v  a2s  . c  o  m*/
 * @param element
 * @return
 */
public static String getElementTextRecursively(final Element element) {
    String result = "";

    if (!(element.getNodeType() == Node.COMMENT_NODE)) {
        int size = element.nodeCount();
        for (int i = 0; i < size; i++) {
            Node node = element.node(i);
            if (node instanceof Element) {
                result += getElementTextRecursively((Element) node);
            } else if (node instanceof Text) {
                result += node.getText();
            }
        }
    }

    return result;
}

From source file:com.flaptor.util.parser.HtmlParser.java

License:Apache License

private void extractTitle(Document htmlDoc, ParseOutput out) {
    Node titleNode = htmlDoc.selectSingleNode("//TITLE|//Title|//title");
    if (null != titleNode) {
        out.setTitle(titleNode.getText());
    }/*from   w  w w. j  a va  2  s.  c o m*/
}

From source file:com.flaptor.util.parser.HtmlParser.java

License:Apache License

/**
 * Simple method to concatenate all readable text in the document and get the outlinks.
 * //from w  w w. ja  v  a  2  s  .co m
 * @param e
 *            the element in where to look for readable text and outlinks.
 * @param out
 *            the parse output so far. For any caller except the getText itself,
 *            should be empty. After return, it contains the readable text
 *            of the html and the outlinks.
 */
protected void extractAllText(final Element e, final ParseOutput out, final String fieldName) {
    //String nodeName = e.getName();
    if (!(e.getNodeType() == Node.COMMENT_NODE)) {
        int size = e.nodeCount();
        for (int i = 0; i < size; i++) {
            Node node = e.node(i);
            if (node instanceof Element) {
                extractAllText((Element) node, out, fieldName);
            } else if (node instanceof Text) {
                String t = node.getText();
                out.addFieldString(fieldName, t);
            }
        }
    }
}

From source file:com.funtl.framework.alipay.trade.util.AlipaySubmit.java

License:Apache License

/**
 * ?query_timestamp???//from w w w.java2 s  . c  om
 * ??XML???SSL?
 *
 * @return 
 * @throws IOException
 * @throws DocumentException
 * @throws MalformedURLException
 */
public static String query_timestamp() throws MalformedURLException, DocumentException, IOException {

    //query_timestamp?URL
    String strUrl = PayManager.HTTPS_MAPI_ALIPAY_COM_GATEWAY_DO + "?" + "service=query_timestamp&partner="
            + AlipayConfig.partner + "&_input_charset" + AlipayConfig.input_charset;
    StringBuffer result = new StringBuffer();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(new URL(strUrl).openStream());

    List<Node> nodeList = doc.selectNodes("//alipay/*");

    for (Node node : nodeList) {
        // ?????
        if (node.getName().equals("is_success") && node.getText().equals("T")) {
            // ??
            List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
            for (Node node1 : nodeList1) {
                result.append(node1.getText());
            }
        }
    }

    return result.toString();
}

From source file:com.github.cutstock.utils.ResourceUtil.java

License:Apache License

public String getNodeValueByName(String name) {
    System.out.println("xml node " + name);
    Node node = document.selectSingleNode(String.format(xpath, name));
    return node.getText();
}

From source file:com.globalsight.cxe.adapter.msoffice.WordRepairer.java

License:Apache License

private static void forTextInWr(Element element) {
    @SuppressWarnings("unchecked")
    List<Node> ts = element.selectNodes("//w:r/text()");

    for (Node t : ts) {
        if (t.getText().matches("[\n\r]*")) {
            continue;
        }/*from   www  . ja  v  a  2 s . c o m*/

        Element wr = t.getParent();

        if (wr == null) {
            continue;
        }

        List<?> els = wr.content();

        StringBuffer sb = new StringBuffer();
        Element wt = null;
        List<DefaultText> texts = new ArrayList<DefaultText>();

        for (Object el : els) {
            if (el instanceof DefaultText) {
                DefaultText text = (DefaultText) el;
                texts.add(text);
                sb.append(text.getStringValue());
            } else if (el instanceof Element) {
                Element elm = (Element) el;
                if ("t".equals(elm.getName())) {
                    wt = elm;
                    sb.append(elm.getStringValue());
                }
            }
        }

        if (wt == null) {
            wt = wr.addElement("w:t");
            wt.addAttribute("xml:space", "preserve");
        }

        wt.setText(sb.toString());

        for (DefaultText text : texts) {
            wr.remove(text);
        }
    }
}

From source file:com.globalsight.cxe.adapter.msoffice.WordRepairer.java

License:Apache License

private static void forTextInWp(Element element) {
    @SuppressWarnings("unchecked")
    List<Node> ts = element.selectNodes("//w:p/text()");

    for (Node t : ts) {
        String c = t.getText();
        if (c.matches("[\n\r]*")) {
            continue;
        }/*w w w  .j ava  2  s  .c  o  m*/

        Element wp = t.getParent();
        Element wr = DocumentHelper.createElement("w:r");
        wp.content().add(wp.indexOf(t), wr);
        Element wt = wr.addElement("w:t");
        wt.setText(t.getText());
        wp.remove(t);
    }
}

From source file:com.globalsight.cxe.adapter.serviceware.ServiceWareAPI.java

License:Apache License

/**
 * Tries to connect to serviceware, and returns the sessionID.
 * // w w w  .  ja  va 2s.c o m
 * @return String
 * @exception Exception
 */
public static String connect() throws Exception {
    StringBuffer url = new StringBuffer(s_apiUrl);
    url.append("?Action=CreateSession&UserName=");
    url.append(s_username);
    url.append("&Password=");
    url.append(s_password);
    url.append("&KArea=");
    url.append(URLEncoder.encode(s_KArea));
    s_logger.debug("URL=" + url.toString());
    String xml = readXml(url.toString());
    s_logger.debug("XML is: " + xml);
    // now parse the XML to get the sessionId
    XmlParser xmlp = XmlParser.hire();
    Document d = xmlp.parseXml(xml);
    Element root = d.getRootElement();
    List nodes = root.selectNodes("/CreateSessionResponse/return/SessionID");
    Node node = (Node) nodes.get(0);
    String sessionId = node.getText();
    XmlParser.fire(xmlp);
    return sessionId;
}