Search in sources :

Example 1 with XPathException

use of javax.xml.xpath.XPathException in project jdk8u_jdk by JetBrains.

the class XPathExceptionInitCause method unpickleXPE.

//Deserialize XPathException with byte array as serial data source
static XPathException unpickleXPE(byte[] ser) throws IOException, ClassNotFoundException {
    XPathException xpe;
    ByteArrayInputStream bis = new ByteArrayInputStream(ser);
    ObjectInputStream xpeis = new ObjectInputStream(bis);
    xpe = (XPathException) xpeis.readObject();
    xpeis.close();
    return xpe;
}
Also used : XPathException(javax.xml.xpath.XPathException) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with XPathException

use of javax.xml.xpath.XPathException in project jangaroo-tools by CoreMedia.

the class PomConverter method changePackaging.

/**
   * Changes the packaging from jangaroo to jangaroo-pkg in {@code /project/packaging}
   */
private static void changePackaging(Document document) throws MojoExecutionException {
    try {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        Node packagingNode = (Node) xPath.evaluate("/project/packaging[text() = 'jangaroo']", document, NODE);
        if (packagingNode != null) {
            packagingNode.setTextContent("jangaroo-pkg");
        }
    } catch (XPathException e) {
        throw new MojoExecutionException("error while generating modified POM", e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) XPathException(javax.xml.xpath.XPathException) Node(org.w3c.dom.Node)

Example 3 with XPathException

use of javax.xml.xpath.XPathException in project jangaroo-tools by CoreMedia.

the class PomConverter method removeExmlPlugin.

/**
   * Replaces exml-maven-plugin configuration by jangaroo-maven-plugin configuration within
   * {@code /project/build/plugins} and {@code /project/build/pluginManagement/plugins}.
   */
private static void removeExmlPlugin(Document document) throws MojoExecutionException {
    try {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        Node pluginsNode = (Node) xPath.evaluate("/project/build/plugins", document, NODE);
        removeExmlPlugin(pluginsNode);
        pluginsNode = (Node) xPath.evaluate("/project/build/pluginManagement/plugins", document, NODE);
        removeExmlPlugin(pluginsNode);
    } catch (XPathException e) {
        throw new MojoExecutionException("error while generating modified POM", e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) XPathException(javax.xml.xpath.XPathException) Node(org.w3c.dom.Node)

Example 4 with XPathException

use of javax.xml.xpath.XPathException in project bazel by bazelbuild.

the class ResourceUsageAnalyzer method createStubIds.

/**
   * Write stub values for IDs to values.xml to match those available in public.xml.
   */
private void createStubIds(File values, Map<File, String> rewritten, File publicXml) throws IOException, ParserConfigurationException, SAXException {
    if (values.exists()) {
        String xml = rewritten.get(values);
        if (xml == null) {
            xml = Files.toString(values, UTF_8);
        }
        List<String> stubbed = Lists.newArrayList();
        Document document = XmlUtils.parseDocument(xml, true);
        Element root = document.getDocumentElement();
        for (Resource resource : model.getResources()) {
            boolean inPublicXml = resource.declarations != null && resource.declarations.contains(publicXml);
            NodeList existing = null;
            try {
                XPathExpression expr = XPathFactory.newInstance().newXPath().compile(String.format("//item[@type=\"id\"][@name=\"%s\"]", resource.name));
                existing = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
            } catch (XPathException e) {
            // Failed to retrieve any existing declarations for resource.
            }
            if (resource.type == ResourceType.ID && inPublicXml && (existing == null || existing.getLength() == 0)) {
                Element item = document.createElement(TAG_ITEM);
                item.setAttribute(ATTR_TYPE, resource.type.getName());
                item.setAttribute(ATTR_NAME, resource.name);
                root.appendChild(item);
                stubbed.add(resource.getUrl());
            }
        }
        logger.fine("Created " + stubbed.size() + " stub IDs for:\n  " + Joiner.on(", ").join(stubbed));
        String formatted = XmlPrettyPrinter.prettyPrint(document, xml.endsWith("\n"));
        rewritten.put(values, formatted);
    }
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) XPathException(javax.xml.xpath.XPathException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Resource(com.android.tools.lint.checks.ResourceUsageModel.Resource) Document(org.w3c.dom.Document)

Example 5 with XPathException

use of javax.xml.xpath.XPathException in project jdk8u_jdk by JetBrains.

the class XPathExceptionInitCause method main.

public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");
    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause() + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }
    //Test serialization/deserialization of initialized XPE
    byte[] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage() + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage() + "' cause='" + xpedeser.getCause().toString() + "'");
    if (xpedeser.getCause() == null || !xpedeser.getCause().toString().equals(cause.toString()) || !xpedeser.getMessage().toString().equals("message 2"))
        throw new Exception("XPathException incorrectly serialized/deserialized");
    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage() + "' cause='" + xpeuninit.getCause() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage() + "' cause='" + xpedeser.getCause() + "'");
    if (xpedeser.getCause() != null || !xpedeser.getMessage().toString().equals("uninitialized cause"))
        throw new Exception("XPathException incorrectly serialized/deserialized");
    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if (xpejdk7 == null || xpejdk7.getCause() == null || !xpejdk7.getMessage().equals("message 2") || !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was " + "incorrectly deserialized.");
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't" + " observed");
    } catch (InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }
}
Also used : XPathException(javax.xml.xpath.XPathException) InvalidClassException(java.io.InvalidClassException) InvalidClassException(java.io.InvalidClassException) IOException(java.io.IOException) XPathException(javax.xml.xpath.XPathException)

Aggregations

XPathException (javax.xml.xpath.XPathException)5 XPath (javax.xml.xpath.XPath)2 XPathFactory (javax.xml.xpath.XPathFactory)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 Node (org.w3c.dom.Node)2 Resource (com.android.tools.lint.checks.ResourceUsageModel.Resource)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InvalidClassException (java.io.InvalidClassException)1 ObjectInputStream (java.io.ObjectInputStream)1 XPathExpression (javax.xml.xpath.XPathExpression)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1