Package org.apache.sling.commons.json

Examples of org.apache.sling.commons.json.JSONArray


            log.error("exception occurred", e);
        }
    }

    private JSONArray convertResponseToJson(List<ReplicationResult> list) throws JSONException {
        JSONArray arr = new JSONArray();

        for (ReplicationResult result : list) {
            JSONObject resultObject = new JSONObject();

            resultObject.put("path", result.getPath());
            resultObject.put("status", result.getStatus().name());
            resultObject.put("version", result.getVersion());

            arr.put(resultObject);
        }
        return arr;
    }
View Full Code Here


    public String getSuccessJSON(final JcrPackage jcrPackage) throws JSONException, RepositoryException {
        final JSONObject json = new JSONObject();

        json.put("status", "success");
        json.put("path", jcrPackage.getNode().getPath());
        json.put("filterSets", new JSONArray());

        final List<PathFilterSet> filterSets = jcrPackage.getDefinition().getMetaInf().getFilter().getFilterSets();
        for (final PathFilterSet filterSet : filterSets) {
            final JSONObject jsonFilterSet = new JSONObject();
            jsonFilterSet.put("importMode", filterSet.getImportMode().name());
View Full Code Here

    public String getPathFilterSetPreviewJSON(final Collection<PathFilterSet> pathFilterSets) throws JSONException {
        final JSONObject json = new JSONObject();

        json.put("status", "preview");
        json.put("path", "Not applicable (Preview)");
        json.put("filterSets", new JSONArray());

        for (final PathFilterSet pathFilterSet : pathFilterSets) {
            final JSONObject tmp = new JSONObject();
            tmp.put("importMode", "Not applicable (Preview)");
            tmp.put("rootPath", pathFilterSet.getRoot());
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    protected static Object convertValue(Object val) throws JSONException {
        if (val.getClass().isArray()) {
            Object[] vals = (Object[]) val;
            JSONArray array = new JSONArray();
            for (Object arrayVal : vals) {
                Object converted = convertValue(arrayVal);
                array.put(converted == null ? arrayVal : converted);
            }
            return array;
        } else if (val instanceof Collection) {
            JSONArray array = new JSONArray();
            for (Object arrayVal : (Collection<?>) val) {
                Object converted = convertValue(arrayVal);
                array.put(converted == null ? arrayVal : converted);
            }
            return array;
        } else if (val instanceof Map) {
            Map<?, ?> valMap = (Map<?, ?>) val;
            JSONObject obj = new JSONObject();
View Full Code Here

        assertTrue("jcr:mixinTypes expected after setting them", json.has("jcr:mixinTypes"));
       
        Object mixObject = json.get("jcr:mixinTypes");
        assertTrue("jcr:mixinTypes must be an array", mixObject instanceof JSONArray);
       
        JSONArray mix = (JSONArray) mixObject;
        assertTrue("jcr:mixinTypes must have a single entry", mix.length() == 1);
        assertEquals("jcr:mixinTypes must have correct value", "mix:versionable", mix.get(0));

        // remove mixin
        props.clear();
        props.put("jcr:mixinTypes@Delete", "-");
        testClient.createNode(location, props);
View Full Code Here

        }
        //assertJavascript(expected, content, TEST_SCRIPT);
        try {
            String actual = "";
            JSONObject obj = new JSONObject(content);
            JSONArray n = obj.names();
            for (int i=0; i<n.length(); i++) {
                String name = n.getString(i);
                Object o = obj.get(name);
                if (o instanceof JSONObject) {
                    actual += name + ",";
                }
            }
View Full Code Here

                list.add(this.toJsonObject((NodeDescription) item));
            } else {
                list.add(item);
            }
        }
        return new JSONArray(list);
    }
View Full Code Here

            node.setPrimaryNodeType(String.valueOf(primaryType));
        }

        Object mixinsObject = obj.opt("jcr:mixinTypes");
        if (mixinsObject instanceof JSONArray) {
            JSONArray mixins = (JSONArray) mixinsObject;
            for (int i = 0; i < mixins.length(); i++) {
                node.addMixinNodeType(mixins.getString(i));
            }
        }

        // add properties and nodes
        JSONArray names = obj.names();
        for (int i = 0; names != null && i < names.length(); i++) {
            String n = names.getString(i);
            // skip well known objects
            if (!ignoredNames.contains(n)) {
                Object o = obj.get(n);
                if (o instanceof JSONObject) {
                    NodeDescription child = this.createNode(n, (JSONObject) o);
View Full Code Here

        property.setName(name);

        // assume simple value
        if (value instanceof JSONArray) {
            // multivalue
            JSONArray array = (JSONArray) value;
            if (array.length() > 0) {
                for (int i = 0; i < array.length(); i++) {
                    property.addValue(array.get(i));
                }
                value = array.opt(0);
            } else {
                property.addValue(null);
                value = null;
            }
View Full Code Here

    assertNotNull(aceString);
   
    JSONObject aceObject = new JSONObject(aceString);
    assertNotNull(aceObject);
   
    JSONArray grantedArray = aceObject.getJSONArray("granted");
    assertNotNull(grantedArray);
    assertEquals("jcr:read", grantedArray.getString(0));

    JSONArray deniedArray = aceObject.getJSONArray("denied");
    assertNotNull(deniedArray);
    assertEquals("jcr:write", deniedArray.getString(0));
  }
View Full Code Here

TOP

Related Classes of org.apache.sling.commons.json.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.