use of org.xml.sax.SAXNotSupportedException in project tika by apache.
the class ParseContext method getSAXParserFactory.
/**
* Returns the SAX parser factory specified in this parsing context.
* If a factory is not explicitly specified, then a default factory
* instance is created and returned. The default factory instance is
* configured to be namespace-aware, not validating, and to use
* {@link XMLConstants#FEATURE_SECURE_PROCESSING secure XML processing}.
*
* @since Apache Tika 0.8
* @return SAX parser factory
*/
public SAXParserFactory getSAXParserFactory() {
SAXParserFactory factory = get(SAXParserFactory.class);
if (factory == null) {
factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (ParserConfigurationException e) {
} catch (SAXNotSupportedException e) {
} catch (SAXNotRecognizedException e) {
// TIKA-271: Some XML parsers do not support the
// secure-processing feature, even though it's required by
// JAXP in Java 5. Ignoring the exception is fine here, as
// deployments without this feature are inherently vulnerable
// to XML denial-of-service attacks.
}
}
return factory;
}
use of org.xml.sax.SAXNotSupportedException in project pentaho-platform by pentaho.
the class ExportManifest method fromXml.
public static ExportManifest fromXml(ByteArrayInputStream input) throws JAXBException {
SAXParserFactory secureSAXParserFactory;
try {
secureSAXParserFactory = XMLParserFactoryProducer.createSecureSAXParserFactory();
} catch (SAXNotSupportedException | SAXNotRecognizedException | ParserConfigurationException ex) {
throw new JAXBException(ex);
}
XMLReader xmlReader;
try {
xmlReader = secureSAXParserFactory.newSAXParser().getXMLReader();
xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
} catch (SAXException | ParserConfigurationException ex) {
throw new JAXBException(ex);
}
Source xmlSource = new SAXSource(xmlReader, new InputSource(input));
JAXBContext jc = JAXBContext.newInstance("org.pentaho.platform.plugin.services.importexport.exportManifest.bindings");
Unmarshaller u = jc.createUnmarshaller();
try {
JAXBElement<ExportManifestDto> o = (JAXBElement) (u.unmarshal(xmlSource));
ExportManifestDto exportManifestDto = o.getValue();
ExportManifest exportManifest = new ExportManifest(exportManifestDto);
return exportManifest;
} catch (Exception e) {
System.out.println(e.toString());
return null;
}
}
use of org.xml.sax.SAXNotSupportedException in project pentaho-platform by pentaho.
the class MimeTypeListFactory method fromXml.
private ImportHandlerMimeTypeDefinitionsDto fromXml(FileInputStream input) throws JAXBException {
SAXParserFactory secureSAXParserFactory;
try {
secureSAXParserFactory = XMLParserFactoryProducer.createSecureSAXParserFactory();
} catch (SAXNotSupportedException | SAXNotRecognizedException | ParserConfigurationException ex) {
throw new JAXBException(ex);
}
XMLReader xmlReader;
try {
xmlReader = secureSAXParserFactory.newSAXParser().getXMLReader();
xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
} catch (SAXException | ParserConfigurationException ex) {
throw new JAXBException(ex);
}
Source xmlSource = new SAXSource(xmlReader, new InputSource(input));
JAXBContext jc = JAXBContext.newInstance("org.pentaho.platform.plugin.services.importer.mimeType.bindings");
Unmarshaller u = jc.createUnmarshaller();
JAXBElement<ImportHandlerMimeTypeDefinitionsDto> o = (JAXBElement) (u.unmarshal(xmlSource));
ImportHandlerMimeTypeDefinitionsDto mimeTypeDefinitions = o.getValue();
return mimeTypeDefinitions;
}
use of org.xml.sax.SAXNotSupportedException in project fabric8 by jboss-fuse.
the class XmlNamespaceFinder method createParser.
protected final SAXParser createParser(SAXParserFactory parserFactory) throws ParserConfigurationException, SAXException {
parserFactory.setNamespaceAware(true);
final SAXParser parser = parserFactory.newSAXParser();
final XMLReader reader = parser.getXMLReader();
// disable DTD validation (bug 63625)
try {
// be sure validation is "off" or the feature to ignore DTD's will not apply
// $NON-NLS-1$
reader.setFeature("http://xml.org/sax/features/validation", false);
// $NON-NLS-1$
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
} catch (SAXNotRecognizedException e) {
// not a big deal if the parser does not recognize the features
} catch (SAXNotSupportedException e) {
// not a big deal if the parser does not support the features
}
return parser;
}
use of org.xml.sax.SAXNotSupportedException in project liferay-ide by liferay.
the class StructuresHandler method createParser.
private final SAXParser createParser(SAXParserFactory parserFactory) throws ParserConfigurationException, SAXException, SAXNotRecognizedException, SAXNotSupportedException {
// Initialize the parser.
final SAXParser parser = parserFactory.newSAXParser();
final XMLReader reader = parser.getXMLReader();
// disable DTD validation
try {
// be sure validation is "off" or the feature to ignore DTD's will not apply
// $NON-NLS-1$
reader.setFeature("http://xml.org/sax/features/validation", false);
// $NON-NLS-1$
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
} catch (SAXNotRecognizedException e) {
// not a big deal if the parser does not recognize the features
} catch (SAXNotSupportedException e) {
// not a big deal if the parser does not support the features
}
return parser;
}
Aggregations