Package org.apache.sling.commons.json

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


        Set<Entry<String, Map<String, Object>>> entrySet = aclMap.entrySet();
        for (Entry<String, Map<String, Object>> entry : entrySet) {
            String principalName = entry.getKey();
            Map<String, Object> value = entry.getValue();

            JSONObject aceObject = new JSONObject();
            aceObject.put("principal", principalName);

            Set<String> grantedSet = (Set<String>) value.get("granted");
            if (grantedSet != null && !grantedSet.isEmpty()) {
                aceObject.put("granted", grantedSet);
            }

            Set<String> deniedSet = (Set<String>) value.get("denied");
            if (deniedSet != null && !deniedSet.isEmpty()) {
                aceObject.put("denied", deniedSet);
            }
            aceObject.put("order", value.get("order"));
            aclList.add(aceObject);
        }
        JSONObject jsonAclMap = new JSONObject(aclMap);
        for ( JSONObject jsonObj : aclList) {
          jsonAclMap.put(jsonObj.getString("principal"), jsonObj);
        }

        return jsonAclMap;
    }
View Full Code Here


            String jsonString = toString(ins).trim();
            if (!jsonString.startsWith("{")) {
                jsonString = "{" + jsonString + "}";
            }

            JSONObject json = new JSONObject(jsonString);
            this.createNode(null, json, contentCreator);
        } catch (JSONException je) {
            throw (IOException) new IOException(je.getMessage()).initCause(je);
        }
    }
View Full Code Here

    throws JSONException {

        final Iterator<Resource> children = resource.listChildren();
        while (children.hasNext()) {
            final Resource res = children.next();
            final JSONObject json = collectResource(res, jsonObj);
            collectChildren(res, json);
        }
    }
View Full Code Here

     * @param level The level where this resource is located.
     * @throws JSONException
     */
    private JSONObject collectResource(final Resource resource, final JSONObject parent)
    throws JSONException {
        final JSONObject o = adapt(resource);
        parent.put(resource.getName(), o);
        return o;
    }
View Full Code Here

        @SuppressWarnings("unchecked")
        final Map propertyMap = (valueMap != null)
                ? valueMap
                : resource.adaptTo(Map.class);

        final JSONObject obj = new JSONObject();

        if (propertyMap == null) {

            // no map available, try string
            final String value = resource.adaptTo(String.class);
            if (value != null) {

                // single value property or just plain String resource or...
                obj.put(resource.getName(), value);

            } else {

                // Try multi-value "property"
                final String[] values = resource.adaptTo(String[].class);
                if (values != null) {
                    obj.put(resource.getName(), new JSONArray(Arrays.asList(values)));
                }

            }
            if ( resource.getResourceType() != null ) {
                obj.put("sling:resourceType", resource.getResourceType());
            }
            if ( resource.getResourceSuperType() != null ) {
                obj.put("sling:resourceSuperType", resource.getResourceSuperType());
            }

        } else {

            @SuppressWarnings("unchecked")
View Full Code Here

                encoding = response.getEntity().getContentEncoding().getValue();
            }
            final String content = IOUtils.toString(response.getEntity().getContent(), encoding);
           
            // Start level is in the props array, with key="Start Level"
            final JSONObject status = new JSONObject(content);
            final JSONArray props = status.getJSONArray("data").getJSONObject(0).getJSONArray("props");
            final String KEY = "key";
            final String SL = "Start Level";
            boolean found = false;
            for(int i=0; i < props.length(); i++) {
                final JSONObject o = props.getJSONObject(i);
                if(o.has(KEY) && SL.equals(o.getString(KEY))) {
                    found = true;
                    assertEquals("Expecting the start level that we set", "99", o.getString("value"));
                }
            }
            assertTrue("Expecting start level to be found in JSON output", found);
        } finally {
            closeConnection(response);
View Full Code Here

     */
    private String getFailure(JSONArray json, String testName) throws JSONException {
        String result = null;
       
        for(int i = 0 ; i < json.length(); i++) {
            final JSONObject obj = json.getJSONObject(i);
            if("test".equals(obj.getString("INFO_TYPE"))) {
                if(obj.getString(DESCRIPTION_FIELD).contains(testName)) {
                    if(obj.has(FAILURE_FIELD)) {
                        result = obj.getString(FAILURE_FIELD);
                        break;
                    }
                }
            }
        }
View Full Code Here

            File file = createFile("helloworld", 170);
            String nodeName = file.getName();
            int chunkSize = 200;
            // uplaod first chunk 200 bytes uploaded
            uploadChunks(parentPath, file, nodeName, 0, chunkSize, 1);
            JSONObject json = getChunkJson(parentPath + "/" + nodeName);
            validate(json, 200, 1);

            chunkSize = 300;
            // upload next two chunks of 300 each.total 800 bytes
            // uploaded
            uploadChunks(parentPath, file, nodeName, 200, chunkSize, 2);
            json = getChunkJson(parentPath + "/" + nodeName);
            validate(json, 800, 3);

            chunkSize = 400;
            // upload two chunk of 400 each. total 1600 bytes and 5 chunks
            // uploaded
            uploadChunks(parentPath, file, nodeName,
                json.getInt(SlingPostConstants.NT_SLING_CHUNKS_LENGTH),
                chunkSize, 2);
            json = getChunkJson(parentPath + "/" + nodeName);
            validate(json, 1600, 5);

            chunkSize = 500;
            uploadChunks(parentPath, file, nodeName,
                json.getInt(SlingPostConstants.NT_SLING_CHUNKS_LENGTH),
                chunkSize, Integer.MAX_VALUE);

            HttpResponse response = httpGet(parentPath + "/" + nodeName);
            InputStream fis = new FileInputStream(file);
            Assert.assertEquals("content stream doesn't match", true,
View Full Code Here

            String nodeName = file.getName();
            int chunkSize = 200;
            // uplaod 3 chunk of 200 bytes uploaded
            uploadChunks(parentPath, file, nodeName, 0, chunkSize, 3);
            JSONObject json = getChunkJson(parentPath + "/" + file.getName());
            validate(json, 600, 3);

            // create 1000 bytes file
            File secondFile = createFile("helloearth", 100);
            chunkSize = 300;
View Full Code Here

            // create 1000 bytes file
            File secondFile = createFile("helloearth", 100);
            int chunkSize = 200;
            // uplaod 3 chunk of 200 bytes uploaded
            uploadChunks(parentPath, secondFile, nodeName, 0, chunkSize, 3);
            JSONObject json = getChunkJson(parentPath + "/" + nodeName);
            validate(json, 600, 3);

            response = httpGet(parentPath + "/" + nodeName);
            fis = new FileInputStream(file);
            Assert.assertEquals("content stream doesn't match", true,
View Full Code Here

TOP

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

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.