Package org.json

Examples of org.json.JSONArray


                    try
                    {
                        api.getTransaction().begin();
                        Query query = api.newQuery("JDOQL", queryString);
                        List result = (List)query.execute();
                        JSONArray array = new JSONArray(result);
                        resp.getWriter().write(array.toString());
                        resp.setHeader("Content-Type", "application/json");
                        resp.setStatus(200);
                        api.getTransaction().commit();
                    }
                    finally
View Full Code Here


    JavascriptAppender.INSTANCE.append(out, gxpContext, (CharSequence)null);
    assertOutputEquals("null");
  }

  public void testWriteJSONArray() throws Exception {
    JSONArray json = new JSONArray();
    json.put(1);
    json.put(true);
    json.put(2.2);
    json.put("foo");
    JavascriptAppender.INSTANCE.append(out, gxpContext, json);
    assertOutputEquals("[1,true,2.2,\"foo\"]");

    json = null;
    try {
View Full Code Here

    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");
View Full Code Here

    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

        // each call is done for a specific node: get the child elements
        // for this node
        String data;
        String nodeId = request.getParameter(PARAM_NODE);
        if (StringHelper.containsNonWhitespace(nodeId)) {
          JSONArray jsonData = new JSONArray();
          List<AjaxTreeNode> children = dataModel.getChildrenFor(nodeId);
          for (AjaxTreeNode child : children) {
            jsonData.put(child);
          }
          data = jsonData.toString();
        } else {
          // something is wrong, maybe some hacker attack
          logError("Got a tree data mapper request but node parameter is missing. Root node title was::" + titleRootNode, null);
          data = "";
        }
View Full Code Here

      pie.put("tip", "#val# of #total#<br>#percent#");
      pie.put("start-angle", 35);
      pie.put("border", 2);
      pie.put("alpha", .6);
     
      JSONArray colors = new JSONArray();
      for (int i = 0; i < COLORS.length; i++)
      {
        colors.put(COLORS[i]);
      }
      pie.put("colours", colors);
     
      JSONArray pieValues = new JSONArray();
      Iterator labelIt = dataset.getKeys().iterator();
      Iterator valueIt = dataset.getValues().iterator();
      while (labelIt.hasNext() && valueIt.hasNext())
      {
        String label = (String) labelIt.next();
        Number value = (Number) valueIt.next();
        JSONObject pieValue = new JSONObject();
        pieValue.put("value", value);
        pieValue.put("label", label);
        pieValues.put(pieValue);
      }
      pie.put("values", pieValues);
     
      JSONArray elements = new JSONArray();
      elements.put(pie);
      chart.put("elements", elements);
     
      return chart.toString();
    }
    catch (JSONException e)
View Full Code Here

      JSONObject chart = new JSONObject();
      chart.put("bg_colour", BGCOLOR);
      chart.put("title", new JSONObject().put("text", title));

      JSONObject xAxis = new JSONObject();
      JSONArray labels = new JSONArray(categories);
      xAxis.put("labels", new JSONObject().put("labels", labels));
      chart.put("x_axis", xAxis);
     
      JSONArray elements = new JSONArray();
      int seriesIdx = 0;
      double max = 0d;
      for (Iterator seriesIt = seriesKeys.iterator(); seriesIt.hasNext();)
      {
        String seriesKey = (String) seriesIt.next();
       
        JSONObject bar = new JSONObject();
        bar.put("type", "bar_glass");
        bar.put("colour", COLORS[seriesIdx % COLORS.length]);
        bar.put("alpha", .9);
       
        JSONArray values = new JSONArray();
        for (Iterator catIt = categories.iterator(); catIt.hasNext();)
        {
          String category = (String) catIt.next();
          Number value = dataset.getValue(seriesKey, category);
          if (value == null)
          {
            value = new Integer(0);
          }
         
          JSONObject valueObject = new JSONObject();
          valueObject.put("top", value);
          valueObject.put("tip", seriesKey + " #top#");
          values.put(valueObject);
         
          if (value.doubleValue() > max)
          {
            max = value.doubleValue();
          }
View Full Code Here

      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

  public Command extractJSCSSCommand() {
    try {     
      JSONObject root = new JSONObject();
     
      //css to add
      JSONArray cssAdd = new JSONArray();
      root.put("cssadd", cssAdd);
      for (String addCss : cssToAdd) {
        // the id and the whole relative css path, e.g. /g/4/my.css
        JSONObject styleinfo = new JSONObject();
        String cssId = cssPathToId.get(addCss);
        styleinfo.put("id", cssId);
        styleinfo.put("url", addCss);
        // on js level only pre and post theme rendering supported
        styleinfo.put("pt", cssPathToIndex.get(addCss) > JSAndCSSAdder.CSS_INDEX_THEME ? true : false);
        cssAdd.put(styleinfo);
      }
     
      //css to remove
      JSONArray cssRemove = new JSONArray();
      root.put("cssrm", cssRemove);
      for (String removeCss : cssToRemove) {
        // the id and the whole relative css path, e.g. /g/4/my.css
        JSONObject styleinfo = new JSONObject();
        String cssId = cssPathToId.get(removeCss);
        styleinfo.put("id", cssId);
        styleinfo.put("url", removeCss);
        cssRemove.put(styleinfo);
      }
     
      //jsToAdd
      JSONArray jsAdd = new JSONArray();
      root.put("jsadd", jsAdd);
      for (String addJs : jsToAdd) {
        // load file with correct encoding. OLAT files are all UTF-8, but some
        // libraries like TinyMCE are ISO-88591. The window.execScript() in IE
        // can fail when the string has the wrong encoding (IE error 8002010)
        String fileEncoding = jsPathToEvalFileEncoding.get(addJs);
        JSONObject fileInfo = new JSONObject();
        fileInfo.put("url", addJs);
        fileInfo.put("enc", fileEncoding);
        // add code to be executed before the js code is inserted
        if (jsPathToEvalBeforeAJAXAddJsCode.containsKey(addJs)) {
          fileInfo.put("before", jsPathToEvalBeforeAJAXAddJsCode.get(addJs));         
        }
        jsAdd.put(fileInfo);
      }
      Command com = CommandFactory.createJSCSSCommand();
      com.setSubJSON(root);
      return com;
    } catch (JSONException e) {
View Full Code Here

      if (dCnt > 0) { // collect the redraw dirties command
        try {     
          JSONObject root = new JSONObject();
          root.put("cc", dirties.size());
          root.put("wts", timestamp);
          JSONArray ja = new JSONArray();
          root.put("cps", ja);
         
          GlobalSettings gsettings = wbackofficeImpl.getGlobalSettings();
         
          synchronized(render_mutex) { //o_clusterOK by:fj
            // we let all dirty components render themselves.
            // not offered (since not usability-useful) is the include of new js-libraries and css-libraries here, since this may invoke a screen reload
            // which disturbes the user and lets him/her loose the focus and the cursor.
            AsyncMediaResponsible amr = null;
 
            long rstart = 0;
            if (isDebugLog) {
              rstart = System.currentTimeMillis();
              debugMsg = new StringBuilder("update:").append(String.valueOf(dCnt)).append(";");
            }
           
            for (int i = 0; i < dCnt; i++) {
              Component toRender = dirties.get(i);
              boolean wasDomR = toRender.isDomReplaceable();
              if (!wasDomR) {
                throw new AssertException("cannot replace as dom fragment:"+toRender.getComponentName()+" ("+toRender.getClass().getName()+"),"+toRender.getExtendedDebugInfo());
              }
             
              Panel wrapper = new Panel("renderpanel");
              wrapper.setDomReplaceable(false); // to omit <div> around the render helper panel
              RenderResult renderResult = null;
              StringOutput jsol = new StringOutput();
              StringOutput hdr = new StringOutput();
              String result = null;
              try {
                toRender.setDomReplaceable(false);
                wrapper.setContent(toRender);
                String newTimestamp = String.valueOf(timestamp);
                URLBuilder ubu = new URLBuilder(uriPrefix,getInstanceId(), newTimestamp,wbackofficeImpl);

                renderResult = new RenderResult();

                // if we have an around-component-interception
                // set the handler for this render cycle
                InterceptHandler interceptHandler = wbackofficeImpl.getInterceptHandler();
                if (interceptHandler != null) {
                  InterceptHandlerInstance dhri = interceptHandler.createInterceptHandlerInstance();
                  renderResult.setInterceptHandlerRenderInstance(dhri);
                }

                Renderer fr = Renderer.getInstance(wrapper,null, ubu, renderResult, gsettings);

                jsol = new StringOutput();
                fr.renderBodyOnLoadJSFunctionCall(jsol,toRender);

                hdr = new StringOutput();
                fr.renderHeaderIncludes(hdr, toRender);

                long pstart = 0;
                if (isDebugLog) {
                  pstart = System.currentTimeMillis();
                }
                result = fr.render(toRender).toString();
                if (isDebugLog) {
                  long pstop = System.currentTimeMillis();
                  debugMsg.append(toRender.getComponentName()).append(":").append((pstop - pstart));
                  if (i < dCnt - 1)
                    debugMsg.append(",");
                }
              } catch (Exception e) {
                throw new OLATRuntimeException(Window.class,renderResult.getLogMsg(), renderResult.getRenderException());
              } finally {
                toRender.setDomReplaceable(true);
              }
              if (renderResult.getRenderException() != null) throw new OLATRuntimeException(Window.class, renderResult.getLogMsg(),
                  renderResult.getRenderException());
             
              AsyncMediaResponsible curAmr = renderResult.getAsyncMediaResponsible();
              if (curAmr != null) {
                if (amr != null) {
                  throw new AssertException("can set amr only once in a screen!");
                } else {
                  amr = curAmr;
                }
              }
             
              JSONObject jo = new JSONObject();
              long cid = toRender.getDispatchID();
              if (Settings.isDebuging()) {
                // for debugging only
                jo.put("cname", toRender.getComponentName());
                jo.put("clisteners",toRender.getListenerInfo());
                jo.put("hfragsize", result.length());
              }           
             
              jo.put("cid", cid);
              jo.put("cidvis", toRender.isVisible());
              jo.put("hfrag", result);
              jo.put("jsol", jsol);
              jo.put("hdr", hdr);
              ja.put(jo);
            }
            //polling case should never set the asyncMediaResp.
            //to null otherwise it possible that e.g. pdf served as following click within a CP component
            if (amr != null) setAsyncMediaResponsible(amr);
                     
View Full Code Here

TOP

Related Classes of org.json.JSONArray

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.