public JSONObject getSavedModels(String contextId) throws IOException { File file = getModelsFile(contextId); JSONObject json = new JSONObject(FileUtil.readFileContentsToString(file, "UTF-8")); return json; }
private void loadDefaultPreferences() throws IOException, URISyntaxException { jsonFile = loadWorkspacePrefTemplateFile(); String templateStr = FileUtil.readFileContentsToString(jsonFile, "UTF-8"); json = new JSONObject(templateStr); }
private void createNewPreferencesFileFromTemplate() throws IOException, URISyntaxException { jsonFile.createNewFile(); File templateFile = loadWorkspacePrefTemplateFile(); json = new JSONObject(FileUtil.readFileContentsToString(templateFile, "UTF-8")); FileUtil.writePrettyPrintedJSONObjectToFile(json, jsonFile); }
public void saveModelUrl(String url, String contextId) throws JSONException, IOException { File file = getModelsFile(contextId); JSONObject json = new JSONObject(FileUtil.readFileContentsToString(file, "UTF-8")); JSONArray models = ((JSONArray)json.get("models")); JSONArray newModels = new JSONArray(); int modelIndex = modelExists(models, url); for(int i = Math.max(0, models.length() - maxNumUrls); i < models.length(); i ++) { if(modelIndex != i) { newModels.put(models.get(i)); } } newModels.put(url); json.put("models", newModels); FileUtil.writePrettyPrintedJSONObjectToFile(json, file); }
public XMLImport(File xmlFile, String worksheetName, Workspace workspace, String encoding, int maxNumLines, JSONArray columnsJson) { super(worksheetName, workspace, encoding); try { String fileContents = FileUtil.readFileContentsToString(xmlFile, encoding); JSONObject jsonObj = XML.toJSONObject(fileContents); Object json = JSONUtil.createJson(jsonObj.toString()); jsonImport = new JsonImport(json,this.getFactory(), this.getWorksheet(), workspace, maxNumLines); } catch (JSONException ex) { logger.error("Error in populating the worksheet with XML", ex); } catch (IOException ex) { logger.error("Error in reading the XML file", ex); } }