List of usage examples for com.google.gson JsonObject addProperty
public void addProperty(String property, Character value)
From source file:com.adobe.acs.commons.packaging.impl.PackageHelperImpl.java
License:Apache License
/** * {@inheritDoc}//from w ww . j av a2s. c o m */ public String getSuccessJSON(final JcrPackage jcrPackage) throws RepositoryException { final JsonObject json = new JsonObject(); json.addProperty(KEY_STATUS, "success"); json.addProperty(KEY_PATH, jcrPackage.getNode().getPath()); JsonArray filterSetsArray = new JsonArray(); json.add(KEY_FILTER_SETS, filterSetsArray); final List<PathFilterSet> filterSets = jcrPackage.getDefinition().getMetaInf().getFilter().getFilterSets(); for (final PathFilterSet filterSet : filterSets) { final JsonObject jsonFilterSet = new JsonObject(); jsonFilterSet.addProperty(KEY_IMPORT_MODE, filterSet.getImportMode().name()); jsonFilterSet.addProperty(KEY_ROOT_PATH, filterSet.getRoot()); filterSetsArray.add(jsonFilterSet); } return json.toString(); }
From source file:com.adobe.acs.commons.packaging.impl.PackageHelperImpl.java
License:Apache License
/** * {@inheritDoc}/* w ww . j a va 2 s .co m*/ */ public String getPathFilterSetPreviewJSON(final Collection<PathFilterSet> pathFilterSets) { final JsonObject json = new JsonObject(); json.addProperty(KEY_STATUS, "preview"); json.addProperty(KEY_PATH, "Not applicable (Preview)"); JsonArray filterSets = new JsonArray(); json.add(KEY_FILTER_SETS, filterSets); for (final PathFilterSet pathFilterSet : pathFilterSets) { final JsonObject tmp = new JsonObject(); tmp.addProperty(KEY_IMPORT_MODE, "Not applicable (Preview)"); tmp.addProperty(KEY_ROOT_PATH, pathFilterSet.getRoot()); filterSets.add(tmp); } return json.toString(); }
From source file:com.adobe.acs.commons.packaging.impl.PackageHelperImpl.java
License:Apache License
/** * {@inheritDoc}/*from w w w. j a v a 2 s. co m*/ */ public String getErrorJSON(final String msg) { Gson gson = new Gson(); final JsonObject json = new JsonObject(); json.addProperty(KEY_STATUS, "error"); json.addProperty(KEY_MSG, msg); return gson.toJson(json); }
From source file:com.adobe.acs.commons.quickly.impl.QuicklyInitServlet.java
License:Apache License
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setHeader("Content-Type", " application/json; charset=UTF-8"); final JsonObject json = new JsonObject(); json.addProperty("user", request.getResourceResolver().getUserID()); json.addProperty("throttle", 200); Gson gson = new Gson(); gson.toJson(json, response.getWriter()); }
From source file:com.adobe.acs.commons.quickly.results.impl.serializers.AbstractResultSerializer.java
License:Apache License
public JsonObject toJSON(final Result result) { final JsonObject json = new JsonObject(); json.addProperty("title", result.getTitle()); json.addProperty("type", result.getResultType()); json.addProperty("description", result.getDescription()); json.addProperty("path", result.getPath()); json.add("action", this.toJSON(result.getAction())); json.add("secondaryAction", this.toJSON(result.getSecondaryAction())); return json;//from ww w . j a va 2s.c o m }
From source file:com.adobe.acs.commons.quickly.results.impl.serializers.AbstractResultSerializer.java
License:Apache License
public JsonObject toJSON(final Action action) { final JsonObject json = new JsonObject(); if (action != null) { Gson gson = new Gson(); json.addProperty("uri", action.getUri()); json.addProperty("method", action.getMethod().name()); json.addProperty("target", action.getTarget().name()); json.addProperty("xhr", false); json.addProperty("script", action.getScript()); json.add("params", gson.toJsonTree(action.getParams())); }//from ww w .j a v a2 s .c o m return json; }
From source file:com.adobe.acs.commons.redirectmaps.impl.RedirectEntriesUtils.java
License:Apache License
protected static final void writeEntriesToResponse(SlingHttpServletRequest request, SlingHttpServletResponse response, String message) throws IOException { log.trace("writeEntriesToResponse"); log.debug("Requesting redirect maps from {}", request.getResource()); RedirectMapModel redirectMap = request.getResource().adaptTo(RedirectMapModel.class); response.setContentType(MediaType.JSON_UTF_8.toString()); JsonObject res = new JsonObject(); res.addProperty("message", message); if (redirectMap != null) { JsonElement entries = gson.toJsonTree(redirectMap.getEntries(), new TypeToken<List<MapEntry>>() { }.getType());//w w w .j a v a2 s . c om res.add("entries", entries); res.add("invalidEntries", gson.toJsonTree(redirectMap.getInvalidEntries(), new TypeToken<List<MapEntry>>() { }.getType())); } else { throw new IOException("Failed to get redirect map from " + request.getResource()); } IOUtils.write(res.toString(), response.getOutputStream(), StandardCharsets.UTF_8); }
From source file:com.adobe.acs.commons.replication.impl.ReplicateVersionServlet.java
License:Apache License
@Override public final void doPost(SlingHttpServletRequest req, SlingHttpServletResponse res) throws ServletException, IOException { log.debug("Entering ReplicatePageVersionServlet.doPost(..)"); String[] rootPaths = req.getParameterValues("rootPaths"); Date date = getDate(req.getParameter("datetimecal")); String[] agents = req.getParameterValues("cmbAgent"); JsonObject obj = validate(rootPaths, agents, date); if (!obj.has(KEY_ERROR)) { log.debug("Initiating version replication"); List<ReplicationResult> response = replicateVersion.replicate(req.getResourceResolver(), rootPaths, agents, date);//from w w w . j av a2s.c o m if (log.isDebugEnabled()) { for (final ReplicationResult replicationResult : response) { log.debug("Replication result: {} -- {}", replicationResult.getPath(), replicationResult.getStatus()); } } JsonArray arr = convertResponseToJson(response); obj = new JsonObject(); obj.add(KEY_RESULT, arr); } else { log.debug("Did not attempt to replicate version due to issue with input params"); res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); obj.addProperty(KEY_STATUS, KEY_ERROR); } res.setContentType("application/json"); res.getWriter().print(obj.toString()); }
From source file:com.adobe.acs.commons.replication.impl.ReplicateVersionServlet.java
License:Apache License
private JsonArray convertResponseToJson(List<ReplicationResult> list) { JsonArray arr = new JsonArray(); for (ReplicationResult result : list) { JsonObject resultObject = new JsonObject(); resultObject.addProperty(KEY_PATH, result.getPath()); resultObject.addProperty(KEY_STATUS, result.getStatus().name()); resultObject.addProperty(KEY_VERSION, result.getVersion()); arr.add(resultObject);/*from w ww . j a va 2 s. c o m*/ } return arr; }
From source file:com.adobe.acs.commons.replication.impl.ReplicateVersionServlet.java
License:Apache License
private JsonObject validate(String[] rootPaths, String[] agents, Date date) { final JsonObject obj = new JsonObject(); if (ArrayUtils.isEmpty(rootPaths)) { obj.addProperty(KEY_ERROR, "Select at least 1 root path."); log.debug("Error validating root paths (they're empty)"); return obj; }/*from w ww . j av a 2 s .co m*/ for (final String rootPath : rootPaths) { if (StringUtils.isBlank(rootPath)) { obj.addProperty(KEY_ERROR, "Root paths cannot be empty."); log.debug("Error validating a root path"); return obj; } } if (date == null) { obj.addProperty(KEY_ERROR, "Specify the date and time to select the appropriate resource versions for replication."); log.debug("Error validating date"); return obj; } if (ArrayUtils.isEmpty(agents)) { obj.addProperty(KEY_ERROR, "Select at least 1 replication agent."); log.debug("Error validating agents"); return obj; } log.debug("Validated all version replication inputs successfully"); return obj; }