use of org.json.JSONTokener in project OpenRefine by OpenRefine.
the class LoadLanguageCommand method loadLanguage.
static JSONObject loadLanguage(RefineServlet servlet, String modname, String lang) throws UnsupportedEncodingException {
ButterflyModule module = servlet.getModule(modname);
JSONObject json = null;
File langFile = new File(module.getPath(), "langs" + File.separator + "translation-" + lang + ".json");
try {
Reader reader = new BufferedReader(new InputStreamReader(new FileInputStream(langFile), "UTF-8"));
json = new JSONObject(new JSONTokener(reader));
} catch (FileNotFoundException e1) {
// Could be normal if we've got a list of languages as fallbacks
} catch (JSONException e) {
logger.error("JSON error reading/writing language file: " + langFile, e);
}
return json;
}
use of org.json.JSONTokener 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);
}
}
use of org.json.JSONTokener in project OpenRefine by OpenRefine.
the class ReconcileCommand method createOperation.
@Override
protected AbstractOperation createOperation(Project project, HttpServletRequest request, JSONObject engineConfig) throws Exception {
String columnName = request.getParameter("columnName");
String configString = request.getParameter("config");
JSONTokener t = new JSONTokener(configString);
JSONObject config = (JSONObject) t.nextValue();
return new ReconOperation(engineConfig, columnName, ReconConfig.reconstruct(config));
}
use of org.json.JSONTokener in project OpenRefine by OpenRefine.
the class ProjectMetadataUtilities method loadFromFile.
protected static ProjectMetadata loadFromFile(File metadataFile) throws Exception {
FileReader reader = new FileReader(metadataFile);
try {
JSONTokener tokener = new JSONTokener(reader);
JSONObject obj = (JSONObject) tokener.nextValue();
return ProjectMetadata.loadFromJSON(obj);
} finally {
reader.close();
}
}
use of org.json.JSONTokener in project OpenRefine by OpenRefine.
the class ParsingUtilities method evaluateJsonStringToArray.
public static JSONArray evaluateJsonStringToArray(String s) throws JSONException {
JSONTokener t = new JSONTokener(s);
Object o = t.nextValue();
if (o instanceof JSONArray) {
return (JSONArray) o;
} else {
throw new JSONException(s + " couldn't be parsed as JSON array");
}
}
Aggregations