use of ddf.catalog.transform.InputTransformer in project ddf by codice.
the class CswTransformProvider method unmarshal.
/**
* Creates a Metacard from the given XML. This method is not typically be called directly, instead
* it is called by another XStream Converter using UnmarshallingContext.convertAnother();
*
* @param reader
* @param context
* @return
*/
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
String keyArg = (String) context.get(CswConstants.TRANSFORMER_LOOKUP_KEY);
String valArg = (String) context.get(CswConstants.TRANSFORMER_LOOKUP_VALUE);
InputTransformer transformer;
if (StringUtils.isNotBlank(keyArg) && StringUtils.isNotBlank(valArg)) {
transformer = inputTransformerManager.getTransformerByProperty(keyArg, valArg);
} else {
transformer = inputTransformerManager.getTransformerBySchema(CswConstants.CSW_OUTPUT_SCHEMA);
}
if (transformer == null) {
throw new ConversionException(String.format("Unable to locate a transformer for %s = %s", keyArg, valArg));
}
/* The CswRecordConverter uses unmarshal, which requires the context */
if (transformer instanceof CswRecordConverter) {
return ((CswRecordConverter) transformer).unmarshal(reader, context);
}
Metacard metacard;
try (InputStream is = readXml(reader, context)) {
InputStream inputStream = is;
if (LOGGER.isDebugEnabled()) {
String originalInputStream = IOUtils.toString(inputStream, StandardCharsets.UTF_8.name());
LOGGER.debug("About to transform\n{}", originalInputStream);
inputStream = new ByteArrayInputStream(originalInputStream.getBytes(StandardCharsets.UTF_8.name()));
}
metacard = transformer.transform(inputStream);
} catch (IOException | CatalogTransformerException e) {
throw new ConversionException("Unable to transform Metacard", e);
}
return metacard;
}
Aggregations