use of org.json.JSONWriter in project OpenRefine by OpenRefine.
the class RefineBrokerImpl method openProject.
// ---------------------------------------------------------------------------------
@Override
protected void openProject(HttpServletResponse response, String pid) 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("data");
writer.value(project.data);
writer.key("metadata");
writer.value(new JSONObject(project.metadata));
writer.key("transformations");
writer.array();
for (String s : project.transformations) {
writer.value(new JSONObject(s));
}
writer.endArray();
writer.endObject();
w.flush();
w.close();
}
use of org.json.JSONWriter in project OpenRefine by OpenRefine.
the class AppEngineRefineBrokerImpl method openProject.
// ---------------------------------------------------------------------------------
protected void openProject(HttpServletResponse response, String pid) 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("data");
writer.value(project.data.toString());
writer.key("transformations");
writer.array();
for (Text s : project.transformations) {
writer.value(s.toString());
}
writer.endArray();
writer.endObject();
w.flush();
w.close();
} finally {
pm.close();
}
}
use of org.json.JSONWriter in project OpenRefine by OpenRefine.
the class GetExpressionLanguageInfoCommand 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("functions");
writer.object();
{
for (Entry<String, Function> entry : ControlFunctionRegistry.getFunctionMapping()) {
writer.key(entry.getKey());
entry.getValue().write(writer, options);
}
}
writer.endObject();
writer.key("controls");
writer.object();
{
for (Entry<String, Control> entry : ControlFunctionRegistry.getControlMapping()) {
writer.key(entry.getKey());
entry.getValue().write(writer, options);
}
}
writer.endObject();
writer.endObject();
} catch (Exception e) {
respondException(response, e);
}
}
use of org.json.JSONWriter in project OpenRefine by OpenRefine.
the class GetImportingConfigurationCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Writer w = response.getWriter();
response.setContentType("application/json");
JSONWriter writer = new JSONWriter(w);
try {
writer.object();
writer.key("config");
ImportingManager.writeConfiguration(writer, new Properties());
writer.endObject();
} catch (JSONException e) {
throw new ServletException(e);
} finally {
w.flush();
w.close();
}
}
use of org.json.JSONWriter in project OpenRefine by OpenRefine.
the class GetLanguagesCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String modname = request.getParameter("module");
if (modname == null) {
modname = "core";
}
ButterflyModule module = this.servlet.getModule(modname);
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
writer.key("languages");
writer.array();
// we always have English and it's always first
writeLangData(writer, "en", "English");
FileFilter fileFilter = new WildcardFileFilter("translation-*.json");
for (File file : new File(module.getPath() + File.separator + "langs").listFiles(fileFilter)) {
String lang = file.getName().split("-")[1].split("\\.")[0];
if (!"en".equals(lang) && !"default".equals(lang)) {
JSONObject json = LoadLanguageCommand.loadLanguage(this.servlet, "core", lang);
if (json != null) {
String label = json.getString("name");
writeLangData(writer, lang, label);
}
}
}
writer.endArray();
writer.endObject();
} catch (JSONException e) {
respondException(response, e);
}
}
Aggregations