Search in sources :

Example 21 with JSONObject

use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.

the class CQIncludePropertyNamespaceServletTest method testNamePropertyUpdater_PropertyValuePatterns.

@Test
public void testNamePropertyUpdater_PropertyValuePatterns() throws Exception {
    final Map<String, Object> config = new HashMap<String, Object>();
    config.put(CQIncludePropertyNamespaceServlet.PROP_NAMESPACEABLE_PROPERTY_VALUE_PATTERNS, new String[] { "^\\./.*" });
    final CQIncludePropertyNamespaceServlet servlet = new CQIncludePropertyNamespaceServlet();
    servlet.activate(config);
    CQIncludePropertyNamespaceServlet.PropertyNamespaceUpdater visitor = servlet.new PropertyNamespaceUpdater("test");
    final JSONObject json = new JSONObject();
    json.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Widget");
    json.put("name", "./myValue");
    json.put("fileName", "./image/myFile");
    json.put("jcr:description", "words");
    json.put("noDotSlash", "no dot slash");
    visitor.accept(json);
    assertEquals("./test/myValue", json.get("name"));
    assertEquals("./test/image/myFile", json.get("fileName"));
    assertEquals("words", json.get("jcr:description"));
    assertEquals("no dot slash", json.get("noDotSlash"));
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) HashMap(java.util.HashMap) JSONObject(org.apache.sling.commons.json.JSONObject) Test(org.junit.Test)

Example 22 with JSONObject

use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.

the class CQIncludePropertyNamespaceServletTest method testNamePropertyUpdater_MultiLevel.

@Test
public void testNamePropertyUpdater_MultiLevel() throws Exception {
    final Map<String, Object> config = new HashMap<String, Object>();
    config.put(CQIncludePropertyNamespaceServlet.PROP_NAMESPACEABLE_PROPERTY_VALUE_PATTERNS, new String[] { "^\\./.*" });
    config.put("namespace.multi-level", true);
    final CQIncludePropertyNamespaceServlet servlet = new CQIncludePropertyNamespaceServlet();
    servlet.activate(config);
    CQIncludePropertyNamespaceServlet.PropertyNamespaceUpdater visitor = servlet.new PropertyNamespaceUpdater("test");
    final JSONObject json = new JSONObject();
    json.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Widget");
    json.put("xtype", "cqinclude");
    json.put("path", "/apps/test.cqinclude.namespace.level-1.json");
    visitor.accept(json);
    assertEquals("/apps/test.cqinclude.namespace.test%252Flevel-1.json", json.get("path"));
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) HashMap(java.util.HashMap) JSONObject(org.apache.sling.commons.json.JSONObject) Test(org.junit.Test)

Example 23 with JSONObject

use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.

the class QrCodeServletTest method doGet.

@Test
public void doGet() throws Exception {
    request.setResource(requestResource);
    when(externalizer.publishLink(request.getResourceResolver(), "/content/externalize-me.html")).thenReturn("http://www.example.com/content/externalize-me.html");
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix("/content/externalize-me.html");
    // requestPathInfo.setExtension("json");
    qrCodeServlet.doGet(request, response);
    JSONObject actual = new JSONObject(response.getOutputAsString());
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    assertEquals(true, actual.getBoolean("enabled"));
    assertEquals("http://www.example.com/content/externalize-me.html", actual.getString("publishURL"));
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) JSONObject(org.apache.sling.commons.json.JSONObject) Test(org.junit.Test)

Example 24 with JSONObject

use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.

the class QuicklyEngineImpl method getJSONResults.

private JSONObject getJSONResults(Command cmd, SlingHttpServletRequest request, final Collection<Result> results) throws JSONException {
    final JSONObject json = new JSONObject();
    json.put(KEY_RESULTS, new JSONArray());
    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) {
            json.accumulate(KEY_RESULTS, tmp);
        }
    }
    return json;
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) ValueMap(org.apache.sling.api.resource.ValueMap) JSONArray(org.apache.sling.commons.json.JSONArray) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) JSONObject(org.apache.sling.commons.json.JSONObject) AuthoringUIMode(com.day.cq.wcm.api.AuthoringUIMode) Result(com.adobe.acs.commons.quickly.results.Result)

Example 25 with JSONObject

use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.

the class QuicklyInitServlet method doGet.

@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();
    try {
        json.put("user", request.getResourceResolver().getUserID());
        json.put("throttle", 200);
        response.getWriter().write(json.toString());
    } catch (JSONException e) {
        response.sendError(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        response.getWriter().print("{\"status:\": \"error\"}");
    }
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) JSONException(org.apache.sling.commons.json.JSONException)

Aggregations

JSONObject (org.apache.sling.commons.json.JSONObject)74 JSONArray (org.apache.sling.commons.json.JSONArray)22 Test (org.junit.Test)20 JSONException (org.apache.sling.commons.json.JSONException)16 HashMap (java.util.HashMap)15 ValueMap (org.apache.sling.api.resource.ValueMap)9 Map (java.util.Map)8 ArrayList (java.util.ArrayList)6 ServletException (javax.servlet.ServletException)6 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)6 Resource (org.apache.sling.api.resource.Resource)6 RepositoryException (javax.jcr.RepositoryException)5 Calendar (java.util.Calendar)4 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)4 Config (com.adobe.acs.commons.workflow.bulk.execution.model.Config)3 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 Session (javax.jcr.Session)3 ModifiableValueMapDecorator (org.apache.sling.api.wrappers.ModifiableValueMapDecorator)3 Form (com.adobe.acs.commons.forms.Form)2