Search in sources :

Example 1 with ValueHolder

use of org.codelibs.core.misc.ValueHolder in project fess by codelibs.

the class FessXpathTransformer method getSingleNodeValue.

protected String getSingleNodeValue(final Document document, final String xpath, final boolean pruned) {
    StringBuilder buf = null;
    NodeList list = null;
    try {
        list = getXPathAPI().selectNodeList(document, xpath);
        for (int i = 0; i < list.getLength(); i++) {
            if (buf == null) {
                buf = new StringBuilder(1000);
            }
            Node node = list.item(i).cloneNode(true);
            if (useGoogleOffOn) {
                node = processGoogleOffOn(node, new ValueHolder<>(true));
            }
            if (pruned) {
                node = pruneNode(node);
            }
            parseTextContent(node, buf);
        }
    } catch (final Exception e) {
        logger.warn("Could not parse a value of {}", xpath);
    }
    if (buf == null) {
        return null;
    }
    return buf.toString().trim();
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ValueHolder(org.codelibs.core.misc.ValueHolder) CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) CrawlerSystemException(org.codelibs.fess.crawler.exception.CrawlerSystemException) TransformerException(javax.xml.transform.TransformerException) MalformedURLException(java.net.MalformedURLException) ChildUrlsException(org.codelibs.fess.crawler.exception.ChildUrlsException)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 TransformerException (javax.xml.transform.TransformerException)1 ValueHolder (org.codelibs.core.misc.ValueHolder)1 ChildUrlsException (org.codelibs.fess.crawler.exception.ChildUrlsException)1 CrawlerSystemException (org.codelibs.fess.crawler.exception.CrawlerSystemException)1 CrawlingAccessException (org.codelibs.fess.crawler.exception.CrawlingAccessException)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1