Example usage for javax.xml.xpath XPathConstants NODE

List of usage examples for javax.xml.xpath XPathConstants NODE

Introduction

In this page you can find the example usage for javax.xml.xpath XPathConstants NODE.

Prototype

QName NODE

To view the source code for javax.xml.xpath XPathConstants NODE.

Click Source Link

Document

The XPath 1.0 NodeSet data type.

Usage

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

protected static String getElemAttrib(Document doc, String tag, String attr) {
    try {// ww  w . ja va  2 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);
    }
}

From source file:com.netscape.cms.tomcat.PKIListener.java

@Override
public void lifecycleEvent(LifecycleEvent event) {

    String type = event.getType();
    logger.info("PKIListener: " + event.getLifecycle().getClass().getName() + " [" + type + "]");

    if (type.equals(Lifecycle.BEFORE_INIT_EVENT)) {

        String wdPipeName = System.getenv("WD_PIPE_NAME");
        if (StringUtils.isNotEmpty(wdPipeName)) {
            startedByWD = true;/* w  w  w  .j a  v a 2 s.co  m*/
            logger.info("PKIListener: Initializing the watchdog");
            WatchdogClient.init();
        }

        logger.info("PKIListener: Initializing TomcatJSS");

        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();

            String catalinaBase = System.getProperty("catalina.base");
            File file = new File(catalinaBase + "/conf/server.xml");
            Document doc = builder.parse(file);

            XPathFactory xPathfactory = XPathFactory.newInstance();
            XPath xpath = xPathfactory.newXPath();

            Element connector = (Element) xpath.evaluate(
                    "/Server/Service[@name='Catalina']/Connector[@name='Secure']", doc, XPathConstants.NODE);

            TomcatJSS tomcatjss = TomcatJSS.getInstance();

            String certDb = connector.getAttribute("certdbDir");
            if (certDb != null)
                tomcatjss.setCertdbDir(certDb);

            String passwordClass = connector.getAttribute("passwordClass");
            if (passwordClass != null)
                tomcatjss.setPasswordClass(passwordClass);

            String passwordFile = connector.getAttribute("passwordFile");
            if (passwordFile != null)
                tomcatjss.setPasswordFile(passwordFile);

            String serverCertNickFile = connector.getAttribute("serverCertNickFile");
            if (serverCertNickFile != null)
                tomcatjss.setServerCertNickFile(serverCertNickFile);

            String enableOCSP = connector.getAttribute("enableOCSP");
            if (enableOCSP != null)
                tomcatjss.setEnableOCSP(Boolean.parseBoolean(enableOCSP));

            String ocspResponderURL = connector.getAttribute("ocspResponderURL");
            if (ocspResponderURL != null)
                tomcatjss.setOcspResponderURL(ocspResponderURL);

            String ocspResponderCertNickname = connector.getAttribute("ocspResponderCertNickname");
            if (ocspResponderCertNickname != null)
                tomcatjss.setOcspResponderCertNickname(ocspResponderCertNickname);

            String ocspCacheSize = connector.getAttribute("ocspCacheSize");
            if (ocspCacheSize != null)
                tomcatjss.setOcspCacheSize(Integer.parseInt(ocspCacheSize));

            String ocspMinCacheEntryDuration = connector.getAttribute("ocspMinCacheEntryDuration");
            if (ocspMinCacheEntryDuration != null)
                tomcatjss.setOcspMinCacheEntryDuration(Integer.parseInt(ocspMinCacheEntryDuration));

            String ocspMaxCacheEntryDuration = connector.getAttribute("ocspMaxCacheEntryDuration");
            if (ocspMaxCacheEntryDuration != null)
                tomcatjss.setOcspMaxCacheEntryDuration(Integer.parseInt(ocspMaxCacheEntryDuration));

            String ocspTimeout = connector.getAttribute("ocspTimeout");
            if (ocspTimeout != null)
                tomcatjss.setOcspTimeout(Integer.parseInt(ocspTimeout));

            String strictCiphers = connector.getAttribute("strictCiphers");
            if (strictCiphers != null)
                tomcatjss.setStrictCiphers(strictCiphers);

            String sslVersionRangeStream = connector.getAttribute("sslVersionRangeStream");
            if (sslVersionRangeStream != null)
                tomcatjss.setSslVersionRangeStream(sslVersionRangeStream);

            String sslVersionRangeDatagram = connector.getAttribute("sslVersionRangeDatagram");
            if (sslVersionRangeDatagram != null)
                tomcatjss.setSslVersionRangeDatagram(sslVersionRangeDatagram);

            String sslRangeCiphers = connector.getAttribute("sslRangeCiphers");
            if (sslRangeCiphers != null)
                tomcatjss.setSslRangeCiphers(sslRangeCiphers);

            String sslOptions = connector.getAttribute("sslOptions");
            if (sslOptions != null)
                tomcatjss.setSslOptions(sslOptions);

            String ssl2Ciphers = connector.getAttribute("ssl2Ciphers");
            if (ssl2Ciphers != null)
                tomcatjss.setSsl2Ciphers(ssl2Ciphers);

            String ssl3Ciphers = connector.getAttribute("ssl3Ciphers");
            if (ssl3Ciphers != null)
                tomcatjss.setSsl3Ciphers(ssl3Ciphers);

            String tlsCiphers = connector.getAttribute("tlsCiphers");
            if (tlsCiphers != null)
                tomcatjss.setTlsCiphers(tlsCiphers);

            tomcatjss.init();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    } else if (type.equals(Lifecycle.AFTER_START_EVENT)) {

        if (startedByWD) {
            logger.info("PKIListener: Sending endInit to the watchdog");
            WatchdogClient.sendEndInit(0);
        }

        verifySubsystems((Server) event.getLifecycle());
    }
}

From source file:Main.java

/**
 * Checks in under a given root element whether it can find a child node
 * which matches the XPath expression supplied. Returns {@link Node} if
 * exists.//w  w  w . j  a va  2  s  .  c  o m
 * 
 * Please note that the XPath parser used is NOT namespace aware. So if you
 * want to find a element <beans><sec:http> you need to use the following
 * XPath expression '/beans/http'.
 * 
 * @param xPathExpression the xPathExpression (required)
 * @param root the parent DOM element (required)
 * 
 * @return the Node if discovered (null if not found)
 */
public static Node findNode(String xPathExpression, Element root) {
    if (xPathExpression == null || root == null || xPathExpression.length() == 0) {
        throw new IllegalArgumentException("Xpath expression and root element required");
    }
    Node node = null;
    try {
        XPathExpression expr = compiledExpressionCache.get(xPathExpression);
        if (expr == null) {
            expr = xpath.compile(xPathExpression);
            compiledExpressionCache.put(xPathExpression, expr);
        }
        node = (Node) expr.evaluate(root, XPathConstants.NODE);
    } catch (XPathExpressionException e) {
        throw new IllegalArgumentException("Unable evaluate xpath expression", e);
    }
    return node;
}

From source file:net.bpelunit.test.util.TestUtil.java

public static Node getNode(Element literalData, NamespaceContextImpl context, String string)
        throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(context);/*from ww w .  j a  v  a2  s  .  c  o  m*/
    return (Node) xpath.evaluate(string, literalData, XPathConstants.NODE);
}

From source file:simple.crawler.ext.vanilla.VanillaForumUtil.java

public static int postDiscussion(HttpContext httpContext, String postURL, String title, String body)
        throws Exception {
    DefaultHttpClient httpclient = HttpClientFactory.getInstance();
    HttpResponse res = httpclient.execute(new HttpGet(postURL), httpContext);
    String html = HttpClientUtil.getContentBodyAsString(res);
    HtmlParser parser = new HtmlParser();
    Document doc = parser.parseNonWellForm(html);
    Node node = (Node) XPathUtil.read(doc, "//*[@id=\"Form_TransientKey\"]", XPathConstants.NODE);
    String postTransientKey = ((Element) node).getAttribute("value");

    HttpPost post = new HttpPost(postURL);
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    list.add(new BasicNameValuePair("Discussion/TransientKey", postTransientKey));
    list.add(new BasicNameValuePair("Discussion/Name", title));
    list.add(new BasicNameValuePair("Discussion/Body", body));
    list.add(new BasicNameValuePair("Discussion/Post_Discussion", "Post Discussion"));
    post.setEntity(new UrlEncodedFormEntity(list));
    res = httpclient.execute(post, httpContext);
    return res.getStatusLine().getStatusCode();
}

From source file:org.opencastproject.remotetest.util.JobUtils.java

/**
 * Parses the job instance represented by <code>xml</code> and extracts the job state.
 * //from w  w w  . j a v a 2s  . c  o m
 * @param xml
 *          the job instance
 * @return the job state
 * @throws Exception
 *           if parsing fails
 */
public static String getJobState(String xml) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(IOUtils.toInputStream(xml, "UTF-8"));
    return ((Element) XPathFactory.newInstance().newXPath().compile("/*").evaluate(doc, XPathConstants.NODE))
            .getAttribute("state");
}

From source file:it.jnrpe.plugin.tomcat.TomcatDataProvider.java

private void parseMemoryData() throws Exception {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    InputSource is = new InputSource(new StringReader(tomcatXML));

    Document doc = builder.parse(is);
    XPathFactory xPathfactory = XPathFactory.newInstance();
    XPath xpath = xPathfactory.newXPath();
    //Element root = (Element) xpath.compile("//status").evaluate(doc.getDocumentElement(), XPathConstants.NODE);
    Element memory = (Element) xpath.compile("//status/jvm/memory").evaluate(doc.getDocumentElement(),
            XPathConstants.NODE);

    long freeMem = Long.parseLong(memory.getAttribute("free"));
    long totalMem = Long.parseLong(memory.getAttribute("total"));
    long maxMem = Long.parseLong(memory.getAttribute("max"));

    jvmMemoryUsage = new MemoryData(freeMem, maxMem, totalMem);
}

From source file:es.juntadeandalucia.panelGestion.negocio.utiles.geosearch.GeosearchDataImportWriter.java

private Node getDocumentNode() throws XPathExpressionException {
    Node document = null;//from   w w w .jav  a 2  s .  c  o  m

    document = (Node) xpath.compile("/dataConfig/document").evaluate(dataImportXML, XPathConstants.NODE);
    if (document == null) {
        document = dataConfig.getOwnerDocument().createElement("document");
        dataConfig.appendChild(document);
    }

    return document;
}

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

public static DocumentType identifyDocType(Document dom) throws XPathExpressionException {
    XPath xpath = null;/*www.ja v a 2s .c  om*/
    xpath = getXPathFactory().newXPath();
    for (Map.Entry<String, DocumentType> entry : NODE_NAME_TO_DOC_TYPE.entrySet()) {
        Node top = (Node) xpath.evaluate("/" + entry.getKey(), dom, XPathConstants.NODE);
        if (top != null) {
            return entry.getValue();
        }
    }
    return DocumentType.UNKNOWN;
}