示例#1
0
 @Override
 public void onResponseCode(Request request, Response response) {
   transientRequest = null;
   if (response.getStatusCode() == SC_CREATED) {
     DatasourceDto datasourceDto = JsonUtils.unsafeEval(response.getText());
     importConfig.setTransientDatasourceName(datasourceDto.getName());
     datasourceDiff(datasourceDto);
   } else {
     getView()
         .showDatasourceCreationError(
             (ClientErrorDto) JsonUtils.unsafeEval(response.getText()));
   }
 }
示例#2
0
  private void stringifySlow(StringBuilder sb) {
    if (this == NULL) {
      sb.append("null");
      return;
    }
    if (isBoolean()) {
      sb.append(asBoolean());
      return;
    }
    if (isNumber()) {
      sb.append(asNumber());
      return;
    }
    if (isString()) {
      sb.append(JsonUtils.escapeValue(asString()));
      return;
    }
    if (isIndexed()) {
      sb.append("[");
      for (int i = 0, j = size(); i < j; i++) {
        if (i > 0) {
          sb.append(",");
        }
        get(i).stringifySlow(sb);
      }
      sb.append("]");
      return;
    }

    sb.append("{");
    boolean needsComma = false;
    for (String key : getPropertyKeys()) {
      if (needsComma) {
        sb.append(",");
      } else {
        needsComma = true;
      }
      JsoSplittable value = get(key);
      if (!value.isFunction()) {
        if ("$H".equals(key)) {
          // Ignore hashcode
          continue;
        }
        sb.append(JsonUtils.escapeValue(key));
        sb.append(":");
        value.stringifySlow(sb);
      }
    }
    sb.append("}");
  }
示例#3
0
  private void buildLessonTree(Response response) {
    TreeItem item = null;
    JsArray<LessonCategoryJS> lessonJSArray = JsonUtils.safeEval(response.getText());

    for (int i = 0; i < lessonJSArray.length(); i++) {
      LessonCategoryJS lessonCategoryJS = lessonJSArray.get(i);
      TreeItem category = new TreeItem();
      category.setText(lessonCategoryJS.getName());

      JsArray<LessonJS> lessons = lessonCategoryJS.getChildren();
      for (int j = 0; j < lessons.length(); j++) {
        LessonJS lesson = lessons.get(j);

        TreeItem lessonItem = new TreeItem();
        Storage sessionStorage = Storage.getSessionStorageIfSupported();
        String lastUrl = sessionStorage.getItem("lastUrl");
        lessonItem.setText(lesson.getText());
        category.addItem(lessonItem);
        lessonsTreeMap.put(lessonItem.getText(), lesson);
        if (lesson.getTechnology().equals(LessonTechnology.GWT.toString())) {
          addLessonToMap(lesson);
        }
        if (lastUrl != null && lastUrl.equals(lesson.getUrl())) {
          item = lessonItem;
          lessonPanel.setSelectedLesson(lesson);
          category.setState(true);
        }
      }
      lessonTree.addItem(category);
    }
    lessonTree.setSelectedItem(item);
  }
示例#4
0
 public String getPayload() {
   if (isString()) {
     return JsonUtils.escapeValue(asString());
   }
   if (stringifyFastSupported()) {
     return stringifyFast();
   }
   return stringifySlow();
 }
 public static Splittable split(String payload) {
   char c = payload.charAt(0);
   boolean isSimple = c != '{' && c != '[';
   if (isSimple) {
     payload = "[" + payload + "]";
   }
   Splittable toReturn = JsonUtils.safeEval(payload).<JsoSplittable>cast();
   if (isSimple) {
     toReturn = toReturn.get(0);
   }
   return toReturn;
 }
  @Override
  public void showError(String message, @Nullable FormField group) {
    if (Strings.isNullOrEmpty(message)) return;

    String msg = message;
    try {
      ClientErrorDto errorDto = JsonUtils.unsafeEval(message);
      msg = errorDto.getStatus();
    } catch (Exception ignored) {
    }
    if (group == null) {
      dialog.addAlert(msg, AlertType.ERROR);
    } else {
      dialog.addAlert(msg, AlertType.ERROR, variableGroup);
    }
  }
    @Override
    public void onResponseCode(Request request, Response response) {
      if (response.getStatusCode() == SC_OK) {
        String uri =
            UriBuilder.create()
                .segment("datasource", "{}", "view", "{}", "variable", "{}")
                .query("comment", getView().getComment())
                .build(table.getDatasourceName(), table.getName(), variable.getName());

        ResourceRequestBuilderFactory.newBuilder() //
            .forResource(uri) //
            .withResourceBody(VariableDto.stringify(newVariable)) //
            .withCallback(new UpdateVariableCallbackHandler(), SC_OK, SC_BAD_REQUEST) //
            .put()
            .send();
      } else {
        NotificationEvent notificationEvent =
            new JSErrorNotificationEventBuilder()
                .build((ClientErrorDto) JsonUtils.unsafeEval(response.getText()));
        fireEvent(notificationEvent);
      }
    }
 public static final JsEmailConfiguration parseJsonString(final String jsonString) {
   return (JsEmailConfiguration) parseEmailConfig(JsonUtils.escapeJsonForEval(jsonString));
 }
示例#9
0
  private static void getSearches(
      final int start, final int length, final JavaScriptObject function) {
    GWTClient.callback(
        function,
        JsonUtils.safeEval("{\"aaData\": [],\"iTotalRecords\" : 0, \"iTotalDisplayRecords\" : 0}"));
    displayedSearches.clear();
    final UserData user = GWTClient.getCurrentUser();
    userService.countUserSearches(
        user.getId(),
        new AsyncCallback<Integer>() {
          @Override
          public void onFailure(Throwable caught) {
            DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default");
            Window.alert("There was an error while counting your saved searches.");
          }

          @Override
          public void onSuccess(final Integer total) {
            userService.scrollSearchesOfUser(
                start,
                length,
                user.getId(),
                new AsyncCallback<List<SearchData>>() {
                  @Override
                  public void onFailure(Throwable caught) {
                    Window.alert("There was an error while getting your saved searches.");
                  }

                  @Override
                  public void onSuccess(List<SearchData> result) {
                    String json = "{\"aaData\": [";
                    for (SearchData search : result) {
                      String advancedText = "";
                      Map<String, String> advanceds = search.getAdvanced();
                      if (advanceds != null && !advanceds.isEmpty()) {
                        advancedText += "<i> (";
                        boolean first = true;
                        List<String> keys = new ArrayList<String>(advanceds.keySet());
                        Collections.sort(keys);
                        String lastKey = "";
                        for (String key : keys) {
                          if ((lastKey + "End").equals(key)) {
                            advancedText += " to " + advanceds.get(key);
                          } else {
                            if (key.endsWith("End")) {
                              advancedText +=
                                  (first ? "" : ", ")
                                      + key.substring(0, key.length() - 3)
                                      + ": * to "
                                      + advanceds.get(key);
                            } else {
                              advancedText += (first ? "" : ", ") + key + ": " + advanceds.get(key);
                            }
                          }
                          first = false;
                          lastKey = key;
                        }
                        advancedText += ")</i>";
                      }
                      displayedSearches.put(search.getId(), search);
                      json +=
                          "[\""
                              + search.getValue().replace("\"", "\\\"")
                              + advancedText.replace("\"", "\\\"")
                              + "\","
                              + search.getId()
                              + ","
                              + "{\"id\":"
                              + search.getId()
                              + ", \"notify\":"
                              + search.isNotify()
                              + "},\""
                              + search.getId()
                              + "\"],";
                    }
                    if (total >= 1) {
                      json = json.substring(0, json.length() - 1);
                    }
                    json +=
                        "],\"iTotalRecords\" : "
                            + total
                            + ", \"iTotalDisplayRecords\" : "
                            + total
                            + "}";
                    clearSearches
                        .getElement()
                        .setClassName(total >= 1 ? "button_black" : "button_disabled");
                    GWTClient.callback(function, JsonUtils.safeEval(json));
                  }
                });
          }
        });
  }
  @Override
  public void start(AcceptsOneWidget panel, final EventBus eventBus) {
    view = clientFactory.getRestAreaView();
    analytics = clientFactory.getAnalytics();
    accessibility = clientFactory.getAccessibility();
    this.eventBus = eventBus;
    view.setPresenter(this);

    Place place = clientFactory.getPlaceController().getWhere();

    if (place instanceof RestAreaPlace) {
      RestAreaPlace restAreaPlace = (RestAreaPlace) place;

      int restAreaId = Integer.valueOf(restAreaPlace.getId());

      String jsonString = AppBundle.INSTANCE.restAreaData().getText();
      RestAreaFeed restAreas = JsonUtils.safeEval(jsonString);

      view.setTitle("Safety Rest Area");

      SafeHtmlBuilder detailsHTMLBuilder = new SafeHtmlBuilder();

      detailsHTMLBuilder.appendEscaped(
          restAreas.getRestAreas().get(restAreaId).getRoute()
              + " - "
              + restAreas.getRestAreas().get(restAreaId).getLocation());

      detailsHTMLBuilder.appendHtmlConstant("<br>");

      detailsHTMLBuilder.appendEscaped(
          "Milepost: "
              + restAreas.getRestAreas().get(restAreaId).getMilepost()
              + " - "
              + restAreas.getRestAreas().get(restAreaId).getDirection());

      view.setDetails(detailsHTMLBuilder.toSafeHtml());

      if (restAreas.getRestAreas().get(restAreaId).getNotes() == null) {
        view.hideNotesHeading();
        view.setNotes("");
      } else {
        view.showNotesHeading();
        view.setNotes(restAreas.getRestAreas().get(restAreaId).getNotes());
      }

      SafeHtmlBuilder amenitiesHTMLBuilder = new SafeHtmlBuilder();

      amenitiesHTMLBuilder.appendHtmlConstant("<ul>");
      for (int i = 0; i < restAreas.getRestAreas().get(restAreaId).getAmenities().length; i++) {
        amenitiesHTMLBuilder.appendHtmlConstant("<li>");
        amenitiesHTMLBuilder.appendEscaped(
            restAreas.getRestAreas().get(restAreaId).getAmenities()[i]);
        amenitiesHTMLBuilder.appendHtmlConstant("</li>");
      }

      if (restAreas.getRestAreas().get(restAreaId).getAmenities().length == 0) {
        view.hideAmenitiesHeading();
      } else {
        view.showAmenitiesHeading();
      }

      amenitiesHTMLBuilder.appendHtmlConstant("</ul>");

      view.setAmenities(amenitiesHTMLBuilder.toSafeHtml());

      view.setLatLon(
          Double.valueOf(restAreas.getRestAreas().get(restAreaId).getLatitude()),
          Double.valueOf(restAreas.getRestAreas().get(restAreaId).getLongitude()));

      view.refresh();
    }

    panel.setWidget(view);
    accessibility.postScreenChangeNotification();
  }
 public static String quote(String raw) {
   return JsonUtils.escapeValue(raw);
 }
示例#12
0
 private JsArray<Worker> getJSONData(String json) {
   return JsonUtils.safeEval(json);
 }