Example usage for javax.xml.xpath XPathExpressionException toString

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:ch.dbs.actions.bestellung.EZBXML.java

private List<String> getJourids(final String content) {

    final List<String> result = new ArrayList<String>();

    try {//from  w ww  . j a va 2s  .c om

        if (content != null) {

            final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            domFactory.setNamespaceAware(true);
            final DocumentBuilder builder = domFactory.newDocumentBuilder();
            final Document doc = builder.parse(new InputSource(new StringReader(content)));

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

            final XPathExpression exprJournals = xpath.compile("//journals/journal");
            final NodeList journals = (NodeList) exprJournals.evaluate(doc, XPathConstants.NODESET);

            for (int i = 0; i < journals.getLength(); i++) {
                final Node firstResultNode = journals.item(i);
                final Element journal = (Element) firstResultNode;

                final String id = journal.getAttribute("jourid");

                if (id != null) {
                    result.add(id);
                }

            }
        }

    } catch (final XPathExpressionException e) {
        LOG.error(e.toString());
    } catch (final SAXParseException e) {
        LOG.error(e.toString());
    } catch (final SAXException e) {
        LOG.error(e.toString());
    } catch (final IOException e) {
        LOG.error(e.toString());
    } catch (final ParserConfigurationException e) {
        LOG.error(e.toString());
    } catch (final Exception e) {
        LOG.error(e.toString());
    }

    return result;
}

From source file:ch.dbs.actions.bestellung.EZBVascoda.java

/**
 * This class uses the EZB API from/*from w ww  . ja  v  a 2  s  .c  o  m*/
 * http://ezb.uni-regensburg.de/ezeit/vascoda/openURL?pid=format%3Dxml. This
 * API differs from the EZB/ZDB API (http://services.dnb.de). It brings back
 * no print information and other information for electronic holdings. It
 * seems to be more stable.
 */
public EZBForm read(final String content) {

    final EZBForm ezbform = new EZBForm();

    try {

        if (content != null) {

            final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            domFactory.setNamespaceAware(true);
            final DocumentBuilder builder = domFactory.newDocumentBuilder();
            final Document doc = builder.parse(new InputSource(new StringReader(content)));

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

            // issns
            final XPathExpression exprRefE = xpath.compile("//OpenURLResponse");
            final NodeList resultListRefE = (NodeList) exprRefE.evaluate(doc, XPathConstants.NODESET);

            String title = null;
            String levelAvailable = null;

            for (int i = 0; i < resultListRefE.getLength(); i++) {
                final Node firstResultNode = resultListRefE.item(i);
                final Element result = (Element) firstResultNode;

                // First ISSN
                //                    final String issn = getValue(result.getElementsByTagName("issn"));
                //                    System.out.println(issn);

                // title
                // unfortunately this will bring back the title sent by OpenURL, unless if not
                // specified in the OpenURL request. It then brings back the title form the EZB...!
                title = getValue(result.getElementsByTagName("title"));
                if (title != null) {
                    title = Jsoup.clean(title, Whitelist.none());
                    title = Jsoup.parse(title).text();
                }

                // this is the overall level of the best match and not the level of each individual result
                final NodeList levelNode = result.getElementsByTagName("available");
                final Element levelElement = (Element) levelNode.item(0);
                if (levelElement != null) {
                    levelAvailable = levelElement.getAttribute("level");
                }

            }

            // electronic data
            final XPathExpression exprE = xpath.compile("//OpenURLResponse/OpenURLResult/Resultlist/Result");
            final NodeList resultListE = (NodeList) exprE.evaluate(doc, XPathConstants.NODESET);

            for (int i = 0; i < resultListE.getLength(); i++) {
                final Node firstResultNode = resultListE.item(i);
                final Element result = (Element) firstResultNode;

                final NodeList state = result.getElementsByTagName("access");
                final Element stateElement = (Element) state.item(0);
                int color = 0;
                if (stateElement != null) {
                    color = Integer.valueOf(stateElement.getAttribute("color"));
                }

                final EZBDataOnline online = new EZBDataOnline();

                // state
                // 1 free accessible
                if (color == EZBState.FREE.getValue()) {
                    online.setAmpel("green");
                    online.setComment("availresult.free");
                    online.setState(JOPState.FREE.getValue()); // translate state to EZB/ZDB-API
                    // 2 licensed ; 3 partially licensed
                } else if (color == EZBState.LICENSED.getValue()
                        || color == EZBState.LICENSED_PARTIALLY.getValue()) {
                    online.setAmpel("yellow");
                    online.setComment("availresult.abonniert");
                    online.setState(JOPState.LICENSED.getValue()); // translate state to EZB/ZDB-API
                    // not licensed
                } else if (color == EZBState.NOT_LICENSED.getValue()) {
                    online.setAmpel("red");
                    online.setComment("availresult.not_licensed");
                    online.setState(JOPState.NOT_LICENSED.getValue()); // translate state to EZB/ZDB-API
                } else {
                    online.setAmpel("red");
                    online.setComment("availresult.not_licensed");
                    online.setState(JOPState.NOT_LICENSED.getValue()); // translate state to EZB/ZDB-API
                }

                // LinkToArticle not always present
                String url = getValue(result.getElementsByTagName("LinkToArticle"));
                // LinkToJournal always present
                if (url == null) {
                    url = getValue(result.getElementsByTagName("LinkToJournal"));
                }
                online.setUrl(url);

                // try to get level from link
                String levelLinkToArticle = null;
                final NodeList levelNode = result.getElementsByTagName("LinkToArticle");
                final Element levelElement = (Element) levelNode.item(0);
                if (levelElement != null) {
                    levelLinkToArticle = levelElement.getAttribute("level");
                }

                if (levelLinkToArticle != null) {
                    online.setLevel(levelLinkToArticle); // specific level of each result
                } else {
                    online.setLevel(levelAvailable); // overall level of best match
                }

                if (title != null) {
                    online.setTitle(title);
                } else {
                    online.setTitle(url);
                }
                online.setReadme(getValue(result.getElementsByTagName("LinkToReadme")));

                ezbform.getOnline().add(online);
            }

            // Title not found
            if (resultListE.getLength() == 0) {
                final EZBDataOnline online = new EZBDataOnline();
                online.setAmpel("red");
                online.setComment("availresult.nohits");
                online.setState(JOPState.NO_HITS.getValue()); // translate state to EZB/ZDB-API

                ezbform.getOnline().add(online);
            }

        }

    } catch (final XPathExpressionException e) {
        LOG.error(e.toString());
    } catch (final SAXParseException e) {
        LOG.error(e.toString());
    } catch (final SAXException e) {
        LOG.error(e.toString());
    } catch (final IOException e) {
        LOG.error(e.toString());
    } catch (final ParserConfigurationException e) {
        LOG.error(e.toString());
    } catch (final Exception e) {
        LOG.error(e.toString());
    }

    return ezbform;
}

From source file:ch.dbs.actions.bestellung.EZBXML.java

public List<JournalDetails> searchByJourids(final List<String> jourids, final String bibid) {

    final List<JournalDetails> list = new ArrayList<JournalDetails>();
    final Http http = new Http();

    final StringBuffer link = new StringBuffer(
            "http://rzblx1.uni-regensburg.de/ezeit/detail.phtml?xmloutput=1&colors=7&lang=de&bibid=");
    link.append(bibid);//from   w ww  .ja va2  s. co m
    link.append("&jour_id=");

    final StringBuffer infoLink = new StringBuffer(
            "http://ezb.uni-regensburg.de/ezeit/detail.phtml?colors=7&lang=de&bibid=");
    infoLink.append(bibid);
    infoLink.append("&jour_id=");

    try {

        for (final String jourid : jourids) {

            final JournalDetails jd = new JournalDetails();

            final String content = http.getContent(link.toString() + jourid, Connect.TIMEOUT_1.getValue(),
                    Connect.TRIES_1.getValue(), null);

            if (content != null) {

                final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
                domFactory.setNamespaceAware(true);
                final DocumentBuilder builder = domFactory.newDocumentBuilder();
                final Document doc = builder.parse(new InputSource(new StringReader(content)));

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

                final XPathExpression exprJournal = xpath.compile("//journal");
                final XPathExpression exprPissns = xpath.compile("//journal/detail/P_ISSNs");
                final XPathExpression exprEissns = xpath.compile("//journal/detail/E_ISSNs");
                final NodeList resultJournal = (NodeList) exprJournal.evaluate(doc, XPathConstants.NODESET);

                for (int i = 0; i < resultJournal.getLength(); i++) {
                    final Node firstResultNode = resultJournal.item(i);
                    final Element journal = (Element) firstResultNode;

                    // Title
                    String title = getValue(journal.getElementsByTagName("title"));
                    if (title != null) {
                        title = Jsoup.clean(title, Whitelist.none());
                        title = Jsoup.parse(title).text();
                    }

                    jd.setZeitschriftentitel(title);

                    // P-ISSNs
                    final NodeList resultPissns = (NodeList) exprPissns.evaluate(doc, XPathConstants.NODESET);

                    // get first pissn
                    for (int z = 0; z < resultPissns.getLength(); z++) {
                        final Node firstPissnsNode = resultPissns.item(i);
                        final Element pissnElement = (Element) firstPissnsNode;
                        final String pissn = getValue(pissnElement.getElementsByTagName("P_ISSN"));
                        jd.setIssn(pissn);
                    }

                    // try to get Eissn if we have no Pissn
                    if (jd.getIssn() == null) {

                        // E-ISSNs
                        final NodeList resultEissns = (NodeList) exprEissns.evaluate(doc,
                                XPathConstants.NODESET);

                        // get first eissn
                        for (int z = 0; z < resultEissns.getLength(); z++) {
                            final Node firstEissnsNode = resultEissns.item(i);
                            final Element eissnElement = (Element) firstEissnsNode;
                            final String eissn = getValue(eissnElement.getElementsByTagName("E_ISSN"));
                            jd.setIssn(eissn);
                        }
                    }

                    // add info link
                    jd.setLink(infoLink.toString() + jourid);

                    list.add(jd);
                }
            }
        }

    } catch (final XPathExpressionException e) {
        LOG.error(e.toString());
    } catch (final SAXParseException e) {
        LOG.error(e.toString());
    } catch (final SAXException e) {
        LOG.error(e.toString());
    } catch (final IOException e) {
        LOG.error(e.toString());
    } catch (final ParserConfigurationException e) {
        LOG.error(e.toString());
    } catch (final Exception e) {
        LOG.error(e.toString());
    }

    return list;
}

From source file:ch.dbs.actions.bestellung.EZBJOP.java

/**
 * This class uses the official EZB/ZDB API from
 * http://services.dnb.de/fize-service/gvr/full.xml.
 *//*  w  ww .  j  av  a2  s  .  co m*/
public EZBForm read(final String content) {

    final EZBForm ezbform = new EZBForm();

    try {

        if (content != null) {

            final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            domFactory.setNamespaceAware(true);
            final DocumentBuilder builder = domFactory.newDocumentBuilder();
            final Document doc = builder.parse(new InputSource(new StringReader(content)));

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

            // references electronic data
            //            final XPathExpression exprRefE = xpath.compile("//ElectronicData/References/Reference");
            //            final NodeList resultListRefE = (NodeList) exprRefE.evaluate(doc, XPathConstants.NODESET);
            //
            //            for (int i = 0; i < resultListRefE.getLength(); i++) {
            //                final Node firstResultNode = resultListRefE.item(i);
            //                final Element result = (Element) firstResultNode;
            //
            //                final EZBReference ref = new EZBReference();
            //
            //                // EZB URLs
            //                final String url = getValue(result.getElementsByTagName("URL"));
            //                ref.setUrl(url);
            //
            //                // Label for URLs
            //                final String label = getValue(result.getElementsByTagName("Label"));
            //                ref.setLabel(label);
            //
            //                ezbform.getReferencesonline().add(ref);
            //            }

            // electronic data
            final XPathExpression exprE = xpath.compile("//ElectronicData/ResultList/Result");
            final NodeList resultListE = (NodeList) exprE.evaluate(doc, XPathConstants.NODESET);

            for (int i = 0; i < resultListE.getLength(); i++) {
                final Node firstResultNode = resultListE.item(i);
                final Element result = (Element) firstResultNode;

                final EZBDataOnline online = new EZBDataOnline();

                // state
                online.setState(Integer.valueOf(result.getAttribute("state")));
                // 0 free accessible
                if (online.getState() == JOPState.FREE.getValue()) {
                    online.setAmpel("green");
                    online.setComment("availresult.free");
                    // 1 partially free accesible
                } else if (online.getState() == JOPState.FREE_PARTIALLY.getValue()) {
                    online.setAmpel("green");
                    online.setComment("availresult.partially_free");
                    // 2 licensed ; 3 partially licensed
                } else if (online.getState() == JOPState.LICENSED.getValue()
                        || online.getState() == JOPState.LICENSED_PARTIALLY.getValue()) {
                    online.setAmpel("yellow");
                    online.setComment("availresult.abonniert");
                    // journal not online for periode
                } else if (online.getState() == JOPState.OUTSIDE_PERIOD.getValue()) {
                    online.setAmpel("red");
                    online.setComment("availresult.timeperiode");
                    // not indexed
                } else if (online.getState() == JOPState.NO_HITS.getValue()) {
                    online.setAmpel("red");
                    online.setComment("availresult.nohits");
                } else {
                    online.setAmpel("red");
                    online.setComment("availresult.not_licensed");
                }

                // title
                String title = getValue(result.getElementsByTagName("Title"));
                if (title != null) {
                    title = Jsoup.clean(title, Whitelist.none());
                    online.setTitle(Jsoup.parse(title).text());
                }

                online.setUrl(getValue(result.getElementsByTagName("AccessURL")));
                online.setLevel(getValue(result.getElementsByTagName("AccessLevel")));
                online.setReadme(getValue(result.getElementsByTagName("ReadmeURL")));
                // National licenses etc.
                online.setAdditional(getValue(result.getElementsByTagName("Additional")));

                ezbform.getOnline().add(online);
            }

            // Title not found
            if (resultListE.getLength() == 0) {
                final EZBDataOnline online = new EZBDataOnline();
                online.setAmpel("red");
                online.setComment("availresult.nohits");
                online.setState(JOPState.NO_HITS.getValue());

                ezbform.getOnline().add(online);
            }

            // references print data
            final XPathExpression exprRefP = xpath.compile("//PrintData/References/Reference");
            final NodeList resultListRefP = (NodeList) exprRefP.evaluate(doc, XPathConstants.NODESET);

            final EZBReference ref = new EZBReference();

            for (int i = 0; i < resultListRefP.getLength(); i++) {
                final Node firstResultNode = resultListRefP.item(i);
                final Element result = (Element) firstResultNode;

                // EZB URLs
                ref.setUrl(getValue(result.getElementsByTagName("URL")));

                // Label for URLs
                //                final String label = getValue(result.getElementsByTagName("Label"));
                ref.setLabel("availresult.link_title_print");

                ezbform.getReferencesprint().add(ref);
            }

            // print data
            final XPathExpression exprP = xpath.compile("//PrintData/ResultList/Result");
            final NodeList resultListP = (NodeList) exprP.evaluate(doc, XPathConstants.NODESET);

            for (int i = 0; i < resultListP.getLength(); i++) {
                final Node firstResultNode = resultListP.item(i);
                final Element result = (Element) firstResultNode;

                final EZBDataPrint print = new EZBDataPrint();

                // state
                print.setState(Integer.valueOf(result.getAttribute("state")));

                // title
                String title = getValue(result.getElementsByTagName("Title"));
                if (title != null) {
                    title = Jsoup.clean(title, Whitelist.none());
                    print.setTitle(Jsoup.parse(title).text());
                }

                print.setLocation(getValue(result.getElementsByTagName("Location")));
                print.setCallnr(getValue(result.getElementsByTagName("Signature")));
                print.setCoverage(getValue(result.getElementsByTagName("Period")));

                // set previous extracted URL and label
                print.setInfo(ref);

                // in stock ; partially in stock
                if (print.getState() == JOPState.LICENSED.getValue()
                        || print.getState() == JOPState.LICENSED_PARTIALLY.getValue()) {
                    print.setAmpel("yellow");
                    print.setComment("availresult.print");
                    // only return if existing in Print
                    ezbform.getPrint().add(print);
                }
            }
        }

    } catch (final XPathExpressionException e) {
        LOG.error(e.toString());
    } catch (final SAXParseException e) {
        LOG.error(e.toString());
    } catch (final SAXException e) {
        LOG.error(e.toString());
    } catch (final IOException e) {
        LOG.error(e.toString());
    } catch (final ParserConfigurationException e) {
        LOG.error(e.toString());
    } catch (final Exception e) {
        LOG.error(e.toString());
    }

    return ezbform;
}

From source file:org.powertac.server.CompetitionSetupService.java

private ArrayList<Object> processBootDataset(URL bootDataset) {
    // Read and convert the bootstrap dataset
    ArrayList<Object> result = new ArrayList<Object>();
    XPathFactory factory = XPathFactory.newInstance();
    XPath xPath = factory.newXPath();
    try {/* w ww . j a va 2s .  c om*/
        InputSource source = new InputSource(bootDataset.openStream());
        // we want all the children of the bootstrap node
        XPathExpression exp = xPath.compile("/powertac-bootstrap-data/bootstrap/*");
        NodeList nodes = (NodeList) exp.evaluate(source, XPathConstants.NODESET);
        log.info("Found " + nodes.getLength() + " bootstrap nodes");
        // Each node is a bootstrap data item
        for (int i = 0; i < nodes.getLength(); i++) {
            String xml = nodeToString(nodes.item(i));
            Object msg = messageConverter.fromXML(xml);
            result.add(msg);
        }
    } catch (XPathExpressionException xee) {
        log.error("runOnce: Error reading config file: " + xee.toString());
    } catch (IOException ioe) {
        log.error("runOnce: reset fault: " + ioe.toString());
    }
    return result;
}

From source file:org.powertac.server.CompetitionSetupService.java

/**
 * Sets up the simulator, with config overrides provided in a file.
 *//*from  www .java  2  s .  c o m*/
public boolean preGame(URL bootFile) {
    log.info("preGame(File) - start");
    // run the basic pre-game setup
    preGame();

    // read the config info from the bootReader - We need to find a Competition
    Competition bootstrapCompetition = null;
    XPathFactory factory = XPathFactory.newInstance();
    XPath xPath = factory.newXPath();
    try {
        // first grab the Competition
        XPathExpression exp = xPath.compile("/powertac-bootstrap-data/config/competition");
        NodeList nodes = (NodeList) exp.evaluate(new InputSource(bootFile.openStream()),
                XPathConstants.NODESET);
        String xml = nodeToString(nodes.item(0));
        bootstrapCompetition = (Competition) messageConverter.fromXML(xml);
    } catch (XPathExpressionException xee) {
        log.error("preGame: Error reading boot dataset: " + xee.toString());
        System.out.println("preGame: Error reading boot dataset: " + xee.toString());
        return false;
    } catch (IOException ioe) {
        log.error("preGame: Error opening file " + bootFile + ": " + ioe.toString());
        System.out.println("preGame: Error opening file " + bootFile + ": " + ioe.toString());
        return false;
    }
    // update the existing Competition - should be the current competition
    Competition.currentCompetition().update(bootstrapCompetition);
    return true;
}