Package net.sf.json

Examples of net.sf.json.JSONObject


        }
        return "success";
    }

    public static void toJsonObject(Map<String,Object> attrMap, HttpServletResponse response) throws EventHandlerException {
        JSONObject json = JSONObject.fromObject(attrMap);
        String jsonStr = json.toString();
        if (jsonStr == null) {
            throw new EventHandlerException("JSON Object was empty; fatal error!");
        }
        // set the X-JSON content type
        response.setContentType("application/json");
View Full Code Here


        }
        return "success";
    }

    public static void toJsonObjectList(List<Map<String,Object>> list, HttpServletResponse response) throws EventHandlerException {
        JSONObject json = null;
        List<JSONObject> jsonList = new ArrayList<JSONObject>();
        if (list != null) {
            for (Map<String,Object> val : list) {
                json = new JSONObject();
                for (String rowKey: val.keySet()) {
                    json.put(rowKey, val.get(rowKey));
                }
                jsonList.add(json);
            }
            String jsonStr = jsonList.toString();
            if (jsonStr == null) {
View Full Code Here

        return "success";
    }

    public static void toJsonObject(Map<String,Object> attrMap, HttpServletResponse response){
        JSONObject json = JSONObject.fromObject(attrMap);
        String jsonStr = json.toString();
        if (jsonStr == null) {
            Debug.logError("JSON Object was empty; fatal error!",module);
        }
        // set the X-JSON content type
        response.setContentType("application/json");
View Full Code Here

                attrMap.remove(ignoreAttr);
            }
        }

        // create a JSON Object for return
        JSONObject json = JSONObject.fromObject(attrMap);
        writeJSONtoResponse(json, request.getMethod(), response);

        return "success";
    }
View Full Code Here


    public static String getJSONuiLabelArray(HttpServletRequest request, HttpServletResponse response) {
        String requiredLabels = request.getParameter("requiredLabels");

        JSONObject uiLabelObject = null;
        if (UtilValidate.isNotEmpty(requiredLabels)) {
            uiLabelObject = new JSONObject();
            // Transform JSON String to Object
            uiLabelObject = (JSONObject) JSONSerializer.toJSON(requiredLabels);
        }

        JSONObject jsonUiLabel = new JSONObject();
        Locale locale = request.getLocale();
        if(!uiLabelObject.isEmpty()) {
            Set<String> resourceSet = UtilGenerics.checkSet(uiLabelObject.keySet());
            // Iterate over the resouce set
            for (String resource : resourceSet) {
                JSONArray labels = uiLabelObject.getJSONArray(resource);
                if (labels.isEmpty() || labels == null) {
                    continue;
                }

                // Iterate over the uiLabel List
                Iterator<String> jsonLabelIterator = UtilGenerics.cast(labels.iterator());
                JSONArray resourceLabelList = new JSONArray();
                while(jsonLabelIterator.hasNext()) {
                    String label = jsonLabelIterator.next();
                    String receivedLabel = UtilProperties.getMessage(resource, label, locale);
                    if (UtilValidate.isNotEmpty(receivedLabel)) {
                        resourceLabelList.add(receivedLabel);
                    }
                }
                jsonUiLabel.element(resource, resourceLabelList);
            }
        }

        writeJSONtoResponse(jsonUiLabel, request.getMethod(), response);
        return "success";
View Full Code Here

    }

    public static String getJSONuiLabel(HttpServletRequest request, HttpServletResponse response) {
        String requiredLabels = request.getParameter("requiredLabel");

        JSONObject uiLabelObject = null;
        if (UtilValidate.isNotEmpty(requiredLabels)) {
            uiLabelObject = new JSONObject();
            // Transform JSON String to Object
            uiLabelObject = (JSONObject) JSONSerializer.toJSON(requiredLabels);
        }

        JSONArray jsonUiLabel = new JSONArray();
        Locale locale = request.getLocale();
        if(!uiLabelObject.isEmpty()) {
            Set<String> resourceSet = UtilGenerics.checkSet(uiLabelObject.keySet());
            // Iterate over the resource set
            // here we need a keySet because we don't now which label resource to load
            // the key set should have the size one, if greater or empty error should returned
            if (UtilValidate.isEmpty(resourceSet)) {
                Debug.logError("No resource and labels found", module);
                return "error";
            } else if (resourceSet.size() > 1) {
                Debug.logError("More than one resource found, please use the method: getJSONuiLabelArray", module);
                return "error";
            }

            for (String resource : resourceSet) {
                String label = uiLabelObject.getString(resource);
                if (UtilValidate.isEmail(label)) {
                    continue;
                }

                String receivedLabel = UtilProperties.getMessage(resource, label, locale);
View Full Code Here

  if (logger.isDebugEnabled())
      logger.debug("Executing the UploadProgress action");

  Object mon_obj = sessionMap.get(ProgressMonitor.SESSION_PROGRESS_MONITOR);

  JSONObject json = new JSONObject();
  if (mon_obj != null) {
      ProgressMonitor monitor = (ProgressMonitor) mon_obj;
      json.accumulate("bytesSent", "" + monitor.getBytesRead());
      json.accumulate("bytesTotal", "" + monitor.getBytesLength());
      json.accumulate("percentComplete", "" + monitor.percentComplete());
     
      if(!monitor.isStillProcessing() || monitor.isAborted()) {
    json.accumulate("aborted", true);
      }else {
    json.accumulate("aborted", false);
      }
        
     
  } else {
      json.accumulate("bytesSent", "" + 0);
      json.accumulate("bytesTotal", "" + 0);
      json.accumulate("percentComplete", "" + 0);
      json.accumulate("aborted", false);
  }

  setStringResult(json.toString());
  if (logger.isDebugEnabled())
      logger.debug("JSON Result is: " + getStringResult());

  return Action.SUCCESS;
    }
View Full Code Here

      if (statusCode != HttpStatus.SC_OK) {
        log.error("Request failed: " + method.getStatusLine());
      }

      JSONObject json = (JSONObject) JSONSerializer.toJSON(method.getResponseBodyAsString());
      JSONArray arr = json.getJSONArray("results");
      for (Object o : arr) {
        JSONObject item = (JSONObject) o;
        CRResolvableBean bean = createBean(item);
        resultlist.add(bean);
      }

    } catch (HttpException e) {
View Full Code Here

   */
  public JSONContentRepository(String[] attr) {

    super(attr);
    this.setResponseEncoding("UTF-8");
    rootObject = new JSONObject();
  }
View Full Code Here

   */
  public JSONContentRepository(String[] attr, String encoding) {

    super(attr);
    this.setResponseEncoding(encoding);
    rootObject = new JSONObject();
  }
View Full Code Here

TOP

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