Example usage for javax.xml.xpath XPathExpressionException printStackTrace

List of usage examples for javax.xml.xpath XPathExpressionException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.xpath XPathExpressionException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Print stack trace to System.err .

Usage

From source file:eu.eexcess.zbw.recommender.PartnerConnector.java

protected String getValueWithXPath(String xpath, Document orgPartnerResult) {
    XPath xPath = XPathFactory.newInstance().newXPath();
    NodeList nodes;//from w w  w  .  j  a v a2s  . c o m
    try {
        nodes = (NodeList) xPath.evaluate(xpath, orgPartnerResult.getDocumentElement(), XPathConstants.NODESET);
        for (int i = 0; i < nodes.getLength();) {
            Element e = (Element) nodes.item(i);
            return e.getTextContent();
        }
    } catch (XPathExpressionException e1) {
        e1.printStackTrace();
    }
    return "";
}

From source file:com.persistent.cloudninja.service.impl.RunningInstancesJSONDataServiceImpl.java

@Override
public List<InstanceHealthRoleInstanceEntity> getRoleAndInstanceFromDeployment() {
    StringBuffer stringBuffer;// w  w  w .j a v a 2s  . c o  m
    List<InstanceHealthRoleInstanceEntity> roleInstanceList = new ArrayList<InstanceHealthRoleInstanceEntity>();
    try {
        stringBuffer = deploymentMonitor.getRoleInfoForDeployment();
        roleInstanceList = parseResponse(stringBuffer);
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return roleInstanceList;
}

From source file:eu.impact_project.wsclient.HtmlServiceProvider.java

private NodeList applyXPath(Document doc, String xpathExpression, String namespace) {

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

    if (!namespace.equals(NO_NAMESPACE))
        xpath.setNamespaceContext(new WSDLNamespaceContext());

    XPathExpression expr;//from   w  w  w .j av  a2s.  co m

    Object result = null;
    try {
        expr = xpath.compile(xpathExpression);
        result = expr.evaluate(doc, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }

    return (NodeList) result;

}

From source file:it.drwolf.ridire.utility.RIDIRECleaner.java

private void getTextWithAlchemy() {
    AlchemyAPI alchemyAPI = AlchemyAPI.GetInstanceFromString(this.alchemyKey);
    StringBuffer buffer = new StringBuffer();
    try {//ww w .  j  av a 2  s.c  om
        Document d = alchemyAPI.HTMLGetText(FileUtils.readFileToString(new File(this.fileName)),
                "http://dummy.it/");
        NodeList list = d.getElementsByTagName("text");
        for (int i = 0; i < list.getLength(); i++) {
            buffer.append(list.item(i).getTextContent() + " ");
        }
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println(buffer.toString());
    System.err.println(RIDIRECleaner.ALCHEMY);
}

From source file:cz.fi.muni.xkremser.editor.server.AuthenticationServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession(true);
    String url = (String) session.getAttribute(HttpCookies.TARGET_URL);
    String root = (URLS.LOCALHOST() ? "http://" : "https://") + req.getServerName() + (URLS.LOCALHOST()
            ? (req.getServerPort() == 80 || req.getServerPort() == 443 ? "" : (":" + req.getServerPort()))
            : "") + URLS.ROOT() + (URLS.LOCALHOST() ? "?gwt.codesvr=127.0.0.1:9997" : "");
    String authHeader = req.getHeader("Authorization");
    if (authHeader != null) {
        String decodedHeader = decode(req, authHeader);
        String pass = configuration.getHttpBasicPass();
        if (pass == null || "".equals(pass.trim()) || pass.length() < 4) {
            requrireAuthentication(resp);
        }/* www.j  a  va  2  s.  c o m*/
        if (decodedHeader.equals(ALLOWED_PREFIX + pass)) {
            session.setAttribute(HttpCookies.TARGET_URL, null);
            session.setAttribute(HttpCookies.SESSION_ID_KEY,
                    "https://www.google.com/profiles/109255519115168093543");
            session.setAttribute(HttpCookies.NAME_KEY, "admin");
            session.setAttribute(HttpCookies.ADMIN, HttpCookies.ADMIN_YES);
            ACCESS_LOGGER.info("LOG IN: [" + FORMATTER.format(new Date()) + "] User "
                    + decodedHeader.substring(0, decodedHeader.indexOf(":")) + " with openID BASIC_AUTH and IP "
                    + req.getRemoteAddr());
            URLS.redirect(resp, url == null ? root : url);
            return;
        } else {
            requrireAuthentication(resp);
            return;
        }
    }
    session.setAttribute(HttpCookies.TARGET_URL, null);
    String token = req.getParameter("token");

    String appID = configuration.getOpenIDApiKey();
    String openIdurl = configuration.getOpenIDApiURL();
    RPX rpx = new RPX(appID, openIdurl);
    Element e = null;
    try {
        e = rpx.authInfo(token);
    } catch (ConnectionException connEx) {
        requrireAuthentication(resp);
        return;
    }
    String idXPath = "//identifier";
    String nameXPath = "//displayName";
    XPathFactory xpfactory = XPathFactory.newInstance();
    XPath xpath = xpfactory.newXPath();
    String identifier = null;
    String name = null;
    try {
        XPathExpression expr1 = xpath.compile(idXPath);
        XPathExpression expr2 = xpath.compile(nameXPath);
        NodeList nodes1 = (NodeList) expr1.evaluate(e.getOwnerDocument(), XPathConstants.NODESET);
        NodeList nodes2 = (NodeList) expr2.evaluate(e.getOwnerDocument(), XPathConstants.NODESET);
        Element el = null;
        if (nodes1.getLength() != 0) {
            el = (Element) nodes1.item(0);
        }
        if (el != null) {
            identifier = el.getTextContent();
        }
        if (nodes2.getLength() != 0) {
            el = (Element) nodes2.item(0);
        }
        if (el != null) {
            name = el.getTextContent();
        }
    } catch (XPathExpressionException e1) {
        e1.printStackTrace();
    }
    if (identifier != null && !"".equals(identifier)) {
        ACCESS_LOGGER.info("LOG IN: [" + FORMATTER.format(new Date()) + "] User " + name + " with openID "
                + identifier + " and IP " + req.getRemoteAddr());
        int userStatus = UserDAO.UNKNOWN;
        try {
            userStatus = userDAO.isSupported(identifier);
        } catch (DatabaseException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        switch (userStatus) {
        case UserDAO.UNKNOWN:
            // TODO handle DB error (inform user)
            break;
        case UserDAO.USER:
            // HttpCookies.setCookie(req, resp, HttpCookies.SESSION_ID_KEY,
            // identifier);
            session.setAttribute(HttpCookies.SESSION_ID_KEY, identifier);
            session.setAttribute(HttpCookies.NAME_KEY, name);
            URLS.redirect(resp, url == null ? root : url);
            break;
        case UserDAO.ADMIN:
            // HttpCookies.setCookie(req, resp, HttpCookies.SESSION_ID_KEY,
            // identifier);
            // HttpCookies.setCookie(req, resp, HttpCookies.ADMIN,
            // HttpCookies.ADMIN_YES);
            session.setAttribute(HttpCookies.SESSION_ID_KEY, identifier);
            session.setAttribute(HttpCookies.NAME_KEY, name);
            session.setAttribute(HttpCookies.ADMIN, HttpCookies.ADMIN_YES);
            URLS.redirect(resp, url == null ? root : url);
            break;
        case UserDAO.NOT_PRESENT:
        default:
            session.setAttribute(HttpCookies.UNKNOWN_ID_KEY, identifier);
            session.setAttribute(HttpCookies.NAME_KEY, name);
            URLS.redirect(resp, root + URLS.INFO_PAGE);
            break;
        }
    } else {
        URLS.redirect(resp, root + (URLS.LOCALHOST() ? URLS.LOGIN_LOCAL_PAGE : URLS.LOGIN_PAGE));
    }

    // System.out.println("ID:" + identifier);

    // if user is supported redirect to homepage else show him a page that he
    // has to be added to system first by admin

}

From source file:org.opencastproject.loadtest.impl.IngestJob.java

/**
 * Parse and change the manifest.xml's id to match the mediapackage id we will be ingesting.
 * //from ww  w . ja v a2  s  . c o m
 * @param filepath
 *          The path to the manifest.xml file.
 */
private void changeManifestID(String filepath) {
    try {
        logger.info("Filepath for changing the manifest id is " + filepath);
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(filepath);

        // Get the mediapackage
        XPath xPath = XPathFactory.newInstance().newXPath();
        Node mediapackage = ((NodeList) xPath.evaluate("//*[local-name() = 'mediapackage']", doc,
                XPathConstants.NODESET)).item(0);

        // update mediapackage attribute
        NamedNodeMap attr = mediapackage.getAttributes();
        Node nodeAttr = attr.getNamedItem("id");
        nodeAttr.setTextContent(id);

        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(new File(filepath));
        transformer.transform(source, result);
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (TransformerException tfe) {
        tfe.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (SAXException sae) {
        sae.printStackTrace();
    } catch (XPathExpressionException xpe) {
        xpe.printStackTrace();
    }
}

From source file:XPathTest.java

public void evaluate() {
        try {/*  w  w w .  j a va2 s.  c o m*/
            String typeName = (String) typeCombo.getSelectedItem();
            QName returnType = (QName) XPathConstants.class.getField(typeName).get(null);
            Object evalResult = path.evaluate(expression.getText(), doc, returnType);
            if (typeName.equals("NODESET")) {
                NodeList list = (NodeList) evalResult;
                StringBuilder builder = new StringBuilder();
                builder.append("{");
                for (int i = 0; i < list.getLength(); i++) {
                    if (i > 0)
                        builder.append(", ");
                    builder.append("" + list.item(i));
                }
                builder.append("}");
                result.setText("" + builder);
            } else
                result.setText("" + evalResult);
        } catch (XPathExpressionException e) {
            result.setText("" + e);
        } catch (Exception e) // reflection exception
        {
            e.printStackTrace();
        }
    }

From source file:it.drwolf.ridire.session.async.JobDBDataUpdater.java

@Asynchronous
public QuartzTriggerHandle updater(@Expiration Date expirationDate, @IntervalCron String cronData,
        @FinalExpiration Date endDate) {
    QuartzTriggerHandle handle = new QuartzTriggerHandle("RIDIRE job data updater");
    try {//from   ww w  . j  a  va 2  s .  c  o  m
        this.create();
        this.update(null);
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HeritrixException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return handle;
}

From source file:org.epop.dataprovider.pubmed.PubMedSearch.java

private void articleToLiterature(String articleID, LiteratureBuilder builder) throws ClientProtocolException,
        IOException, ParserConfigurationException, URISyntaxException, XPathExpressionException, SAXException {

    String pubMedURL = "http://www.ncbi.nlm.nih.gov/pubmed/" + articleID;
    HTMLPage htmlPage = new HTMLPage(pubMedURL);

    HTMLPage page = new HTMLPage("http://www.ncbi.nlm.nih.gov/pubmed/" + articleID + "?report=xml&format=text");
    String xmlCode = StringEscapeUtils.unescapeHtml(page.getStringByXPath("html/body/pre/text()"));
    XMLPage xmlPage = new XMLPage(xmlCode);

    // title/*from w w w. j  a va  2  s . c o  m*/
    try {
        builder.setTitle(xmlPage.getStringByXPath("//ArticleTitle/text()"));
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // abstract text
    try {
        NodeList nodes = xmlPage.getNodeSetByXPath("//Abstract");
        int i = 0;
        Node node;
        StringBuilder stringBuilder = new StringBuilder("<html>");
        while ((node = nodes.item(i)) != null) {
            if (node.getAttributes().getNamedItem("Label") != null) {
                stringBuilder.append("<b>");
                stringBuilder.append(node.getAttributes().getNamedItem("Label").getTextContent());
                stringBuilder.append("</b><br/>");
            }
            stringBuilder.append(node.getTextContent().trim().replaceAll("\t", "").replaceAll("\\s{2,}", " "));
            stringBuilder.append("<br/>");
            i++;
        }
        builder.setAbstractText(stringBuilder.toString() + "</html>");
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // authors
    try {
        Set<Author> authors = new HashSet<>();
        int i = 0;
        while (true) {
            i++;
            String lastName = xmlPage.getStringByXPath("//AuthorList/Author[" + i + "]/ForeName");
            String firstName = xmlPage.getStringByXPath("//AuthorList/Author[" + i + "]/LastName");
            if (lastName.isEmpty() && firstName.isEmpty())
                break;
            authors.add(new AuthorBuilder().setFirstName(firstName).setLastName(lastName).getObject());
        }
        builder.setAuthors(authors);
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // DOI
    try {
        String doi = xmlPage.getStringByXPath("//ArticleId[@IdType='doi']/text()");
        if (doi != null && !doi.isEmpty())
            builder.setDOI(doi);
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // year
    try {
        String year = xmlPage.getStringByXPath("//DateRevised/Year/text()");
        if (year != null && !year.isEmpty())
            builder.setYear(Integer.parseInt(year));
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // publication context
    try {
        String journalTitle = xmlPage.getStringByXPath("//Article/Journal/Title/text()");
        if (journalTitle != null && !journalTitle.isEmpty()) {
            builder.setPublicationContext(journalTitle);
            builder.setType(LiteratureType.JOURNAL_PAPER);
        }
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // URLs
    try {

        NodeList nodes = htmlPage
                .getNodeSetByXPath(".//*[@id='maincontent']//div[@class='linkoutlist']/ul[1]/li");
        int i = 0;
        Node node;
        Set<Link> webSiteLinks = new HashSet<>();
        Set<Link> fullTextLinkSet = new HashSet<Link>();

        // add pubmed page
        webSiteLinks.add(new Link("PubMed", pubMedURL));

        while ((node = nodes.item(i)) != null) {

            if (node.getFirstChild().getAttributes().getNamedItem("href") == null) {
                i++;
                continue;
            }

            String linkText = node.getFirstChild().getTextContent();
            String uri = node.getFirstChild().getAttributes().getNamedItem("href").getTextContent();
            webSiteLinks.add(new Link(linkText, uri));

            if (linkText.equals("PubMed Central")) {
                HTMLPage pmcPage = new HTMLPage(uri);
                Node pdfLinkNode = pmcPage
                        .getNodeByXPath(".//*[@id='rightcolumn']//div[@class='format-menu']/ul/li[4]/a/@href");
                String pdfLink = pdfLinkNode.getTextContent();
                fullTextLinkSet.add(new Link(linkText, "http://www.ncbi.nlm.nih.gov" + pdfLink));
            }

            i++;

        }
        builder.setWebsiteURLs(webSiteLinks);
        builder.setFulltextURLs(fullTextLinkSet);
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:betullam.xmlmodifier.XMLmodifier.java

private boolean isModsMets(Document xmlDoc) {
    boolean isMets = true;
    XPath xPath = XPathFactory.newInstance().newXPath();
    XPathExpression xPathExpression;

    // Check for the goobi mods extension. If we find it, the XML document is not a classical MODS/METS document:
    try {// ww  w  .j  av a 2  s. c o  m
        xPathExpression = xPath.compile("/mets/dmdSec/mdWrap/xmlData/mods/extension/goobi");
        NodeList nodeList = (NodeList) xPathExpression.evaluate(xmlDoc, XPathConstants.NODESET);
        if (nodeList.getLength() > 0) {
            isMets = false;
        }
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }

    return isMets;
}