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();
}
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations