use of javax.xml.parsers.SAXParserFactory in project camel by apache.
the class XmlConverter method toSAXSourceFromStream.
@Converter
public SAXSource toSAXSourceFromStream(StreamSource source, Exchange exchange) throws SAXException {
InputSource inputSource;
if (source.getReader() != null) {
inputSource = new InputSource(source.getReader());
} else {
inputSource = new InputSource(source.getInputStream());
}
inputSource.setSystemId(source.getSystemId());
inputSource.setPublicId(source.getPublicId());
XMLReader xmlReader = null;
try {
// use the SAXPaserFactory which is set from exchange
if (exchange != null) {
SAXParserFactory sfactory = exchange.getProperty(Exchange.SAXPARSER_FACTORY, SAXParserFactory.class);
if (sfactory != null) {
if (!sfactory.isNamespaceAware()) {
sfactory.setNamespaceAware(true);
}
xmlReader = sfactory.newSAXParser().getXMLReader();
}
}
if (xmlReader == null) {
if (xmlReaderPool == null) {
xmlReaderPool = new XMLReaderPool(createSAXParserFactory());
}
xmlReader = xmlReaderPool.createXMLReader();
}
} catch (Exception ex) {
LOG.warn("Cannot create the SAXParser XMLReader, due to {}", ex);
}
return new SAXSource(xmlReader, inputSource);
}
use of javax.xml.parsers.SAXParserFactory in project groovy by apache.
the class XmlUtil method newSAXParser.
private static SAXParser newSAXParser(boolean namespaceAware, boolean validating, Schema schema1) throws ParserConfigurationException, SAXException {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(validating);
factory.setNamespaceAware(namespaceAware);
factory.setSchema(schema1);
return factory.newSAXParser();
}
use of javax.xml.parsers.SAXParserFactory in project OpenPanodroid by duerrfk.
the class RESTRequestorXML method parseResponse.
@Override
protected void parseResponse(InputStream is, int contentLength) {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
DefaultHandler saxHandler = createSAXHandler();
if (saxHandler == null) {
setSuccessState(false);
} else {
parser.parse(is, saxHandler);
}
} catch (Exception ex) {
setErrorMsg(ex.getLocalizedMessage());
setSuccessState(false);
}
}
use of javax.xml.parsers.SAXParserFactory in project che by eclipse.
the class CheCodeFormatterOptions method getCheDefaultSettings.
private Map<String, String> getCheDefaultSettings() {
SAXParserFactory factory = SAXParserFactory.newInstance();
XMLParser parserXML = new XMLParser();
try {
SAXParser parser = factory.newSAXParser();
parser.parse(getClass().getResourceAsStream(DEFAULT_CODESTYLE), parserXML);
} catch (ParserConfigurationException | SAXException | IOException e) {
LOG.error("It is not possible to parse file " + DEFAULT_CODESTYLE, e);
}
return parserXML.getSettings();
}
use of javax.xml.parsers.SAXParserFactory in project jetty.project by eclipse.
the class XmlParser method setValidating.
/* ------------------------------------------------------------ */
public void setValidating(boolean validating) {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(validating);
_parser = factory.newSAXParser();
try {
if (validating)
_parser.getXMLReader().setFeature("http://apache.org/xml/features/validation/schema", validating);
} catch (Exception e) {
if (validating)
LOG.warn("Schema validation may not be supported: ", e);
else
LOG.ignore(e);
}
_parser.getXMLReader().setFeature("http://xml.org/sax/features/validation", validating);
_parser.getXMLReader().setFeature("http://xml.org/sax/features/namespaces", true);
_parser.getXMLReader().setFeature("http://xml.org/sax/features/namespace-prefixes", false);
try {
if (validating)
_parser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", validating);
} catch (Exception e) {
LOG.warn(e.getMessage());
}
} catch (Exception e) {
LOG.warn(Log.EXCEPTION, e);
throw new Error(e.toString());
}
}
Aggregations