Mercurial > hg > LGServices
view src/main/java/de/mpiwg/gazetteer/utils/JSONUtils.java @ 105:16a0796e3871 default tip
remove "console.log" from general.js
author | Calvin Yeh <cyeh@mpipw-berlin.mpg.com> |
---|---|
date | Fri, 29 Sep 2017 16:18:02 +0200 |
parents | 3e62083dbcbf |
children |
line wrap: on
line source
package de.mpiwg.gazetteer.utils; import org.json.JSONObject; import de.mpiwg.gazetteer.bo.LGBranch; import de.mpiwg.gazetteer.bo.LGFile; public class JSONUtils { public static String getString(JSONObject json, String label){ try { return (json.has(label)) ? json.getString(label) : null; } catch (Exception e) {} return null; } public static Long getLong(JSONObject json, String label){ try { return (json.has(label)) ? json.getLong(label) : null; } catch (Exception e) {} return null; } public static JSONObject branch2JSON(LGBranch branch){ JSONObject json = new JSONObject(); try { json.put("id", branch.getId()); json.put("label", branch.getLabel()); json.put("sectionId", branch.getSectionId()); json.put("currentLastFileId", branch.getCurrentLastFileId()); json.put("creatorId", branch.getUserId()); json.put("creationDate", branch.getFomattedCreation()); json.put("info", branch.getInfo()); } catch (Exception e) { e.printStackTrace(); } return json; } public static JSONObject file2JSON(LGFile file, boolean includeText){ JSONObject json = new JSONObject(); try { json.put("id", file.getId()); json.put("version", file.getVersion()); json.put("fileName", file.getFileName()); json.put("info", file.getInfo()); json.put("creatorId", file.getUserId()); json.put("creationDate", file.getFomattedCreation()); if(includeText){ json.put("text", file.getContent()); } } catch (Exception e) { e.printStackTrace(); } return json; } }