use of org.xml.sax.InputSource in project camel by apache.
the class XmlConverter method toSAXSourceFromStAX.
@Converter
public SAXSource toSAXSourceFromStAX(StAXSource source, Exchange exchange) throws TransformerException {
String str = toString(source, exchange);
StringReader reader = new StringReader(str);
return new SAXSource(new InputSource(reader));
}
use of org.xml.sax.InputSource in project camel by apache.
the class XmlConverter method toStreamSourceFromSAX.
@Converter
public StreamSource toStreamSourceFromSAX(SAXSource source, Exchange exchange) throws TransformerException {
InputSource inputSource = source.getInputSource();
if (inputSource != null) {
if (inputSource.getCharacterStream() != null) {
return new StreamSource(inputSource.getCharacterStream());
}
if (inputSource.getByteStream() != null) {
return new StreamSource(inputSource.getByteStream());
}
}
String result = toString(source, exchange);
return new StringSource(result);
}
use of org.xml.sax.InputSource in project camel by apache.
the class XmlConverter method toDOMSource.
@Converter
public DOMSource toDOMSource(InputStream is, Exchange exchange) throws ParserConfigurationException, IOException, SAXException {
InputSource source = new InputSource(is);
String systemId = source.getSystemId();
DocumentBuilder builder = getDocumentBuilderFactory(exchange).newDocumentBuilder();
Document document = builder.parse(source);
return new DOMSource(document, systemId);
}
use of org.xml.sax.InputSource 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 org.xml.sax.InputSource in project camel by apache.
the class XmlConverter method toSAXSourceFromDOM.
@Converter
public SAXSource toSAXSourceFromDOM(DOMSource source, Exchange exchange) throws TransformerException {
String str = toString(source, exchange);
StringReader reader = new StringReader(str);
return new SAXSource(new InputSource(reader));
}
Aggregations