@Override
    public JSONObject toJSON() {
      JSONObject json = new JSONObject();
      json.put("pic", "user");

      switch (eventType) {
        case PUBLICATION_ANNOTATION_ADD:
          json.put("action", "add");
          break;
        case PUBLICATION_ANNOTATION_DELETE:
          json.put("action", "delete");
          break;
        case PUBLICATION_ANNOTATION_EDIT:
          json.put("action", "edit");
          break;
        default:
          // pass
      }
      json.put("annotationId", annotationId);
      json.put("oldAnnotation", oldAnnotation);
      json.put("annotation", annotation);

      JSONObject nodes = new JSONObject();
      nodes.put("user", createUserNode());
      nodes.put("pub", createSimplePublicationNode(pubId, title));
      json.put("nodes", nodes);

      return json;
    }
Пример #2
0
  @AfterRender
  public void afterRender(MarkupWriter writer) {
    writer.end();

    String id = field.getClientId();

    if (options == null) options = new JSONObject();
    JSONObject opt = new JSONObject();
    opt.put("id", id);
    opt.put("params", options);

    javaScriptSupport.require("kawwa/productquantity").with(opt);
  }
Пример #3
0
  protected void configure(final JSONObject config) {
    super.configure(config);

    if (this.resources.isBound("updateElementFunction")) {
      config.put("updateElement", new JSONLiteral(updateElementFunction));
    }
  }
  public String getBookDetailsAsString(String id) {
    Book book = hBookDetails.get(id);
    String json = "";
    ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
    JSONObject ret = new JSONObject();

    ret.put("id", book.getId());
    ret.put("author", book.getAuthor());
    ret.put("name", book.getName());
    ret.put("description", book.getDescription());
    ret.put("category", book.getCategory());
    ret.put("price", book.getPrice());
    ret.put("isNew", book.getIsNew());

    try {

      json = ow.writeValueAsString(book.getComments());
      ret.put("comments", new JSONArray(json));

    } catch (IOException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return ret.toString();
  }
Пример #5
0
  @AfterRender
  void afterRender() {

    if (params == null) params = new JSONObject();

    final JSONObject options = new JSONObject();
    options.put("selector", selector);

    JQueryUtils.merge(options, params);

    javaScriptSupport.require("tjq/gallery").with(options);
  }
  public String getInitialization() {
    Locale locale = threadLocale.getLocale();

    JSONObject spec = new JSONObject();

    DateFormatSymbols symbols = new DateFormatSymbols(locale);

    spec.put("months", new JSONArray((Object[]) symbols.getMonths()));

    StringBuilder days = new StringBuilder();

    String[] weekdays = symbols.getWeekdays();

    Calendar c = Calendar.getInstance(locale);

    int firstDay = c.getFirstDayOfWeek();

    // DatePicker needs them in order from monday to sunday.

    for (int i = Calendar.MONDAY; i <= Calendar.SATURDAY; i++) {
      days.append(weekdays[i].substring(0, 1));
    }

    days.append(weekdays[Calendar.SUNDAY].substring(0, 1));

    spec.put("days", days.toString().toLowerCase(locale));

    // jQuery DatePicker widget expects 0 to be sunday. Calendar defines SUNDAY as 1, MONDAY as 2,
    // etc.
    spec.put("firstDay", firstDay - 1);

    // set language
    spec.put("language", locale.getLanguage());

    // TODO: Skip localization if locale is English?

    return String.format("Tapestry.DateField.initLocalization(%s);", spec.toString(compactJSON));
  }
Пример #7
0
  @CommitAfter
  JSONObject onSuccessFromTagForm() {
    List<Tag> tolist = tagDAO.findByName(fname);
    JSONObject json = new JSONObject();
    if (tolist.size() > 0) {
      String markup = "<p>  <b>" + fname + "</b> already exists. <p>";
      json.put("content", markup);

    } else {
      tag = new Tag();
      tag.setName(fname);

      tagDAO.doSave(tag);
      String markup =
          "<p> You just submitted <b>"
              + tag.getName()
              + "</b>. Please add it using the dropdown <p>";
      json.put("content", markup);
    }

    // return new TextStreamResponse("text/json", json.toString());
    return json;
  }
Пример #8
0
  Block onChangeFromFlagSelect(String selected) {
    JSONObject json = new JSONObject();
    if (selected != null && !selected.equals("")) {
      json.put("flag", selected);
      // Active, Incorrect, Spam, Inappropriate, Copyright, Attention
      if (selected.equals("Incorrect")) {
        flags = flagDAO.FindAllByFlagType(ContentType.Question, ContentFlag.Incorrect);
      } else if (selected.equals("Spam")) {
        flags = flagDAO.FindAllByFlagType(ContentType.Question, ContentFlag.Spam);
      } else if (selected.equals("Inappropriate")) {
        flags = flagDAO.FindAllByFlagType(ContentType.Question, ContentFlag.Inappropriate);
      } else if (selected.equals("Copyright")) {
        flags = flagDAO.FindAllByFlagType(ContentType.Question, ContentFlag.Copyright);
      } else if (selected.equals("Attention")) {
        flags = flagDAO.FindAllByFlagType(ContentType.Question, ContentFlag.Attention);
      }

      // json.put("content", r.getBody());
    } else {
      json.put("flag", "-1");
    }

    return resultblock;
  }
Пример #9
0
  @OnEvent(component = "uploadFile", value = JQueryEventConstants.NON_XHR_UPLOAD)
  Object onNonXHRUploadFile(UploadedFileItem uploadedFile) {

    logger.info(" >>> onNonXHRUploadFile");

    if (uploadedFile != null) {
      this.uploadedFiles.add(uploadedFile);
    }

    final JSONObject result = new JSONObject();
    final JSONObject params =
        new JSONObject()
            .put("url", resources.createEventLink("myCustomEvent", "NON_XHR_UPLOAD").toURI())
            .put("zoneId", "uploadResult");

    result.put(AjaxUpload.UPDATE_ZONE_CALLBACK, params);
    return result;
  }
Пример #10
0
  public void beginRender(MarkupWriter writer) {
    String value = tracker.getInput(this);

    if (value == null) {
      value = formatCurrentValue();
    }

    String clientId = getClientId();
    String triggerId = clientId + "-trigger";

    writer.element(
        "input",
        "type",
        hideTextField ? "hidden" : "text",
        "name",
        getControlName(),
        "id",
        clientId,
        "value",
        value);

    if (isDisabled()) {
      writer.attributes("disabled", "disabled");
    }

    validate.render(writer);

    resources.renderInformalParameters(writer);

    decorateInsideField();

    writer.end();

    // Now the trigger icon.

    writer.element(
        "img",
        "id",
        triggerId,
        "class",
        "t-calendar-trigger",
        "src",
        icon.toClientURL(),
        "alt",
        "[Show]");
    writer.end(); // img

    writeTimeZone(writer);

    JSONObject spec =
        new JSONObject(
                "clientId", clientId, "clientDateFormat", formatConverter.convertToClient(format))
            .put("time", time)
            .put("singleClick", singleClick);

    if (max != null) {
      spec.put("max", convertDateToClientTimeZone(max).getTime());
    }

    if (min != null) {
      spec.put("min", convertDateToClientTimeZone(min).getTime());
    }

    javascriptSupport.addInitializerCall("tapxDateField", spec);
  }
Пример #11
0
  @AfterRender
  public void afterRender(MarkupWriter writer) {
    String id;
    if (elementName == null) {
      elementName = resources.getElementName();
      if (elementName == null) {
        elementName = "ul";
      }
    }
    if (draggableName == null) {
      draggableName = "div";
      if (elementName.equals("ul")) {
        draggableName = "li";
      }
    }

    Object compoment = resources.getContainer();
    if (ClientElement.class.isAssignableFrom(compoment.getClass())) {
      id = ((ClientElement) compoment).getClientId();
    } else {
      id = javaScriptSupport.allocateClientId(resources);
    }
    if (Grid.class.isAssignableFrom(compoment.getClass())) {
      elementName = "tbody";
      draggableName = "tr";
    }

    element = writer.getElement();

    element.visit(
        new Visitor() {

          public void visit(Element e) {
            if (e.getName().equals(elementName)) {
              element = e;
            }
            if (e.getName().equals("tr")) {
              String c = e.getAttribute("class");
              if (c != null) {
                e.forceAttributes("id", c.split(" ")[0]);
              }
            }
          }
        });
    String currentID = element.getAttribute("id");
    if (currentID != null) {
      id = currentID;
    } else {
      element.forceAttributes("id", id);
    }
    // element.addClassName("sortable");
    // logger.info("spec {}",spec);
    if (!spec.has("selector")) {
      spec.put("selector", String.format("#%s %s", id, draggableName));
    }
    if (!spec.has("context")) {
      ArrayEventContext aec = new ArrayEventContext(typeCoercer, defaulted(context));
      spec.put("context", String.format("/%s", contextPathEncoder.encodeIntoPath(aec)));
    }
    javaScriptSupport.addInitializerCall("jqDraggable", spec);
  }
Пример #12
0
  /**
   * Ajax event handler, form client side to get the data to display to parse it according to the
   * server-side format. see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data for
   * more details
   */
  @OnEvent(value = "Data")
  JSONObject onData() {
    String page = request.getParameter(PAGE);

    int requestedPageNumber = Integer.parseInt(page);
    String search = request.getParameter(SEARCH);
    String searchField = request.getParameter(SEARCH_FIELD);
    String searchString = request.getParameter(SEARCH_STRING);
    String searchOper = request.getParameter(SEARCH_OPER);
    // searchField=tax&searchString=100&searchOper=gt

    if (search.equals("false")) source.resetFilter();
    else if (searchField != null && searchOper != null && searchString != null) {
      SearchOperator op = SearchOperator.valueOf(searchOper);
      Class searchType = getDataModel().get(searchField).getConduit().getPropertyType();
      Object searchValue = typeCoercer.coerce(searchString, searchType);
      SearchConstraint searchFor =
          new SearchConstraint(
              searchField, op, searchValue, getDataModel().get(searchField).getConduit());
      List<SearchConstraint> lst = new ArrayList();
      lst.add(searchFor);
      source.setFilter(lst);
    }

    String nd = request.getParameter(ND);

    String rowsSelected = request.getParameter(ROWS);
    int rowsPerPage = Integer.parseInt(rowsSelected);

    String sidx = request.getParameter(SIDX);
    String arrayString[] = sidx.split("\\s+");
    // get only the start
    sidx = arrayString[0];

    String sord = request.getParameter(SORD);

    JSONObject response = new JSONObject();
    int records = source.getAvailableRows();

    int nbPages = records / rowsPerPage;
    int modulo = records % rowsPerPage;
    if (modulo > 0) nbPages++;

    int startIndex = 0 + (requestedPageNumber - 1) * rowsPerPage;
    int endIndex = startIndex + rowsPerPage - 1;
    if (endIndex > records - 1) endIndex = records - 1;

    response.put("page", requestedPageNumber);
    response.put("total", nbPages);

    response.put("records", records);

    List<SortConstraint> sortConstraints = new ArrayList();
    if (!sidx.isEmpty()) {
      GridSortModel sortModel = getSortModel();
      ColumnSort colSort = sortModel.getColumnSort(sidx);
      if (sord.equals("asc")) setSortAscending(true);
      else setSortAscending(false);
      sortModel.updateSort(sidx);
      sortConstraints = sortModel.getSortConstraints();
    }
    source.prepare(startIndex, endIndex, sortConstraints);

    JSONArray rows = new JSONArray();

    for (int index = startIndex; index <= endIndex; index++) {
      JSONObject row = new JSONObject();
      row.put("id", index);
      JSONArray cell = new JSONArray();
      // Class c = dataSource.getRowType();
      Object obj = source.getRowValue(index);
      List<String> names = getDataModel().getPropertyNames();
      for (String name : names) {

        PropertyConduit conduit = getDataModel().get(name).getConduit();
        Class type = conduit.getPropertyType();
        // Block displayBlock =
        // defaultBeanBlockSource.getDisplayBlock(getDataModel().get(name).getDataType());

        try {
          String cellValue;
          Object val = conduit.get(obj);
          // todo use BeanBlockSource or ...
          if (type.equals(Date.class)) {
            // mimic PropertyDisplayBlock
            Date cellDate = (Date) val;
            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
            cellValue = dateFormat.format(cellDate);
          } else if (type.equals(Enum.class)) {
            cellValue =
                TapestryInternalUtils.getLabelForEnum(overrides.getOverrideMessages(), (Enum) val);
          } else {
            if (val == null) cellValue = "undefined " + name;
            else cellValue = typeCoercer.coerce(val, String.class);
            // ValueEncoder valueEncoder =encoderSource.getValueEncoder(type);
            // cellValue = valueEncoder.toClient(val);
          }
          cell.put(cellValue);
        } catch (NullPointerException ex) {
          cell.put("undefined " + name);
        }
      }
      row.put("cell", cell);
      rows.put(row);
    }
    response.put("rows", rows);

    // {"page":"1","total":2,"records":"13",
    // "rows":[{"id":"13","cell":["13","2007-10-06","Client 3","1000.00","0.00","1000.00",null]},
    //		   {"id":"12","cell":["12","2007-10-06","Client 2","700.00","140.00","840.00",null]},
    //        {"id":"11","cell":["11","2007-10-06","Client 1","600.00","120.00","720.00",null]},
    //        {"id":"10","cell":["10","2007-10-06","Client 2","100.00","20.00","120.00",null]},
    //        {"id":"9","cell":["9","2007-10-06","Client 1","200.00","40.00","240.00",null]},
    //        {"id":"8","cell":["8","2007-10-06","Client 3","200.00","0.00","200.00",null]},
    //        {"id":"7","cell":["7","2007-10-05","Client 2","120.00","12.00","134.00",null]},
    //        {"id":"6","cell":["6","2007-10-05","Client 1","50.00","10.00","60.00",""]},
    //        {"id":"5","cell":["5","2007-10-05","Client 3","100.00","0.00","100.00","no tax at
    // all"]},
    ///       {"id":"4","cell":["4","2007-10-04","Client 3","150.00","0.00","150.00","no tax"]}],

    JSONObject userdata = new JSONObject();
    response.put("userdata", userdata);
    // "userdata":{"amount":3220,"tax":342,"total":3564,"name":"Totals:"}}
    return response;
  }
 public JSONObject getOptions() {
   JSONObject opt = new JSONObject("width", "100");
   opt.put("height", "30");
   opt.put("style", "inherit");
   return opt;
 }
Пример #14
0
  private JSONObject setI18NMessages() {
    JSONObject language = new JSONObject();
    language.put("sProcessing", messages.get("datatable.sProcessing"));
    language.put("sSearch", messages.get("datatable.sSearch"));
    language.put("sLengthMenu", messages.get("datatable.sLengthMenu"));
    language.put("sInfo", messages.get("datatable.sInfo"));
    language.put("sInfoEmpty", messages.get("datatable.sInfoEmpty"));
    language.put("sInfoFiltered", messages.get("datatable.sInfoFiltered"));
    language.put("sInfoPostFix", messages.get("datatable.sInfoPostFix"));
    language.put("sLoadingRecords", messages.get("datatable.sLoadingRecords"));
    language.put("sZeroRecords", messages.get("datatable.sZeroRecords"));
    language.put("sEmptyTable", messages.get("datatable.sEmptyTable"));
    language.put(
        "oPaginate",
        new JSONObject(
            "sFirst", messages.get("datatable.oPaginate.sFirst"),
            "sPrevious", messages.get("datatable.oPaginate.sPrevious"),
            "sNext", messages.get("datatable.oPaginate.sNext"),
            "sLast", messages.get("datatable.oPaginate.sLast")));
    language.put(
        "oAria",
        new JSONObject(
            "sSortAscending", messages.get("datatable.oAria.sSortAscending"),
            "sSortDescending", messages.get("datatable.oAria.sSortDescending")));

    return language;
  }
Пример #15
0
  /** This method will construct the JSON options and call the DataTable contructor */
  @AfterRender
  void setJS() {

    JSONObject setup = new JSONObject();

    setup.put("id", getClientId());

    JSONObject dataTableParams = new JSONObject();

    if (getMode()) {
      dataTableParams.put("sAjaxSource", resources.createEventLink("data").toAbsoluteURI());
      dataTableParams.put("bServerSide", "true");
      dataTableParams.put("bProcessing", "true");
    }

    dataTableParams.put("sPaginationType", "full_numbers");

    dataTableParams.put("iDisplayLength", getRowsPerPage());

    dataTableParams.put(
        "aLengthMenu",
        new JSONLiteral(
            "[["
                + getRowsPerPage()
                + ","
                + (getRowsPerPage() * 2)
                + ","
                + (getRowsPerPage() * 4)
                + "],["
                + getRowsPerPage()
                + ","
                + (getRowsPerPage() * 2)
                + ","
                + (getRowsPerPage() * 4)
                + "]]"));

    // We set the bSortable parameters for each column. Cf :
    // http://www.datatables.net/usage/columns
    // We set also the mDataProp parameters to handle ColReorder plugin. Cf
    // :
    // http://datatables.net/release-datatables/extras/ColReorder/server_side.html
    JSONArray columnConfs = new JSONArray();
    for (String propertyName : getPropertyNames()) {
      JSONObject confs = new JSONObject();
      confs.put("mDataProp", propertyName);
      confs.put("bSortable", getModel().get(propertyName).isSortable());
      columnConfs.put(confs);
    }

    dataTableParams.put("aoColumns", columnConfs);

    dataTableParams.put("oLanguage", setI18NMessages());

    JQueryUtils.merge(dataTableParams, getOptions());
    setup.put("params", dataTableParams);

    support.addInitializerCall("dataTable", setup);
  }
Пример #16
0
  void beginRender(MarkupWriter writer) {

    String clientId = getClientId();

    writer.element("table", "id", clientId);
    writer.end();
    writer.element("div", "id", "pager" + clientId);
    writer.end();

    JSONObject setup = new JSONObject();
    setup.put("field", clientId);

    /*url:'server.php?q=2',
    datatype: "json",*/

    JSONObject jqgridParams = new JSONObject();
    jqgridParams.put("url", resources.createEventLink("data").toAbsoluteURI());
    jqgridParams.put("datatype", "json");

    // colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
    JSONArray colNames = new JSONArray();
    List<String> names = getDataModel().getPropertyNames();
    for (String name : names) colNames.put(name);
    jqgridParams.put("colNames", colNames);

    /*colModel:[
    	{name:'id',index:'id', width:55},
    	{name:'invdate',index:'invdate', width:90},
    	{name:'name',index:'name', width:100},
    	{name:'amount',index:'amount', width:80, align:"right"},
    	{name:'tax',index:'tax', width:80, align:"right"},
    	{name:'total',index:'total', width:80,align:"right"},
    	{name:'note',index:'note', width:150, sortable:false}
    ],*/

    JSONArray colModel = new JSONArray();
    for (String name : names) {
      JSONObject model = new JSONObject();
      model.put("name", name);

      model.put("index", name);
      model.put("width", 100);
      colModel.put(model);
      // is this column sorted?
      if (sortAscending != null) {
        ColumnSort colSort = getSortModel().getColumnSort(name);
        if (colSort != ColumnSort.UNSORTED) {
          // sortname: 'id',
          jqgridParams.put("sortname", name);
          // sortorder: "desc",
          if (colSort == ColumnSort.ASCENDING) jqgridParams.put("sortorder", "asc");
          else jqgridParams.put("sortorder", "dsc");
        }
      }
    }
    jqgridParams.put("colModel", colModel);

    // rowNum:10,
    jqgridParams.put("rowNum", rowsPerPage);

    // rowList:[10,20,30],

    // pager: '#pager5',
    jqgridParams.put("pager", "#pager" + clientId);

    // viewrecords: true,

    // caption:"Simple data manipulation",
    jqgridParams.put("caption", "Simple data manipulation");

    // editurl:"someurl.php"
    jqgridParams.put("editurl", resources.createEventLink("edit").toAbsoluteURI());

    jqgridParams
        .put("sortable", true)
        .put("viewrecords", true)
        .put("rowList", new JSONLiteral("[5,10,15]"));

    JQueryUtils.merge(jqgridParams, additionalParams);

    setup.put("params", jqgridParams);

    if (request.getAttribute(LOCALIZATION_CONFIGURED_FLAG) == null) {
      JSONObject spec = new JSONObject();
      request.setAttribute(LOCALIZATION_CONFIGURED_FLAG, true);
    }

    support.addInitializerCall("jqGrid", setup);
  }
Пример #17
0
 private void putConditionally(String key, Object value) {
   if (!params.has(key)) {
     params.put(key, value);
   }
 }
Пример #18
0
  @Profiled()
  @SuppressWarnings("unchecked")
  Object onJSON(String query, String callback) {
    //		List<PersonProfile> persons = null;
    //		List<Author> authors = new ArrayList<Authors.Author>();
    Author[] authors = null;
    List<Authors.Author> authorList = null;
    // if query match ":top hindex", return top h-index authors.
    if (query.equals(":top hindex")) {

      Set<Long> idList = featureService.topAuthors(AuthorFeatureType.HINDEX, 0, 1000);
      List<Integer> ids = Lists.newArrayList();
      if (null != idList) {
        for (Long id : idList) {
          ids.add(id.intValue());
        }
      }
      authors =
          authorService.getAuthors(idList, AuthorFieldSelector.create().feature().contact(), null);
      //			persons = personService.getProfile((short) (PersonService.CONTACT |
      // PersonService.PERSON_FEATURE), ids);
    } else if (query.startsWith(":jconf")) {
      String[] split = query.split(" ");
      Long jconfid = Long.parseLong(split[1]);
      Integer year = Integer.parseInt(split[2]);
      List<Long> autherIDList = jconfAuthorService.getAutherIDListByJconfIDByYear(jconfid, year);
      authors =
          authorService.getAuthors(
              autherIDList, AuthorFieldSelector.create().contact().feature(), null);
      //			persons = personService.getProfile(autherIDList, (short) (PersonService.CONTACT |
      // PersonService.PERSON_FEATURE));

    } else {
      SearchCriteria criteria = new SearchCriteria();
      criteria.setQuery(query);
      criteria.setItemsPerPage(1000);
      SearchResultMeta result = search.searchExperts2(criteria);
      authorList = (List<Authors.Author>) result.getData();
      //			persons = (List<PersonProfile>) result.getData();
    }

    if (authorList == null && authors != null) {
      authorList = new ArrayList<Authors.Author>();
      for (Author a : authors) {
        authorList.add(a);
      }
    }

    // TODO: batch get service;

    JSONObject json = new JSONObject();
    json.put("query", query);
    for (Author author : authorList) {
      if (null == author) continue;
      JSONObject object = new JSONObject();
      object.put("id", author.getId());
      object.put("name", author.getNames(0));
      object.put("degree", author.getFeature().getHindex());

      //			ContactInformation info = person.getContactInformation();
      Contact contact = author.getContact();

      object.put("img", contact.getAvatar());
      object.put("affiliation", contact.getAffiliation());

      object.put("url", URLWriter.getPersonURL((int) author.getId(), author.getNames(0)));

      Map<String, Object> params = new HashMap<String, Object>();
      params.put("aid", (int) author.getId());
      PersonGeo geo = crudService.findUniqueWithNamedQuery(PersonGeo.BY_AID, params);

      if (geo != null) {
        object.put("lat", geo.getLat());
        object.put("lng", geo.getLng());
        json.append("results", object);
      }
    }
    //		for (PersonProfile person : persons) {
    //			JSONObject object = new JSONObject();
    //			object.put("id", person.getId());
    //			object.put("name", person.getRealPerson().getName());
    //
    //			object.put("degree", person.getPersonFeatureData().getHindex());
    //
    //			ContactInformation info = person.getContactInformation();
    //			object.put("img", info.getDisplayImage(ContactInformation.IMG_SIZE_SMALL));
    //			object.put("affiliation", info.get_sAffiliation());
    //			object.put("url", URLWriter.getPersonURL(person.getRealPerson()));
    //
    //			Map<String, Object> params = new HashMap<String, Object>();
    //			params.put("aid", person.getId());
    //			PersonGeo geo = crudService.findUniqueWithNamedQuery(PersonGeo.BY_AID, params);
    //
    //			if (geo != null) {
    //				object.put("lat", geo.getLat());
    //				object.put("lng", geo.getLng());
    //				json.append("results", object);
    //			}
    //		}
    if (null == callback) {
      return new TextStreamResponse("application/json", json.toCompactString());
    } else {
      String jsonp = json.toCompactString();
      jsonp = jsonp.replaceAll("\n", " ");
      jsonp = String.format("%s(%s);", callback, jsonp);
      return new TextStreamResponse("application/json", jsonp);
    }
  }