- public void writeTo(StructuredData t, Class<?> type, Type genericType, Annotation[] annotations,
- MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
- throws IOException, WebApplicationException {
- CompositeNode data = t.getData();
- Document domTree = NodeUtils.buildShadowDomTree(data);
-
+ public void writeTo(final StructuredData t, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType,
+ final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException,
+ WebApplicationException {
+ final CompositeNode data = t.getData();
+ if (data == null) {
+ throw new RestconfDocumentedException(Response.Status.NOT_FOUND);
+ }
+
+ final Transformer trans;
+ try {
+ trans = TRANSFORMER.get();
+ if (t.isPrettyPrintMode()) {
+ trans.setOutputProperty(OutputKeys.INDENT, "yes");
+ } else {
+ trans.setOutputProperty(OutputKeys.INDENT, "no");
+ }
+ } catch (final RuntimeException e) {
+ throw new RestconfDocumentedException(e.getMessage(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED);
+ }
+
+ // FIXME: BUG-1281: eliminate the intermediate Document
+ final Document domTree = new XmlMapper().write(data, (DataNodeContainer) t.getSchema());