Example usage for javax.xml.xpath XPathExpressionException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.opens.tanaguru.processor.DOMHandlerImpl.java

@Override
@Deprecated//from w  w w .  j  a v  a 2  s. co  m
public TestSolution checkEachWithXpath(String expr) {
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node node : selectedElementList) {
        TestSolution tempResult = TestSolution.PASSED;
        try {
            XPathExpression xPathExpression = xpath.compile(expr);
            Boolean check = (Boolean) xPathExpression.evaluate(node, XPathConstants.BOOLEAN);
            if (!check.booleanValue()) {
                tempResult = TestSolution.FAILED;
                // addSourceCodeRemark(result, node,
                // "wrong value, does not respect xpath expression : " +
                // expr, node.getNodeValue());
            }
        } catch (XPathExpressionException ex) {
            LOGGER.error(ex.getMessage() + " occured requesting " + expr + " on " + ssp.getURI());
            throw new RuntimeException(ex);
        }
        resultSet.add(tempResult);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}

From source file:org.orcid.core.cli.LoadFundRefData.java

/**
 * Executes the import process//w  ww .j  a v  a2  s.  co  m
 * */
private void execute() {
    try {
        long start = System.currentTimeMillis();
        FileInputStream file = new FileInputStream(fileToLoad);
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        Document xmlDocument = builder.parse(file);
        // Parent node
        NodeList nodeList = (NodeList) xPath.compile(conceptsExpression).evaluate(xmlDocument,
                XPathConstants.NODESET);
        for (int i = 0; i < nodeList.getLength(); i++) {
            RDFOrganization rdfOrganization = getOrganization(xmlDocument, nodeList.item(i).getAttributes());
            LOGGER.info(
                    "Processing organization from RDF, doi:{}, name:{}, country:{}, state:{}, stateCode:{}, type:{}, subtype:{}",
                    new String[] { rdfOrganization.doi, rdfOrganization.name, rdfOrganization.country,
                            rdfOrganization.state, rdfOrganization.stateCode, rdfOrganization.type,
                            rdfOrganization.subtype });
            // #1: Look for an existing org
            OrgDisambiguatedEntity existingEntity = findByDetails(rdfOrganization);
            if (existingEntity != null) {
                // #2: If the name, city or region changed, update those values
                if (entityChanged(rdfOrganization, existingEntity)) {
                    existingEntity.setCity(rdfOrganization.city);
                    Iso3166Country country = StringUtils.isNotBlank(rdfOrganization.country)
                            ? Iso3166Country.fromValue(rdfOrganization.country)
                            : null;
                    existingEntity.setCountry(country);
                    existingEntity.setName(rdfOrganization.name);
                    String orgType = rdfOrganization.type
                            + (StringUtils.isNotBlank(rdfOrganization.subtype) ? ('/' + rdfOrganization.subtype)
                                    : "");
                    existingEntity.setOrgType(orgType);
                    existingEntity.setRegion(rdfOrganization.stateCode);
                    existingEntity.setSourceId(rdfOrganization.doi);
                    existingEntity.setSourceType(FUNDREF_SOURCE_TYPE);
                    existingEntity.setSourceUrl(rdfOrganization.doi);
                    orgDisambiguatedDao.merge(existingEntity);
                    updatedOrgs += 1;
                } else if (idChanged(rdfOrganization, existingEntity)) {
                    // #3: If the ID changed, create an external identifier
                    createExternalIdentifier(existingEntity, rdfOrganization.doi);
                    addedExternalIdentifiers += 1;
                }
            } else {
                // #4: Else, create the new org
                OrgDisambiguatedEntity newOrg = createDisambiguatedOrg(rdfOrganization);
                addedDisambiguatedOrgs += 1;
            }
        }

        long end = System.currentTimeMillis();
        LOGGER.info("Time taken to process the files: {}", (end - start));
    } catch (FileNotFoundException fne) {
        LOGGER.error("Unable to read file {}", fileToLoad);
    } catch (ParserConfigurationException pce) {
        LOGGER.error("Unable to initialize the DocumentBuilder");
    } catch (IOException ioe) {
        LOGGER.error("Unable to parse document {}", fileToLoad);
    } catch (SAXException se) {
        LOGGER.error("Unable to parse document {}", fileToLoad);
    } catch (XPathExpressionException xpe) {
        LOGGER.error("XPathExpressionException {}", xpe.getMessage());
    } finally {
        LOGGER.info("Number new Disambiguated Orgs={}, Updated Orgs={}, new External Identifiers={}",
                new Object[] { addedDisambiguatedOrgs, updatedOrgs, addedExternalIdentifiers, getTotal() });
    }

}

From source file:org.orcid.core.cli.LoadFundRefData.java

/**
 * Get an RDF organization from the given RDF file
 * *//*from w  w  w  . ja  va 2  s  .c o  m*/
private RDFOrganization getOrganization(Document xmlDocument, NamedNodeMap attrs) {
    RDFOrganization organization = new RDFOrganization();
    try {
        Node node = attrs.getNamedItem("rdf:resource");
        String itemDoi = node.getNodeValue();
        LOGGER.info("Processing item {}", itemDoi);
        // Get organization name
        String orgName = (String) xPath.compile(orgNameExpression.replace("%s", itemDoi)).evaluate(xmlDocument,
                XPathConstants.STRING);
        // Get country code
        Node countryNode = (Node) xPath.compile(orgCountryExpression.replace("%s", itemDoi))
                .evaluate(xmlDocument, XPathConstants.NODE);
        NamedNodeMap countryAttrs = countryNode.getAttributes();
        String countryGeonameUrl = countryAttrs.getNamedItem("rdf:resource").getNodeValue();
        String countryCode = fetchFromGeoNames(countryGeonameUrl, "countryCode");

        // Get state name
        Node stateNode = (Node) xPath.compile(orgStateExpression.replace("%s", itemDoi)).evaluate(xmlDocument,
                XPathConstants.NODE);
        String stateName = null;
        String stateCode = null;
        if (stateNode != null) {
            NamedNodeMap stateAttrs = stateNode.getAttributes();
            String stateGeoNameCode = stateAttrs.getNamedItem("rdf:resource").getNodeValue();
            stateName = fetchFromGeoNames(stateGeoNameCode, "name");
            stateCode = fetchFromGeoNames(stateGeoNameCode, STATE_NAME);
        }

        // Get type
        String orgType = (String) xPath.compile(orgTypeExpression.replace("%s", itemDoi)).evaluate(xmlDocument,
                XPathConstants.STRING);
        // Get subType
        String orgSubType = (String) xPath.compile(orgSubTypeExpression.replace("%s", itemDoi))
                .evaluate(xmlDocument, XPathConstants.STRING);

        // Fill the organization object
        organization.doi = itemDoi;
        organization.name = orgName;
        organization.country = countryCode;
        organization.state = stateName;
        organization.stateCode = stateCode;
        // TODO: since we don't have city, we fill this with the state, this
        // should be modified soon
        organization.city = stateCode;
        organization.type = orgType;
        organization.subtype = orgSubType;
    } catch (XPathExpressionException xpe) {
        LOGGER.error("XPathExpressionException {}", xpe.getMessage());
    }

    return organization;
}

From source file:org.rhq.modules.plugins.jbossas7.AbstractBaseDiscovery.java

/**
 * Run the passed xpathExpression on the prepopulated hostXml document and
 * return the target element or attribute as a String.
 * @param xpathExpression XPath Expression to evaluate
 * @return String value of the Element or Attribute the XPath was pointing to.
 *     Null in case the xpathExpression could not be evaluated.
 * @throws IllegalArgumentException if hostXml is null
 *
 *//*from   w  w  w.j  a v a 2  s .  c om*/
protected String obtainXmlPropertyViaXPath(String xpathExpression) {
    if (hostXml == null)
        throw new IllegalArgumentException(CALL_READ_STANDALONE_OR_HOST_XML_FIRST);

    XPath xpath = factory.newXPath();
    try {
        XPathExpression expr = xpath.compile(xpathExpression);

        Object result = expr.evaluate(hostXml, XPathConstants.STRING);

        return result.toString();
    } catch (XPathExpressionException e) {
        log.error("Evaluation XPath expression failed: " + e.getMessage());
        return null;
    }
}

From source file:org.rhq.modules.plugins.jbossas7.helper.HostConfiguration.java

/**
 * Run the passed xpathExpression on the prepopulated hostXml document and
 * return the target element or attribute as a String.
 * @param xpathExpression XPath Expression to evaluate
 * @return String value of the Element or Attribute the XPath was pointing to.
 *     Null in case the xpathExpression could not be evaluated.
 * @throws IllegalArgumentException if hostXml is null
 *//*from   ww w. ja va  2  s  .c o m*/
public String obtainXmlPropertyViaXPath(String xpathExpression) {
    XPath xpath = this.xpathFactory.newXPath();
    try {
        XPathExpression expr = xpath.compile(xpathExpression);
        Object result = expr.evaluate(this.document, XPathConstants.STRING);
        return result.toString();
    } catch (XPathExpressionException e) {
        log.error("Evaluation of XPath expression failed: " + e.getMessage());
        return null;
    }
}

From source file:org.rhq.modules.plugins.jbossas7.helper.JBossCliConfiguration.java

private Object xpathExpression(String xpathExpression, QName returnType) {
    XPath xpath = this.xpathFactory.newXPath();
    try {//from  w ww . ja  v  a2  s  .  c o m
        XPathExpression expr = xpath.compile(xpathExpression);
        return expr.evaluate(this.document, returnType);
    } catch (XPathExpressionException e) {
        log.error("Evaluation of XPath expression failed: " + e.getMessage());
        return null;
    }
}

From source file:org.rhq.modules.plugins.wildfly10.helper.HostConfiguration.java

/**
 * /*from  ww  w.j  a  v  a  2  s.c om*/
 * @return true if $local authentication is the only authentication configured for realm associated to native management interface
 */
public boolean isNativeLocalOnly() {
    String nativeRealm = getManagementSecurityRealm();
    if (nativeRealm != null) {
        XPath xpath = this.xpathFactory.newXPath();
        try {
            XPathExpression expr = xpath.compile("count(//management/security-realms/security-realm[@name='"
                    + nativeRealm + "']/authentication[count(local) = count(*)]) = 1");
            return (Boolean) expr.evaluate(this.document, XPathConstants.BOOLEAN);
        } catch (XPathExpressionException e) {
            log.error("Evaluation of XPath expression failed: " + e.getMessage());
            return false;
        }
    }
    return false;
}

From source file:org.searsia.engine.Resource.java

private SearchResult searsiaSearch(String jsonPage) {
    SearchResult result = new SearchResult();
    JSONObject json = new JSONObject(jsonPage);
    JSONArray hits = json.getJSONArray("hits");
    for (int i = 0; i < hits.length(); i += 1) {
        result.addHit(new Hit((JSONObject) hits.get(i)));
    }/*from   w  w w .  ja  v a 2  s.co m*/
    if (json.has("resource")) {
        try {
            Resource engine = new Resource(json.getJSONObject("resource"));
            result.setResource(engine);
        } catch (XPathExpressionException e) {
            LOGGER.warn("Warning: " + e.getMessage());
        }
    }
    return result;
}

From source file:org.searsia.engine.Resource.java

private Hit extractHit(Node item) {
    Hit hit = new Hit();
    for (TextExtractor extractor : this.extractors) {
        try {//from  w  w w.  j  av a  2s .  c  o m
            extractor.extract(item, hit);
        } catch (XPathExpressionException e) {
            LOGGER.warn(e.getMessage()); // TODO: handle this gracefully :-)
        }
    }
    return hit;
}

From source file:org.staticioc.SpringConfigParser.java

public SpringConfigParser() throws ParserConfigurationException {
    // Init DocumentBuilderFactory
    dbf = DocumentBuilderFactory.newInstance();

    dbf.setNamespaceAware(false);//ww w.j  av  a 2 s.  com
    dbf.setValidating(false);
    dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
    dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
    dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    dbf.setFeature("http://xml.org/sax/features/use-entity-resolver2", false);

    db = dbf.newDocumentBuilder();

    xPathFactory = XPathFactory.newInstance();

    beanContainer = new BeanContainerImpl();

    namespaceParsers = new LinkedList<NamespaceParser>();
    addNamespaceParser(new SpringBeansNameSpaceParser());
    addNamespaceParser(new SpringPNameSpaceParser());

    try {
        final XPath xPathBeans = xPathFactory.newXPath();
        xBeans = xPathBeans.compile(XPATH_BEAN);

        final XPath xPathImports = xPathFactory.newXPath();
        xImports = xPathImports.compile(XPATH_IMPORT);

        final XPath xPathBeanRoot = xPathFactory.newXPath();
        xBeanRoot = xPathBeanRoot.compile(XPATH_BEANS_NODE);
    } catch (XPathExpressionException e) {
        throw new ParserConfigurationException("Error compiling XPaths :" + e.getMessage());
    }
}