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:it.ciroppina.idol.generic.tunnel.IdolOEMTunnel.java

/**
 * executes the IDOL Server GetVersion action 
 * @return a String containing the Json compact response
 * //from ww w  .  jav  a 2s. c om
 * @throws XPathExpressionException
 */
@WebMethod(operationName = "getversion")
public String getversion() {
    // We'll issue a GetVersion action and use the supplied DOM Document processor to process the response...
    Document response = this.aciService.executeAction(new AciParameters(AciConstants.ACTION_GET_VERSION),
            new DocumentProcessor());
    // Use XPath to pull out the value of the field the contains the type of the ACI server...
    try {
        final XPath xpath = XPathFactory.newInstance().newXPath();
        return (String) xpath.evaluate("/autnresponse/responsedata/producttypecsv", response,
                XPathConstants.STRING) + ", version: "
                + (String) xpath.evaluate("/autnresponse/responsedata/version", response, XPathConstants.STRING)
                + " - " + (String) xpath.evaluate("/autnresponse/responsedata/aciversion", response,
                        XPathConstants.STRING);
    } catch (XPathExpressionException xpe) {
        xpe.printStackTrace();
        return "IdolOEMTunnel - getversion: Error Occurred - not a valid XML autnresponse";
    } catch (Exception e) {
        e.printStackTrace();
        return "IdolOEMTunnel - getversion: unexpected Error Occurred";
    }
}

From source file:betullam.xmlmodifier.XMLmodifier.java

private List<Element> getElementsForInsertion(String condStructureElements, Document xmlDoc) {

    List<Element> elementsForInsertion = new ArrayList<Element>();
    List<String> dmdLogIds = new ArrayList<String>();
    List<String> structureElements = Arrays.asList(condStructureElements.split("\\s*,\\s*"));
    XPath xPath = XPathFactory.newInstance().newXPath();
    XPathExpression xPathExpression;

    // First, get all DMDLOG-IDs from the structMap-Node:
    for (String structureElement : structureElements) {

        try {/*from ww  w.jav a2  s  . co m*/
            xPathExpression = xPath
                    .compile("//mets/structMap[@TYPE='LOGICAL']//div[@TYPE='" + structureElement + "']");
            NodeList nodeList = (NodeList) xPathExpression.evaluate(xmlDoc, XPathConstants.NODESET);

            if (nodeList.getLength() > 0) {
                for (int i = 0; i < nodeList.getLength(); i++) {
                    if (nodeList.item(i).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
                        Element structMapElement = (Element) nodeList.item(i);
                        String dmdLogId = (!structMapElement.getAttribute("DMDID").isEmpty())
                                ? structMapElement.getAttribute("DMDID")
                                : null;
                        if (dmdLogId != null) {
                            dmdLogIds.add(dmdLogId);
                        }
                    }
                }
            }
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        }
    }

    // Now get all subnodes of the mets:dmdSec nodes with the right ID where we want to insert the new element:
    for (String dmdLogId : dmdLogIds) {
        try {
            if (isModsMets(xmlDoc) == true) {
                xPathExpression = xPath.compile("//mets/dmdSec[@ID='" + dmdLogId + "']/mdWrap/xmlData/mods");
            } else {
                xPathExpression = xPath
                        .compile("//mets/dmdSec[@ID='" + dmdLogId + "']/mdWrap/xmlData/mods/extension/goobi");
            }
            NodeList nodeList = (NodeList) xPathExpression.evaluate(xmlDoc, XPathConstants.NODESET);
            if (nodeList.getLength() > 0) {
                for (int i = 0; i < nodeList.getLength(); i++) {
                    if (nodeList.item(i).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
                        Element elementForInsertion = (Element) nodeList.item(i);
                        elementsForInsertion.add(elementForInsertion);
                    }
                }
            }
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        }
    }

    return elementsForInsertion;

}

From source file:uk.org.openeyes.diagnostics.AbstractFieldProcessor.java

/**
 *
 * Evaluates an xpath expression.//  w w w  .ja  v  a2  s .c o m
 *
 * @param document non-null XML document to test.
 *
 * @param xpath xpath object (non-null) to test the pattern.
 *
 * @param pattern non-null pattern to test.
 *
 * @return the string representing the result of evaluating the given
 * pattern; null otherwise.
 */
private String evaluate(Document document, XPath xpath, String pattern) {
    String metaData = null;
    try {
        metaData = xpath.compile(pattern).evaluate(document);
    } catch (XPathExpressionException e) {
        // nothing to do
        e.printStackTrace();
    }
    return metaData;
}

From source file:org.openmrs.module.rheashradapter.web.controller.RHEApatientController.java

private Map<String, String> identifyPreUpdateIdentifiers(String message) {
    Map<String, String> preUpdateIdentifiers = new HashMap<String, String>();

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);/*w  w  w . ja v  a 2  s  .  c  om*/
    org.w3c.dom.Document doc = null;
    XPathExpression expr = null;
    XPathExpression exprIdType = null;

    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        doc = builder.parse(new InputSource(new StringReader(message)));

        XPathFactory xFactory = XPathFactory.newInstance();

        XPath xpath = xFactory.newXPath();
        expr = xpath.compile("//preUpdateIdentifiers/preUpdateIdentifier/identifier/text()");
        Object result = expr.evaluate(doc, XPathConstants.NODESET);

        XPath xpathIdType = xFactory.newXPath();
        exprIdType = xpathIdType.compile(
                "//preUpdateIdentifiers/preUpdateIdentifier/identifierDomain/universalIdentifierTypeCode/text()");
        Object resultIdType = exprIdType.evaluate(doc, XPathConstants.NODESET);
        NodeList nodes = (NodeList) result;
        NodeList nodesIdType = (NodeList) resultIdType;

        for (int i = 0; i < nodes.getLength(); i++) {
            preUpdateIdentifiers.put(nodesIdType.item(i).getTextContent(), nodes.item(i).getTextContent());
        }

    } catch (XPathExpressionException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return preUpdateIdentifiers;
}

From source file:org.openmrs.module.rheashradapter.web.controller.RHEApatientController.java

private Map<String, String> identifyPostUpdateIdentifiers(String message) {
    Map<String, String> postUpdateIdentifiers = new HashMap<String, String>();

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);/* w  ww  .  j a  va  2s  . c o  m*/
    org.w3c.dom.Document doc = null;
    XPathExpression expr = null;
    XPathExpression exprIdType = null;

    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        doc = builder.parse(new InputSource(new StringReader(message)));

        XPathFactory xFactory = XPathFactory.newInstance();

        XPath xpath = xFactory.newXPath();
        expr = xpath.compile("//postUpdateIdentifiers/postUpdateIdentifier/identifier/text()");
        Object result = expr.evaluate(doc, XPathConstants.NODESET);

        XPath xpathIdType = xFactory.newXPath();
        exprIdType = xpathIdType.compile(
                "//postUpdateIdentifiers/postUpdateIdentifier/identifierDomain/universalIdentifierTypeCode/text()");
        Object resultIdType = exprIdType.evaluate(doc, XPathConstants.NODESET);
        NodeList nodes = (NodeList) result;
        NodeList nodesIdType = (NodeList) resultIdType;

        for (int i = 0; i < nodes.getLength(); i++) {
            postUpdateIdentifiers.put(nodesIdType.item(i).getTextContent(), nodes.item(i).getTextContent());
        }

    } catch (XPathExpressionException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return postUpdateIdentifiers;
}

From source file:com.geodan.ngr.serviceintegration.CSWTransformer.java

/**
 * Parses the InputStream to valid WMSResponses and returns them in a list using XPath.
 *
 * This method is essentially unchanged from the old Geodan implementation except it now parses a String.
 *
 * @param response      the String that contains the response from the GetRecords request
 * @return         a List that contains WMSResources or errors
 * @throws java.io.IOException in case of exception
 * @throws javax.xml.parsers.ParserConfigurationException in case of exception
 * @throws org.xml.sax.SAXException in case of exception
 *//*from  www . ja va2s  . c o m*/
private List<WMSResource> parse(String response)
        throws ParserConfigurationException, IOException, SAXException {

    List<WMSResource> wmsresourcelist = new ArrayList<WMSResource>();

    //
    // Create DOM document from response
    //
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    InputSource source = new InputSource(new StringReader(response));
    Document xmldoc = factory.newDocumentBuilder().parse(source);

    // With XPath get the WMS data
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContext nsContext = new CSWNamespaceContext();
    xpath.setNamespaceContext(nsContext);

    // The XML parse expression
    String expr = "/GetRecordsResponse/SearchResults/MD_Metadata/distributionInfo/MD_Distribution/transferOptions/MD_DigitalTransferOptions/onLine/CI_OnlineResource";
    try {
        // Run XPath
        NodeList nodes = (NodeList) xpath.evaluate(expr, xmldoc, XPathConstants.NODESET);

        // Check for nodes else generate error no records available
        if (nodes != null && nodes.getLength() > 0) {

            // Get for every node the values if no name and URL are available then generate a error. If the title has no value then the name can be the title.
            for (int i = 0; i < nodes.getLength(); i++) {
                Element el = (Element) nodes.item(i);
                String title = findTitle(el);
                String description = findDescription(el);
                String url = getValue(el, "gmd:linkage");
                String protocol = getValue(el, "gmd:protocol");
                String name = getValue(el, "gmd:name");
                if (name != null && url != null && !name.equals("") && !url.equals("")) {
                    WMSResource wmsresource = new WMSResource(title, url, protocol, name, description);
                    if (title == null) {
                        wmsresource.setTitle(name);
                    }
                    wmsresourcelist.add(wmsresource);
                } else {
                    // Because there already is an List<WMSRecords> the method "getException" will not be used
                    WMSResource wmsresource = new WMSResource(" \"records\": []}}");
                    wmsresourcelist.add(wmsresource);
                }
            }
        } else {
            // Because there already is an List<WMSRecords> the method "getException" will not be used
            WMSResource wmsresource = new WMSResource(" \"records\": []}}");
            wmsresourcelist.add(wmsresource);
        }
    } catch (XPathExpressionException e) {
        // Because there already is an List<WMSRecords> the method "getException" will not be used
        WMSResource wmsresource = new WMSResource("\"error\": \"There is an XPathExpressionException\"}}");
        wmsresourcelist.add(wmsresource);
    } catch (Exception e) {
        log.error("ERROR: " + e.getMessage());
        e.printStackTrace();
        // Because there already is an List<WMSRecords> the method "getException" will not be used
        WMSResource wmsresource = new WMSResource("\"error\": \"The result could not be parsed\"}}");
        wmsresourcelist.add(wmsresource);
    }
    // Return the results
    return wmsresourcelist;
}

From source file:it.drwolf.ridire.session.CrawlerManager.java

public void updateJobsList(User currentUser) throws HeritrixException {
    try {//from  ww w .j  a  va2 s.c o m
        this.doGetJobs(null, currentUser);
    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.glite.lb.NotifParser.java

/**
 * a method for handling xpath queries//from w ww .j a va  2s .co  m
 *
 * @param xpathString xpath expression
 * @return the result nodelist
 */
private NodeList evaluateXPath(String xpathString) {
    try {
        XPathFactory xfactory = XPathFactory.newInstance();
        XPath xpath = xfactory.newXPath();
        XPathExpression expr = xpath.compile(xpathString);
        return (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
    } catch (XPathExpressionException ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:org.iish.visualmets.services.TocDaoImp.java

private TocFolderItem createFolder(Document doc, String group, int recursive) {
    XPathExpression expr = null;//ww  w.j  a  v a 2  s . c  om
    try {
        // als geen group pak dan root mets:div directory
        if (group.equals("")) {
            //                expr = getXPathExpression("/mets:mets/mets:structMap/mets:div");
            expr = getXPathExpression("/" + namespaceName + "mets/" + namespaceName + "structMap");
        } else {
            expr = getXPathExpression("/" + namespaceName + "mets/" + namespaceName + "structMap//"
                    + namespaceName + "div[@ID='" + group + "']");
        }
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }

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

    NodeList nodes = (NodeList) result;

    //        System.out.println("++++ " + "/mets:mets/mets:structMap//mets:div[@ID='" + group +"']");

    TocFolderItem folderItem = new TocFolderItem();

    folderItem.setIndex(nodes.item(0).getAttributes().getNamedItem("ID").getNodeValue());
    folderItem.setTitle(nodes.item(0).getAttributes().getNamedItem("LABEL").getNodeValue());

    // does node (directory) have subdirectories (also a node, but watch out, files are also nodes)
    String hasDirs = "false";
    ArrayList<String> listOfSubDirectories = getArrayOfSubDirectories(nodes.item(0));
    if (listOfSubDirectories.size() > 0) {
        hasDirs = "true";
    }
    folderItem.setHaschildren(hasDirs);

    //
    ArrayList<TocMetsItem> lijst = new ArrayList<TocMetsItem>();
    System.out.println("ID: " + nodes.item(0).getAttributes().getNamedItem("ID").getNodeValue());
    lijst = getFilesRecursive(doc, lijst, nodes.item(0).getAttributes().getNamedItem("ID").getNodeValue(),
            recursive);

    for (TocMetsItem tocMetsItem : lijst) {
        folderItem.add(tocMetsItem);
    }

    return folderItem;
}