gilvansfilho commented on code in PR #10388:
URL: https://github.com/apache/camel/pull/10388#discussion_r1230902810


##########
core/camel-core-languages/src/main/java/org/apache/camel/language/csimple/CSimpleHelper.java:
##########
@@ -163,6 +178,40 @@ public static String bodyOneLine(Exchange exchange) {
         return body;
     }
 
+    public static String prettyBody(Exchange exchange) {
+        String body = exchange.getIn().getBody(String.class);
+
+        if (body == null) {
+            return null;
+        } else if (body.startsWith("{") && body.endsWith("}") || 
body.startsWith("[") && body.endsWith("]")) {
+            body = Jsoner.prettyPrint(body); //json
+        } else if (body.startsWith("<") && body.endsWith(">")) {
+            return CSimpleHelper.prettyXml(body); //xml
+        }
+
+        return body;
+    }
+
+    private static String prettyXml(String rawXml) {
+        try {
+            InputSource src = new InputSource(new StringReader(rawXml));
+            Document document = 
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src);
+
+            TransformerFactory transformerFactory = 
TransformerFactory.newInstance();
+            transformerFactory.setAttribute("indent-number", 2);
+            Transformer transformer = transformerFactory.newTransformer();
+            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, 
"yes");

Review Comment:
   I was looking a way to use original XML Declaration instead replace with new 
one (which is what `Transformer` does) but I am going to replace this block by 
`org.apache.camel.util.xml.XmlPrettyPrinter`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to