Example usage for org.xml.sax SAXException getException

List of usage examples for org.xml.sax SAXException getException

Introduction

In this page you can find the example usage for org.xml.sax SAXException getException.

Prototype

public Exception getException() 

Source Link

Document

Return the embedded exception, if any.

Usage

From source file:org.hippoecm.repository.impl.SessionDecorator.java

@Override
public File exportEnhancedSystemViewPackage(final String parentAbsPath, final boolean recurse)
        throws IOException, RepositoryException {
    Item item = getItem(parentAbsPath);/* ww w.  ja  va  2s. c om*/
    if (!item.isNode()) {
        // there's a property, though not a node at the specified path
        throw new PathNotFoundException(parentAbsPath);
    }
    final File xml = File.createTempFile("esv", "xml");
    final Collection<File> binaries = new ArrayList<>();
    final FileOutputStream out = new FileOutputStream(xml);
    try {
        final ContentHandler handler = getExportContentHandler(out);
        postMountEnabled(false);
        new DereferencedSysViewSAXEventGenerator((Node) item, !recurse, handler, binaries).serialize();
        final EnhancedSystemViewPackage pckg = EnhancedSystemViewPackage.create(xml, binaries);
        return pckg.toZipFile();
    } catch (SAXException e) {
        if (e.getException() instanceof IOException) {
            throw (IOException) e.getException();
        }
        if (e.getException() instanceof RepositoryException) {
            throw (RepositoryException) e.getException();
        }
        throw new RepositoryException(e);
    } finally {
        postMountEnabled(true);
        IOUtils.closeQuietly(out);
        FileUtils.deleteQuietly(xml);
        for (File binary : binaries) {
            FileUtils.deleteQuietly(binary);
        }
    }
}

From source file:org.j2free.error.HoptoadNotifier.java

/**
 * Looks up and returns the root cause of an exception. If none is found, returns
 * supplied Throwable object unchanged. If root is found, recursively "unwraps" it,
 * and returns the result to the user./* w  w  w . j  a  v  a 2  s .c  o  m*/
 */
private Throwable unwindException(Throwable thrown) {
    if (thrown instanceof SAXException) {
        SAXException saxe = (SAXException) thrown;
        if (saxe.getException() != null)
            return unwindException(saxe.getException());
    } else if (thrown instanceof SQLException) {
        SQLException sqle = (SQLException) thrown;
        if (sqle.getNextException() != null)
            return unwindException(sqle.getNextException());
    } else if (thrown.getCause() != null)
        return unwindException(thrown.getCause());

    return thrown;
}

From source file:org.jahia.services.content.JCRSessionWrapper.java

/**
 * Calls {@link Session#exportDocumentView(String, ContentHandler, boolean, boolean)}
 * with the given arguments and a {@link ContentHandler} that serializes
 * SAX events to the given output stream.
 *
 * @param absPath    passed through/*from  w  ww .j  a v a  2  s.  c o m*/
 * @param out        output stream to which the SAX events are serialized
 * @param skipBinary passed through
 * @param noRecurse  passed through
 * @throws IOException         if the SAX serialization failed
 * @throws RepositoryException if another error occurs
 */
public void exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
        throws IOException, RepositoryException {
    try {
        ContentHandler handler = getExportContentHandler(out);
        exportDocumentView(absPath, handler, skipBinary, noRecurse);
    } catch (SAXException e) {
        Exception exception = e.getException();
        if (exception instanceof RepositoryException) {
            throw (RepositoryException) exception;
        } else if (exception instanceof IOException) {
            throw (IOException) exception;
        } else {
            throw new RepositoryException("Error serializing document view XML", e);
        }
    }
}

From source file:org.jahia.services.content.JCRSessionWrapper.java

/**
 * Calls {@link Session#exportSystemView(String, ContentHandler, boolean, boolean)}
 * with the given arguments and a {@link ContentHandler} that serializes
 * SAX events to the given output stream.
 *
 * @param absPath    passed through//from  w  w  w  . j a va2  s .  c  o  m
 * @param out        output stream to which the SAX events are serialized
 * @param skipBinary passed through
 * @param noRecurse  passed through
 * @throws IOException         if the SAX serialization failed
 * @throws RepositoryException if another error occurs
 */
public void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
        throws IOException, RepositoryException {
    try {
        ContentHandler handler = getExportContentHandler(out);
        exportSystemView(absPath, handler, skipBinary, noRecurse);
    } catch (SAXException e) {
        Exception exception = e.getException();
        if (exception instanceof RepositoryException) {
            throw (RepositoryException) exception;
        } else if (exception instanceof IOException) {
            throw (IOException) exception;
        } else {
            throw new RepositoryException("Error serializing system view XML", e);
        }
    }
}

From source file:org.kepler.sms.util.OntologyConfiguration.java

/**
 * Initialize the catalog TODO: read from config file
 *///from  www  .j a  v a2s.c o  m
public void initialize() {
    // load the index file
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        initializePaths();
        _document = builder.parse(INDEX_FILE);
        // System.out.println("Reading ontology file: " + new
        // File(INDEX_FILE).getAbsolutePath());
    } catch (SAXException sxe) {
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        x.printStackTrace();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:org.lnicholls.galleon.util.Configurator.java

private void loadDocument(AppManager appManager, File file) {
    ServerConfiguration serverConfiguration = Server.getServer().getServerConfiguration();
    // Need to handle previous version of configuration file
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    //factory.setValidating(true);
    //factory.setNamespaceAware(true);
    try {//w w  w  . j a v  a2  s  .  co m
        FileInputStream in = null;
        DocumentBuilder builder = factory.newDocumentBuilder();
        in = new FileInputStream(file);
        Document document = builder.parse(in);
        in.close();
        in = null;

        // <configuration>
        Node domNode = document.getFirstChild();
        if (log.isDebugEnabled())
            log.debug("document:" + domNode.getNodeName());

        if (domNode.getNodeName().equalsIgnoreCase(TAG_CONFIGURATION)) {
            NamedNodeMap namedNodeMap = domNode.getAttributes();
            if (namedNodeMap != null) {
                // Check for required attributes
                Node attribute = namedNodeMap.getNamedItem(ATTRIBUTE_VERSION);
                if (log.isDebugEnabled())
                    log.debug(domNode.getNodeName() + ":" + attribute.getNodeName() + "="
                            + attribute.getNodeValue());
                loadDocument(domNode, appManager);
                if (!attribute.getNodeValue().equals(serverConfiguration.getVersion()))
                    save(appManager);
            }
        }
    } catch (SAXParseException spe) {
        // Error generated by the parser
        log.error("Parsing error, line " + spe.getLineNumber() + ", uri " + spe.getSystemId());
        log.error("   " + spe.getMessage());
        Tools.logException(Configurator.class, spe);

        // Use the contained exception, if any
        Exception x = spe;
        if (spe.getException() != null)
            x = spe.getException();
        Tools.logException(Configurator.class, x);

    } catch (SAXException sxe) {
        // Error generated during parsing)
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        Tools.logException(Configurator.class, x);
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        log.error("Cannot get context" + file.getAbsolutePath());
        Tools.logException(Configurator.class, pce);
    } catch (IOException ioe) {
        // I/O error
        log.error("Cannot get context" + file.getAbsolutePath());
        Tools.logException(Configurator.class, ioe);
    } finally {
    }
}

From source file:org.lnicholls.galleon.util.Configurator.java

private void loadDocument(Node configurationNode, AppManager appManager) {
    ServerConfiguration serverConfiguration = Server.getServer().getServerConfiguration();
    try {//  ww w  .j  av a  2  s  . co m
        // <server>, <app>
        for (int i = 0; i < configurationNode.getChildNodes().getLength(); i++) {
            Node node = configurationNode.getChildNodes().item(i);
            if (log.isDebugEnabled())
                log.debug("node:" + node.getNodeName());

            if (node.getNodeType() == Node.ELEMENT_NODE) {
                if (node.getNodeName().equals(TAG_SERVER)) {
                    if (log.isDebugEnabled())
                        log.debug("Found server");
                    NamedNodeMap namedNodeMap = node.getAttributes();
                    if (namedNodeMap != null) {
                        Node attribute = namedNodeMap.getNamedItem(ATTRIBUTE_RELOAD);
                        // Required attributes
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            try {
                                int reload = Integer.parseInt(attribute.getNodeValue());
                                serverConfiguration.setReload(reload);
                            } catch (NumberFormatException ex) {
                                log.error("Invalid " + ATTRIBUTE_RELOAD + " for " + TAG_SERVER + ": "
                                        + attribute.getNodeValue());
                            }
                        }
                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_PORT);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            try {
                                int port = Integer.parseInt(attribute.getNodeValue());
                                serverConfiguration.setPort(port);
                            } catch (NumberFormatException ex) {
                                log.error("Invalid " + ATTRIBUTE_PORT + " for " + TAG_SERVER + ": "
                                        + attribute.getNodeValue());
                            }
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_HTTP_PORT);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            try {
                                int port = Integer.parseInt(attribute.getNodeValue());
                                serverConfiguration.setHttpPort(port);
                            } catch (NumberFormatException ex) {
                                log.error("Invalid " + ATTRIBUTE_HTTP_PORT + " for " + TAG_SERVER + ": "
                                        + attribute.getNodeValue());
                            }
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_TITLE);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            serverConfiguration.setName(attribute.getNodeValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_IP_ADDRESS);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            String address = attribute.getNodeValue();
                            // Fix IP address if needed
                            if (!Tools.isLocalAddress(address)) {
                                log.error("Invalid server IP address: " + address);
                                address = Tools.getLocalIpAddress();
                                log.debug("Changing IP address to: " + address);
                            }

                            serverConfiguration.setIPAddress(address);
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_PUBLIC_IP_ADDRESS);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            serverConfiguration.setPublicIPAddress(attribute.getNodeValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_PIN);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue().length());
                            serverConfiguration.setPin(attribute.getNodeValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_PASSWORD);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue().length());
                            serverConfiguration.setPassword(attribute.getNodeValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_SHUFFLE_ITEMS);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            serverConfiguration
                                    .setShuffleItems(Boolean.valueOf(attribute.getNodeValue()).booleanValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_GENERATE_THUMBNAILS);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            serverConfiguration.setGenerateThumbnails(
                                    Boolean.valueOf(attribute.getNodeValue()).booleanValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_RECORDINGS_PATH);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            serverConfiguration.setRecordingsPath(Tools
                                    .unEscapeXMLChars(URLDecoder.decode(attribute.getNodeValue(), ENCODING)));
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_MEDIA_ACCESS_KEY);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue().length());
                            serverConfiguration.setMediaAccessKey(attribute.getNodeValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_SKIN);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue().length());
                            serverConfiguration.setSkin(attribute.getNodeValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_DEBUG);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            serverConfiguration
                                    .setDebug(Boolean.valueOf(attribute.getNodeValue()).booleanValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_TIMEOUT);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            serverConfiguration.setDisableTimeout(
                                    Boolean.valueOf(attribute.getNodeValue()).booleanValue());
                        }

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_MENU);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            serverConfiguration
                                    .setMenu(Boolean.valueOf(attribute.getNodeValue()).booleanValue());
                        }
                    }
                } else if (node.getNodeName().equals(TAG_APP)) {
                    if (log.isDebugEnabled())
                        log.debug("Found app");
                    NamedNodeMap namedNodeMap = node.getAttributes();
                    if (namedNodeMap != null) {
                        String title = null;
                        String className = null;
                        Node attribute = namedNodeMap.getNamedItem(ATTRIBUTE_NAME);
                        // Check for required attributes
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            title = attribute.getNodeValue();
                        } else
                            log.error("Missing required " + ATTRIBUTE_NAME + " attribute for " + TAG_APP);

                        attribute = namedNodeMap.getNamedItem(ATTRIBUTE_CLASS);
                        if (attribute != null) {
                            if (log.isDebugEnabled())
                                log.debug(node.getNodeName() + ":" + attribute.getNodeName() + "="
                                        + attribute.getNodeValue());
                            className = attribute.getNodeValue();
                        } else
                            log.error("Missing required " + ATTRIBUTE_CLASS + " attribute for " + TAG_APP);

                        if (className != null) {
                            if (className.indexOf('$') != -1)
                                className = className.substring(0, className.indexOf('$'));
                            else
                                className = className.substring(0,
                                        className.length() - "Configuration".length());
                            Object appConfiguration = null;
                            Iterator appDescriptorIterator = appManager.getAppDescriptors().iterator();
                            while (appDescriptorIterator.hasNext()) {
                                AppDescriptor appDescriptor = (AppDescriptor) appDescriptorIterator.next();
                                if (appDescriptor.getClassName().equals(className)) {
                                    AppContext appContext = new AppContext(appDescriptor);
                                    if (appContext.getConfiguration() != null) {
                                        try {
                                            BeanReader beanReader = new BeanReader();
                                            beanReader.getXMLIntrospector().setAttributesForPrimitives(true);
                                            beanReader.registerBeanClass("app",
                                                    appContext.getConfiguration().getClass());

                                            ByteArrayOutputStream bos = new ByteArrayOutputStream();
                                            OutputFormat of = new OutputFormat("XML", ENCODING, true);
                                            XMLSerializer serializer = new XMLSerializer(bos, of);
                                            serializer.asDOMSerializer();
                                            serializer.serialize((Element) node);

                                            StringReader xmlReader = new StringReader(bos.toString());
                                            bos.close();

                                            appConfiguration = beanReader.parse(xmlReader);
                                            appContext.setConfiguration(appConfiguration);

                                            appManager.createApp(appContext);

                                            if (log.isDebugEnabled())
                                                log.debug("App=" + appContext);
                                        } catch (IntrospectionException ex) {
                                            log.error("Could not load app " + title + " (" + className + ")");
                                        }
                                    } else
                                        log.error("Could not find app " + title + " (" + className + ")");
                                }
                            }

                            if (appConfiguration == null) {
                                log.error("Could not find app " + title + " (" + className + ")");
                            }
                        }
                    }
                } else if (node.getNodeName().equals(TAG_TIVO)) {
                    if (log.isDebugEnabled())
                        log.debug("Found TiVo");
                    try {
                        BeanReader beanReader = new BeanReader();
                        beanReader.getXMLIntrospector().setAttributesForPrimitives(true);
                        beanReader.registerBeanClass("tivo", TiVo.class);

                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        OutputFormat of = new OutputFormat("XML", ENCODING, true);
                        XMLSerializer serializer = new XMLSerializer(bos, of);
                        serializer.asDOMSerializer();
                        serializer.serialize((Element) node);

                        StringReader xmlReader = new StringReader(bos.toString());
                        bos.close();

                        TiVo tivo = (TiVo) beanReader.parse(xmlReader);

                        serverConfiguration.addTiVo(tivo);

                        if (log.isDebugEnabled())
                            log.debug("TiVo=" + tivo);
                    } catch (IntrospectionException ex) {
                        log.error("Could not load tivo");
                    }
                } else if (node.getNodeName().equals(TAG_RULE)) {
                    if (log.isDebugEnabled())
                        log.debug("Found Rule");
                    try {
                        BeanReader beanReader = new BeanReader();
                        beanReader.getXMLIntrospector().setAttributesForPrimitives(true);
                        beanReader.registerBeanClass("rule", Rule.class);

                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        OutputFormat of = new OutputFormat("XML", ENCODING, true);
                        XMLSerializer serializer = new XMLSerializer(bos, of);
                        serializer.asDOMSerializer();
                        serializer.serialize((Element) node);

                        StringReader xmlReader = new StringReader(bos.toString());
                        bos.close();

                        Rule rule = (Rule) beanReader.parse(xmlReader);

                        serverConfiguration.addRule(rule);

                        if (log.isDebugEnabled())
                            log.debug("Rule=" + rule);
                    } catch (IntrospectionException ex) {
                        log.error("Could not load rule");
                    }
                } else if (node.getNodeName().equals(TAG_MUSIC_PLAYER_CONFIGURATION)) {
                    if (log.isDebugEnabled())
                        log.debug("Found Music Player Configuration");
                    try {
                        BeanReader beanReader = new BeanReader();
                        beanReader.getXMLIntrospector().setAttributesForPrimitives(true);
                        beanReader.registerBeanClass("musicPlayerConfiguration",
                                MusicPlayerConfiguration.class);

                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        OutputFormat of = new OutputFormat("XML", ENCODING, true);
                        XMLSerializer serializer = new XMLSerializer(bos, of);
                        serializer.asDOMSerializer();
                        serializer.serialize((Element) node);

                        StringReader xmlReader = new StringReader(bos.toString());
                        bos.close();

                        MusicPlayerConfiguration musicPlayerConfiguration = (MusicPlayerConfiguration) beanReader
                                .parse(xmlReader);

                        serverConfiguration.setMusicPlayerConfiguration(musicPlayerConfiguration);

                        if (log.isDebugEnabled())
                            log.debug("MusicPlayerConfiguration=" + musicPlayerConfiguration);
                    } catch (IntrospectionException ex) {
                        log.error("Could not load Music Player Configuration");
                    }
                } else if (node.getNodeName().equals(TAG_DATA_CONFIGURATION)) {
                    if (log.isDebugEnabled())
                        log.debug("Found Data Configuration");
                    try {
                        BeanReader beanReader = new BeanReader();
                        beanReader.getXMLIntrospector().setAttributesForPrimitives(true);
                        beanReader.registerBeanClass("dataConfiguration", DataConfiguration.class);

                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        OutputFormat of = new OutputFormat("XML", ENCODING, true);
                        XMLSerializer serializer = new XMLSerializer(bos, of);
                        serializer.asDOMSerializer();
                        serializer.serialize((Element) node);

                        StringReader xmlReader = new StringReader(bos.toString());
                        bos.close();

                        DataConfiguration dataConfiguration = (DataConfiguration) beanReader.parse(xmlReader);

                        serverConfiguration.setDataConfiguration(dataConfiguration);

                        if (log.isDebugEnabled())
                            log.debug("DataConfiguration=" + dataConfiguration);
                    } catch (IntrospectionException ex) {
                        log.error("Could not load Data Configuration");
                    }
                } else if (node.getNodeName().equals(TAG_GOBACK_CONFIGURATION)) {
                    if (log.isDebugEnabled())
                        log.debug("Found GoBack Configuration");
                    try {
                        BeanReader beanReader = new BeanReader();
                        beanReader.getXMLIntrospector().setAttributesForPrimitives(true);
                        beanReader.registerBeanClass("goBackConfiguration", GoBackConfiguration.class);

                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        OutputFormat of = new OutputFormat("XML", ENCODING, true);
                        XMLSerializer serializer = new XMLSerializer(bos, of);
                        serializer.asDOMSerializer();
                        serializer.serialize((Element) node);

                        StringReader xmlReader = new StringReader(bos.toString());
                        bos.close();

                        GoBackConfiguration goBackConfiguration = (GoBackConfiguration) beanReader
                                .parse(xmlReader);

                        serverConfiguration.setGoBackConfiguration(goBackConfiguration);

                        if (log.isDebugEnabled())
                            log.debug("GoBackConfiguration=" + goBackConfiguration);
                    } catch (IntrospectionException ex) {
                        log.error("Could not load GoBack Configuration");
                    }
                } else if (node.getNodeName().equals(TAG_DOWNLOAD_CONFIGURATION)) {
                    if (log.isDebugEnabled())
                        log.debug("Found Download Configuration");
                    try {
                        BeanReader beanReader = new BeanReader();
                        beanReader.getXMLIntrospector().setAttributesForPrimitives(true);
                        beanReader.registerBeanClass("downloadConfiguration", DownloadConfiguration.class);

                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        OutputFormat of = new OutputFormat("XML", ENCODING, true);
                        XMLSerializer serializer = new XMLSerializer(bos, of);
                        serializer.asDOMSerializer();
                        serializer.serialize((Element) node);

                        StringReader xmlReader = new StringReader(bos.toString());
                        bos.close();

                        DownloadConfiguration downloadConfiguration = (DownloadConfiguration) beanReader
                                .parse(xmlReader);

                        serverConfiguration.setDownloadConfiguration(downloadConfiguration);

                        if (log.isDebugEnabled())
                            log.debug("DownloadConfiguration=" + downloadConfiguration);
                    } catch (IntrospectionException ex) {
                        log.error("Could not load Download Configuration");
                    }
                }
            }
        }
    } catch (SAXParseException spe) {
        // Error generated by the parser
        log.error("Parsing error, line " + spe.getLineNumber() + ", uri " + spe.getSystemId());
        log.error("   " + spe.getMessage());
        Tools.logException(Configurator.class, spe);

        // Use the contained exception, if any
        Exception x = spe;
        if (spe.getException() != null)
            x = spe.getException();
        Tools.logException(Configurator.class, x);

    } catch (SAXException sxe) {
        // Error generated during parsing)
        Exception x = sxe;
        if (sxe.getException() != null)
            x = sxe.getException();
        Tools.logException(Configurator.class, x);
    } catch (IOException ioe) {
        // I/O error
        Tools.logException(Configurator.class, ioe, "Cannot get context");
    } catch (Exception ioe) {
        // I/O error
        Tools.logException(Configurator.class, ioe, "Cannot get context");
    } finally {
    }
}

From source file:org.nuxeo.ecm.platform.xmlrpc.connector.NuxeoXmlRpcServletServer.java

/**
 * Same as base class method, but with an additionnal parameter
 * that contains component name extracted from request.
 *
 * @param pConfig/*  w  w w . j  a  v a 2 s .  c om*/
 * @param pStream
 * @param handlerPrefix componentName extracted from request
 * @return
 * @throws XmlRpcException
 */
protected XmlRpcRequest getRequest(final XmlRpcStreamRequestConfig pConfig, InputStream pStream,
        final String handlerPrefix) throws XmlRpcException {

    final XmlRpcRequestParser parser = new XmlRpcRequestParser(pConfig, getTypeFactory());
    final XMLReader xr = SAXParsers.newXMLReader();
    xr.setContentHandler(parser);
    try {
        xr.parse(new InputSource(pStream));
    } catch (SAXException e) {
        Exception ex = e.getException();
        if (ex != null && ex instanceof XmlRpcException) {
            throw (XmlRpcException) ex;
        }
        throw new XmlRpcException("Failed to parse XML-RPC request: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new XmlRpcException("Failed to read XML-RPC request: " + e.getMessage(), e);
    }
    final List params = parser.getParams();
    return new XmlRpcRequest() {
        public XmlRpcRequestConfig getConfig() {
            return pConfig;
        }

        public String getMethodName() {
            String mName = parser.getMethodName();
            if (handlerPrefix == null || "".equals(handlerPrefix)) {
                return mName;
            } else {
                return handlerPrefix + '.' + mName;
            }
        }

        public int getParameterCount() {
            return params == null ? 0 : params.size();
        }

        public Object getParameter(int pIndex) {
            return params.get(pIndex);
        }
    };
}

From source file:org.objectstyle.cayenne.util.Util.java

/**
 * Looks up and returns the root cause of an exception. If none is found, 
 * returns supplied Throwable object unchanged. If root is found,
 * recursively "unwraps" it, and returns the result to the user.
 *//*from  w w  w.  j  av a  2  s . c  om*/
public static Throwable unwindException(Throwable th) {
    if (th instanceof CayenneException) {
        CayenneException e = (CayenneException) th;
        if (e.getCause() != null) {
            return unwindException(e.getCause());
        }
    } else if (th instanceof CayenneRuntimeException) {
        CayenneRuntimeException e = (CayenneRuntimeException) th;
        if (e.getCause() != null) {
            return unwindException(e.getCause());
        }
    } else if (th instanceof InvocationTargetException) {
        InvocationTargetException e = (InvocationTargetException) th;
        if (e.getTargetException() != null) {
            return unwindException(e.getTargetException());
        }
    } else if (th instanceof SAXException) {
        SAXException sax = (SAXException) th;
        if (sax.getException() != null) {
            return unwindException(sax.getException());
        }
    } else if (th instanceof SQLException) {
        SQLException sql = (SQLException) th;
        if (sql.getNextException() != null) {
            return unwindException(sql.getNextException());
        }
    }

    return th;
}

From source file:org.openadaptor.auxil.processor.xml.XmlValidator.java

/**
   * Take the record, ensure it's a string and validate it against the schema
   * defined in the config file.//from  w ww . ja  v  a  2 s  .  co m
   *
   * @param data the XML to be validated
   *
   * @return Object[] with zero or more records, resulting from the processing
   *         operation.
   *
   * @throws RuntimeException if the record is not a string 
   * 
   * @throws ProcessingException if the record does not contain
   * valid XML or if it fails to be validated against the schema and 
   * enableXMLValidationException is false (default is false)
   *  
   * @throws XMLValidationException if the record does not contain
   * valid XML or if it fails to be validated against the schema and 
   * enableXMLValidationException is true (default is false)
   * 
   * Adaptors configured to catch ProcessingException will still catch them even if an 
   * XMLValidationException is thrown as XMLValidationException extends ProcessingException
   * 
   * The property enableXMLValidationException can be set to true if the user wants a XMLValidationException
   * instead of a ProcessingException 
   * 
   * The reasoning behind throwing a XMLValidationException instead of ProcessingException when 
   * the XML fails validation is to allow fine tuning of the exception handling
   *  
   */
public Object[] process(Object data) {
    if (!(data instanceof String)) {
        throw new RuntimeException("data is not a string");
    }

    try {
        if (log.isDebugEnabled()) {
            log.debug("Data to be validated: " + data);
        }
        in.setCharacterStream(new StringReader((String) data));
        parser.parse(in);
    } catch (SAXException se) {
        if (enableXMLValidationException() == true && se.getException() != null
                && se.getException() instanceof SAXParseException) {
            throw new XMLValidationException("xml is invalid", se, this);
        } else {
            throw new ProcessingException("xml is invalid", se, this);
        }
    } catch (Exception e) {
        throw new ProcessingException("xml is invalid", e, this);
    }

    log.debug("XML validated");
    return new Object[] { data };
}