Package org.json

Examples of org.json.JSONObject


    public RegionWidgetWrapper prepareForRender(RegionWidgetWrapper item) {
        throw new UnsupportedOperationException();
    }

    private String getWidgetScript(RegionWidget item, Widget widget) {
        JSONObject userPrefs = new JSONObject();
        if (item.getPreferences() != null) {
            for (RegionWidgetPreference regionWidgetPreference : item.getPreferences()) {
                try {
                    userPrefs.put(regionWidgetPreference.getName(), regionWidgetPreference.getValue());
                } catch (JSONException e) {
                    logger.error("Exception caught adding preference to JSONObject: " + regionWidgetPreference, e);
                }
            }
        }

        // get attributes about the sub page this regionWidget is on.  This is needed to assist the client in
        // determining which gadgets are on visible tabs/sub pages initially to make widget rendering more efficient
        String pageId = null;
        String pageName = "";
        boolean isDefault = false;
        Page page =  item.getRegion().getPage();
        if (PageType.SUB_PAGE.equals(page.getPageType())) {
            pageId = "'" + page.getId() + "'";
            pageName = page.getName();
            // check to see if this regionWidget is on the first sub page, which will be the default
            // subpage rendered if the user doesn't specify which subpage via the URL hash
            isDefault = isDefaultSubPage(page);
        }

        return String.format(SCRIPT_BLOCK,
                item.getRegion().getId(),
                Constants.WIDGET_TYPE,
                item.getId(),
                widget.getUrl(),
                securityTokenService.getEncryptedSecurityToken(item, widget),
                openSocialService.getGadgetMetadata(widget.getUrl()),
                userPrefs.toString(),
                item.isCollapsed(),
                widget.getId(),
                item.isLocked(),
                item.isHideChrome(),
                pageId,
View Full Code Here


     * @param url url for the widget
     * @return
     */
    public Widget getMetadata(String url) {
        Widget widget = new WidgetImpl();
        JSONObject jsonGadget = null;
        try {
            jsonGadget = (JSONObject) new JSONTokener(gadgetMetadataRepository.getGadgetMetadata(url)).nextValue();
            if (jsonGadget != null) {
                String query = jsonGadget.getString("modulePrefs");
                if (query != null) {
                    JSONObject jsonModulePrefsObject = (JSONObject) new JSONTokener(query).nextValue();
                    if (jsonModulePrefsObject != null) {
                        widget.setTitle(parseProperty(jsonModulePrefsObject, "title"));
                        widget.setTitleUrl(parseProperty(jsonModulePrefsObject, "titleUrl"));
                        widget.setDescription(parseProperty(jsonModulePrefsObject, "description"));
                        widget.setAuthor(parseProperty(jsonModulePrefsObject, "author"));
                        widget.setAuthorEmail(parseProperty(jsonModulePrefsObject, "authorEmail"));
                        widget.setThumbnailUrl(parseProperty(jsonModulePrefsObject, "thumbnail"));
                        widget.setScreenshotUrl(parseProperty(jsonModulePrefsObject, "screenshot"));
                        widget.setUrl(url);
                        widget.setType(getSupportedContext());
                    }
                }
            }
        } catch (JSONException e) {
            try {
                String query = jsonGadget.getString("error");
                if (query != null) {
                    JSONObject jsonModuleErrorObject = (JSONObject) new JSONTokener(query).nextValue();
                    if (jsonModuleErrorObject != null) {
                        String errorMessage = jsonModuleErrorObject.getString("message");
                        String errorCode = jsonModuleErrorObject.getString("code");
                        throw new IllegalArgumentException("HTTP error: " + errorCode + ". Message: " + errorMessage);
                    }
                }
            } catch (JSONException e1) {
                logger.info("Error while reading: " + e.getLocalizedMessage(), e);
View Full Code Here

        public JpaSerializableApplicationData(Long entityId, String userId, String appUrl, Map<String, String> data) {
            super(entityId, userId, appUrl, data);
        }

        public void serializeData() {
            serializedData = new JSONObject(this.getData()).toString();
        }
View Full Code Here

        public void deserializeData() {
            try {
                Map<String, String> data = new HashMap<String, String>();
                if (StringUtils.isNotBlank(serializedData)) {
                    JSONObject jsonObject = new JSONObject(serializedData);
                    Iterator keys = jsonObject.keys();
                    while (keys.hasNext()) {
                        String key = (String) keys.next();
                        data.put(key, (String) jsonObject.get(key));
                    }
                }
                this.setData(data);
            } catch (JSONException e) {
                throw new DataSerializationException("Exception caught while deserializing data: " + serializedData, e);
View Full Code Here

        public JpaSerializableApplicationData(Long entityId, String userId, String appUrl, Map<String, String> data) {
            super(entityId, userId, appUrl, data);
        }

        public void serializeData() {
            serializedData = new JSONObject(this.getData()).toString();
        }
View Full Code Here

        public void deserializeData() {
            try {
                Map<String, String> data = new HashMap<String, String>();
                if (StringUtils.isNotBlank(serializedData)) {
                    JSONObject jsonObject = new JSONObject(serializedData);
                    Iterator keys = jsonObject.keys();
                    while (keys.hasNext()) {
                        String key = (String) keys.next();
                        data.put(key, (String) jsonObject.get(key));
                    }
                }
                this.setData(data);
            } catch (JSONException e) {
                throw new DataSerializationException("Exception caught while deserializing data: " + serializedData, e);
View Full Code Here

            if (!isSuccessStatus(responseStatus))
                return failureResultForStatusCode(responseStatus);

            ResourceProxy resource = new ResourceProxy(path);

            JSONObject json = new JSONObject(get.getResponseBodyAsString());
            String primaryType = json.optString(Repository.JCR_PRIMARY_TYPE);
            if (primaryType != null) { // TODO - needed?
                resource.addProperty(Repository.JCR_PRIMARY_TYPE, primaryType);
            }

            // TODO - populate all properties

            for (Iterator<?> keyIterator = json.keys(); keyIterator.hasNext();) {

                String key = (String) keyIterator.next();
                JSONObject value = json.optJSONObject(key);
                if (value != null) {
                    ResourceProxy child = new ResourceProxy(PathUtil.join(path, key));
                    child.addProperty(Repository.JCR_PRIMARY_TYPE, value.optString(Repository.JCR_PRIMARY_TYPE));
                    resource.addChild(child);
                }
            }
       
            return AbstractResult.success(resource);
View Full Code Here

        //TODO change responseAsString with something like
        // return EncodingUtil.getString(rawdata, m.getResponseCharSet());
            if (!isSuccessStatus(responseStatus))
                return failureResultForStatusCode(responseStatus);

            JSONObject result = new JSONObject(get.getResponseBodyAsString());

            ResourceProxy resource = new ResourceProxy(path);
            JSONArray names = result.names();
            for (int i = 0; i < names.length(); i++) {
                String name = names.getString(i);
                Object object = result.get(name);
                if (object instanceof String) {
                    resource.addProperty(name, object);
                } else {
                    System.out.println("Property '" + name + "' of type '" + object.getClass().getName()
                            + " is not handled");
View Full Code Here

                throw new HttpException("Got status code " + result + " for call to " + method.getURI());
            }

            input = method.getResponseBodyAsStream();

            JSONObject object = new JSONObject(new JSONTokener(new InputStreamReader(input)));

            JSONArray bundleData = object.getJSONArray("data");
            for (int i = 0; i < bundleData.length(); i++) {
                JSONObject bundle = bundleData.getJSONObject(i);
                String remotebundleSymbolicName = bundle.getString("symbolicName");
                Version bundleVersion = new Version(bundle.getString("version"));

                if (bundleSymbolicName.equals(remotebundleSymbolicName)) {
                    return bundleVersion;
                }
            }
View Full Code Here

                configureRequest(method);

                int status = httpClient.executeMethod(method);
                if (status != 200) {
                    try {
                        JSONObject result = parseResult(method);
                        if (result.has("message")) {
                            throw new OsgiClientException(result.getString("message"));
                        }
                    } catch (JSONException e) {
                        // ignore, fallback to status code reporting
                    }
                    throw new OsgiClientException("Method execution returned status " + status);
                }

                JSONObject obj = parseResult(method);

                if ("OK".equals(obj.getString("status"))) {
                    return;
                }

                String errorMessage = obj.has("message") ? "Bundle deployment failed, please check the Sling logs"
                        : obj.getString("message");

                throw new OsgiClientException(errorMessage);

            } catch (IOException e) {
                throw new OsgiClientException(e);
View Full Code Here

TOP

Related Classes of org.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.