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