List of usage examples for com.google.gson JsonArray JsonArray
public JsonArray()
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 w w w . jav a2 s.com } 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 ww w . j a v a 2s .c o 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 .j a va 2 s . c om */ 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}//ww w . ja va2 s . 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}// ww w . j av a 2s. 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.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 a 2 s . c om 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);//from www. jav a 2s . c om } 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); }//from ww w. 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()); }
From source file:com.adobe.acs.commons.wcm.impl.CustomPollingImporterListServlet.java
License:Apache License
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { XSSAPI xssApi = request.adaptTo(XSSAPI.class); JsonObject result = new JsonObject(); JsonArray list = new JsonArray(); result.add("list", list); ServiceReference[] services = tracker.getServiceReferences(); if (services != null) { for (ServiceReference service : services) { String displayName = PropertiesUtil.toString(service.getProperty("displayName"), null); String[] schemes = PropertiesUtil.toStringArray(service.getProperty(Importer.SCHEME_PROPERTY)); if (displayName != null && schemes != null) { for (String scheme : schemes) { JsonObject obj = new JsonObject(); obj.addProperty("qtip", ""); obj.addProperty("text", displayName); obj.addProperty("text_xss", xssApi.encodeForJSString(displayName)); obj.addProperty("value", scheme); list.add(obj);/* ww w .ja v a 2 s .c o m*/ } } } } response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); Gson gson = new Gson(); gson.toJson(result, response.getWriter()); }
From source file:com.adobe.acs.commons.wcm.impl.RTEConfigurationServlet.java
License:Apache License
private void writeConfigResource(Resource resource, String rteName, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { JsonObject widget = createEmptyWidget(rteName); // these two size properties seem to be necessary to get the size correct // in a component dialog widget.addProperty("width", RTE_WIDTH); widget.addProperty("height", RTE_HEIGHT); RequestParameterMap map = request.getRequestParameterMap(); for (Map.Entry<String, RequestParameter[]> entry : map.entrySet()) { String key = entry.getKey(); RequestParameter[] params = entry.getValue(); if (params != null && (params.length > 1 || EXTERNAL_STYLESHEETS_PROPERTY.equals(key))) { JsonArray arr = new JsonArray(); for (int i = 0; i < params.length; i++) { arr.add(new JsonPrimitive(params[i].getString())); }// ww w .ja v a 2s . c o m widget.add(key, arr); } else if (params != null && params.length == 1) { widget.addProperty(key, params[0].getString()); } } if (widget.has("fieldLabel")) { widget.remove("hideLabel"); } JsonObject config = toJsonObject(resource); if (config == null) { config = new JsonObject(); } if (config.has("includeDefault") && config.get("includeDefault").getAsBoolean()) { config = underlay(config, resource.getResourceResolver().getResource(DEFAULT_CONFIG)); } widget.add("rtePlugins", config); JsonObject parent = new JsonObject(); parent.addProperty("xtype", "dialogfieldset"); parent.addProperty("border", false); parent.addProperty("padding", 0); parent.add("items", widget); Gson gson = new Gson(); gson.toJson(parent, response.getWriter()); }