Example usage for org.xml.sax SAXParseException getLineNumber

List of usage examples for org.xml.sax SAXParseException getLineNumber

Introduction

In this page you can find the example usage for org.xml.sax SAXParseException getLineNumber.

Prototype

public int getLineNumber() 

Source Link

Document

The line number of the end of the text where the exception occurred.

Usage

From source file:org.jajuk.base.Collection.java

/**
 * parsing warning.//w ww.j av  a2  s  .  com
 *
 * @param spe 
 * @throws SAXException the SAX exception
 */
@Override
@SuppressWarnings("ucd")
//NOSONAR
public void warning(SAXParseException spe) throws SAXException {
    throw new SAXException(Messages.getErrorMessage(5) + " / " + spe.getSystemId() + "/" + spe.getLineNumber()
            + "/" + spe.getColumnNumber() + " : " + spe.getMessage());
}

From source file:org.jajuk.base.Collection.java

/**
 * parsing error.// w  w w. j av  a2  s.co m
 *
 * @param spe 
 * @throws SAXException the SAX exception
 */
@Override
@SuppressWarnings("ucd")
public void error(SAXParseException spe) throws SAXException {
    throw new SAXException(Messages.getErrorMessage(5) + " / " + spe.getSystemId() + "/" + spe.getLineNumber()
            + "/" + spe.getColumnNumber() + " : " + spe.getMessage());
}

From source file:org.jajuk.base.Collection.java

/**
 * parsing fatal error./*from w  ww .ja  v  a  2 s  .  c  o m*/
 *
 * @param spe 
 * @throws SAXException the SAX exception
 */
@Override
@SuppressWarnings("ucd")
public void fatalError(SAXParseException spe) throws SAXException {
    throw new SAXException(Messages.getErrorMessage(5) + " / " + spe.getSystemId() + "/" + spe.getLineNumber()
            + "/" + spe.getColumnNumber() + " : " + spe.getMessage());
}

From source file:org.jboss.web.tomcat.tc4.SingleSignOnContextConfig.java

/**
 * Process the application configuration file, if it exists.
 *///  ww w .j  a  v  a2  s.  co  m
private void applicationConfig() {

    // Open the application web.xml file, if it exists
    InputStream stream = null;
    ServletContext servletContext = context.getServletContext();
    if (servletContext != null)
        stream = servletContext.getResourceAsStream(Constants.ApplicationWebXml);
    if (stream == null) {
        log(sm.getString("contextConfig.applicationMissing"));
        return;
    }

    // Process the application web.xml file
    synchronized (webDigester) {
        try {
            URL url = servletContext.getResource(Constants.ApplicationWebXml);
            InputSource is = new InputSource(url.toExternalForm());
            is.setByteStream(stream);
            webDigester.setDebug(getDebug());
            if (context instanceof StandardContext) {
                ((StandardContext) context).setReplaceWelcomeFiles(true);
            }
            webDigester.clear();
            webDigester.push(context);
            webDigester.parse(is);
        } catch (SAXParseException e) {
            log(sm.getString("contextConfig.applicationParse"), e);
            log(sm.getString("contextConfig.applicationPosition", "" + e.getLineNumber(),
                    "" + e.getColumnNumber()));
            ok = false;
        } catch (Exception e) {
            log(sm.getString("contextConfig.applicationParse"), e);
            ok = false;
        } finally {
            try {
                if (stream != null) {
                    stream.close();
                }
            } catch (IOException e) {
                log(sm.getString("contextConfig.applicationClose"), e);
            }
        }
    }

}

From source file:org.kitodo.editor.XMLEditor.java

/**
 * Check and return whether the given String 'xmlCode' contains well formed XML
 * code or not.// ww w.j a  va  2 s  .  com
 *
 * @param facesContext
 *            the current FacesContext
 * @param uiComponent
 *            the component containing the String that is being validated
 * @param xmlCode
 *            XML code that will be validated
 * @return whether 'xmlCode' is well formed or not
 */
public boolean validateXMLConfiguration(FacesContext facesContext, UIComponent uiComponent, String xmlCode) {
    if (!Objects.equals(documentBuilder, null)) {
        InputSource inputSource = new InputSource(new StringReader(xmlCode));
        try {
            documentBuilder.parse(inputSource);
            return true;
        } catch (SAXParseException e) {
            // parse method throwing an SAXParseException means given xml code is not well
            // formed!
            String errorString = "Error while parsing XML: line = " + e.getLineNumber() + ", column = "
                    + e.getColumnNumber() + ": " + e.getMessage();
            FacesMessage errorMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, "XML parsing error",
                    errorString);
            facesContext.addMessage(uiComponent.getClientId(), errorMessage);
            logger.error(errorString);
            return false;
        } catch (SAXException e) {
            logger.error("SAXException: " + e.getMessage());
            return false;
        } catch (IOException e) {
            logger.error("IOException: " + e.getMessage());
            return false;
        }
    } else {
        logger.error("ERROR: document builder is null!");
        return false;
    }
}

From source file:org.kuali.core.db.torque.KualiXmlToAppData.java

/**
 * Parses a XML input file and returns a newly created and
 * populated Database structure./*from   w ww.  j  av a  2  s .co  m*/
 *
 * @param xmlFile The input file to parse.
 * @return Database populated by <code>xmlFile</code>.
 */
public KualiDatabase parseFile(String xmlFile) throws EngineException {
    try {
        // in case I am missing something, make it obvious
        if (!firstPass) {
            throw new Error("No more double pass");
        }
        // check to see if we alread have parsed the file
        if ((alreadyReadFiles != null) && alreadyReadFiles.contains(xmlFile)) {
            return database;
        } else if (alreadyReadFiles == null) {
            alreadyReadFiles = new Vector(3, 1);
        }

        // remember the file to avoid looping
        alreadyReadFiles.add(xmlFile);

        currentXmlFile = xmlFile;

        saxFactory.setValidating(false);
        SAXParser parser = saxFactory.newSAXParser();

        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(xmlFile);
        } catch (FileNotFoundException fnfe) {
            throw new FileNotFoundException(new File(xmlFile).getAbsolutePath());
        }
        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
        try {
            log.info("Parsing file: '" + (new File(xmlFile)).getName() + "'");
            InputSource is = new InputSource(bufferedInputStream);
            is.setSystemId(xmlFile);
            parser.parse(is, this);
        } finally {
            bufferedInputStream.close();
        }
    } catch (SAXParseException e) {
        throw new EngineException("Sax error on line " + e.getLineNumber() + " column " + e.getColumnNumber()
                + " : " + e.getMessage(), e);
    } catch (Exception e) {
        throw new EngineException(e);
    }
    if (!isExternalSchema) {
        firstPass = false;
    }
    database.doFinalInitialization();
    return database;
}

From source file:org.kuali.kfs.sys.exception.XmlErrorHandler.java

private String assembleMessage(String messageType, SAXParseException e) {
    StringBuffer message = new StringBuffer(messageType);
    message.append(" Parsing error was encountered on line ");
    message.append(e.getLineNumber());
    message.append(", column ");
    message.append(e.getColumnNumber());
    message.append(": ");
    message.append(e.getMessage());/* ww w.  ja  v  a  2  s .c  o m*/

    return message.toString();
}

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 {//from w ww. j a va2  s. c om
        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 {//from w  w  w .  ja  v  a2  s.c om
        // <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.mule.config.spring.AbstractSchemaValidationTestCase.java

protected void doTest(String config) throws SAXException, IOException {
    try {//from  www  .  j  a  v a  2 s .c  o m
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        schemaFactory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
        Schema schema = schemaFactory.newSchema(getSchemasAsSources());
        schema.newValidator().validate(load(config));
    } catch (SAXParseException ex) {
        System.err.println(MessageFormat.format("SAX parsing exception occurs at line {0}, column {1}",
                ex.getLineNumber(), ex.getColumnNumber()));
        throw ex;
    }
}