List of usage examples for com.google.gson JsonObject addProperty
public void addProperty(String property, Character value)
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); }// ww w . j a v a 2s .c om } } } } 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);/*from w w w. j ava 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.QrCodeServlet.java
License:Apache License
@Override protected final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); if (externalizer == null) { log.warn("Externalizer is not configured. This is required for QR Code servlet to work."); response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR); } else if (request.getResource().getValueMap().get(PN_ENABLED, false)) { final JsonObject json = new JsonObject(); final String publishUrl = externalizer.publishLink(request.getResourceResolver(), request.getRequestPathInfo().getSuffix()); log.debug("Externalized path [ {} ] for QR Code generation to [ {} ]", request.getRequestPathInfo().getSuffix(), publishUrl); if (StringUtils.isNotBlank(publishUrl)) { json.addProperty(JSON_KEY_ENABLED, true); json.addProperty(JSON_KEY_PUBLISH_URL, publishUrl); Gson gson = new Gson(); gson.toJson(json, response.getWriter()); response.getWriter().flush(); } else {//from ww w. j av a 2s .c o m log.warn("Externalizer configuration for AEM Publish did not yield a valid URL"); response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } else { log.warn("Externalizer configuration for AEM Publish did not yield a valid URL"); response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.adobe.acs.commons.wcm.impl.RTEConfigurationServlet.java
License:Apache License
@Override protected JsonObject createEmptyWidget(String rteName) { JsonObject object = new JsonObject(); object.addProperty("xtype", "richtext"); object.addProperty("name", "./" + xssApi.encodeForJSString(rteName)); object.addProperty("hideLabel", true); object.addProperty("jcr:primaryType", "cq:Widget"); return object; }
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())); }// w ww .j a v a 2 s . 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()); }
From source file:com.adobe.acs.commons.wcm.impl.TagWidgetConfigurationServlet.java
License:Apache License
@Override protected JsonObject createEmptyWidget(String propertyName) { JsonObject object = new JsonObject(); object.addProperty("xtype", "tags"); object.addProperty("name", "./" + xssApi.encodeForJSString(propertyName)); object.addProperty("fieldLabel", "Tags/Keywords"); object.addProperty("jcr:primaryType", "cq:Widget"); return object; }
From source file:com.adobe.acs.commons.wcm.impl.TagWidgetConfigurationServlet.java
License:Apache License
private void writeConfigResource(Resource resource, String propertyName, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { JsonObject widget = createEmptyWidget(propertyName); RequestParameterMap map = request.getRequestParameterMap(); for (Map.Entry<String, RequestParameter[]> entry : map.entrySet()) { String key = entry.getKey(); RequestParameter[] params = entry.getValue(); if (params != null) { if (params.length > 1) { JsonArray arr = new JsonArray(); for (int i = 0; i < params.length; i++) { arr.add(new JsonPrimitive(params[i].getString())); }/*from w w w.jav a 2s .c o m*/ widget.add(key, arr); } else if (params.length == 1) { widget.addProperty(key, params[0].getString()); } } } widget = underlay(widget, resource); JsonObject parent = new JsonObject(); parent.addProperty("xtype", "dialogfieldset"); parent.addProperty("border", false); parent.addProperty("padding", 0); parent.addProperty("style", "padding: 0px"); parent.add("items", widget); Gson gson = new Gson(); gson.toJson(parent, response.getWriter()); }
From source file:com.adobe.acs.commons.wcm.views.impl.WCMViewsServlet.java
License:Apache License
@Override protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); if (WCMMode.DISABLED.equals(WCMMode.fromRequest(request))) { response.setStatus(SlingHttpServletResponse.SC_NOT_FOUND); response.getWriter().write(""); return;/* w ww .j av a2 s.co m*/ } /* Valid WCMMode */ final PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class); final Page page = pageManager.getContainingPage(request.getResource()); final WCMViewsResourceVisitor visitor = new WCMViewsResourceVisitor(); visitor.accept(page.getContentResource()); final Set<String> viewSet = new HashSet<String>(visitor.getWCMViews()); // Get the Views provided by the Servlet for (final Map.Entry<String, String[]> entry : this.defaultViews.entrySet()) { if (StringUtils.startsWith(page.getPath(), entry.getKey())) { viewSet.addAll(Arrays.asList(entry.getValue())); } } final List<String> views = new ArrayList<String>(viewSet); Collections.sort(views); log.debug("Collected WCM Views {} for Page [ {} ]", views, page.getPath()); final JsonArray jsonArray = new JsonArray(); for (final String view : views) { final JsonObject json = new JsonObject(); json.addProperty("title", StringUtils.capitalize(view) + " View"); json.addProperty("value", view); jsonArray.add(json); } Gson gson = new Gson(); gson.toJson(jsonArray, response.getWriter()); }
From source file:com.adobe.acs.commons.workflow.bulk.execution.impl.servlets.InitFormServlet.java
License:Apache License
@Override protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); final JsonObject json = new JsonObject(); // Runners/*from w w w . j av a 2 s .c o m*/ accumulate(json, KEY_RUNNER_TYPES, withLabelValue("AEM Workflow", AEMWorkflowRunnerImpl.class.getName())); accumulate(json, KEY_RUNNER_TYPES, withLabelValue("Synthetic Workflow (Single-threaded)", SyntheticWorkflowRunnerImpl.class.getName())); accumulate(json, KEY_RUNNER_TYPES, withLabelValue("Synthetic Workflow (Multi-threaded)", FastActionManagerRunnerImpl.class.getName())); // Query Types accumulate(json, KEY_QUERY_TYPES, withLabelValue("QueryBuilder", "queryBuilder")); accumulate(json, KEY_QUERY_TYPES, withLabelValue("List", "list")); accumulate(json, KEY_QUERY_TYPES, withLabelValue("xPath", "xpath")); accumulate(json, KEY_QUERY_TYPES, withLabelValue("JCR-SQL2", "JCR-SQL2")); accumulate(json, KEY_QUERY_TYPES, withLabelValue("JCR-SQL", "JCR-SQL")); // User Event Data accumulate(json, KEY_USER_EVENT_DATA, withLabelValue("Custom user-event-data", "")); accumulate(json, KEY_USER_EVENT_DATA, withLabelValue("changedByWorkflowProcess", "changedByWorkflowProcess")); accumulate(json, KEY_USER_EVENT_DATA, withLabelValue("acs-aem-commons.bulk-workflow-manager", "acs-aem-commons.bulk-workflow-manager")); // Workflow Models final WorkflowSession workflowSession = workflowService .getWorkflowSession(request.getResourceResolver().adaptTo(Session.class)); try { final WorkflowModel[] workflowModels = workflowSession.getModels(); for (final WorkflowModel workflowModel : workflowModels) { boolean transientWorkflow = isTransient(request.getResourceResolver(), workflowModel.getId()); String workflowLabel = workflowModel.getTitle(); if (transientWorkflow) { workflowLabel += " ( Transient )"; } JsonObject jsonWorkflow = withLabelValue(workflowLabel, workflowModel.getId()); jsonWorkflow.addProperty("transient", transientWorkflow); accumulate(json, "workflowModels", jsonWorkflow); } response.getWriter().write(json.toString()); } catch (WorkflowException e) { log.error("Could not create workflow model drop-down.", e); JSONErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not collect workflows", e.getMessage()); } }
From source file:com.adobe.acs.commons.workflow.bulk.execution.impl.servlets.InitFormServlet.java
License:Apache License
private JsonObject withLabelValue(String label, String value) { JsonObject obj = new JsonObject(); obj.addProperty(KEY_LABEL, label); obj.addProperty(KEY_VALUE, value);//from w w w. ja va2 s. co m return obj; }