Package org.json.simple

Examples of org.json.simple.JSONObject


    if (l != null) {
      l.networkListReturned(new ArrayList<contentNetworkDetails>(0));
      return;
    }

    JSONObject parameters = new JSONObject();

    parameters.put("azver", Constants.AZUREUS_VERSION);

    PlatformMessage message = new PlatformMessage("AZMSG", LISTENER_ID,
        OP_LIST_CNETORKS, parameters, maxDelayMS);

    PlatformMessengerListener listener = new PlatformMessengerListener() {
View Full Code Here


            valueStack.push(token.value);
            break;
          case Yytoken.TYPE_LEFT_BRACE:
            status=S_IN_OBJECT;
            statusStack.push(new Integer(status));
            valueStack.push(new JSONObject());
            break;
          case Yytoken.TYPE_LEFT_SQUARE:
            status=S_IN_ARRAY;
            statusStack.push(new Integer(status));
            valueStack.push(new JSONArray());
            break;
          default:
            status=S_IN_ERROR;
          }//inner switch
          break;
         
        case S_IN_FINISHED_VALUE:
          if(token.type==Yytoken.TYPE_EOF)
            return valueStack.pop();
          else
            return null;
         
        case S_IN_OBJECT:
          switch(token.type){
          case Yytoken.TYPE_COMMA:
            break;
          case Yytoken.TYPE_VALUE:
            if(token.value instanceof String){
              String key=(String)token.value;
              valueStack.push(key);
              status=S_PASSED_PAIR_KEY;
              statusStack.push(new Integer(status));
            }
            else{
              status=S_IN_ERROR;
            }
            break;
          case Yytoken.TYPE_RIGHT_BRACE:
            if(valueStack.size()>1){
              statusStack.pop();
              JSONObject map = (JSONObject)valueStack.pop();
              map.compactify(-0.9f);
              status=peekStatus(statusStack);
            }
            else{
              status=S_IN_FINISHED_VALUE;
            }
            break;
          default:
            status=S_IN_ERROR;
            break;
          }//inner switch
          break;
         
        case S_PASSED_PAIR_KEY:
          switch(token.type){
          case Yytoken.TYPE_COLON:
            break;
          case Yytoken.TYPE_VALUE:
            statusStack.pop();
            String key=(String)valueStack.pop();
            JSONObject parent=(JSONObject)valueStack.peek();
            parent.put(key,token.value);
            status=peekStatus(statusStack);
            break;
          case Yytoken.TYPE_LEFT_SQUARE:
            statusStack.pop();
            key=(String)valueStack.pop();
            parent=(JSONObject)valueStack.peek();
            JSONArray newArray=new JSONArray();
            parent.put(key,newArray);
            status=S_IN_ARRAY;
            statusStack.push(new Integer(status));
            valueStack.push(newArray);
            break;
          case Yytoken.TYPE_LEFT_BRACE:
            statusStack.pop();
            key=(String)valueStack.pop();
            parent=(JSONObject)valueStack.peek();
            JSONObject newObject=new JSONObject();
            parent.put(key,newObject);
            status=S_IN_OBJECT;
            statusStack.push(new Integer(status));
            valueStack.push(newObject);
            break;
          default:
            status=S_IN_ERROR;
          }
          break;
         
        case S_IN_ARRAY:
          switch(token.type){
          case Yytoken.TYPE_COMMA:
            break;
          case Yytoken.TYPE_VALUE:
            JSONArray val=(JSONArray)valueStack.peek();
            val.add(token.value);
            break;
          case Yytoken.TYPE_RIGHT_SQUARE:
            if(valueStack.size()>1){
              statusStack.pop();
              valueStack.pop();
              status=peekStatus(statusStack);
            }
            else{
              status=S_IN_FINISHED_VALUE;
            }
            break;
          case Yytoken.TYPE_LEFT_BRACE:
            val=(JSONArray)valueStack.peek();
            JSONObject newObject=new JSONObject();
            val.add(newObject);
            status=S_IN_OBJECT;
            statusStack.push(new Integer(status));
            valueStack.push(newObject);
            break;
View Full Code Here

   * @return
   *
   * @since 3.0.1.5
   */
  public static Map encodeToJSONObject(Map map) {
    Map newMap = new JSONObject();

    for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
      String key = (String) iter.next();
      Object value = map.get(key);

      if (value instanceof byte[]) {
        key += ".B64";
        value = Base64.encode((byte[]) value);
      }

      value = coerce(value);

      newMap.put(key, value);
    }
    return newMap;
  }
View Full Code Here

    ModelAndView mav = adapter.handle(request, response, restController);
    view.render(mav.getModel(), request, response);
    response.flushBuffer();
    Object json = new JSONParser().parse(response.getContentAsString());
    Assert.assertTrue(json instanceof JSONObject);
    JSONObject jsonObject = (JSONObject) json;
    JSONArray features = (JSONArray) jsonObject.get("features");
    JSONObject feature = (JSONObject) features.get(0);
    JSONObject geometry = (JSONObject) feature.get("geometry");
    GeometryJSON g = new GeometryJSON(0);
    Geometry m = g.read(geometry.toJSONString());
    Envelope envelope = new Envelope(0, 1, 0, 1);
    Geometry orig = JTS.toGeometry(envelope);
    Geometry m2 = geoservice.transform(orig, "EPSG:4326", "EPSG:900913");
    // equality check on buffer, JTS equals does not do the trick !
    Assert.assertTrue(m.buffer(0.01).contains(m2));
View Full Code Here

       
        // Export to JSON and verify
        File tempJson = File.createTempFile("Standard1", ".json");
        SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[]{asHex("rowExclude")});
       
        JSONObject json = (JSONObject)JSONValue.parse(new FileReader(tempJson));
       
        JSONArray rowA = (JSONArray)json.get(asHex("rowA"));
        JSONArray colA = (JSONArray)rowA.get(0);
        assert hexToBytes((String)colA.get(1)).equals(ByteBufferUtil.bytes("valA"));

        JSONArray colExp = (JSONArray)rowA.get(1);
        assert ((Long)colExp.get(4)) == 42;
        assert ((Long)colExp.get(5)) == nowInSec;
       
        JSONArray rowB = (JSONArray)json.get(asHex("rowB"));
        JSONArray colB = (JSONArray)rowB.get(0);
        assert !(Boolean)colB.get(3);

        JSONArray rowExclude = (JSONArray)json.get(asHex("rowExclude"));
        assert rowExclude == null;
    }
View Full Code Here

       
        // Export to JSON and verify
        File tempJson = File.createTempFile("Super4", ".json");
        SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[]{asHex("rowExclude")});
       
        JSONObject json = (JSONObject)JSONValue.parse(new FileReader(tempJson));
       
        JSONObject rowA = (JSONObject)json.get(asHex("rowA"));
        JSONObject superA = (JSONObject)rowA.get(cfamily.getComparator().getString(ByteBufferUtil.bytes("superA")));
        JSONArray subColumns = (JSONArray)superA.get("subColumns");
        JSONArray colA = (JSONArray)subColumns.get(0);
        JSONObject rowExclude = (JSONObject)json.get(asHex("rowExclude"));
        assert hexToBytes((String)colA.get(1)).equals(ByteBufferUtil.bytes("valA"));
        assert !(Boolean)colA.get(3);
        assert rowExclude == null;
    }
View Full Code Here

   */
  private void executeDoGetStatus(final HttpServletRequest request,
      final HttpServletResponse response) {

    ApplicationStatus as = fireApplication.getStatus();
    JSONObject jsonObject = new JSONObject();

    jsonObject.put("status", new Integer(as.getCurrentState()));

    JSONArray errorCodeJson = new JSONArray();
    errorCodeJson.addAll(as.getErrorCodes());
    jsonObject.put("errorCodes", errorCodeJson);

    response.setStatus(HttpServletResponse.SC_OK);
    try {
      response.getWriter().println(jsonObject.toString());
    } catch (IOException e) {
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      log(LogService.LOG_ERROR,
          "unable to write response about application status", e);
    }
View Full Code Here

    }
  }

  private void executeDoGetDevices(HttpServletRequest req,
      HttpServletResponse resp) {
    JSONObject devices = new JSONObject();

    // pumps
    List pumps = fireApplication.getPumps();
    JSONArray pumpsArray = new JSONArray();
    for (Iterator it = pumps.iterator(); it.hasNext();) {
      EndPointService es = (EndPointService) it.next();
      String name = es.getName();
      String friendlyName = getDeviceFriendlyNameId(es);
      name = name + " " + friendlyName;

      // remove first # from friendlyname
      friendlyName = friendlyName.replaceAll("#", "");

      String id = PUMP_PREFIX_ID + friendlyName;
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, ZIGBEE_TECHNO);
      properties.put(IMG_PROP, PUMP_IMG);
      JSONObject pumpJs = new JSONObject(properties);
      pumpsArray.add(pumpJs);
    }
   
    // GreenNet switches is also viewed as a pump (i.e. actuator)
    List greenNetSwitches = fireApplication.getGreenNetSwitches();
    for(Iterator it = greenNetSwitches.iterator(); it.hasNext();) {
      Device greenNetSwitch = (Device) it.next();
      String id = ((Actuator)greenNetSwitch).getNode().getIdentifier();
      String name = "Air extractor";
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, GREENNET_TECHNO);
      properties.put(IMG_PROP, GREENNET_AIR_EJECTOR_IMG);
      JSONObject pumpJs = new JSONObject(properties);
      pumpsArray.add(pumpJs);
    }
    devices.put(PUMPS_PROP, pumpsArray);

    // ias zones
    List zones = fireApplication.getZoneDevices();
    JSONArray zonesArray = new JSONArray();
    for (Iterator it = zones.iterator(); it.hasNext();) {
      EndPointService es = (EndPointService) it.next();
      String name = es.getName();
      String friendlyName = getDeviceFriendlyNameId(es);
      name = name + " " + friendlyName;

      // remove first # from friendlyname
      friendlyName = friendlyName.replaceAll("#", "");
      String id = IAS_ZONES_PREFIX_ID + friendlyName;
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, ZIGBEE_TECHNO);
      properties.put(IMG_PROP, SMOKE_DETECTOR_IMG);
      JSONObject zoneJs = new JSONObject(properties);
      zonesArray.add(zoneJs);
    }
    devices.put(IAS_ZONES_PROP, zonesArray);

    // warning devices
    List warnings = fireApplication.getWarningDevices();
    JSONArray warningArray = new JSONArray();
    for (Iterator it = warnings.iterator(); it.hasNext();) {
      EndPointService es = (EndPointService) it.next();
      String name = es.getName();
      String friendlyName = getDeviceFriendlyNameId(es);
      name = name + " " + friendlyName;

      // remove first # from friendlyname
      friendlyName = friendlyName.replaceAll("#", "");
      String id = IAS_WARNING_PREFIX_ID + friendlyName;
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, ZIGBEE_TECHNO);
      properties.put(IMG_PROP, WARNING_IMG);
      JSONObject warningJs = new JSONObject(properties);
      warningArray.add(warningJs);
    }
   
    // x3d dimmers are also considered as warning devices
    List x3dDimmers = fireApplication.getX3DDimmers();
    int index = 1;
    for(Iterator it = x3dDimmers.iterator(); it.hasNext();) {
      X3DLightDimmer dimmer = (X3DLightDimmer) it.next();
     
      String id = X3D_DIMMER_PREFIX_ID + dimmer.getX3DDevice().getDeviceUri();
      id = id.replaceAll(" ", "");
      id = id.replaceAll("/", "");
      id = id.replaceAll(":", "");
      String name = "X3D Dimmer #" + index;
      index++;
     
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, X3D_TECHNO);
      properties.put(IMG_PROP, X3D_DIMMER_IMG);
      JSONObject warningJs = new JSONObject(properties);
      warningArray.add(warningJs);
    }
   
    // hue light are also considered as warning devices
    List hueLights = fireApplication.getHueLights();
    for(Iterator it = hueLights.iterator(); it.hasNext();) {
      HueLightDevice hld = (HueLightDevice) it.next();
      String name = hld.getName();
      String id = HUE_PREFIX_ID + hld.getId();
     
      Map properties = new HashMap();
      properties.put(ID_PROP, id);
      properties.put(NAME_PROP, name);
      properties.put(TECHNO_PROP, HUE_TECHNO);
      properties.put(IMG_PROP, HUE_LIGHT_IMG);
      JSONObject warningJs = new JSONObject(properties);
      warningArray.add(warningJs);
    }
    devices.put(IAS_WARNING_PROP, warningArray);
   
   
View Full Code Here

   *
   * @return a JSON representation of the payload under construction (possibly with an abbreviated alert body)
   */
  @SuppressWarnings("unchecked")
  public String buildWithMaximumLength(final int maximumPayloadLength) {
    final JSONObject payload = new JSONObject();

    {
      final JSONObject aps = new JSONObject();

      if (this.badgeNumber != null) {
        aps.put(BADGE_KEY, this.badgeNumber);
      }

      if (this.soundFileName != null) {
        aps.put(SOUND_KEY, this.soundFileName);
      }

      if (this.categoryName != null) {
        aps.put(CATEGORY_KEY, this.categoryName);
      }

      if (this.contentAvailable) {
        aps.put(CONTENT_AVAILABLE_KEY, 1);
      }

      final Object alertObject = this.createAlertObject();

      if (alertObject != null) {
        aps.put(ALERT_KEY, alertObject);
      }

      payload.put(APS_KEY, aps);
    }

View Full Code Here

    }
  }

  @SuppressWarnings("unchecked")
  private void replaceMessageBody(final JSONObject payload, final String messageBody) {
    final JSONObject aps = (JSONObject) payload.get(APS_KEY);
    final Object alert = aps.get(ALERT_KEY);

    if (alert != null) {
      if (alert instanceof String) {
        aps.put(ALERT_KEY, messageBody);
      } else {
        final JSONObject alertObject = (JSONObject) alert;

        if (alertObject.get(ALERT_BODY_KEY) != null) {
          alertObject.put(ALERT_BODY_KEY, messageBody);
        } else {
          throw new IllegalArgumentException("Payload has no message body.");
        }
      }
    } else {
View Full Code Here

TOP

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