Search in sources :

Example 31 with SAXParser

use of javax.xml.parsers.SAXParser in project grails-core by grails.

the class CorePluginFinder method loadCorePluginsFromResources.

@SuppressWarnings("rawtypes")
private void loadCorePluginsFromResources(Resource[] resources) throws IOException {
    LOG.debug("Attempting to load [" + resources.length + "] core plugins");
    try {
        SAXParser saxParser = SpringIOUtils.newSAXParser();
        for (Resource resource : resources) {
            InputStream input = null;
            try {
                input = resource.getInputStream();
                PluginHandler ph = new PluginHandler();
                saxParser.parse(input, ph);
                for (String pluginType : ph.pluginTypes) {
                    Class<?> pluginClass = attemptCorePluginClassLoad(pluginType);
                    if (pluginClass != null) {
                        addPlugin(pluginClass);
                        binaryDescriptors.put(pluginClass, new BinaryGrailsPluginDescriptor(resource, ph.pluginClasses));
                    }
                }
            } finally {
                if (input != null) {
                    input.close();
                }
            }
        }
    } catch (ParserConfigurationException e) {
        throw new GrailsConfigurationException("XML parsing error loading core plugins: " + e.getMessage(), e);
    } catch (SAXException e) {
        throw new GrailsConfigurationException("XML parsing error loading core plugins: " + e.getMessage(), e);
    }
}
Also used : GrailsConfigurationException(org.grails.core.exceptions.GrailsConfigurationException) InputStream(java.io.InputStream) UrlResource(org.springframework.core.io.UrlResource) Resource(org.springframework.core.io.Resource) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 32 with SAXParser

use of javax.xml.parsers.SAXParser in project groovy-core by groovy.

the class XmlUtil method newSAXParser.

/**
     * Factory method to create a SAXParser configured to validate according to a particular schema language and
     * optionally providing the schema sources to validate with.
     *
     * @param schemaLanguage the schema language used, e.g. XML Schema or RelaxNG (as per the String representation in javax.xml.XMLConstants)
     * @param namespaceAware will the parser be namespace aware
     * @param validating     will the parser also validate against DTDs
     * @param schemas        the schemas to validate against
     * @return the created SAXParser
     * @throws SAXException
     * @throws ParserConfigurationException
     * @since 1.8.7
     */
public static SAXParser newSAXParser(String schemaLanguage, boolean namespaceAware, boolean validating, Source... schemas) throws SAXException, ParserConfigurationException {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(validating);
    factory.setNamespaceAware(namespaceAware);
    if (schemas.length != 0) {
        SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
        factory.setSchema(schemaFactory.newSchema(schemas));
    }
    SAXParser saxParser = factory.newSAXParser();
    if (schemas.length == 0) {
        saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", schemaLanguage);
    }
    return saxParser;
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 33 with SAXParser

use of javax.xml.parsers.SAXParser in project translationstudio8 by heartsome.

the class Xlsx2TmxHelper method parse.

public void parse(InputStream sheetInputStream, ReadOnlySharedStringsTable sharedStringsTable, AbstractWriter tmxWriter) throws ParserConfigurationException, SAXException, IOException {
    InputSource sheetSource = new InputSource(sheetInputStream);
    SAXParserFactory saxFactory = SAXParserFactory.newInstance();
    SAXParser saxParser = saxFactory.newSAXParser();
    XMLReader sheetParser = saxParser.getXMLReader();
    ContentHandler handler = new XSSFHander(sharedStringsTable);
    sheetParser.setContentHandler(handler);
    sheetParser.parse(sheetSource);
    if (langCodes.isEmpty()) {
        throw new SAXException("EMPTY-LANG-CODE");
    }
    writeEnd();
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader) ContentHandler(org.xml.sax.ContentHandler) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 34 with SAXParser

use of javax.xml.parsers.SAXParser in project android_frameworks_base by AOSPA.

the class OMAParser method parse.

public MOTree parse(String text, String urn) throws IOException, SAXException {
    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        parser.parse(new InputSource(new StringReader(text)), this);
        return new MOTree(mRoot, urn);
    } catch (ParserConfigurationException pce) {
        throw new SAXException(pce);
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 35 with SAXParser

use of javax.xml.parsers.SAXParser in project OpenClinica by OpenClinica.

the class RuleXmlParser method parseDocument.

private void parseDocument(File f) {
    // get a factory
    SAXParserFactory spf = SAXParserFactory.newInstance();
    try {
        // get a new instance of parser
        SAXParser sp = spf.newSAXParser();
        // parse the file and also register this class for call backs
        sp.parse(f, this);
    } catch (SAXException se) {
        se.printStackTrace();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (IOException ie) {
        ie.printStackTrace();
    }
}
Also used : SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Aggregations

SAXParser (javax.xml.parsers.SAXParser)235 SAXParserFactory (javax.xml.parsers.SAXParserFactory)142 SAXException (org.xml.sax.SAXException)112 InputSource (org.xml.sax.InputSource)95 IOException (java.io.IOException)80 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)71 DefaultHandler (org.xml.sax.helpers.DefaultHandler)37 XMLReader (org.xml.sax.XMLReader)36 File (java.io.File)35 ByteArrayInputStream (java.io.ByteArrayInputStream)28 StringReader (java.io.StringReader)27 InputStream (java.io.InputStream)24 Attributes (org.xml.sax.Attributes)22 SAXSource (javax.xml.transform.sax.SAXSource)17 SAXParseException (org.xml.sax.SAXParseException)17 ArrayList (java.util.ArrayList)13 JAXBContext (javax.xml.bind.JAXBContext)12 Unmarshaller (javax.xml.bind.Unmarshaller)12 FileNotFoundException (java.io.FileNotFoundException)10 ValidationEvent (javax.xml.bind.ValidationEvent)9