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();
}
}
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();
}
}
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();
}
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();
}
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);
}
}
Aggregations