Example usage for org.springframework.util.xml SimpleSaxErrorHandler SimpleSaxErrorHandler

List of usage examples for org.springframework.util.xml SimpleSaxErrorHandler SimpleSaxErrorHandler

Introduction

In this page you can find the example usage for org.springframework.util.xml SimpleSaxErrorHandler SimpleSaxErrorHandler.

Prototype

public SimpleSaxErrorHandler(Log logger) 

Source Link

Document

Create a new SimpleSaxErrorHandler for the given Commons Logging logger instance.

Usage

From source file:com.gfactor.jpa.core.MyPersistenceUnitReader.java

/**
 * Parse and build all persistence unit infos defined in the given XML files.
 * @param persistenceXmlLocations the resource locations (can be patterns)
 * @return the resulting PersistenceUnitInfo instances
 *//*from   w  w  w. j a  va2s .  c o m*/
public MySpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations) {
    ErrorHandler handler = new SimpleSaxErrorHandler(logger);
    List<MySpringPersistenceUnitInfo> infos = new LinkedList<MySpringPersistenceUnitInfo>();
    String resourceLocation = null;
    try {
        for (String location : persistenceXmlLocations) {
            Resource[] resources = this.resourcePatternResolver.getResources(location);
            for (Resource resource : resources) {
                resourceLocation = resource.toString();
                InputStream stream = resource.getInputStream();
                try {
                    Document document = buildDocument(handler, stream);
                    parseDocument(resource, document, infos);
                } finally {
                    stream.close();
                }
            }
        }
    } catch (IOException ex) {
        throw new IllegalArgumentException("Cannot parse persistence unit from " + resourceLocation, ex);
    } catch (SAXException ex) {
        throw new IllegalArgumentException("Invalid XML in persistence unit from " + resourceLocation, ex);
    } catch (ParserConfigurationException ex) {
        throw new IllegalArgumentException("Internal error parsing persistence unit from " + resourceLocation);
    }

    return infos.toArray(new MySpringPersistenceUnitInfo[infos.size()]);
}

From source file:com.diaimm.april.db.jpa.hibernate.multidbsupport.PersistenceUnitReader.java

/**
 * Parse and build all persistence unit infos defined in the given XML files.
 * @param persistenceXmlLocations the resource locations (can be patterns)
 * @return the resulting PersistenceUnitInfo instances
 *///from w ww.  j  ava2 s  .  com
public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations) {
    ErrorHandler handler = new SimpleSaxErrorHandler(logger);
    List<SpringPersistenceUnitInfo> infos = new LinkedList<SpringPersistenceUnitInfo>();
    String resourceLocation = null;
    try {
        for (String location : persistenceXmlLocations) {
            Resource[] resources = this.resourcePatternResolver.getResources(location);
            for (Resource resource : resources) {
                resourceLocation = resource.toString();
                InputStream stream = resource.getInputStream();
                try {
                    Document document = buildDocument(handler, stream);
                    parseDocument(resource, document, infos);
                } finally {
                    stream.close();
                }
            }
        }
    } catch (IOException ex) {
        throw new IllegalArgumentException("Cannot parse persistence unit from " + resourceLocation, ex);
    } catch (SAXException ex) {
        throw new IllegalArgumentException("Invalid XML in persistence unit from " + resourceLocation, ex);
    } catch (ParserConfigurationException ex) {
        throw new IllegalArgumentException("Internal error parsing persistence unit from " + resourceLocation);
    }

    return infos.toArray(new SpringPersistenceUnitInfo[infos.size()]);
}

From source file:com.apdplat.platform.spring.APDPlatPersistenceUnitReader.java

/**
 * Parse and build all persistence unit infos defined in the given XML files.
 * @param persistenceXmlLocations the resource locations (can be patterns)
 * @return the resulting PersistenceUnitInfo instances
 *///from w  w  w.j a v a2 s.  c o m
public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations) {
    ErrorHandler handler = new SimpleSaxErrorHandler(LogFactory.getLog(getClass()));
    List<SpringPersistenceUnitInfo> infos = new LinkedList<SpringPersistenceUnitInfo>();
    String resourceLocation = null;
    try {
        for (String location : persistenceXmlLocations) {
            Resource[] resources = this.resourcePatternResolver.getResources(location);
            for (Resource resource : resources) {
                resourceLocation = resource.toString();
                InputStream stream = resource.getInputStream();
                try {
                    Document document = buildDocument(handler, stream);
                    parseDocument(resource, document, infos);
                } finally {
                    stream.close();
                }
            }
        }
    } catch (IOException ex) {
        throw new IllegalArgumentException("Cannot parse persistence unit from " + resourceLocation, ex);
    } catch (SAXException ex) {
        throw new IllegalArgumentException("Invalid XML in persistence unit from " + resourceLocation, ex);
    } catch (ParserConfigurationException ex) {
        throw new IllegalArgumentException("Internal error parsing persistence unit from " + resourceLocation);
    }

    return infos.toArray(new SpringPersistenceUnitInfo[infos.size()]);
}

From source file:org.openehealth.ipf.platform.camel.core.dataformat.GnodeDataFormat.java

private XmlParser parser() throws Exception {
    XmlParser xmlParser = new XmlParser(saxParser());
    xmlParser.setErrorHandler(new SimpleSaxErrorHandler(LOG));
    return xmlParser;
}

From source file:org.openehealth.ipf.platform.camel.core.dataformat.GpathDataFormat.java

private XmlSlurper slurper() throws Exception {
    XmlSlurper slurper = new XmlSlurper(saxParser());
    slurper.setErrorHandler(new SimpleSaxErrorHandler(LOG));
    return slurper;
}

From source file:org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader.java

/**
 * Parse and build all persistence unit infos defined in the given XML files.
 * @param persistenceXmlLocations the resource locations (can be patterns)
 * @return the resulting PersistenceUnitInfo instances
 *//*from w w w  .  j a  v  a2s . c o  m*/
public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations) {
    ErrorHandler handler = new SimpleSaxErrorHandler(logger);
    List<SpringPersistenceUnitInfo> infos = new LinkedList<>();
    String resourceLocation = null;
    try {
        for (String location : persistenceXmlLocations) {
            Resource[] resources = this.resourcePatternResolver.getResources(location);
            for (Resource resource : resources) {
                resourceLocation = resource.toString();
                InputStream stream = resource.getInputStream();
                try {
                    Document document = buildDocument(handler, stream);
                    parseDocument(resource, document, infos);
                } finally {
                    stream.close();
                }
            }
        }
    } catch (IOException ex) {
        throw new IllegalArgumentException("Cannot parse persistence unit from " + resourceLocation, ex);
    } catch (SAXException ex) {
        throw new IllegalArgumentException("Invalid XML in persistence unit from " + resourceLocation, ex);
    } catch (ParserConfigurationException ex) {
        throw new IllegalArgumentException("Internal error parsing persistence unit from " + resourceLocation);
    }

    return infos.toArray(new SpringPersistenceUnitInfo[infos.size()]);
}

From source file:org.springframework.webflow.engine.model.builder.xml.DefaultDocumentLoader.java

public Document loadDocument(Resource resource) throws IOException, ParserConfigurationException, SAXException {
    InputStream is = null;//  www  .ja  va 2  s  . c om
    try {
        is = resource.getInputStream();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(isValidating());
        factory.setNamespaceAware(true);
        try {
            factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE, XSD_SCHEMA_LANGUAGE);
        } catch (IllegalArgumentException ex) {
            throw new IllegalStateException("Unable to validate using XSD: Your JAXP provider [" + factory
                    + "] does not support XML Schema. "
                    + "Are you running on Java 1.4 or below with Apache Crimson? "
                    + "If so you must upgrade to Apache Xerces (or Java 5 or >) for full XSD support.");
        }
        DocumentBuilder docBuilder = factory.newDocumentBuilder();
        docBuilder.setErrorHandler(new SimpleSaxErrorHandler(logger));
        docBuilder.setEntityResolver(getEntityResolver());
        return docBuilder.parse(is);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}

From source file:org.springmodules.remoting.xmlrpc.dom.AbstractDomXmlRpcParser.java

public AbstractDomXmlRpcParser() {
    super();
    setEntityResolver(new XmlRpcDtdResolver());
    setErrorHandler(new SimpleSaxErrorHandler(logger));
}

From source file:org.springmodules.remoting.xmlrpc.dom.AbstractDomXmlRpcWriter.java

public AbstractDomXmlRpcWriter() {
    super();
    setErrorHandler(new SimpleSaxErrorHandler(logger));
}