Search in sources :

Example 51 with JSONObject

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

the class PackageHelperImpl method getPathFilterSetPreviewJSON.

/**
 * {@inheritDoc}
 */
public String getPathFilterSetPreviewJSON(final Collection<PathFilterSet> pathFilterSets) throws JSONException {
    final JSONObject json = new JSONObject();
    json.put(KEY_STATUS, "preview");
    json.put(KEY_PATH, "Not applicable (Preview)");
    json.put(KEY_FILTER_SETS, new JSONArray());
    for (final PathFilterSet pathFilterSet : pathFilterSets) {
        final JSONObject tmp = new JSONObject();
        tmp.put(KEY_IMPORT_MODE, "Not applicable (Preview)");
        tmp.put(KEY_ROOT_PATH, pathFilterSet.getRoot());
        json.accumulate("filterSets", tmp);
    }
    return json.toString();
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) JSONArray(org.apache.sling.commons.json.JSONArray)

Example 52 with JSONObject

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

the class PackageHelperImplTest method testGetPreviewJSON.

@Test
public void testGetPreviewJSON() throws Exception {
    final Set<Resource> resources = new HashSet<Resource>();
    resources.add(slingContext.create().resource("/a/b/c"));
    resources.add(slingContext.create().resource("/d/e/f"));
    resources.add(slingContext.create().resource("/g/h/i"));
    final String actual = packageHelper.getPreviewJSON(resources);
    final JSONObject json = new JSONObject(actual);
    assertEquals("preview", json.getString("status"));
    assertEquals("Not applicable (Preview)", json.getString("path"));
    final String[] expectedFilterSets = new String[] { "/a/b/c", "/d/e/f", "/g/h/i" };
    JSONArray actualArray = json.getJSONArray("filterSets");
    for (int i = 0; i < actualArray.length(); i++) {
        JSONObject tmp = actualArray.getJSONObject(i);
        assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
    }
    assertEquals(expectedFilterSets.length, actualArray.length());
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) Resource(org.apache.sling.api.resource.Resource) JSONArray(org.apache.sling.commons.json.JSONArray) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with JSONObject

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

the class CQIncludePropertyNamespaceServletTest method testNamePropertyUpdater_PropertyNames.

@Test
public void testNamePropertyUpdater_PropertyNames() throws Exception {
    final Map<String, Object> config = new HashMap<String, Object>();
    config.put(CQIncludePropertyNamespaceServlet.PROP_NAMESPACEABLE_PROPERTY_NAMES, new String[] { "fileName", "name", "noDotSlash" });
    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", "./myFile");
    json.put("jcr:description", "words");
    json.put("noDotSlash", "no dot slash");
    visitor.accept(json);
    assertEquals("./test/myValue", json.get("name"));
    assertEquals("./test/myFile", json.get("fileName"));
    assertEquals("words", json.get("jcr:description"));
    assertEquals("test/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 54 with JSONObject

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

the class CQIncludePropertyNamespaceServletTest method testIsCqincludeNamspaceWidget.

@Test
public void testIsCqincludeNamspaceWidget() throws JSONException {
    CQIncludePropertyNamespaceServlet.PropertyNamespaceUpdater pnu = new CQIncludePropertyNamespaceServlet().new PropertyNamespaceUpdater("my-namespace");
    final JSONObject json = new JSONObject();
    json.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Widget");
    json.put("xtype", "cqinclude");
    json.put("path", "/apps/test.cqinclude.namespace.test.json");
    assertEquals(true, pnu.isCqincludeNamespaceWidget(json));
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) Test(org.junit.Test)

Example 55 with JSONObject

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

the class CQIncludePropertyNamespaceServletTest method testMakeMultiLevel.

@Test
public void testMakeMultiLevel() throws JSONException {
    CQIncludePropertyNamespaceServlet.PropertyNamespaceUpdater pnu = new CQIncludePropertyNamespaceServlet().new PropertyNamespaceUpdater("my-namespace");
    final JSONObject json = new JSONObject();
    json.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Widget");
    json.put("xtype", "cqinclude");
    json.put("path", "/apps/test.cqinclude.namespace.test.json");
    JSONObject actual = pnu.makeMultiLevel(json);
    assertEquals("/apps/test.cqinclude.namespace.my-namespace%252Ftest.json", actual.getString("path"));
}
Also used : JSONObject(org.apache.sling.commons.json.JSONObject) Test(org.junit.Test)

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