Search in sources :

Example 36 with SAXParser

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

the class XmlParser 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)

Example 37 with SAXParser

use of javax.xml.parsers.SAXParser in project OpenAM by OpenRock.

the class PerThreadSAXParserProviderTest method shouldReturnSameInstanceForSameThread.

@Test
public void shouldReturnSameInstanceForSameThread() throws Exception {
    // Given
    boolean validating = false;
    // When
    SAXParser parser1 = testProvider.getSAXParser(validating);
    SAXParser parser2 = testProvider.getSAXParser(validating);
    // Then
    assertThat(parser1).isSameAs(parser2);
}
Also used : SAXParser(javax.xml.parsers.SAXParser) Test(org.testng.annotations.Test)

Example 38 with SAXParser

use of javax.xml.parsers.SAXParser in project OpenAM by OpenRock.

the class PerThreadSAXParserProviderTest method shouldEvictLeastRecentlyAccessedElements.

@Test
public void shouldEvictLeastRecentlyAccessedElements() throws Exception {
    // Given
    int maxSize = 1;
    boolean validating = false;
    ExecutorService otherThread = Executors.newSingleThreadExecutor();
    testProvider = new PerThreadSAXParserProvider(new MockSAXParserProvider(), maxSize);
    // When
    SAXParser parser1 = testProvider.getSAXParser(validating);
    // Get a parser from another thread, causing maxSize (1) to be exceeded, evicting the least recently
    // accessed entry
    otherThread.submit(getParserAction(validating)).get();
    // Accessing again from the main thread should cause a new parser instance to be created
    SAXParser parser2 = testProvider.getSAXParser(validating);
    // Then
    assertThat(parser1).isNotSameAs(parser2);
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) SAXParser(javax.xml.parsers.SAXParser) Test(org.testng.annotations.Test)

Example 39 with SAXParser

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

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 40 with SAXParser

use of javax.xml.parsers.SAXParser in project robo4j by Robo4J.

the class XmlConfigurationFactory method fromXml.

public static Configuration fromXml(String xml) throws ConfigurationFactoryException {
    DefaultConfiguration config = new DefaultConfiguration();
    SAXParser saxParser;
    try {
        saxParser = SAXParserFactory.newInstance().newSAXParser();
        saxParser.parse(new ByteArrayInputStream(xml.getBytes(Constants.DEFAULT_ENCODING)), new ConfigurationHandler(config));
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new ConfigurationFactoryException("Could not parse the configuration", e);
    }
    return config;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) 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