Package com.dotmarketing.util.json

Examples of com.dotmarketing.util.json.JSONObject


                responseMessage.append( xmlBuilder );
            } else {

                //TODO: Handle JSON and JSONP the same

                JSONObject jsonResponse = new JSONObject();
                jsonResponse.put( "success", true );
                jsonResponse.put( "message", "Success message" );
                jsonResponse.put( "param1", param1 );
                jsonResponse.put( "param2", param2 );

                responseMessage.append( jsonResponse.toString() );
            }


        } catch ( Exception e ) {
            Logger.error( this.getClass(), "Error on test method.", e );
View Full Code Here


        notificationAPI.markNotificationsAsRead(user.getUserId());

        List<Notification> notifications = allUsers?notificationAPI.getNotifications(offset, limit):notificationAPI.getNotifications(user.getUserId(), offset, limit);

        for (Notification n : notifications) {
          JSONObject notificationJSON = new JSONObject();
          notificationJSON.put("id", n.getId());
          notificationJSON.put("message", n.getMessage());
          notificationJSON.put("type", n.getType().name());
          notificationJSON.put("level", n.getLevel().name());
          notificationJSON.put("time_sent", DateUtil.prettyDateSince(n.getTimeSent()));
          notificationsJSON.add(notificationJSON);
    }

        return Response.ok( notificationsJSON.toString()).header("Content-Range", "items " + offset + "-" + limit + "/" + total).build() ;
View Full Code Here

      InitDataObject initData = init( params, true, request, true );
      ResourceResponse responseResource = new ResourceResponse( initData.getParamsMap() );

      User user = initData.getUser();

      JSONObject newNotificationsCountJSON = new JSONObject();

      Long newNotificationsCount = APILocator.getNotificationAPI().getNewNotificationsCount(user.getUserId());

      newNotificationsCountJSON.put("newNotificationsCount", newNotificationsCount);

      return responseResource.response( newNotificationsCountJSON.toString() );

    }
View Full Code Here

    //Using JsonArray instead of manually creating the json object
    JSONArray jsonEnvironments = new JSONArray();

    //First objects is expected to be blank
    JSONObject jsonEnvironmentFirst = new JSONObject();
    jsonEnvironmentFirst.put( "id", "0" );
    jsonEnvironmentFirst.put( "name", "");

    jsonEnvironments.add(jsonEnvironmentFirst);

    Role role = APILocator.getRoleAPI().loadRoleById(roleId);
    User user = APILocator.getUserAPI().loadUserById(role.getRoleKey());
    boolean isAdmin = APILocator.getUserAPI().isCMSAdmin(user);

    List<Role> roles = APILocator.getRoleAPI().loadRolesForUser(user.getUserId(),true);
    Set<Environment> environments = new HashSet<Environment>();
    if(isAdmin){
      List<Environment> app = APILocator.getEnvironmentAPI().findEnvironmentsWithServers();
      for(Environment e:app)
        environments.add(e);
    }
    else
      for(Role r: roles)
        environments.addAll(APILocator.getEnvironmentAPI().findEnvironmentsByRole(r.getId()));

    //For each env, create one json and add it to the array
    for(Environment e : environments) {

      JSONObject environmentBundle = new JSONObject();
      environmentBundle.put( "id", e.getId() );
      //Escape name for cases like: dotcms's
      environmentBundle.put( "name", StringEscapeUtils.unescapeJava( e.getName() ));

      jsonEnvironments.add(environmentBundle);
    }

    CacheControl cc = new CacheControl();
View Full Code Here

TOP

Related Classes of com.dotmarketing.util.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.