Package org.apache.sling.commons.json

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


    private Throwable error;

    public JSONResponse() throws JSONResponseException {
        try {
            json = new JSONObject();
            changes = new JSONArray();
            json.put(PROP_CHANGES, changes);
        } catch (Throwable e) {
            throw new JSONResponseException(e);
        }
View Full Code Here


    }

    public void onChange(String type, String... arguments)
            throws JSONResponseException {
        try {
            JSONObject change = new JSONObject();
            change.put(PROP_TYPE, type);
            for (String argument : arguments) {
                change.accumulate(PROP_ARGUMENT, argument);
            }
            changes.put(change);
        } catch (JSONException e) {
            throw new JSONResponseException(e);
        }
View Full Code Here

    @Override
    public void setError(Throwable error) {
        try {
            this.error = error;
            JSONObject jsonError = new JSONObject();
            jsonError.put("class", error.getClass().getName());
            jsonError.put("message", error.getMessage());
            json.put("error", jsonError);
        } catch (JSONException e) {
            throw new JSONResponseException(e);
        }
    }
View Full Code Here

                builder.buildGetRequest(path)
                .withCredentials(username, password)
        ).assertStatus(200)
        .getContent();
       
        final JSONObject root = new JSONObject(content);
        if(!root.has(JSON_KEY_DATA)) {
            fail(path + " does not provide '" + JSON_KEY_DATA + "' element, JSON content=" + content);
        }
        final JSONArray data = root.getJSONArray(JSON_KEY_DATA);
        if(data.length() < 1) {
            fail(path + "." + JSON_KEY_DATA + " is empty, JSON content=" + content);
        }
        final JSONObject bundle = data.getJSONObject(0);
        if(!bundle.has(JSON_KEY_STATE)) {
            fail(path + ".data[0].state missing, JSON content=" + content);
        }
        return bundle;
    }
View Full Code Here

        return bundle;
    }

    /** Get bundle id */
    public long getBundleId(String symbolicName) throws Exception {
        final JSONObject bundle = getBundleData(symbolicName);
        return bundle.getLong(JSON_KEY_ID);
    }
View Full Code Here

            if (parentResource.getChild(childName) != null) {
                throw new IllegalArgumentException("Resource does already exist: " + destPath);
            }

            String jsonString = convertToJsonString(inputStream).trim();
            JSONObject json = new JSONObject(jsonString);
            return this.createResource(parentResource, childName, json);
        } catch (JSONException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
View Full Code Here

        return bundle.getLong(JSON_KEY_ID);
    }
   
    /** Get bundle version **/
    public String getBundleVersion(String symbolicName) throws Exception {
        final JSONObject bundle = getBundleData(symbolicName);
        return bundle.getString(JSON_KEY_VERSION);
    }
View Full Code Here

        return bundle.getString(JSON_KEY_VERSION);
    }
   
    /** Get specified bundle state */
    public String getBundleState(String symbolicName) throws Exception {
        final JSONObject bundle = getBundleData(symbolicName);
        return bundle.getString(JSON_KEY_STATE);
    }
View Full Code Here

                }
                final String jsonText = get.getResponseBodyAsString();
                try {
                    JSONArray array = new JSONArray(jsonText);
                    for(int i=0; i<array.length(); i++) {
                        final JSONObject obj = array.getJSONObject(i);
                        final String pid = obj.getString("pid");
                        final String path = obj.getJSONObject("provider.file").getString("value");
                        final String roots = obj.getJSONObject("provider.roots").getString("value");
                        if ( path != null && path.startsWith(this.project.getBasedir().getAbsolutePath()) ) {
                            getLog().debug("Found configuration with pid: " + pid + ", path: " + path + ", roots: " + roots);
                            result.put(pid, new String[] {path, roots});
                        }
                    }
View Full Code Here

                    getLog().debug("Response has zero length. Assuming older version of web console.");
                    return null;
                }
                final String jsonText = gm.getResponseBodyAsString();
                try {
                    final JSONObject obj = new JSONObject(jsonText);
                    final JSONArray props = obj.getJSONArray("props");
                    for(int i=0; i<props.length(); i++) {
                        final JSONObject property = props.getJSONObject(i);
                        if ( "Version".equals(property.get("key")) ) {
                            final String version = property.getString("value");
                            getLog().debug("Found web console version " + version);
                            return version;
                        }
                    }
                    getLog().debug("Version property not found in response. Assuming older version.");
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.