List of usage examples for com.google.gson JsonArray add
public void add(JsonElement element)
From source file:com.adobe.acs.commons.audit_log_search.impl.AuditLogSearchServlet.java
License:Apache License
@SuppressWarnings("unchecked") private JsonArray getModifiedProperties(ValueMap properties) throws IOException { JsonArray modifiedProperties = new JsonArray(); InputStream is = properties.get("cq:properties", InputStream.class); if (is != null) { ObjectInputStream ois = new ObjectInputStream(is); ois.readInt();/*from www . j av a2 s . c o m*/ while (ois.available() != -1) { try { Object obj = ois.readObject(); if (obj instanceof HashSet) { Set<String> propertiesSet = (Set<String>) obj; for (String property : propertiesSet) { modifiedProperties.add(new JsonPrimitive(property)); } break; } } catch (Exception e) { break; } } } return modifiedProperties; }
From source file:com.adobe.acs.commons.dam.impl.CustomComponentActivatorListServlet.java
License:Apache License
@Activate protected void activate(Config conf) { Map<String, String> components = ParameterUtil .toMap(PropertiesUtil.toStringArray(conf.components(), DEFAULT_COMPONENTS), "="); JsonArray array = new JsonArray(); for (Map.Entry<String, String> entry : components.entrySet()) { JsonObject obj = new JsonObject(); obj.addProperty("propertyName", entry.getKey()); obj.addProperty("componentPath", entry.getValue()); array.add(obj); }/*from w w w. j ava 2s . c o m*/ this.json = new JsonObject(); json.add("components", array); }
From source file:com.adobe.acs.commons.exporters.impl.users.Parameters.java
License:Apache License
protected JsonArray getCustomPropertiesAsJSON() { final JsonArray jsonArray = new JsonArray(); for (String customProperty : customProperties) { final JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(RELATIVE_PROPERTY_PATH, customProperty); jsonArray.add(jsonObject); }//from ww w . j a v a 2s .c o m return jsonArray; }
From source file:com.adobe.acs.commons.exporters.impl.users.UsersInitServlet.java
License:Apache License
/** * Creates a JSON array of the User Groups principals in the system. * @param resourceResolver the security context used to collect the groups. * @return a JSON Array of all the user group principals name that the resourceResolver can read. * @throws RepositoryException//from w w w . j a v a 2s . co m */ private JsonArray getGroupOptions(ResourceResolver resourceResolver) throws RepositoryException { final JsonArray jsonArray = new JsonArray(); final QueryManager queryManager = resourceResolver.adaptTo(Session.class).getWorkspace().getQueryManager(); final Query query = queryManager.createQuery(QUERY, Query.JCR_SQL2); final NodeIterator nodeIter = query.execute().getNodes(); while (nodeIter.hasNext()) { Resource resource = resourceResolver.getResource(nodeIter.nextNode().getPath()); jsonArray.add(new JsonPrimitive(resource.getValueMap().get("rep:principalName", "Unknown"))); } return jsonArray; }
From source file:com.adobe.acs.commons.exporters.impl.users.UsersInitServlet.java
License:Apache License
/** * Creates a list of options for the Group Filter list. * @return a JSON Array of the available group filter options. * @throws JSONException/* w w w . ja va 2 s. co m*/ */ private JsonArray getGroupFilterOptions() { JsonObject both = new JsonObject(); both.addProperty(KEY_TEXT, "Direct or Indirect Membership"); both.addProperty(KEY_VALUE, GROUP_FILTER_BOTH); JsonObject direct = new JsonObject(); direct.addProperty(KEY_TEXT, "Direct Membership"); direct.addProperty(KEY_VALUE, GROUP_FILTER_DIRECT); JsonObject indirect = new JsonObject(); indirect.addProperty(KEY_TEXT, "Indirect Membership"); indirect.addProperty(KEY_VALUE, GROUP_FILTER_INDIRECT); JsonArray jsonArray = new JsonArray(); jsonArray.add(direct); jsonArray.add(indirect); jsonArray.add(both); return jsonArray; }
From source file:com.adobe.acs.commons.packaging.impl.PackageHelperImpl.java
License:Apache License
/** * {@inheritDoc}//from w ww.ja va 2 s. c om */ 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 . ja v a 2s. c o 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.quickly.impl.QuicklyEngineImpl.java
License:Apache License
private JsonObject getJSONResults(Command cmd, SlingHttpServletRequest request, final Collection<Result> results) { final JsonObject json = new JsonObject(); JsonArray resultArray = new JsonArray(); json.add(KEY_RESULTS, resultArray);/*from w w w. ja v a2 s. co m*/ final ValueMap requestConfig = new ValueMapDecorator(new HashMap<String, Object>()); // Collect all items collected from OSGi Properties requestConfig.putAll(this.config); // Add Request specific configurations requestConfig.put(AuthoringUIMode.class.getName(), authoringUIModeService.getAuthoringUIMode(request)); for (final Result result : results) { final JsonObject tmp = resultBuilder.toJSON(cmd, result, requestConfig); if (tmp != null) { resultArray.add(tmp); } } return json; }
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); }//w w w . ja v a2 s . co m return arr; }
From source file:com.adobe.acs.commons.wcm.datasources.impl.DataSourceBuilderImpl.java
License:Apache License
@Override public void writeDataSourceOptions(final SlingHttpServletRequest slingRequest, final SlingHttpServletResponse slingResponse) throws IOException { final DataSource datasource = (DataSource) slingRequest.getAttribute(DataSource.class.getName()); final JsonArray jsonArray = new JsonArray(); if (datasource != null) { final Iterator<Resource> iterator = datasource.iterator(); if (iterator != null) { while (iterator.hasNext()) { final Resource dataResource = iterator.next(); if (dataResource != null) { final ValueMap dataProps = dataResource.adaptTo(ValueMap.class); if (dataProps != null) { final JsonObject json = new JsonObject(); json.addProperty(TEXT, dataProps.get(TEXT, "")); json.addProperty(VALUE, dataProps.get(VALUE, "")); jsonArray.add(json); }//w ww . j av a 2s . c o m } } } } slingResponse.setContentType("application/json; charset=UTF-8"); slingResponse.setCharacterEncoding("UTF-8"); Gson gson = new Gson(); gson.toJson(jsonArray, slingResponse.getWriter()); }