use of org.milyn.Smooks in project coprhd-controller by CoprHD.
the class SmooksUtil method getParsedXMLJavaResult.
/**
* This initializes the Smooks & parse the given inputStream and returns the javaResult.
*
* @param inputStream : Response in inputStream received from server.
* @param configFile : Smooks configuration file.
* @return
*/
public static JavaResult getParsedXMLJavaResult(InputStream inputStream, String configFile) {
Smooks smooks = null;
JavaResult javaResult = null;
try {
smooks = new Smooks(configFile);
log.debug("initialized smooks");
ExecutionContext executionContext = smooks.createExecutionContext();
// The result of this transform is a set of Java objects...
javaResult = new JavaResult();
// Filter the input message to extract, using the execution context...
smooks.filterSource(executionContext, new StreamSource(inputStream), javaResult);
log.debug("Parsing completed");
} catch (Exception e) {
log.error("Unable to parse the response received from server.", e);
throw HDSException.exceptions.unableToParseResponse();
} finally {
if (null != smooks) {
smooks.close();
}
}
return javaResult;
}
use of org.milyn.Smooks in project tutorials by eugenp.
the class OrderValidator method validate.
public ValidationResult validate(String path) throws IOException, SAXException {
Smooks smooks = new Smooks(OrderValidator.class.getResourceAsStream("/smooks/smooks-validation.xml"));
try {
StringResult xmlResult = new StringResult();
JavaResult javaResult = new JavaResult();
ValidationResult validationResult = new ValidationResult();
smooks.filterSource(new StreamSource(OrderValidator.class.getResourceAsStream(path)), xmlResult, javaResult, validationResult);
return validationResult;
} finally {
smooks.close();
}
}
use of org.milyn.Smooks in project tutorials by eugenp.
the class OrderConverter method convertOrderXMLToOrderObject.
public Order convertOrderXMLToOrderObject(String path) throws IOException, SAXException {
Smooks smooks = new Smooks(OrderConverter.class.getResourceAsStream("/smooks/smooks-mapping.xml"));
try {
JavaResult javaResult = new JavaResult();
smooks.filterSource(new StreamSource(OrderConverter.class.getResourceAsStream(path)), javaResult);
return (Order) javaResult.getBean("order");
} finally {
smooks.close();
}
}
use of org.milyn.Smooks in project tutorials by eugenp.
the class OrderConverter method convertDocumentWithTempalte.
private String convertDocumentWithTempalte(String path, String config) throws IOException, SAXException {
Smooks smooks = new Smooks(config);
try {
StringResult stringResult = new StringResult();
smooks.filterSource(new StreamSource(OrderConverter.class.getResourceAsStream(path)), stringResult);
return stringResult.toString();
} finally {
smooks.close();
}
}
Aggregations