Package org.json

Examples of org.json.JSONObject$Null


        new Coordinate(12.0, 34.23), new Coordinate(12.000, 54.555), new Coordinate(7, 8),
        new Coordinate(12.0, 34.23)});
    LinearRing ring = new LinearRing(coords, factory);
    Polygon p = new Polygon(ring, new LinearRing[] {}, factory);
    MultiPolygon m = new MultiPolygon(new Polygon[] {p}, factory);
    JSONObject jo = (JSONObject) ser.marshall(null, m);
    assertEquals("MultiPolygon", jo.get("type").toString());
    assertEquals("31300", jo.get("srid").toString());
    assertEquals("2", jo.get("precision").toString());
    JSONArray polygons = jo.getJSONArray("polygons");
    JSONObject polygon = polygons.getJSONObject(0);
    assertEquals("Polygon", polygon.get("type").toString());
    assertEquals("[]", polygon.get("holes").toString());
    assertEquals("31300", polygon.get("srid").toString());
    assertEquals("2", polygon.get("precision").toString());
    JSONObject shell = polygon.getJSONObject("shell");
    assertEquals("LineString", shell.get("type").toString());
    assertEquals("31300", shell.get("srid").toString());
    assertEquals("2", shell.get("precision").toString());
    assertEquals("[12,34.23,12,54.56,7,8,12,34.23]", shell.get("coordinates").toString());
  }
View Full Code Here


    GeometryFactory factory = new GeometryFactory(new PrecisionModel(100.0), 31300);
    CoordinateArraySequence coords = new CoordinateArraySequence(new Coordinate[] {
        new Coordinate(12.0, 34.23), new Coordinate(12.000, 54.555), new Coordinate(-0.01, -0.0)});
    LineString l = new LineString(coords, factory);
    MultiLineString m = new MultiLineString(new LineString[] {l}, factory);
    JSONObject jo = (JSONObject) ser.marshall(null, m);
    assertEquals("MultiLineString", jo.get("type").toString());
    assertEquals("31300", jo.get("srid").toString());
    assertEquals("2", jo.get("precision").toString());
    JSONArray lineStrings = jo.getJSONArray("lineStrings");
    JSONObject lineString = lineStrings.getJSONObject(0);
    assertEquals("LineString", lineString.get("type").toString());
    assertEquals("31300", lineString.get("srid").toString());
    assertEquals("2", lineString.get("precision").toString());
    assertEquals("[12,34.23,12,54.56,-0.01,0]", lineString.get("coordinates").toString());
  }
View Full Code Here

  public void testPoint() throws MarshallException, GeomajasException {
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(10000.0), 31300);
    CoordinateArraySequence coords = new CoordinateArraySequence(new Coordinate[] { new Coordinate(12.3456,
        34567.3456) });
    Point p = new Point(coords, factory);
    JSONObject jtsJson = (JSONObject) jtsSerializer.marshall(null, p);
    Geometry dto = converter.toDto(p);
    JSONObject dtoJson = (JSONObject) dtoSerializer.marshall(null, dto);
    Assert.assertEquals(jtsJson.toString(), dtoJson.toString());
  }
View Full Code Here

  public void testLineString() throws MarshallException, GeomajasException {
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(10000.0), 31300);
    CoordinateArraySequence coords = new CoordinateArraySequence(new Coordinate[] { new Coordinate(12.0, 34.23),
        new Coordinate(12.000, 54.555), new Coordinate(-0.01, 0.0) });
    LineString p = new LineString(coords, factory);
    JSONObject jtsJson = (JSONObject) jtsSerializer.marshall(null, p);
    Geometry dto = converter.toDto(p);
    JSONObject dtoJson = (JSONObject) dtoSerializer.marshall(null, dto);
    Assert.assertEquals(jtsJson.toString(), dtoJson.toString());
  }
View Full Code Here

        new Coordinate(12.000, 54.555), new Coordinate(7, 8), new Coordinate(12.0, 34.23) });
    LinearRing ring = new LinearRing(coords, factory);
    Polygon p = new Polygon(ring, null, factory);
    Geometry dto = converter.toDto(p);

    JSONObject jtsJson = (JSONObject) jtsSerializer.marshall(null, p);
    JSONObject dtoJson = (JSONObject) dtoSerializer.marshall(null, dto);
    Assert.assertEquals(jtsJson.toString().length(), dtoJson.toString().length());
    Assert.assertEquals(jtsJson.get("type").toString(), dtoJson.get("type").toString());
    Assert.assertEquals(jtsJson.get("holes").toString(), dtoJson.get("holes").toString());
    Assert.assertEquals(jtsJson.get("srid").toString(), dtoJson.get("srid").toString());
    Assert.assertEquals(jtsJson.get("precision").toString(), dtoJson.get("precision").toString());

    JSONObject jtsShell = jtsJson.getJSONObject("shell");
    JSONObject dtoShell = dtoJson.getJSONObject("shell");
    Assert.assertEquals(jtsShell.get("type").toString(), dtoShell.get("type").toString());
    Assert.assertEquals(jtsShell.get("srid").toString(), dtoShell.get("srid").toString());
    Assert.assertEquals(jtsShell.get("precision").toString(), dtoShell.get("precision").toString());
    Assert.assertEquals(jtsShell.get("coordinates").toString(), dtoShell.get("coordinates").toString());
  }
View Full Code Here

    LinearRing ring = new LinearRing(coords, factory);
    Polygon p = new Polygon(ring, new LinearRing[] {}, factory);
    MultiPolygon m = new MultiPolygon(new Polygon[] { p }, factory);
    Geometry dto = converter.toDto(m);

    JSONObject jtsJson = (JSONObject) jtsSerializer.marshall(null, m);
    JSONObject dtoJson = (JSONObject) dtoSerializer.marshall(null, dto);
    Assert.assertEquals(jtsJson.toString().length(), dtoJson.toString().length());
    Assert.assertEquals(jtsJson.get("type").toString(), dtoJson.get("type").toString());
    Assert.assertEquals(jtsJson.get("srid").toString(), dtoJson.get("srid").toString());
    Assert.assertEquals(jtsJson.get("precision").toString(), dtoJson.get("precision").toString());

    JSONObject jtsPolygon = jtsJson.getJSONArray("polygons").getJSONObject(0);
    JSONObject dtoPolygon = dtoJson.getJSONArray("polygons").getJSONObject(0);
    Assert.assertEquals(jtsPolygon.get("type").toString(), dtoPolygon.get("type").toString());
    Assert.assertEquals(jtsPolygon.get("holes").toString(), dtoPolygon.get("holes").toString());
    Assert.assertEquals(jtsPolygon.get("srid").toString(), dtoPolygon.get("srid").toString());
    Assert.assertEquals(jtsPolygon.get("precision").toString(), dtoPolygon.get("precision").toString());

    JSONObject jtsShell = jtsPolygon.getJSONObject("shell");
    JSONObject dtoShell = dtoPolygon.getJSONObject("shell");
    Assert.assertEquals(jtsShell.get("type").toString(), dtoShell.get("type").toString());
    Assert.assertEquals(jtsShell.get("srid").toString(), dtoShell.get("srid").toString());
    Assert.assertEquals(jtsShell.get("precision").toString(), dtoShell.get("precision").toString());
    Assert.assertEquals(jtsShell.get("coordinates").toString(), dtoShell.get("coordinates").toString());
  }
View Full Code Here

    GeometryFactory factory = new GeometryFactory(new PrecisionModel(10000.0), 31300);
    CoordinateArraySequence coords = new CoordinateArraySequence(new Coordinate[] { new Coordinate(12.0, 34.23),
        new Coordinate(12.000, 54.555), new Coordinate(-0.01, 0.0) });
    LineString l = new LineString(coords, factory);
    MultiLineString m = new MultiLineString(new LineString[] { l }, factory);
    JSONObject jtsJson = (JSONObject) jtsSerializer.marshall(null, m);
    Geometry dto = converter.toDto(m);
    JSONObject dtoJson = (JSONObject) dtoSerializer.marshall(null, dto);
    Assert.assertEquals(jtsJson.toString(), dtoJson.toString());
  }
View Full Code Here

  public void setHighLightingEnabled(boolean enabled) {
    myContent.contextPut("highlight", Boolean.valueOf(enabled));
  }

  public MediaResource extractMediaResource(boolean wrapHTML) {
    JSONObject json = getAndClearJSON();
    String res;
    String jsonText = json.toString();
    //System.out.println("jsontext:"+jsonText);
    if (wrapHTML) {
      // most ajax responses are a lot smaller than 16k
      StringBuffer sb = new StringBuffer(16384);
      sb.append("<html><head><script type=\"text/javascript\">\n/* <![CDATA[ */\nfunction invoke(){var r=")
        .append(jsonText).append("; ")
        .append("if (parent!=self&&parent.window.o_info){")
        .append("parent.window.o_ainvoke(r);")
          // normal case: ajax result can be delivered into the hidden iframe.
          // else: no parent frame or parent frame is not olat -> reasons:
          // a) mouse-right-click to open in new tab/window
          // b) fast double-click when target causes a 302 and browser's window's document has been updated, but old link was still clickable
          // c) ...
          // -> in all cases, do not show the json command, but reload the window which contained the link clicked (= window id of url)
         
        .append("} else {")
          // inform user that ajax-request cannot be opened in a new window,
          // todo felix: maybe send back request to bookmark-launch current url? -> new window?
          // we could then come near to what the user probably wanted when he/she opened a link in a new window
        .append("this.document.location=\"")
        .append(StaticMediaDispatcher.createStaticURIFor("msg/json/en/info.html"))
        .append("\";")
          //.append("window.open(self.location+\"?o_win_jsontop=1\"); this.close();")
          //.append("this.document.location=self.location+\"?o_win_jsontop=1\";")
        .append("}}")
        .append("\n/* ]]> */\n</script></head><body onLoad=\"invoke()\">");
          if (showJSON) {
            try {
              sb.append("<pre style=\"font-size:12px;\">len:").append(jsonText.length()).append(":\n").append(StringEscapeUtils.escapeHtml(json.toString(2))).append("</pre>");
            } catch (JSONException e) {
              sb.append("error while prettyprinting json for debug mode: ").append(e.getMessage());
            }
          }
          sb.append("</body></html>");
View Full Code Here

  private JSONObject createJSON(WindowCommand wc) {
    Command c = wc.getCommand();
    WindowBackOffice wbo = wc.getWindowBackOffice();
    long winId = wbo.getWindow().getDispatchID();
    JSONObject jo = new JSONObject();
    try {
      jo.put("cmd", c.getCommand());
      jo.put("w", winId);
      jo.put("cda", c.getSubJSON());
      return jo;
    } catch (JSONException e) {
      throw new AssertException("json exception:", e);
    }
  }
View Full Code Here

  /**
   * @param moreCmds a List of WindowCommand objects
   * @return
   */
  private JSONObject getAndClearJSON() {
    JSONObject root = new JSONObject();
   

    try {
      if (Settings.isDebuging()) {
        long time = System.currentTimeMillis();
        root.put("time", time);
      }
      synchronized (windowcommands) { //o_clusterOK by:fj
        // handle all windowcommands now, create json
        int sum = windowcommands.size();
        root.put("cmdcnt", sum); // number of commands: 0..n
        if (sum > 0) {
          JSONArray ja = new JSONArray();
          root.put("cmds", ja);
          // treat commands waiting for the poll
          for (int i = 0; i < sum; i++) {
            WindowCommand wc = windowcommands.get(i);
            JSONObject jo = createJSON(wc);
            ja.put(jo);
          }
          windowcommands.clear();
        }
       
View Full Code Here

TOP

Related Classes of org.json.JSONObject$Null

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.