public JsonImport(String jsonString, String worksheetName, Workspace workspace, String encoding, int maxNumLines) { this(JSONUtil.createJson(jsonString), worksheetName, workspace, encoding, maxNumLines); }
@Override public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) { pw.println(prefix + "{"); String newPref = prefix + " "; pw.println(newPref + JSONUtil.json(GenericJsonKeys.updateType, getUpdateType())); pw.println(newPref + JSONUtil.json(JsonKeys.worksheet, worksheetId)); pw.println(newPref + JSONUtil.json(JsonKeys.nodeId, nodeId)); pw.println(newPref + JSONUtil.json(JsonKeys.newStatus, newStatus.getCodedStatus())); pw.println(newPref + JSONUtil.json(JsonKeys.expandedValue, newValue.asString())); String displayValueString = newValue.asString(); int maxValueLength = vWorkspace.getPreferences().getIntViewPreferenceValue( ViewPreference.maxCharactersInCell); if(displayValueString.length() > maxValueLength) { displayValueString = JSONUtil.truncateCellValue( displayValueString,maxValueLength); } pw.println(newPref + JSONUtil.jsonLast(JsonKeys.displayValue, displayValueString)); pw.println(prefix + "}"); }
public JsonImport(File jsonFile, String worksheetName, Workspace workspace,String encoding, int maxNumLines, JSONArray tree,boolean isJSONLines) throws FileNotFoundException, Exception { super(worksheetName, workspace, encoding); FileObject fo = new FileObject(jsonFile, encoding); if(isJSONLines){ this.json = JSONUtil.convertJSONLinesToJSONArray(new FileInputStream(fo.file), fo.encoding); } else{ this.json = fo; } this.workspace = workspace; this.maxNumLines = maxNumLines; this.columnsJson = tree; this.worksheetName = worksheetName; this.encoding = encoding; }
public static Object createJson(Reader reader) { // This is an ugly, and surely inefficient solution, but I can't figure // out a way around it. String x = readerToString(reader); return createJson(x); }
public static Object createJson(String jsonString) { Object result = createJSONObject(new JSONTokener(jsonString)); if (result == null) { result = createJSONArray(new JSONTokener(jsonString)); } if (result == null) { logger.error("Could not parse as JSONObject or JSONArray"); } return result; }
@Override public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) { pw.println(prefix + "{"); String newPref = prefix + " "; pw.println(newPref + JSONUtil.json(GenericJsonKeys.updateType, getUpdateType())); pw.println(newPref + JSONUtil.jsonStartList(JsonKeys.commands)); commandHistory.generateFullHistoryJson(newPref + " ", pw, vWorkspace); pw.println(newPref + "]"); pw.println(prefix + "}"); }
public void generateWorksheetListJson(String prefix, PrintWriter pw) { pw.println(prefix + "{"); String newPref = prefix + " "; pw.println(newPref + JSONUtil.json(WorksheetListUpdate.JsonKeys.worksheetId, this.getWorksheetId())); pw.println(newPref + JSONUtil.json(WorksheetListUpdate.JsonKeys.isUpToDate, upToDate)); pw.println(newPref + JSONUtil.json(WorksheetListUpdate.JsonKeys.isCollapsed, collapsed)); pw.println(newPref + JSONUtil.json(WorksheetListUpdate.JsonKeys.encoding, worksheet.getEncoding())); pw.println(newPref + JSONUtil.jsonLast(WorksheetListUpdate.JsonKeys.title, worksheet.getTitle())); pw.println(prefix + "}"); } }
logger.info(extractions); JSONArray result = (JSONArray) JSONUtil.createJson(extractions); addValues.put(addValuesObj); System.out.println(JSONUtil.prettyPrintJson(addValues.toString()));
@Override public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace, HistoryType historyType) { pw.println(prefix + "{"); String newPref = prefix + " "; generateCommandJSONAttributes(prefix, pw, vWorkspace, historyType); pw.println("," + newPref + JSONUtil.jsonLast(JsonKeys.worksheetId, getWorksheetId())); pw.println(prefix + "}"); } }
@Override public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) { Collection<VWorksheet> vWorksheetList = vWorkspace.getViewFactory().getVWorksheets(); pw.println(prefix + "{"); String prefix1 = prefix + " "; pw.println(prefix1 + JSONUtil.json(GenericJsonKeys.updateType, getUpdateType())); generateWorksheetListJson(prefix, pw, vWorksheetList, prefix1); pw.println(prefix + "}"); }
Object b = a2.get(i); if(!compareJSONObjects(a, b)) return false; return false; if(!compareJSONObjects(val1, val2)) return false;
protected void generateCommandJSONAttributes(String prefix, PrintWriter pw, VWorkspace vWorkspace, HistoryType historyType) { String newPref = prefix + " "; pw.println(newPref + JSONUtil.json(JsonKeys.commandId, getId())); pw.println(newPref + JSONUtil.json(JsonKeys.title, getTitle())); pw.println(newPref + JSONUtil.json(JsonKeys.description, getDescription())); pw.println(newPref + JSONUtil.json(JsonKeys.historyType, historyType.name())); pw.println(newPref + JSONUtil.jsonLast(JsonKeys.commandType, getCommandType() .name())); }
public void generateJson(String prefix, PrintWriter pw, VWorkspace vWorkspace) { pw.println(prefix + "{"); String newPref = prefix + " "; pw.println(newPref + JSONUtil.json(JsonKeys.workspaceId, vWorkspace.getWorkspace() .getId())); pw.println(newPref + JSONUtil.jsonStartList(JsonKeys.elements)); Iterator<AbstractUpdate> it = updates.iterator(); while (it.hasNext()) { AbstractUpdate update = it.next(); update.generateJson(newPref + " ", pw, vWorkspace); if (it.hasNext()) { pw.println(newPref + " ,"); } } pw.println(newPref + "]"); pw.println(prefix + "}"); }
public JsonImport(String jsonString, RepFactory repFactory, Worksheet wk, Workspace workspace, int maxNumLines) { this(JSONUtil.createJson(jsonString), repFactory, wk, workspace, maxNumLines); }
private Worksheet generateWorksheetFromJLStream(String sourceName, InputStream is, InputProperties inputTypeParams, Workspace workspace) throws Exception{ Worksheet worksheet; String encoding = (String)inputTypeParams.get(InputProperty.ENCODING); int maxNumLines = (inputTypeParams.get(InputProperty.MAX_NUM_LINES) != null)? (int)inputTypeParams.get(InputProperty.MAX_NUM_LINES) : -1; Object json=JSONUtil.convertJSONLinesToJSONArray(is,encoding); JsonImport imp = new JsonImport(json, sourceName, workspace, encoding, maxNumLines); worksheet = imp.generateWorksheet(); return worksheet; } }
public static String prettyPrintJson(String jsonString) { try { Object o = createJson(jsonString); if (o instanceof JSONObject) { return ((JSONObject) o).toString(4); } else if (o instanceof JSONArray) { return ((JSONArray) o).toString(4); } else { return "not JSON"; } } catch (JSONException e) { e.printStackTrace(); return "not JSON"; } }
output = XML.toJSONObject(responseString.toString()); } else if(entity.getContentType().toString().indexOf("json") != -1){ output = JSONUtil.createJson(responseString.toString());
private String parseChildren(String inputJSON, Workspace workspace) { JSONArray array = (JSONArray) JSONUtil.createJson(inputJSON); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); String hNodeId = obj.getString(ClientJsonKeys.id.name()); HNode node = workspace.getFactory().getHNode(hNodeId); JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory()); obj.put(ClientJsonKeys.id.name(), hNodeRepresentation); if (obj.has(ClientJsonKeys.children.name())) obj.put(ClientJsonKeys.children.name(), parseChildren(obj.get(ClientJsonKeys.children.name()).toString(), workspace)); } return array.toString(); }
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); } }
if(jsonFile.exists()){ json = (JSONObject) JSONUtil.createJson(new FileReader(jsonFile)); if(json == null) {