Package org.richfaces.json

Examples of org.richfaces.json.JSONObject


    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        try {
            if (value.charAt(0) == '{') {
                return new JSONObject(value);
            }
            return new JSONArray(value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
View Full Code Here


        // Mark current user as actual
        userTracker.addUserId(userId, ApplicationUtils.getSession().getId());
    }

    public boolean authenticateWithFacebook() {
        JSONObject userInfo = fBean.getUserInfo();

        try {
            String pictureUrl = userInfo.getJSONObject("picture").getJSONObject("data").getString("url");
            userBean.setFbPhotoUrl(pictureUrl);

            String facebookId = userInfo.getString("id");

            if (!userBean.isLoggedIn()) { // user is not logged in
                user = userBean.facebookLogIn(facebookId); // try logging with Facebook

                if (user != null) {
                    addToTracker(user.getId());
                    return true;
                }

                // Facebook id was not found, creating new account
                User newUser = new User();

                newUser.setFbId(facebookId);
                newUser.setFirstName(userInfo.getString("first_name"));
                newUser.setSecondName(userInfo.getString("last_name"));
                newUser.setEmail(userInfo.getString("email"));

                String username = userInfo.has("username") ? userInfo.getString("username") : userInfo.getString("first_name");
                newUser.setLogin(username);

                String sex = userInfo.getString("gender");
                newUser.setSex(sex.equals("male") ? Sex.MALE : Sex.FEMALE);

                SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
                newUser.setBirthDate(sdf.parse(userInfo.getString("birthday")));

                // random password, the user will not be using this to log in
                newUser.setPasswordHash(HashUtils.hash("facebook" + System.currentTimeMillis()));

                userAction.register(newUser);
View Full Code Here

            return false;
        }
    }

    public boolean authenticateWithGPlus() {
        JSONObject userInfo = gBean.getUserInfo();

        try {
            // String pictureUrl = userInfo.getJSONObject("picture").getJSONObject("data").getString("url");
            // userBean.setFbPhotoUrl(pictureUrl);

            String gPlusId = userInfo.getString("id");

            if (!userBean.isLoggedIn()) {
                user = userBean.gPlusLogIn(gPlusId);

                if (user != null) {
                    addToTracker(user.getId());
                    return true;
                }

                User newUser = new User();

                newUser.setgPlusId(gPlusId);
                newUser.setFirstName(userInfo.getJSONObject("name").getString("givenName"));
                newUser.setSecondName(userInfo.getJSONObject("name").getString("familyName"));
                newUser.setEmail(userInfo.optString("email", "mail@mail.com"));

                String username = userInfo.optString("nickname", newUser.getFirstName());
                newUser.setLogin(username);

                String sex = userInfo.getString("gender");
                newUser.setSex(sex.equals("male") ? Sex.MALE : Sex.FEMALE);

                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                String birthday = userInfo.optString("birthday", "1900-01-01");
                newUser.setBirthDate(sdf.parse(birthday));

                // random password, the user will not be using this to log in
                newUser.setPasswordHash(HashUtils.hash("gPlus" + System.currentTimeMillis()));
View Full Code Here

        ExtDraggableRendererContributor contributor = ExtDraggableRendererContributor
                .getInstance();
        ScriptOptions dragOptions = contributor.buildOptions(context, column,
                dragSourceScriptId, indicatorId);

        JSONObject dndParams = new JSONObject();
        try {
            dndParams.put("label", dragLabel == null ? "" : dragLabel);
        } catch (JSONException e) {
        }
        dragOptions.addOption("dndParams", dndParams.toString());

        function.addParameter(dragOptions);
        function.appendScript(buffer);

        String scriptContribution = contributor.getScriptContribution(context,
View Full Code Here

        String varName = "DnD_ExtSimpleDropZone_"+column.getId().replaceAll("[^A-Za-z0-9_]", "_") + (before?"L":"R");
        StringBuffer buffer = new StringBuffer("delete " + varName + ";\nvar " + varName + " = ");
        JSFunction function = new JSFunction("new DnD.ExtSimpleDropZone");
        function.addParameter(dropTargetId);
        ScriptOptions dropOptions = contributor.buildOptions(context, column);
        JSONObject dndParams = new JSONObject();
        dropOptions.addOption("dndParams", dndParams.toString());

        function.addParameter(dropOptions);
        function.appendScript(buffer);

        String dropTargetScriptId = column.getClientId(context) + ":"
View Full Code Here

    private String currentAlbumId;
    private String currentImageId;

    public void setAll(String json) {
        try {
            JSONObject jo = new JSONObject(json);
            if (!jo.has("albums")) {
                return;
            }

            storeAlbums(jo.getJSONArray("albums"), jo.getJSONArray("covers"));
            storeImagesToAlbum(jo.getJSONArray("images"));
            setNeedsUpdate(false);
        } catch (JSONException e) {
            error.fire(new ErrorEvent("Error: ", e.getMessage()));
        }
    }
View Full Code Here

    }

    public void setAlbumImages(String imagesArray) {
        String imageId = "";
        String albumId = "";
        JSONObject jo;

        try {
            JSONArray ja = new JSONArray(imagesArray);
            albumId = ja.getJSONObject(0).getString("fullAlbumId");

            currentAlbumId = albumId;

            if (images.get(albumId) != null) {
                // these images are already cached
                return;
            }
           
            int size = ja.length();
           
            // put size in the album
            albums.get(albumId).put("size", size);

            images.put(albumId, new HashMap<String, JSONObject>());

            for (int i = 0; i < size; i++) {
                jo = ja.getJSONObject(i);

                if (!jo.has("albumId") || !jo.has("id")) {
                    error.fire(new ErrorEvent("Error, object does not contain images"));

                }

                imageId = jo.getString("id");

                images.get(albumId).put(imageId, jo);
            }

            albums.get(albumId).put("size", images.get(albumId).size());
View Full Code Here

        }
    }

    public void setAlbums(String json) {
        try {
            JSONObject jo = new JSONObject(json);
            if (!jo.has("albums")) {
                return;
            }

            storeAlbums(jo.getJSONArray("albums"), jo.getJSONArray("covers"));
        } catch (JSONException e) {
            error.fire(new ErrorEvent("Error: ", e.getMessage()));
        }
    }
View Full Code Here

        return images.containsKey(albumId) && (images.get(albumId) != null);
    }

    public void setAlbumAndImages(String aiJson) {
        try {
            JSONObject jAlbum = new JSONObject(aiJson);

            JSONArray albumImages = jAlbum.getJSONArray("images");
            jAlbum.remove("images");

            String albumId = jAlbum.getString("fullId");
            int size = albumImages.length();
           
            jAlbum.put("size", size);
            albums.put(albumId, jAlbum);
            images.put(albumId, new HashMap<String, JSONObject>());

            JSONObject jo;
            String imageId;
            Map<String, JSONObject> album = images.get(albumId);
            for (int i = 0; i < albumImages.length(); i++) {
                jo = albumImages.getJSONObject(i);

                if (!jo.has("id")) {
                    error.fire(new ErrorEvent("Error, object does not contain images"));
                }

                imageId = jo.getString("id");

                album.put(imageId, jo);
            }

        } catch (JSONException je) {
View Full Code Here

        storeAlbums(jAlbums, jCovers, false);
    }

    public void storeAlbums(JSONArray jAlbums, JSONArray jCovers, boolean rewrite) {
        String albumId;
        JSONObject jo;
        JSONObject jc;
        int offset = 0;

        try {
            for (int i = 0; i < jAlbums.length(); i++) {
                jo = jAlbums.getJSONObject(i);
                jc = jCovers.getJSONObject(i - offset);

                if (!jo.has("id")) {
                    error.fire(new ErrorEvent("Error, object does not contain albums"));
                }

                albumId = jo.getString("id");

                if (jc.getString("pid").equals(jo.getString("cpid"))) {
                    jo.put("coverUrl", jc.getString("coverUrl"));
                } else { // album without cover -> empty
                    offset++;
                    jo.put("coverUrl", "resources/img/shell/frame_photo_120.png");
                    jo.put("empty", true);
                }
View Full Code Here

TOP

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