Search in sources :

Example 1 with UntypedItemJson

use of org.platformlayer.UntypedItemJson in project platformlayer by platformlayer.

the class PlatformLayerCommandRunnerBase method formatRaw.

@Override
public void formatRaw(Object o, PrintWriter writer) {
    String data;
    if (o instanceof UntypedItemXml) {
        UntypedItemXml item = (UntypedItemXml) o;
        Source src = new DOMSource(item.getRoot());
        String xml = DomUtils.toXml(src, 4);
        data = xml;
    } else if (o instanceof UntypedItemJson) {
        UntypedItemJson item = (UntypedItemJson) o;
        JSONObject root = item.getRoot();
        try {
            data = root.toString(2);
        } catch (JSONException e) {
            throw new IllegalStateException("Error formatting JSON", e);
        }
    } else {
        super.formatRaw(o, writer);
        return;
    }
    Ansi ansi = new Ansi(writer);
    ansi.print(data);
    ansi.println();
    ansi.reset();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) JSONObject(org.json.JSONObject) UntypedItemXml(org.platformlayer.UntypedItemXml) UntypedItemJson(org.platformlayer.UntypedItemJson) JSONException(org.json.JSONException) Ansi(com.fathomdb.cli.commands.Ansi) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source)

Aggregations

Ansi (com.fathomdb.cli.commands.Ansi)1 Source (javax.xml.transform.Source)1 DOMSource (javax.xml.transform.dom.DOMSource)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 UntypedItemJson (org.platformlayer.UntypedItemJson)1 UntypedItemXml (org.platformlayer.UntypedItemXml)1