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.cruxframework.crux.core.declarativeui.ViewParser.java

/**
 * @param htmlDocument/*w  ww .j  a v  a2 s  . c o  m*/
 * @return
 * @throws ViewParserException
 */
private Element getPageHeadElement(Document htmlDocument) throws ViewParserException {
    try {
        NodeList headNodes = (NodeList) findHTMLHeadExpression.evaluate(htmlDocument, XPathConstants.NODESET);
        if (headNodes.getLength() > 0) {
            return (Element) headNodes.item(0);
        }
        Element headElement = htmlDocument.createElementNS(XHTML_NAMESPACE, "head");
        Element bodyElement = getPageBodyElement(htmlDocument);
        if (bodyElement != null) {
            htmlDocument.getDocumentElement().insertBefore(headElement, bodyElement);
            return headElement;
        }
        htmlDocument.getDocumentElement().appendChild(headElement);
        return headElement;
    } catch (XPathExpressionException e) {
        throw new ViewParserException(e.getMessage(), e);
    }
}

From source file:org.lockss.plugin.clockss.XPathXmlMetadataParser.java

/**
 * Extract metadata from the XML source specified by the input stream using
 * the constructor-set xPath definitions.
 * @param target //from ww w . j av a  2s .c om
 * @param cu the CachedUrl for the XML source file
 * @return list of ArticleMetadata objects; one per record in the XML
 * @throws IOException
 * @throws SAXException 
 */
public List<ArticleMetadata> extractMetadata(MetadataTarget target, CachedUrl cu)
        throws IOException, SAXException {
    if (cu == null) {
        throw new IllegalArgumentException("Null CachedUrl");
    }
    if (!cu.hasContent()) {
        throw new IllegalArgumentException("CachedUrl has no content: " + cu.getUrl());
    }
    List<ArticleMetadata> amList = makeNewAMList();
    ArticleMetadata globalAM = null;

    Document doc = null;
    // this could throw IO or SAX exception - handled  upstream
    doc = createDocumentTree(cu);

    // no exception thrown but the document wasn't succesfully created
    if (doc == null)
        return amList; // return empty list

    try {
        /* GLOBAL - If global data map exists, collect it and put it in a temporary AM */
        if (gXPathList.length > 0) {
            log.debug3("extracting global metadata");
            globalAM = extractDataFromNode(doc, gXPathList);
        }
        if (aXPathList.length > 0) {
            /* ARTICLE - If there is no definition of an article node, collect article data from entire tree */
            if (articlePath == null) {
                log.debug3("extract article data from entire document");
                ArticleMetadata oneAM = extractDataFromNode(doc, aXPathList);
                addGlobalToArticleAM(globalAM, oneAM);
                amList.add(oneAM);
            } else {
                /* Get a list of article nodes from the full tree and then collect article data from each one */
                Object result;
                log.debug3("extracting article data from each article path:" + articlePath);
                // if no articles, this returns an empty nodelist, not null
                result = articlePath.evaluate(doc, XPathConstants.NODESET);
                NodeList nodeList = (NodeList) result;
                for (int j = 0; j < nodeList.getLength(); j++) {
                    Node articleNode = nodeList.item(j);
                    log.debug3("Article node");
                    if (articleNode == null) {
                        log.debug3("NULL article node");
                        continue;
                    } else {
                        ArticleMetadata singleAM = extractDataFromNode(articleNode, aXPathList);
                        addGlobalToArticleAM(globalAM, singleAM);
                        amList.add(singleAM); // before going on to the next individual item
                    }
                }
            }
        } else {
            /* No article map, but if there was a global map, use that */
            if (globalAM != null) {
                amList.add(globalAM);
            }
        }

    } catch (XPathExpressionException e) {
        // indicates bath xPath expression,not bad xml
        log.warning("ignoring xpath error - " + e.getMessage());
    }
    return amList;
}

From source file:org.mule.ibeans.IBeansSupport.java

/**
 * Select a single XML node using an Xpath
 * @param xpath the XPath expression to evaluate
 * @param node the node (or document) to exaluate on
 * @return the result of the evaluation.  Note that if an error occurs, the error is logged and null is returned
 *//*www. j  av a  2  s.co  m*/
public static Node selectOne(String xpath, Node node) {
    try {
        XPath xp = createXPath(node);
        return (Node) xp.evaluate(xpath, node, XPathConstants.NODE);
    } catch (XPathExpressionException e) {
        logger.error(e.getMessage());
        return null;
    }
}

From source file:org.mule.ibeans.IBeansSupport.java

/**
 * Select a single XML String value using an Xpath
 * @param xpath the XPath expression to evaluate
 * @param node the node (or document) to exaluate on
 * @return the result of the evaluation.  Note that if an error occurs, the error is logged and null is returned
 *//*  w  w  w  . ja  v  a  2 s.c  om*/
public static String selectValue(String xpath, Node node) {
    try {
        XPath xp = createXPath(node);
        return (String) xp.evaluate(xpath, node, XPathConstants.STRING);
    } catch (XPathExpressionException e) {
        logger.error(e.getMessage());
        return null;
    }
}

From source file:org.mule.ibeans.IBeansSupport.java

/**
 * Select a set of Node objects using the Xpath expression
 * @param xpath the XPath expression to evaluate
 * @param node the node (or document) to exaluate on
 * @return the result of the evaluation.  Note that if an error occurs, the error is logged and null is returned
 *///from  w  ww.  j ava  2 s.  co  m
public static List<Node> select(String xpath, Node node) {
    try {
        XPath xp = createXPath(node);
        NodeList nl = (NodeList) xp.evaluate(xpath, node, XPathConstants.NODESET);
        List<Node> nodeList = new ArrayList<Node>(nl.getLength());
        for (int i = 0; i < nl.getLength(); i++) {
            nodeList.add(nl.item(i));
        }
        return nodeList;
    } catch (XPathExpressionException e) {
        logger.error(e.getMessage());
        return null;
    }
}

From source file:org.opencastproject.mediapackage.elementbuilder.AbstractAttachmentBuilderPlugin.java

/**
 * This implementation of <code>accept</code> tests for the correct node type (attachment).
 * //ww  w .j a v a2 s  .c o  m
 * @see org.opencastproject.mediapackage.elementbuilder.MediaPackageElementBuilderPlugin#accept(org.w3c.dom.Node)
 */
public boolean accept(Node elementNode) {
    try {
        // Test for attachment
        String nodeName = elementNode.getNodeName();
        if (nodeName.contains(":")) {
            nodeName = nodeName.substring(nodeName.indexOf(":") + 1);
        }
        if (!MediaPackageElement.Type.Attachment.toString().equalsIgnoreCase(nodeName))
            return false;
        // Check flavor
        if (this.flavor != null) {
            String nodeFlavor = (String) xpath.evaluate("@type", elementNode, XPathConstants.STRING);
            if (!flavor.eq(nodeFlavor))
                return false;
        }
        // Check mime type
        if (mimeTypes != null && mimeTypes.size() > 0) {
            String nodeMimeType = (String) xpath.evaluate("mimetype", elementNode, XPathConstants.STRING);
            MimeType mimeType = MimeTypes.parseMimeType(nodeMimeType);
            if (!mimeTypes.contains(mimeType))
                return false;
        }

        return true;
    } catch (XPathExpressionException e) {
        logger.warn("Error while reading attachment flavor from manifest: " + e.getMessage());
        return false;
    }
}

From source file:org.opencastproject.mediapackage.elementbuilder.CatalogBuilderPlugin.java

/**
 * {@inheritDoc}// w  ww.  j  av a  2s  . c om
 * 
 * @see org.opencastproject.mediapackage.elementbuilder.MediaPackageElementBuilderPlugin#elementFromManifest(org.w3c.dom.Node,
 *      org.opencastproject.mediapackage.MediaPackageSerializer)
 */
@Override
public MediaPackageElement elementFromManifest(Node elementNode, MediaPackageSerializer serializer)
        throws UnsupportedElementException {
    String id = null;
    String flavor = null;
    URI url = null;
    long size = -1;
    Checksum checksum = null;
    MimeType mimeType = null;
    String reference = null;

    try {
        // id
        id = (String) xpath.evaluate("@id", elementNode, XPathConstants.STRING);

        // url
        url = serializer.resolvePath(xpath.evaluate("url/text()", elementNode).trim());

        // flavor
        flavor = (String) xpath.evaluate("@type", elementNode, XPathConstants.STRING);

        // reference
        reference = (String) xpath.evaluate("@ref", elementNode, XPathConstants.STRING);

        // size
        String documentSize = xpath.evaluate("size/text()", elementNode).trim();
        if (!"".equals(documentSize))
            size = Long.parseLong(documentSize);

        // checksum
        String checksumValue = (String) xpath.evaluate("checksum/text()", elementNode, XPathConstants.STRING);
        String checksumType = (String) xpath.evaluate("checksum/@type", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(checksumValue) && checksumType != null)
            checksum = Checksum.create(checksumType.trim(), checksumValue.trim());

        // mimetype
        String mimeTypeValue = (String) xpath.evaluate("mimetype/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(mimeTypeValue))
            mimeType = MimeTypes.parseMimeType(mimeTypeValue);

        // create the catalog
        Catalog dc = CatalogImpl.fromURI(url);
        if (StringUtils.isNotEmpty(id))
            dc.setIdentifier(id);

        // Add url
        dc.setURI(url);

        // Add flavor
        if (flavor != null)
            dc.setFlavor(MediaPackageElementFlavor.parseFlavor(flavor));

        // Add reference
        if (StringUtils.isNotEmpty(reference))
            dc.referTo(MediaPackageReferenceImpl.fromString(reference));

        // Set size
        if (size > 0)
            dc.setSize(size);

        // Set checksum
        if (checksum != null)
            dc.setChecksum(checksum);

        // Set Mimetype
        if (mimeType != null)
            dc.setMimeType(mimeType);

        // Tags
        NodeList tagNodes = (NodeList) xpath.evaluate("tags/tag", elementNode, XPathConstants.NODESET);
        for (int i = 0; i < tagNodes.getLength(); i++) {
            dc.addTag(tagNodes.item(i).getTextContent());
        }

        return dc;
    } catch (XPathExpressionException e) {
        throw new UnsupportedElementException(
                "Error while reading catalog information from manifest: " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        throw new UnsupportedElementException("Unsupported digest algorithm: " + e.getMessage());
    } catch (URISyntaxException e) {
        throw new UnsupportedElementException(
                "Error while reading dublin core catalog " + url + ": " + e.getMessage());
    }
}

From source file:org.opencastproject.mediapackage.elementbuilder.PublicationBuilderPlugin.java

@Override
public MediaPackageElement elementFromManifest(Node elementNode, MediaPackageSerializer serializer)
        throws UnsupportedElementException {

    String id = null;// ww w  . j ava2  s . c o m
    MimeType mimeType = null;
    MediaPackageElementFlavor flavor = null;
    String reference = null;
    String channel = null;
    URI url = null;
    long size = -1;
    Checksum checksum = null;

    try {
        // id
        id = (String) xpath.evaluate("@id", elementNode, XPathConstants.STRING);
        if (StringUtils.isEmpty(id)) {
            throw new UnsupportedElementException("Unvalid or missing id argument!");
        }

        // url
        url = serializer.resolvePath(xpath.evaluate("url/text()", elementNode).trim());

        // channel
        channel = (String) xpath.evaluate("@channel", elementNode).trim();
        if (StringUtils.isEmpty(channel)) {
            throw new UnsupportedElementException("Unvalid or missing channel argument!");
        }

        // reference
        reference = (String) xpath.evaluate("@ref", elementNode, XPathConstants.STRING);

        // size
        String trackSize = xpath.evaluate("size/text()", elementNode).trim();
        if (!"".equals(trackSize))
            size = Long.parseLong(trackSize);

        // flavor
        String flavorValue = (String) xpath.evaluate("@type", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(flavorValue))
            flavor = MediaPackageElementFlavor.parseFlavor(flavorValue);

        // checksum
        String checksumValue = (String) xpath.evaluate("checksum/text()", elementNode, XPathConstants.STRING);
        String checksumType = (String) xpath.evaluate("checksum/@type", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(checksumValue) && checksumType != null)
            checksum = Checksum.create(checksumType.trim(), checksumValue.trim());

        // mimetype
        String mimeTypeValue = (String) xpath.evaluate("mimetype/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(mimeTypeValue)) {
            mimeType = MimeTypes.parseMimeType(mimeTypeValue);
        } else {
            throw new UnsupportedElementException("Unvalid or missing mimetype argument!");
        }

        // Build the publication element
        PublicationImpl publication = new PublicationImpl(id, channel, url, mimeType);

        if (StringUtils.isNotBlank(id))
            publication.setIdentifier(id);

        // Add url
        publication.setURI(url);

        // Add reference
        if (StringUtils.isNotEmpty(reference))
            publication.referTo(MediaPackageReferenceImpl.fromString(reference));

        // Set size
        if (size > 0)
            publication.setSize(size);

        // Set checksum
        if (checksum != null)
            publication.setChecksum(checksum);

        // Set mimetpye
        if (mimeType != null)
            publication.setMimeType(mimeType);

        if (flavor != null)
            publication.setFlavor(flavor);

        // description
        String description = (String) xpath.evaluate("description/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotBlank(description))
            publication.setElementDescription(description.trim());

        // tags
        NodeList tagNodes = (NodeList) xpath.evaluate("tags/tag", elementNode, XPathConstants.NODESET);
        for (int i = 0; i < tagNodes.getLength(); i++) {
            publication.addTag(tagNodes.item(i).getTextContent());
        }

        return publication;
    } catch (XPathExpressionException e) {
        throw new UnsupportedElementException(
                "Error while reading track information from manifest: " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        throw new UnsupportedElementException("Unsupported digest algorithm: " + e.getMessage());
    } catch (URISyntaxException e) {
        throw new UnsupportedElementException(
                "Error while reading presenter track " + url + ": " + e.getMessage());
    }
}

From source file:org.openengsb.openengsbplugin.Checkstyle.java

@Override
protected final void modifyMojoConfiguration(String pomPath, Document configuredPom)
        throws MojoExecutionException {
    if (pomPath.equals("pom.xml")) {
        try {/*from ww  w  .ja  v  a  2  s. co m*/
            checkstyleCheckerConfigTmp = createCheckstyleCheckerConfiguration();
            FILES_TO_REMOVE_FINALLY.add(checkstyleCheckerConfigTmp);
            insertCheckstyleConfigLocation(configuredPom, cocProfileXpath, checkstyleCheckerConfigTmp);
        } catch (XPathExpressionException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
}

From source file:org.openengsb.openengsbplugin.Eclipse.java

@Override
protected void modifyMojoConfiguration(String pomPath, Document configuredPom) throws MojoExecutionException {
    if (pomPath.equals("pom.xml")) {
        try {/*from  w ww .  j a v a 2s . c  o  m*/
            File checkstyleEclipseConfig = writeCheckstyleEclipseConfigAndSetCheckerConfigPath();
            FILES_TO_REMOVE_FINALLY.add(checkstyleEclipseConfig);
            setCheckstyleEclipseConfigLocation(configuredPom, cocProfileXpath,
                    checkstyleEclipseConfig.getAbsolutePath());
        } catch (XPathExpressionException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
}