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:br.com.sistemapetshop.util.WebServiceCep.java

/**
 * Faz uma busca a partir do cep enviado, no site
 * <a href="http://www.republicavirtual.com.br"
 * target="_blank">republicavirtual.com.br</a>, retornando o resultado em um
 * objeto {@link WebServiceCep}./*from  www .j a  v a2 s.  co m*/
 * <BR>
 * <BR>No se faz necessrio formataes, a string pode ser enviada em
 * qualquer formatao, pois s sero consideradas os primeiros 8 numeros da
 * string.
 * <BR>Por Exemplo:
 * <BR>Uma <tt>{@link String} "14.568-910"</tt>  automaticamente passada
 * para
 * <tt>"14568910"</tt>.
 * <BR>Uma <tt>{@link String} "1%4#5?55%16a8&910"</tt>  automaticamente
 * passada para
 * <tt>"14555168"</tt>, s levando em conta os primeiros 8 nmeros.
 *
 * @param cep Nmero do cep a ser carregado. S sero considerados os
 * primeiros 8 nmeros da {@link String} enviada. Todos os caracters no
 * numricos sero removidos, e a string ser truncada caso seja maior que 8
 * caracters.
 * @return {@link WebServiceCep} contendo as informaes da pesquisa.
 */
public static WebServiceCep searchCep(String cep) {
    cep = cep.replaceAll("\\D*", ""); //To numeric digits only
    if (cep.length() > 8) {
        cep = cep.substring(0, 8);
    }
    WebServiceCep loadCep = new WebServiceCep(cep);
    try {
        XmlEnums enums = new XmlEnums();
        for (Element e : getElements(cep)) {
            enums.getXml(e.getQualifiedName()).setCep(e.getText(), loadCep);
        }
    } catch (DocumentException ex) {
        if (ex.getNestedException() != null
                && ex.getNestedException() instanceof java.net.UnknownHostException) {
            loadCep.setResultText("Site no encontrado.");
            loadCep.setResulCode(-14);
        } else {
            loadCep.setResultText("No foi possivel ler o documento xml.");
            loadCep.setResulCode(-15);
        }
        loadCep.setExceptio(ex);
    } catch (MalformedURLException ex) {
        loadCep.setExceptio(ex);
        loadCep.setResultText("Erro na formao da url.");
        loadCep.setResulCode(-16);
    } catch (Exception ex) {
        loadCep.setExceptio(ex);
        loadCep.setResultText("Erro inesperado.");
        loadCep.setResulCode(-17);
    }
    return loadCep;
}

From source file:classes.WebServiceCep.java

License:Open Source License

/**
 * Faz uma busca a partir do cep enviado, no site 
 * <a href="http://www.republicavirtual.com.br" 
 * target="_blank">republicavirtual.com.br</a>, retornando o resultado em um objeto
 * {@link WebServiceCep}.// w ww  . jav a2  s. c  o m
 * <BR>
 * <BR>No se faz necessrio formataes, a string pode ser enviada em qualquer
 * formatao, pois s sero consideradas os primeiros 8 numeros da string.
 * <BR>Por Exemplo:
 * <BR>Uma <tt>{@link String} "14.568-910"</tt>  automaticamente passada para
 * <tt>"14568910"</tt>.
 * <BR>Uma <tt>{@link String} "1%4#5?55%16a8&910"</tt>  automaticamente passada para
 * <tt>"14555168"</tt>, s levando em conta os primeiros 8 nmeros.
 * @param   cep Nmero do cep a ser carregado. S sero considerados os primeiros 8 
 *          nmeros da {@link String} enviada. Todos os caracters no numricos sero
 *          removidos, e a string ser truncada caso seja maior que 8 caracters.
 * @return {@link WebServiceCep} contendo as informaes da pesquisa.
 */
public static WebServiceCep searchCep(String cep) {
    cep = cep.replaceAll("\\D*", ""); //To numeric digits only
    if (cep.length() > 8)
        cep = cep.substring(0, 8);
    WebServiceCep loadCep = new WebServiceCep(cep);
    try {
        XmlEnums enums = new XmlEnums();
        for (Element e : getElements(cep))
            enums.getXml(e.getQualifiedName()).setCep(e.getText(), loadCep);
    } catch (DocumentException ex) {
        if (ex.getNestedException() != null
                && ex.getNestedException() instanceof java.net.UnknownHostException) {
            loadCep.setResultText("Site no encontrado.");
            loadCep.setResulCode(-14);
        } else {
            loadCep.setResultText("No foi possivel ler o documento xml.");
            loadCep.setResulCode(-15);
        }
        loadCep.setExceptio(ex);
    } catch (MalformedURLException ex) {
        loadCep.setExceptio(ex);
        loadCep.setResultText("Erro na formao da url.");
        loadCep.setResulCode(-16);
    } catch (Exception ex) {
        loadCep.setExceptio(ex);
        loadCep.setResultText("Erro inesperado.");
        loadCep.setResulCode(-17);
    }
    return loadCep;
}

From source file:com.arc.cdt.debug.seecode.internal.ui.GuihiliPage.java

License:Open Source License

private void createControlActual() {
    mCreated = false; // for benefit of property change listener
    fGUI.setFrame(mParentControl.getShell());
    IComponentFactory factory = UISeeCodePlugin.getWidgetFactory();
    fGUI.setComponentFactory(factory);/*w w w. ja  v  a2s  .c o m*/
    // ScrolledComposite scroller = new ScrolledComposite(mParentControl,SWT.V_SCROLL|SWT.H_SCROLL);
    // scroller.setExpandVertical(true);
    // scroller.setExpandHorizontal(true);
    Composite scroller = mParentControl;
    // We can't compute the Guihili panel until the
    // target machine is known.
    IContainer pane = factory.wrapContainer(scroller, IComponentFactory.NO_STYLE);
    MyLayout layout = new MyLayout();
    mParentControl.setLayout(layout);
    fGUI.setParent(pane);

    try {
        // Toggle.set("TRACE_GUI", true);
        fGUI.readXML("features");
    } catch (SAXParseException x) {
        String msg = "At " + x.getSystemId() + ", line " + x.getLineNumber();
        Exception e = x.getException();
        if (e != null)
            msg += ": " + e.getMessage();
        else
            msg += ": " + x.getMessage();
        setErrorMessage("Internal error:\n" + msg);
        String scdir = (String) fGUI.getEnvironment().getSymbolValue("SCDIR");
        if (scdir == null)
            scdir = "";
        else
            scdir = "(at " + scdir + ")";
        UISeeCodePlugin.showError("(Internal Error) Debugger Options File Parse Error",
                "A syntax error was detected in one of the MetaWare Debugger's Options\n" + "Description files "
                        + scdir + "\n\n" + msg);
    } catch (SAXException x) {
        Throwable e = x.getException();
        String msg;
        if (e != null) {
            if (e instanceof DocumentException) {
                DocumentException dx = (DocumentException) e;
                if (dx.getNestedException() != null) {
                    e = dx.getNestedException();
                }
            }
            msg = e.getMessage();
            if (msg == null || msg.trim().length() == 0) {
                msg = e.toString();
            }
        } else
            msg = x.toString();
        setErrorMessage("Form description error\n(" + msg + ")");
        String scdir = (String) fGUI.getEnvironment().getSymbolValue("SCDIR");
        if (scdir == null)
            scdir = "";
        else
            scdir = "(at " + scdir + ")";
        UISeeCodePlugin.showError("Debugger Installation Error",
                "The MetaWare debugger " + scdir
                        + "\nmay not be installed correctly or there is an internal error\n"
                        + "with one of its Debugger Options description files:\n\n" + msg);
    } catch (FileNotFoundException x) {
        if (x.getMessage() != null && x.getMessage().indexOf("feature") >= 0) {
            setErrorMessage("Can't find the debugger on the search path");
            UISeeCodePlugin.showError("Installation Error",
                    "Cannot find the MetaWare debugger on the search path");
        } else {
            setErrorMessage("The debugger seems to be missing option description files: " + x);
            String scdir = (String) fGUI.getEnvironment().getSymbolValue("SCDIR");
            if (scdir == null)
                scdir = "";
            else
                scdir = "(at " + scdir + ")";
            UISeeCodePlugin.showError("Installation Error",
                    "The MetaWare debugger " + scdir
                            + "\nmay not be installed correctly or there is an internal error\n"
                            + "with one of its Debugger Options description files:\n\n"
                            + "Cannot find the debugger description file: " + x);
        }
    } catch (Exception x) {
        setErrorMessage(x.toString());
        String scdir = (String) fGUI.getEnvironment().getSymbolValue("SCDIR");
        if (scdir == null)
            scdir = "";
        else
            scdir = "(at " + scdir + ") ";
        UISeeCodePlugin.showError("Options File Exception",
                "An unexpected exception occurred while reading a MetaWare Debugger\n" + scdir
                        + "Options Description file: " + x.toString());
    }
    Control[] children = scroller.getChildren();
    if (children.length > 0) { // should always be true
        // scroller.setMinSize(children[0].computeSize(SWT.DEFAULT,SWT.DEFAULT));
        // scroller.setContent(children[0]);
        constructOptionField(scroller);
    } else
        mOptions = null; // something messed up.
    mParentControl.layout(true);
    mCreated = true;
    mOriginalPropertyNames = fGUI.getPropertyNames(); // in case we need to revert.
    // If shell already rendered, then size may have increased; so we must
    // repack.
    // However, don't do it for Linux/GTK. For some reason, the dialog
    // just keeps getting wider and wider.
    // CORRECTON: packing just plain messes things up for some unknown reason.
    // The dialog gets pathalogically large on Windows with Eclipse 3.2
    // Just estimate a minimum size and reset the bounds without moving the
    // display, unless the display goes outside the screen
    if (mParentControl.getShell().isVisible()) {
        // NO. pack() has issues under Linux and under Windows with Eclipse 3.2
        // It causes the display to be pathologically large. Don't know why.
        // mParentControl.getShell().pack(true);
        Rectangle bounds = mParentControl.getShell().getBounds();
        Rectangle screenSize = mParentControl.getShell().getDisplay().getClientArea();
        boolean changed = false;
        if (bounds.width < MIN_PREFERRED_WIDTH) {
            bounds.width = Math.min(screenSize.width, MIN_PREFERRED_WIDTH);
            if (bounds.x + bounds.width > screenSize.width) {
                bounds.x = screenSize.width - bounds.width;
            }
            changed = true;
        }
        if (bounds.height < MIN_PREFERRED_HEIGHT) {
            bounds.height = Math.min(screenSize.height, MIN_PREFERRED_HEIGHT);
            if (bounds.y + bounds.height > screenSize.height) {
                bounds.y = screenSize.height - bounds.height;
            }
            changed = true;
        }
        if (changed)
            mParentControl.getShell().setBounds(bounds);
    }
    // printSizes(scroller,0);
}

From source file:com.cladonia.xml.XMLUtilities.java

License:Open Source License

public static synchronized XDocument parseRemote(URL url) throws IOException, SAXParseException {
    if (DEBUG)//  w  w w .jav a  2 s.c o m
        System.out.println("XMLUtilities.parseRemote( " + url + ")");

    XDocument document = null;

    try {
        SAXReader reader = getReader(false);

        URLConnection connection = (URLConnection) url.openConnection();
        connection.setDefaultUseCaches(false);
        connection.setUseCaches(false);
        connection.connect();
        InputStream stream = connection.getInputStream();

        XMLReader xmlReader = replaceAmp(url);

        document = (XDocument) reader.read(xmlReader, url.toString());

        document.setEncoding(xmlReader.getEncoding());
        document.setVersion(xmlReader.getVersion());

        stream.close();
    } catch (DocumentException e) {
        Exception x = (Exception) e.getNestedException();

        if (x instanceof SAXParseException) {
            SAXParseException spe = (SAXParseException) x;
            Exception ex = spe.getException();

            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (SAXParseException) x;
            }
        } else if (x instanceof IOException) {
            throw (IOException) x;
        }
    }

    return document;
}

From source file:com.cladonia.xml.XMLUtilities.java

License:Open Source License

private static synchronized XDocument parse(SAXReader reader, XMLReader xmlReader, String systemId)
        throws IOException, SAXParseException {
    if (DEBUG)/*from   w  w w . j  a  va2s. com*/
        System.out.println("XMLUtilities.parse( " + xmlReader + ", " + systemId + ")");

    XDocument document = null;

    try {
        document = (XDocument) reader.read(xmlReader, systemId);

        document.setEncoding(xmlReader.getEncoding());
        document.setVersion(xmlReader.getVersion());

    } catch (DocumentException e) {
        Exception x = (Exception) e.getNestedException();

        if (x instanceof SAXParseException) {
            SAXParseException spe = (SAXParseException) x;
            Exception ex = spe.getException();

            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (SAXParseException) x;
            }
        } else if (x instanceof IOException) {
            throw (IOException) x;
        }
    }

    return document;
}

From source file:com.cladonia.xml.XMLUtilities.java

License:Open Source License

/**
 * Validates the document for this URL./*from  w w  w  .ja va 2  s  .  c o m*/
 *
 * @param url the URL of the document.
 *
 * @return the Dom4J document.
 */
public static synchronized void validate(URL url) throws IOException, SAXParseException {
    if (DEBUG)
        System.out.println("XMLUtilities.validate( " + url + ")");

    try {
        SAXReader reader = getReader(true);
        reader.read(url);

    } catch (DocumentException e) {
        Exception x = (Exception) e.getNestedException();

        if (x instanceof SAXParseException) {
            SAXParseException spe = (SAXParseException) x;
            Exception ex = spe.getException();

            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (SAXParseException) x;
            }
        } else if (x instanceof IOException) {
            throw (IOException) x;
        }
    }
}

From source file:com.cladonia.xml.XMLUtilities.java

License:Open Source License

/**
 * Validates the document for this URL.//from   w ww  .  j a  v a 2  s  .  co m
 *
 * @param url the URL of the document.
 *
 * @return the Dom4J document.
 */
public static synchronized XDocument validate(ErrorHandler handler, BufferedReader isReader, String systemId)
        throws IOException, SAXParseException {
    if (DEBUG)
        System.out.println("DocumentUtilities.validate( " + isReader + ", " + systemId + ")");

    XDocument document = null;

    try {
        SAXReader reader = createReader(true, false);
        reader.setEntityResolver(getCatalogResolver());
        reader.setErrorHandler(handler);
        String encoding = null;

        try {
            isReader.mark(1024);
            encoding = getXMLDeclaration(isReader).getEncoding();
            //         } catch ( NotXMLException e) {
            //            e.printStackTrace();
            //            throw( e);
        } finally {
            isReader.reset();
        }

        XMLReader xmlReader = createReader(isReader, encoding);

        document = (XDocument) reader.read(xmlReader, systemId);

        document.setEncoding(xmlReader.getEncoding());
        document.setVersion(xmlReader.getVersion());

    } catch (DocumentException e) {
        Exception x = (Exception) e.getNestedException();

        if (x instanceof SAXParseException) {
            SAXParseException spe = (SAXParseException) x;
            Exception ex = spe.getException();

            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (SAXParseException) x;
            }
        } else if (x instanceof IOException) {
            throw (IOException) x;
        }
    }

    return document;
}

From source file:org.adempierelbr.util.WebServiceCep.java

License:Open Source License

/**
 * Faz uma busca a partir do cep enviado, no site 
 * <a href="http://www.republicavirtual.com.br" 
 * target="_blank">republicavirtual.com.br</a>, retornando o resultado em um objeto
 * {@link WebServiceCep}./*from  w  w  w  .j  av  a  2s  .c o m*/
 * <BR>
 * <BR>No se faz necessrio formataes, a string pode ser enviada em qualquer
 * formatao, pois s sero consideradas os primeiros 8 numeros da string.
 * <BR>Por Exemplo:
 * <BR>Uma <tt>{@link String} "14.568-910"</tt>  automaticamente passada para
 * <tt>"14568910"</tt>.
 * <BR>Uma <tt>{@link String} "1%4#5?55%16a8&910"</tt>  automaticamente passada para
 * <tt>"14555168"</tt>, s levando em conta os primeiros 8 nmeros.
 * @param   cep Nmero do cep a ser carregado. S sero considerados os primeiros 8 
 *          nmeros da {@link String} enviada. Todos os caracters no numricos sero
 *          removidos, e a string ser truncada caso seja maior que 8 caracters.
 * @return {@link WebServiceCep} contendo as informaes da pesquisa.
 */
public static WebServiceCep searchCep(String cep) {
    cep = cep.replaceAll("\\D*", ""); //To numeric digits only
    if (cep.length() > 8)
        cep = cep.substring(0, 8);
    WebServiceCep loadCep = new WebServiceCep(cep);
    try {
        XmlEnums enums = new XmlEnums();
        for (Element e : getElements(cep))
            enums.getXml(e.getQualifiedName()).setCep(e.getText(), loadCep);
    } catch (DocumentException ex) {
        if (ex.getNestedException() != null
                && ex.getNestedException() instanceof java.net.UnknownHostException) {
            loadCep.setResultText("Site no encontrado.");
            loadCep.setResulCode(-14);
        } else {
            loadCep.setResultText("No foi possivel ler o documento xml.");
            loadCep.setResulCode(-15);
        }
        loadCep.setExceptio(ex);
    } catch (MalformedURLException ex) {
        loadCep.setExceptio(ex);
        loadCep.setResultText("Erro na formao da url.");
        loadCep.setResulCode(-16);
    } catch (Exception ex) {
        loadCep.setExceptio(ex);
        loadCep.setResultText("Erro inesperado.");
        loadCep.setResulCode(-17);
    }
    return loadCep;
}

From source file:org.dom4j.samples.AbstractDemo.java

License:Open Source License

protected static void run(AbstractDemo demo, String[] args) {
    try {//from w  w w  . j a v  a  2  s  .c  o  m
        demo.run(args);
    } 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.dom4j.samples.validate.JARVDemo.java

License:Open Source License

public void run(String[] args) {
    try {/*w  w w  .jav a 2  s.c o m*/
        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 = new SAXReader();
        Document document = reader.read(xmlFile);
        process(document, schema);
    } 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();
    }
}