use of com.google.refine.preference.PreferenceStore in project OpenRefine by OpenRefine.
the class GetPreferenceCommand method doGet.
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Project project = request.getParameter("project") != null ? getProject(request) : null;
PreferenceStore ps = project != null ? project.getMetadata().getPreferenceStore() : ProjectManager.singleton.getPreferenceStore();
String prefName = request.getParameter("name");
Object pref = ps.get(prefName);
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
writer.key("value");
if (pref == null || pref instanceof String || pref instanceof Number || pref instanceof Boolean) {
writer.value(pref);
} else if (pref instanceof TopList) {
TopList tl = (TopList) pref;
tl.write(writer, new Properties());
} else {
writer.value(pref.toString());
}
writer.endObject();
} catch (JSONException e) {
respondException(response, e);
}
}
use of com.google.refine.preference.PreferenceStore in project OpenRefine by OpenRefine.
the class LoadLanguageCommand method doPost.
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String modname = request.getParameter("module");
if (modname == null) {
modname = "core";
}
String[] langs = request.getParameterValues("lang");
if (langs == null || "".equals(langs[0])) {
PreferenceStore ps = ProjectManager.singleton.getPreferenceStore();
if (ps != null) {
langs = new String[] { (String) ps.get("userLang") };
}
}
// TODO: Switch this to just use English as the default language so we
// so we don't have to maintain a separate redundant file.
langs = Arrays.copyOf(langs, langs.length + 1);
langs[langs.length - 1] = "default";
JSONObject json = null;
boolean loaded = false;
for (String lang : langs) {
json = loadLanguage(this.servlet, modname, lang);
if (json != null) {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
try {
json.write(response.getWriter());
} catch (JSONException e) {
logger.error("Error writing language labels to response stream");
}
response.getWriter().flush();
response.getWriter().close();
loaded = true;
break;
}
}
if (!loaded) {
logger.error("Failed to load any language files");
}
}
use of com.google.refine.preference.PreferenceStore in project OpenRefine by OpenRefine.
the class GetAllPreferencesCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Project project = request.getParameter("project") != null ? getProject(request) : null;
PreferenceStore ps = project != null ? project.getMetadata().getPreferenceStore() : ProjectManager.singleton.getPreferenceStore();
try {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Type", "application/json");
JSONWriter writer = new JSONWriter(response.getWriter());
writer.object();
for (String key : ps.getKeys()) {
Object pref = ps.get(key);
if (pref == null || pref instanceof String || pref instanceof Number || pref instanceof Boolean) {
writer.key(key);
writer.value(pref);
}
}
writer.endObject();
} catch (JSONException e) {
respondException(response, e);
}
}
use of com.google.refine.preference.PreferenceStore in project OpenRefine by OpenRefine.
the class SetPreferenceCommand method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Project project = request.getParameter("project") != null ? getProject(request) : null;
PreferenceStore ps = project != null ? project.getMetadata().getPreferenceStore() : ProjectManager.singleton.getPreferenceStore();
String prefName = request.getParameter("name");
String valueString = request.getParameter("value");
try {
Object o = valueString == null ? null : new JSONTokener(valueString).nextValue();
ps.put(prefName, PreferenceStore.loadObject(o));
respond(response, "{ \"code\" : \"ok\" }");
} catch (JSONException e) {
respondException(response, e);
}
}
Aggregations