use of com.siemens.ct.exi.EXIFactory in project arctic-sea by 52North.
the class EXIBinding method decode.
/**
* Parse the incoming EXI encoded {@link InputStream} transform to
* {@link XmlObject}
*
* @param request
* {@link HttpServletRequest} with EXI encoded
* {@link InputStream}
* @return {@link XmlObject} created from the EXI encoded
* {@link InputStream}
* @throws OwsExceptionReport
* If an error occurs during parsing
*/
protected XmlObject decode(HttpServletRequest request) throws OwsExceptionReport {
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
EXIFactory ef = this.exiUtils.newEXIFactory();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
if (ef.isFragment()) {
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
}
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
// decode EXI encoded InputStream
EXISource exiSource = new EXISource(ef);
XMLReader exiReader = exiSource.getXMLReader();
InputSource inputSource = new InputSource(request.getInputStream());
inputSource.setEncoding(request.getCharacterEncoding());
SAXSource saxSource = new SAXSource(inputSource);
saxSource.setXMLReader(exiReader);
transformer.transform(saxSource, new StreamResult(os));
// create XmlObject from OutputStream
return XmlHelper.parseXmlString(os.toString(StandardCharsets.UTF_8.name()));
} catch (IOException | EXIException ex) {
throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while reading request! Message: %s", ex.getMessage());
} catch (TransformerException ex) {
throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while transforming request! Message: %s", ex.getMessage());
} catch (DecodingException ex) {
throw new NoApplicableCodeException().causedBy(ex).withMessage("Error while parsing request! Message: %s", ex.getMessage());
}
}
use of com.siemens.ct.exi.EXIFactory in project arctic-sea by 52North.
the class EXIUtils method newEXIFactory.
/**
* @return An {@link EXIFactory} instance configured according the service
* configuration.
*
* @throws UnsupportedOption
* if one of the fidelity options is not supported.
*/
public EXIFactory newEXIFactory() throws UnsupportedOption {
EXIFactory factory = DefaultEXIFactory.newInstance();
factory.setGrammars(getGrammars());
// something else?
if (this.isStrict) {
factory.setFidelityOptions(FidelityOptions.createStrict());
} else if (this.isDefault) {
factory.setFidelityOptions(FidelityOptions.createDefault());
} else {
FidelityOptions options = factory.getFidelityOptions();
options.setFidelity(FidelityOptions.FEATURE_COMMENT, this.preserveComments);
options.setFidelity(FidelityOptions.FEATURE_PI, this.preserveProcessingInstructions);
options.setFidelity(FidelityOptions.FEATURE_DTD, this.preserveDTD);
options.setFidelity(FidelityOptions.FEATURE_PREFIX, this.preservePrefixes);
options.setFidelity(FidelityOptions.FEATURE_LEXICAL_VALUE, this.preserveLexicalValue);
}
factory.setCodingMode(alignment);
// }
return factory;
}
Aggregations