import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
-
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-
import org.opendaylight.controller.sal.rest.api.Draft02;
import org.opendaylight.controller.sal.rest.api.RestconfService;
import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
@Provider
@Produces({ Draft02.MediaTypes.API + RestconfService.XML, Draft02.MediaTypes.DATA + RestconfService.XML,
- Draft02.MediaTypes.OPERATION + RestconfService.XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ Draft02.MediaTypes.OPERATION + RestconfService.XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public enum StructuredDataToXmlProvider implements MessageBodyWriter<StructuredData> {
INSTANCE;
};
@Override
- public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
- return type.equals( StructuredData.class );
+ public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.equals(StructuredData.class);
}
@Override
- public long getSize(final StructuredData t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
+ public long getSize(final StructuredData t, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType) {
return -1;
}
@Override
- 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 {
+ 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 {
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 (RuntimeException e) {
- throw new RestconfDocumentedException(e.getMessage(), ErrorType.TRANSPORT,
- ErrorTag.OPERATION_FAILED);
+ throw new RestconfDocumentedException(e.getMessage(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED);
}
// FIXME: BUG-1281: eliminate the intermediate Document
trans.transform(new DOMSource(domTree), new StreamResult(entityStream));
} catch (TransformerException e) {
LOG.error("Error during translation of Document to OutputStream", e);
- throw new RestconfDocumentedException(e.getMessage(), ErrorType.TRANSPORT,
- ErrorTag.OPERATION_FAILED);
+ throw new RestconfDocumentedException(e.getMessage(), ErrorType.TRANSPORT, ErrorTag.OPERATION_FAILED);
}
}