Example usage for org.dom4j DocumentHelper createXPath

List of usage examples for org.dom4j DocumentHelper createXPath

Introduction

In this page you can find the example usage for org.dom4j DocumentHelper createXPath.

Prototype

public static XPath createXPath(String xpathExpression) throws InvalidXPathException 

Source Link

Document

createXPath parses an XPath expression and creates a new XPath XPath instance using the singleton DocumentFactory .

Usage

From source file:com.vmware.o11n.plugin.powershell.remote.impl.winrm.FaultExtractor.java

License:Open Source License

public XPath getXPath() {
    final XPath xPath = DocumentHelper.createXPath("//" + ns.getPrefix() + ":" + expr);
    xPath.setNamespaceContext(namespaceContext);
    return xPath;
}

From source file:cz.mzk.editor.server.fedora.utils.Dom4jUtils.java

License:Open Source License

/**
 * Creates Xpath with prefixes from class Namespaces
 * // ww w.java2s.  c o  m
 * @param expression
 * @return
 */
public static XPath createXPath(String expression) {
    XPath result = DocumentHelper.createXPath(expression);
    result.setNamespaceURIs(Namespaces.getPrefixUriMap());
    return result;
}

From source file:cz.mzk.editor.server.handler.FindMetadataHandler.java

License:Open Source License

public String findSysno(String barcode) {

    String alephUrl = EditorConfiguration.ServerConstants.Z3950_DEFAULT_HOSTS[z39Client.getProfileIndex()];

    if (alephUrl == null || "".equals(alephUrl))
        return null;

    if (!alephUrl.startsWith("http")) {
        alephUrl = "http://" + alephUrl;
    }/*from w  w w  .  j  ava2  s .c  om*/

    String urlToSetNum = alephUrl + "/X?op=find&code=BAR&request=%s&base=";
    String urlToSysno = alephUrl + "/X?op=present&set_entry=1&set_number=";

    String completeUrlToSetNum = String.format(urlToSetNum, barcode);
    String[] oaiBases = configuration.getOaiBases();
    String sysno = null;

    for (String base : oaiBases) {
        try {
            InputStream inputStream = RESTHelper.get(completeUrlToSetNum + base, null, null, false);
            Document records = Dom4jUtils.loadDocument(inputStream, true);

            XPath xpath = DocumentHelper.createXPath("/find/set_number");
            Node resultNode = xpath.selectSingleNode(records);

            if (resultNode != null) {
                String setNumber = resultNode.getText();
                InputStream sysnoStream = RESTHelper.get(urlToSysno + setNumber, null, null, false);
                Document sysnoDoc = Dom4jUtils.loadDocument(sysnoStream, true);
                xpath = DocumentHelper.createXPath("/present/record/doc_number");
                Node sysnoNode = xpath.selectSingleNode(sysnoDoc);
                if (sysnoNode != null)
                    sysno = sysnoNode.getText();
                break;
            }

        } catch (IOException e) {
            LOGGER.error(e.getMessage());
            e.printStackTrace();
        } catch (DocumentException e) {
            LOGGER.error(e.getMessage());
            e.printStackTrace();
        }

    }

    return sysno;
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.io.reader.MASCReader.java

License:Apache License

private XPath createXPath(String xpathExpr) {
    HashMap<String, String> namespaceURIMap = new HashMap<String, String>();
    namespaceURIMap.put("masc", "http://www.xces.org/ns/GrAF/1.0/");

    XPath path = DocumentHelper.createXPath(xpathExpr);
    path.setNamespaceContext(new SimpleNamespaceContext(namespaceURIMap));

    return path;//w  w w  . ja v a 2 s . c  o m
}

From source file:eu.scape_project.planning.services.taverna.parser.T2FlowParser.java

License:Apache License

/**
 * Reads the ID annotation of the t2flow.
 * //  www.  j a  va  2s .c  om
 * @return the id the workflow adheres to
 * @throws TavernaParserException
 */
public String getId() throws TavernaParserException {

    log.debug("Extracting profile ID");

    XPath xpath = DocumentHelper.createXPath("/t2f:workflow/t2f:dataflow[@role='top']/@id");

    xpath.setNamespaceURIs(T2FLOW_NAMESPACE_MAP);
    Node node = xpath.selectSingleNode(doc);
    if (node == null) {
        return null;
    }
    return node.getText();
}

From source file:eu.scape_project.planning.services.taverna.parser.T2FlowParser.java

License:Apache License

/**
 * Reads the name annotation of the t2flow.
 * //from  w  w  w . j  a v a  2  s .c  o  m
 * @return the name of the workflow
 * @throws TavernaParserException
 */
public String getName() throws TavernaParserException {

    log.debug("Extracting workflow name");

    XPath xpath = DocumentHelper.createXPath(
            "/t2f:workflow/t2f:dataflow[@role='top']/t2f:annotations/*/*/*/*/annotationBean[@class='net.sf.taverna.t2.annotation.annotationbeans.DescriptiveTitle']/text");

    xpath.setNamespaceURIs(T2FLOW_NAMESPACE_MAP);
    Node node = xpath.selectSingleNode(doc);
    if (node == null) {
        return null;
    }
    return node.getText();
}

From source file:eu.scape_project.planning.services.taverna.parser.T2FlowParser.java

License:Apache License

/**
 * Reads the description annotation of the t2flow.
 * //from   w ww  . jav  a2  s  .  co m
 * @return the description of the workflow
 * @throws TavernaParserException
 */
public String getDescription() throws TavernaParserException {

    log.debug("Extracting workflow description");

    XPath xpath = DocumentHelper.createXPath(
            "/t2f:workflow/t2f:dataflow[@role='top']/t2f:annotations/*/*/*/*/annotationBean[@class='net.sf.taverna.t2.annotation.annotationbeans.FreeTextDescription']/text");

    xpath.setNamespaceURIs(T2FLOW_NAMESPACE_MAP);
    Node node = xpath.selectSingleNode(doc);
    if (node == null) {
        return null;
    }
    return node.getText();
}

From source file:eu.scape_project.planning.services.taverna.parser.T2FlowParser.java

License:Apache License

/**
 * Reads the author annotation of the t2flow.
 * /*from w ww  .ja va2  s. com*/
 * @return the author of the workflow
 * @throws TavernaParserException
 */
public String getAuthor() throws TavernaParserException {

    log.debug("Extracting workflow author");

    XPath xpath = DocumentHelper.createXPath(
            "/t2f:workflow/t2f:dataflow[@role='top']/t2f:annotations/*/*/*/*/annotationBean[@class='net.sf.taverna.t2.annotation.annotationbeans.Author']/text");

    xpath.setNamespaceURIs(T2FLOW_NAMESPACE_MAP);
    Node node = xpath.selectSingleNode(doc);
    if (node == null) {
        return null;
    }
    return node.getText();
}

From source file:fedora.server.messaging.FedoraTypes.java

License:fedora commons license

public String getDatatype(String method, String param) {
    String key = method + "." + param;

    if (!method2datatype.containsKey(key)) {
        String query = String.format("/xsd:schema/xsd:element[@name='%s']" + "/xsd:complexType/xsd:sequence"
                + "/xsd:element[@name='%s']/@type", method, param);
        XPath xpath = DocumentHelper.createXPath(query);
        xpath.setNamespaceURIs(ns2prefix);
        String datatype = xpath.valueOf(getDocument());
        if (datatype.equals("")) {
            datatype = null;/*www  . j  av a2s.  co m*/
        }
        method2datatype.put(key, datatype);
    }
    return method2datatype.get(key);
}

From source file:fedora.server.messaging.FedoraTypes.java

License:fedora commons license

public String getResponseParameter(String response) {
    if (!response2parameter.containsKey(response)) {
        String query = String.format(
                "/xsd:schema/xsd:element[@name='%s']" + "/xsd:complexType/xsd:sequence" + "/xsd:element/@name",
                response);//  w  w w  .j av  a 2s . com
        XPath xpath = DocumentHelper.createXPath(query);
        xpath.setNamespaceURIs(ns2prefix);
        String param = xpath.valueOf(getDocument());
        if (param.equals("")) {
            param = null;
        }
        response2parameter.put(response, param);
    }
    return response2parameter.get(response);
}