Search in sources :

Example 41 with JSONTokener

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;
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) JSONException(org.json.JSONException) File(java.io.File) ButterflyModule(edu.mit.simile.butterfly.ButterflyModule) FileInputStream(java.io.FileInputStream)

Example 42 with JSONTokener

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);
    }
}
Also used : JSONTokener(org.json.JSONTokener) Project(com.google.refine.model.Project) JSONException(org.json.JSONException) PreferenceStore(com.google.refine.preference.PreferenceStore)

Example 43 with JSONTokener

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));
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) ReconOperation(com.google.refine.operations.recon.ReconOperation)

Example 44 with JSONTokener

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();
    }
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) FileReader(java.io.FileReader)

Example 45 with JSONTokener

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");
    }
}
Also used : JSONTokener(org.json.JSONTokener) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject)

Aggregations

JSONTokener (org.json.JSONTokener)63 JSONObject (org.json.JSONObject)60 JSONException (org.json.JSONException)32 JSONArray (org.json.JSONArray)23 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)12 InputStream (java.io.InputStream)10 GraphObject (com.facebook.model.GraphObject)8 FileInputStream (java.io.FileInputStream)8 File (java.io.File)6 HashMap (java.util.HashMap)6 HttpEntity (org.apache.http.HttpEntity)5 HttpResponse (org.apache.http.HttpResponse)5 BufferedReader (java.io.BufferedReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStreamReader (java.io.InputStreamReader)4 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)4 HttpPost (org.apache.http.client.methods.HttpPost)4 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)4 FacebookException (com.facebook.FacebookException)3