TidyJsonItemWriter.java 2.55 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Node
 *  javax.jcr.NodeIterator
 *  javax.jcr.Property
 *  javax.jcr.RepositoryException
 *  javax.jcr.ValueFormatException
 *  org.apache.sling.commons.json.JSONException
 *  org.apache.sling.commons.json.io.JSONWriter
 *  org.apache.sling.commons.json.jcr.JsonItemWriter
 */
package com.day.cq.commons;

import com.day.cq.commons.TidyJSONWriter;
import java.io.Writer;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.apache.sling.commons.json.jcr.JsonItemWriter;

public class TidyJsonItemWriter
extends JsonItemWriter {
    private boolean tidy;

    public TidyJsonItemWriter(Set<String> propertyNamesToIgnore) {
        super(propertyNamesToIgnore);
    }

    public boolean isTidy() {
        return this.tidy;
    }

    public void setTidy(boolean tidy) {
        this.tidy = tidy;
    }

    public void dump(Node node, JSONWriter w, int maxRecursionLevels) throws RepositoryException, JSONException {
        this.dump(node, w, 0, maxRecursionLevels);
    }

    public void dump(Node node, Writer w, int maxRecursionLevels) throws RepositoryException, JSONException {
        TidyJSONWriter jw = new TidyJSONWriter(w);
        jw.setTidy(this.tidy);
        this.dump(node, (JSONWriter)jw, 0, maxRecursionLevels);
    }

    public void dump(NodeIterator it, JSONWriter w) throws RepositoryException, JSONException {
        w.array();
        while (it.hasNext()) {
            this.dumpSingleNode(it.nextNode(), w, 1, 0);
        }
        w.endArray();
    }

    public void dump(NodeIterator it, Writer out) throws RepositoryException, JSONException {
        TidyJSONWriter w = new TidyJSONWriter(out);
        w.setTidy(this.tidy);
        w.array();
        while (it.hasNext()) {
            this.dumpSingleNode(it.nextNode(), (JSONWriter)w, 1, 0);
        }
        w.endArray();
    }

    public void dump(Property p, JSONWriter w) throws JSONException, RepositoryException {
        w.object();
        this.writeProperty(w, p);
        w.endObject();
    }

    public void dump(Property p, Writer w) throws JSONException, ValueFormatException, RepositoryException {
        TidyJSONWriter jw = new TidyJSONWriter(w);
        jw.setTidy(this.tidy);
        jw.object();
        this.writeProperty((JSONWriter)jw, p);
        jw.endObject();
    }
}