Example usage for org.xml.sax SAXParseException getSystemId

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

Introduction

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

Prototype

public String getSystemId() 

Source Link

Document

Get the system identifier of the entity where the exception occurred.

Usage

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

/**
 * parsing error./*w ww.ja  v  a2s  . c  om*/
 *
 * @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  w w . jav  a  2s.  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.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  www .  java2 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 {//from ww w  .j a v  a  2 s.  c o  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.oclc.os.SRW.SRUServerTester.java

public Document renderXML(String record) {
    Document document;/*from  w  ww.  j  a  v  a2  s . c om*/
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    //factory.setValidating(true);
    factory.setNamespaceAware(true);
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(new org.xml.sax.ErrorHandler() {
            // ignore fatal errors (an exception is guaranteed)
            @Override
            public void fatalError(SAXParseException exception) throws SAXException {
            }

            // treat validation errors as fatal   
            @Override
            public void error(SAXParseException e) throws SAXParseException {
                throw e;
            }

            // dump warnings too   
            @Override
            public void warning(SAXParseException err) throws SAXParseException {
                out("** Warning");
                out(", line ");
                out(err.getLineNumber());
                out(", uri ");
                out(err.getSystemId());
                out('\n');
                out("   ");
                out(err.getMessage());
                out('\n');
            }
        });
        document = builder.parse(new InputSource(new StringReader(record)));
    } catch (java.io.IOException e) {
        out("</pre><pre class='red'>");
        out("test failed: unable to parse record: ");
        out(e.getMessage());
        out('\n');
        out(record);
        out('\n');
        out("</pre><pre>");
        return null;
    } catch (javax.xml.parsers.ParserConfigurationException e) {
        out("</pre><pre class='red'>");
        out("test failed: unable to parse record: ");
        out(e.getMessage());
        out('\n');
        out(record);
        out('\n');
        out("</pre><pre>");
        return null;
    } catch (org.xml.sax.SAXException e) {
        out("</pre><pre class='red'>");
        out("test failed: unable to parse record: ");
        out(e.getMessage());
        out('\n');
        out(record);
        out('\n');
        out("</pre><pre>");
        return null;
    }
    return document;
}

From source file:org.orbeon.oxf.xml.dom4j.LocationData.java

public LocationData(SAXParseException exception) {
    systemID = exception.getSystemId();
    line = exception.getLineNumber();
    col = exception.getColumnNumber();
}

From source file:org.sakaibrary.osid.repository.xserver.AssetIterator.java

/**
 * This method parses the xml StringBuilder and creates Assets, Records
 * and Parts in the Repository with the given repositoryId.
 *
 * @param xml input xml in "sakaibrary" format
 * @param log the log being used by the Repository
 * @param repositoryId the Id of the Repository in which to create Assets,
 * Records and Parts./*w  w w .  j a va  2  s.c o m*/
 *
 * @throws org.osid.repository.RepositoryException
 */
private void createAssets(java.io.ByteArrayInputStream xml, org.osid.shared.Id repositoryId)
        throws org.osid.repository.RepositoryException {
    this.repositoryId = repositoryId;
    recordStructureId = RecordStructure.getInstance().getId();
    textBuffer = new StringBuilder();

    // use a SAX parser
    javax.xml.parsers.SAXParserFactory factory;
    javax.xml.parsers.SAXParser saxParser;

    // set up the parser
    factory = javax.xml.parsers.SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);

    // start parsing
    try {
        saxParser = factory.newSAXParser();
        saxParser.parse(xml, this);
        xml.close();
    } catch (SAXParseException spe) {
        // Use the contained exception, if any
        Exception x = spe;

        if (spe.getException() != null) {
            x = spe.getException();
        }

        // Error generated by the parser
        LOG.warn("createAssets() parsing exception: " + spe.getMessage() + " - xml line " + spe.getLineNumber()
                + ", uri " + spe.getSystemId(), x);
    } catch (SAXException sxe) {
        // Error generated by this application
        // (or a parser-initialization error)
        Exception x = sxe;

        if (sxe.getException() != null) {
            x = sxe.getException();
        }

        LOG.warn("createAssets() SAX exception: " + sxe.getMessage(), x);
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        LOG.warn("createAssets() SAX parser cannot be built with " + "specified options");
    } catch (IOException ioe) {
        // I/O error
        LOG.warn("createAssets() IO exception", ioe);
    }
}

From source file:org.sakaibrary.xserver.XMLCleanup.java

public ByteArrayOutputStream cleanup(InputStream xml) throws XServerException {
    inputXml = xml;//from  w  w  w  .  ja  va 2 s. c o m

    // Use the default (non-validating) parser
    SAXParserFactory factory = SAXParserFactory.newInstance();

    try {
        // Parse the input
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(inputXml, this);

        // close the stream
        inputXml.close();
    } catch (SAXParseException spe) {
        // Use the contained exception, if any
        Exception x = spe;

        if (spe.getException() != null) {
            x = spe.getException();
        }

        // Error generated by the parser
        LOG.warn("XMLCleanup.cleanup() parsing exception: " + spe.getMessage() + " - xml line "
                + spe.getLineNumber() + ", uri " + spe.getSystemId(), x);
    } catch (SAXException sxe) {
        // Error generated by this application
        // (or a parser-initialization error)
        Exception x = sxe;

        if (sxe.getException() != null) {
            x = sxe.getException();
        }

        LOG.warn("XMLCleanup.cleanup() SAX exception: " + sxe.getMessage(), x);
    } catch (ParserConfigurationException pce) {
        // Parser with specified options can't be built
        LOG.warn("XMLCleanup.cleanup() SAX parser cannot be built with " + "specified options");
    } catch (IOException ioe) {
        // I/O error
        LOG.warn("XMLCleanup.cleanup() IO exception", ioe);
    } catch (Throwable t) {
        LOG.warn("XMLCleanup.cleanup() exception", t);
    }

    if (error) {
        throw new XServerException(error_code, error_text);
    }

    return bytes;
}

From source file:org.sakaibrary.xserver.XMLCleanup.java

public void warning(SAXParseException err) throws SAXParseException {
    LOG.warn("SAXParser warning" + ", xml line " + err.getLineNumber() + ", uri " + err.getSystemId());
    LOG.warn("   " + err.getMessage());
}

From source file:org.toobsframework.servlet.filters.compression.CompressionFilterDAO.java

private Element loadDocument(URL url) {
    Document doc = null;/*from   w  w  w  .  ja  v a 2 s .  c  o  m*/
    try {
        InputSource xmlInp = new InputSource(url.openStream());

        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
        doc = parser.parse(xmlInp);
        Element root = doc.getDocumentElement();
        root.normalize();
        return root;
    } catch (SAXParseException err) {
        log.fatal("CompressionFilterDAO ** Parsing error" + ", line " + err.getLineNumber() + ", uri "
                + err.getSystemId());
        log.fatal("CompressionFilterDAO error: " + err.getMessage());
    } catch (SAXException e) {
        log.fatal("CompressionFilterDAO error: " + e);
    } catch (java.net.MalformedURLException mfx) {
        log.fatal("CompressionFilterDAO error: " + mfx);
    } catch (java.io.IOException e) {
        log.fatal("CompressionFilterDAO error: " + e);
    } catch (Exception pce) {
        log.fatal("CompressionFilterDAO error: " + pce);
    }
    return null;
}