Search in sources :

Example 1 with JSONWriter

use of org.json.JSONWriter in project OpenRefine by OpenRefine.

the class RefineBrokerImpl method getState.

// ---------------------------------------------------------------------------------
@Override
protected void getState(HttpServletResponse response, String pid, String uid, int rev) throws Exception {
    Project project = getProject(pid);
    Writer w = response.getWriter();
    JSONWriter writer = new JSONWriter(w);
    writer.object();
    writer.key("status");
    writer.value("ok");
    writer.key("transformations");
    writer.array();
    int size = project.transformations.size();
    for (int i = rev; i < size; i++) {
        writer.value(new JSONObject(project.transformations.get(i)));
    }
    writer.endArray();
    EntityCursor<Lock> cursor = locksByProject.subIndex(pid).entities();
    try {
        writer.key("locks");
        writer.array();
        for (Lock lock : cursor) {
            writer.value(lockToJSON(lock, uid));
        }
        writer.endArray();
        writer.endObject();
        w.flush();
        w.close();
    } finally {
        cursor.close();
    }
}
Also used : JSONWriter(org.json.JSONWriter) JSONObject(org.json.JSONObject) JSONWriter(org.json.JSONWriter) Writer(java.io.Writer)

Example 2 with JSONWriter

use of org.json.JSONWriter in project OpenRefine by OpenRefine.

the class AppEngineRefineBrokerImpl method getHistory.

protected void getHistory(HttpServletResponse response, String pid, int tindex) throws Exception {
    PersistenceManager pm = pmfInstance.getPersistenceManager();
    try {
        Project project = getProject(pm, pid);
        Writer w = response.getWriter();
        JSONWriter writer = new JSONWriter(w);
        writer.object();
        writer.key("transformations");
        writer.array();
        int size = project.transformations.size();
        for (int i = tindex; i < size; i++) {
            writer.value(project.transformations.get(i).toString());
        }
        writer.endArray();
        writer.endObject();
        w.flush();
        w.close();
    } finally {
        pm.close();
    }
}
Also used : JSONWriter(org.json.JSONWriter) PersistenceManager(javax.jdo.PersistenceManager) JSONWriter(org.json.JSONWriter) Writer(java.io.Writer)

Example 3 with JSONWriter

use of org.json.JSONWriter in project OpenRefine by OpenRefine.

the class Command method respondJSON.

protected static void respondJSON(HttpServletResponse response, Jsonizable o, Properties options) throws IOException, JSONException {
    response.setCharacterEncoding("UTF-8");
    response.setHeader("Content-Type", "application/json");
    response.setHeader("Cache-Control", "no-cache");
    Writer w = response.getWriter();
    JSONWriter writer = new JSONWriter(w);
    o.write(writer, options);
    w.flush();
    w.close();
}
Also used : JSONWriter(org.json.JSONWriter) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) JSONWriter(org.json.JSONWriter) Writer(java.io.Writer)

Example 4 with JSONWriter

use of org.json.JSONWriter in project opennms by OpenNMS.

the class SnmpAgentConfig method toProtocolConfigString.

public String toProtocolConfigString() {
    final JSONWriter writer = new JSONStringer().object().key("snmp").object();
    toMap().entrySet().stream().forEach(e -> writer.key(e.getKey()).value(e.getValue()));
    return writer.endObject().endObject().toString();
}
Also used : JSONWriter(org.json.JSONWriter) JSONStringer(org.json.JSONStringer)

Example 5 with JSONWriter

use of org.json.JSONWriter in project OpenRefine by OpenRefine.

the class GetAllProjectMetadataCommand method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Type", "application/json");
        JSONWriter writer = new JSONWriter(response.getWriter());
        Properties options = new Properties();
        writer.object();
        writer.key("projects");
        writer.object();
        Map<Long, ProjectMetadata> m = ProjectManager.singleton.getAllProjectMetadata();
        for (Entry<Long, ProjectMetadata> e : m.entrySet()) {
            ProjectMetadata pm = e.getValue();
            if (pm != null) {
                writer.key(e.getKey().toString());
                e.getValue().write(writer, options);
            }
        }
        writer.endObject();
        writer.endObject();
    } catch (JSONException e) {
        respondException(response, e);
    }
}
Also used : JSONWriter(org.json.JSONWriter) ProjectMetadata(com.google.refine.ProjectMetadata) JSONException(org.json.JSONException) Properties(java.util.Properties)

Aggregations

JSONWriter (org.json.JSONWriter)26 Writer (java.io.Writer)9 StringWriter (java.io.StringWriter)8 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)6 JSONException (org.json.JSONException)6 Test (org.junit.Test)6 JsonFactory (com.fasterxml.jackson.core.JsonFactory)5 JsonParser (com.fasterxml.jackson.core.JsonParser)5 JSONObject (org.json.JSONObject)5 IOException (java.io.IOException)4 PrintWriter (java.io.PrintWriter)3 Properties (java.util.Properties)3 ServletException (javax.servlet.ServletException)3 JSONStringer (org.json.JSONStringer)3 TypeFormatterImportsUUT (com.instagram.common.json.annotation.processor.parent.TypeFormatterImportsUUT)2 FormatterUUT (com.instagram.common.json.annotation.processor.uut.FormatterUUT)2 OutputStreamWriter (java.io.OutputStreamWriter)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2