Package org.json

Examples of org.json.JSONObject$Null


   * tells the ajax-command interpreter to reload the main (=ajax's parent) window
   * @param redirectURL e.g. /olat/m/10001/
   * @return the generated command
   */
  public static Command createParentRedirectTo(String redirectURL) {
    JSONObject root = new JSONObject();
    try {
      root.put("rurl", redirectURL);
    } catch (JSONException e) {
      throw new AssertException("wrong data put into json object", e);
    }
    Command c = new Command(3);
    c.setSubJSON(root);
View Full Code Here


  /**
   * - resets the js flag which is set when the user changes form data and is checked when an other link is clicked.(to prevent form data loss).<br>
   * @return the command
   */
  public static Command createPrepareClientCommand(String businessControlPath) {
    JSONObject root = new JSONObject();
    try {
      root.put("bc", businessControlPath==null? "":businessControlPath);
    } catch (JSONException e) {
      throw new AssertException("wrong data put into json object", e);
    }
    Command c = new Command(6);
    c.setSubJSON(root);
View Full Code Here

  /**
   * @param res
   * @return
   */
  public static Command createParentRedirectForExternalResource(String redirectMapperURL) {
    JSONObject root = new JSONObject();
    try {
      root.put("rurl", redirectMapperURL);
    } catch (JSONException e) {
      throw new AssertException("wrong data put into json object", e);
    }
    Command c = new Command(5);
    c.setSubJSON(root);
View Full Code Here

   * Create a command that executes arbitrary JS code
   * @param javaScriptCode
   */
  public JSCommand(String javaScriptCode) {
    super(1); // do not change this command id, it is in js also
    JSONObject subjo = new JSONObject();
    try {
      subjo.put("e", javaScriptCode);
    } catch (JSONException e) {
      throw new AssertException("json exception:", e);
    }
    setSubJSON(subjo);   
  }
View Full Code Here

 
  public String generatePieChart(String title, FillPieDataset dataset)
  {
    try
    {
      JSONObject chart = new JSONObject();
      chart.put("bg_colour", BGCOLOR);
      chart.put("title", new JSONObject().put("text", title));
     
      JSONObject pie = new JSONObject();
      pie.put("type", "pie");
      pie.put("animate", true);
      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();
View Full Code Here

    try
    {
      Set seriesKeys = dataset.getSeriesKeys();
      Set categories = dataset.getCategories();
     
      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();
          }
        }
        bar.put("values", values);
       
        elements.put(bar);
        ++seriesIdx;
      }
     
      int yMax = (int) Math.ceil(max);
      int m = 1;
      while (yMax > 100)
      {
        yMax = (int) Math.ceil(yMax / 10d);
        m *= 10;
      }
      yMax = 5 * (int) Math.ceil(yMax / 5d);
      yMax *= m;
      int steps = yMax / 5;
     
      JSONObject yAxis = new JSONObject();
      yAxis.put("max", yMax);
      yAxis.put("steps", steps);
      chart.put("y_axis", yAxis);
     
     
      chart.put("elements", elements);
     
View Full Code Here

   * @param jsonRenderInstruction
   * @param acceptedInstructions
   */
  public static void appendRenderInstructions(StringOutput sb,
      String jsonRenderInstruction, Set acceptedInstructions) {
    JSONObject instr;
    try {
      instr = new JSONObject(jsonRenderInstruction);
      sb.append(" ");// ensure blank before appending instructions -> '
              // '...
      for (Iterator iter = acceptedInstructions.iterator(); iter
          .hasNext();) {
        String accepted = (String) iter.next();
        if (instr.get(accepted) != null) {
          // generates i.e. 'class=\"thevalueclass\" '
          sb.append(accepted);// accepted key is also use as attribute
          sb.append("=\"");
          sb.append(instr.getString(accepted));
          sb.append("\" ");
        }
      }
    } catch (JSONException e) {
      throw new OLATRuntimeException(
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);
View Full Code Here

      ct.visitAll(null);
     
      int dCnt = dirties.size();
      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

    // less data efficient for foreign character sets but it is
    // needed to support naughty browsers such as Konqueror and Safari
    // which do not honour the charset set in the response
    response.setContentType("text/plain;charset=utf-8");

    JSONObject jsonReq = null;
    JSONRPCResult jsonRes = null;

    // Decode using the charset in the request if it exists otherwise
    // use UTF-8 as this is what all browser implementations use.
    // The JSON-RPC-Java JavaScript client is ASCII clean so it
    // although here we can correctly handle data from other clients
    // that do not escape non ASCII data
    String charset = request.getCharacterEncoding();
    if (charset == null) {
      charset = "UTF-8";
    }
    BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), charset));

    // Read the request
    CharArrayWriter data = new CharArrayWriter();
    char[] buf = new char[BUFFER_SIZE];
    int ret;
    while ((ret = in.read(buf, 0, BUFFER_SIZE)) != -1) {
      data.write(buf, 0, ret);
    }
    writeReceive(data.toString());
    try {
      jsonReq = new JSONObject(data.toString());
      // Process the request
      jsonRes = jsonBridge.call(new Object[] { request }, jsonReq);
    } catch (ParseException e) {
      log.error("can't parse call: " + data, e);
      jsonRes = new JSONRPCResult(JSONRPCResult.CODE_ERR_PARSE, null, JSONRPCResult.MSG_ERR_PARSE);
    }

    // Write the response
    JsonObjectWriter writer = new JsonObjectWriter(response.getWriter(), 3);
    writer.write(jsonRes);
    writer.flush();

    JSONArray jsonArray = (JSONArray) jsonReq.get("params");
    long millis = System.currentTimeMillis() - startTime;
    log.debug("Command execution time: " + millis + " ms - class=" + jsonArray.toString());
  }
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.