Example usage for org.dom4j DocumentException getNestedException

List of usage examples for org.dom4j DocumentException getNestedException

Introduction

In this page you can find the example usage for org.dom4j DocumentException getNestedException.

Prototype

@Deprecated
    public Throwable getNestedException() 

Source Link

Usage

From source file:org.dom4j.samples.validate.JARVDemo2.java

License:Open Source License

public void run(String[] args) {
    try {//from   w ww . j  av  a2 s  .  c  om
        if (args.length < 2) {
            System.out.println("usage: <xmlDoc> <schemaDoc>");
            System.out.println("Which validates the given XML document against the given schema document");
            System.out.println("The schema can be XML Schema, RelaxNG, Relax or TREX");
            return;
        }
        String xmlFile = args[0];
        String schema = args[1];

        SAXReader reader = createSAXReader(schema);
        Document document = reader.read(xmlFile);

        System.out.println("Parsed document: " + xmlFile + " correctly.");
    } catch (DocumentException e) {
        System.out.println("Exception occurred: " + e);
        Throwable nestedException = e.getNestedException();
        if (nestedException != null) {
            System.out.println("NestedException: " + nestedException);
            nestedException.printStackTrace();
        } else {
            e.printStackTrace();
        }
    } catch (Throwable t) {
        System.out.println("Exception occurred: " + t);
        t.printStackTrace();
    }
}

From source file:org.jboss.seam.wiki.util.XmlDeploymentHandler.java

License:LGPL

public Map<String, Element> getDescriptorsAsXmlElements() {
    // Lazy access to streams
    if (elements == null) {
        elements = new HashMap<String, Element>();
        for (FileDescriptor fileDescriptor : getResources()) {
            try {
                SAXReader saxReader = new SAXReader();
                saxReader.setMergeAdjacentText(true);

                if (isSchemaValidating()) {
                    saxReader.setEntityResolver(new DTDEntityResolver());
                    saxReader.setValidation(true);
                    saxReader.setFeature("http://apache.org/xml/features/validation/schema", true);
                }//from  w  w  w  .  j a va 2s . co  m

                elements.put(fileDescriptor.getName(),
                        saxReader.read(fileDescriptor.getUrl().openStream()).getRootElement());

            } catch (DocumentException dex) {
                Throwable nested = dex.getNestedException();
                if (nested != null) {
                    if (nested instanceof FileNotFoundException) {
                        throw new RuntimeException("Can't find schema/DTD reference for file: "
                                + fileDescriptor.getName() + "':  " + nested.getMessage(), dex);
                    } else if (nested instanceof UnknownHostException) {
                        throw new RuntimeException("Cannot connect to host from schema/DTD reference: "
                                + nested.getMessage() + " - check that your schema/DTD reference is current",
                                dex);
                    }
                }
                throw new RuntimeException("Could not parse XML file: " + fileDescriptor.getName(), dex);
            } catch (Exception ex) {
                throw new RuntimeException("Could not parse XML file: " + fileDescriptor.getName(), ex);
            }
        }
    }
    return elements;
}

From source file:org.localmatters.serializer.config.XmlSerializationParser.java

License:Apache License

/**
 * @see org.localmatters.serializer.config.SerializationParser#parse(java.io.InputStream)
 *//*  w  w  w .j av  a  2s  . co m*/
public Map<String, Serialization> parse(InputStream input) throws IOException {
    try {
        SerializationElementHandler handler = new SerializationElementHandler();

        SAXReader saxReader = new SAXReader();
        saxReader.addHandler("/" + SerializationElementHandler.TYPE_ROOT, handler);
        saxReader.setEncoding(getDefaultEncoding());
        saxReader.read(input);
        return handler.getSerializations();

    } catch (DocumentException e) {
        if (e.getNestedException() instanceof ConfigurationException) {
            throw (ConfigurationException) e.getNestedException();
        }
        throw new ConfigurationException("Unable to parse the serialization configuration!", e);
    } finally {
        IOUtils.closeQuietly(input);
    }
}

From source file:org.lushlife.guicexml.internal.xml.XML.java

License:Apache License

public static Element getRootElement(InputStream stream) throws DocumentException {
    try {/*w w w .j  av  a  2  s.c o  m*/
        SAXReader saxReader = new SAXReader();
        saxReader.setMergeAdjacentText(true);
        return saxReader.read(stream).getRootElement();
    } catch (DocumentException e) {
        Throwable nested = e.getNestedException();
        if (nested != null) {
            if (nested instanceof FileNotFoundException) {
                throw new RuntimeException("Can't find schema/DTD reference: " + nested.getMessage(), e);
            } else if (nested instanceof UnknownHostException) {
                throw new RuntimeException("Cannot connect to host from schema/DTD reference: "
                        + nested.getMessage() + " - check that your schema/DTD reference is current", e);
            }
        }
        throw e;
    }
}