Java Code Examples for com.google.gwt.core.client.JsonUtils

The following examples show how to use com.google.gwt.core.client.JsonUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gwt-material-demo   Source File: MaterialCandleStick.java    License: Apache License 2.0 6 votes vote down vote up
private void draw() {
	JsArrayMixed dataArray = JsonUtils.unsafeEval("[['Mon',20,28,38,45],['Tue',31,38,55,66],['Wed',50,55,77,80],['Thu',77,77,66,50],['Fri',68,66,22,15]]");

	// Prepare the data
	DataTable dataTable = ChartHelper.arrayToDataTable(dataArray, true);

	// Set options
	CandlestickChartOptions options = CandlestickChartOptions.create();
	BackgroundColor bgColor = BackgroundColor.create();
	bgColor.setStroke("#2196f3");
	bgColor.setFill("#90caf9");
	bgColor.setStrokeWidth(2);
	
	
	
	options.setLegend(Legend.create(LegendPosition.NONE));
	options.setFallingColor(bgColor);
	options.setRisingColor(bgColor);

	// Draw the chart
	chart.draw(dataTable, options);
}
 
Example 2
Source Project: gwt-material-demo   Source File: MaterialComboCharts.java    License: Apache License 2.0 6 votes vote down vote up
private void draw() {
	JsArrayMixed dataArray = JsonUtils
			.unsafeEval("[['Month', 'Bolivia', 'Ecuador', 'Madagascar', 'Papua  Guinea', 'Rwanda', 'Average'],['2004/05', 165, 938, 522, 998, 450, 614.6],['2005/06', 135, 1120, 599, 1268, 288, 682],['2006/07', 157, 1167, 587, 807, 397, 623],['2007/08', 139, 1110, 615, 968, 215, 609.4],['2008/09', 136, 691, 629, 1026, 366, 569.6]]");

	// Prepare the data
	DataTable dataTable = ChartHelper.arrayToDataTable(dataArray);

	// Set options
	ComboChartOptions options = ComboChartOptions.create();
	options.setFontName("Tahoma");
	options.setTitle("Monthly Coffee Production by Country");
	options.setHAxis(HAxis.create("Cups"));
	options.setVAxis(VAxis.create("Month"));
	options.setSeriesType(SeriesType.BARS);
	ComboChartSeries series = ComboChartSeries.create();
	series.setType(SeriesType.LINE);
	options.setSeries(5, series);

	// Draw the chart
	chart.draw(dataTable, options);
}
 
Example 3
Source Project: swellrt   Source File: AnnotationRegistry.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Define a new custom annotation.
 *
 * @param key annotation's name
 * @param cssClass a css class for the html container
 * @param cssStyle css styles for the html container
 */
public static void define(String key, String cssClass, JavaScriptObject cssStyleObj) throws SEditorException {

  if (key == null || key.startsWith("paragraph") || key.startsWith(AnnotationConstants.STYLE_PREFIX) || CANONICAL_KEYS.getString(key) != null) {
    throw new SEditorException("Not valid annotation name");
  }

  JsoView cssStyles = null;
  if (JsEditorUtils.isString(cssStyleObj)) {
    JavaScriptObject o = JsonUtils.unsafeEval(cssStyleObj.toString());
    if (o != null) {
      cssStyles = JsoView.as(o);
    }
  } else {
    cssStyles = JsoView.as(cssStyleObj);
  }

  AnnotationController annotation = new AnnotationController(key);
  store.put(key, annotation);
  UserAnnotationHandler.register(Editor.ROOT_REGISTRIES, key, cssClass, cssStyles,
      annotation.getTextEventHanlder(), annotation.getTextEventHanlder(),
      annotation.getTextEventHanlder());
}
 
Example 4
Source Project: gwtbootstrap3-extras   Source File: SliderBase.java    License: Apache License 2.0 6 votes vote down vote up
private List<Double> getNumberArrayAttribute(SliderOption option, List<Double> defaultValue) {

        // Get array attribute
        JsArrayNumber array = null;
        if (isAttached()) {
            array = getNumberArrayAttribute(getElement(), option.getName());
        } else {
            String value = attributeMixin.getAttribute(option.getDataAttribute());
            if (value != null && !value.isEmpty()) {
                array = JsonUtils.safeEval(value);
            }
        }

        // Attribute not set
        if (array == null) {
            return defaultValue;
        }

        // Put array to list
        List<Double> list = new ArrayList<Double>(array.length());
        for (int i = 0; i < array.length(); i++) {
            list.add(array.get(i));
        }
        return list;
    }
 
Example 5
Source Project: gwtbootstrap3-extras   Source File: SliderBase.java    License: Apache License 2.0 6 votes vote down vote up
private List<String> getStringArrayAttribute(SliderOption option, List<String> defaultValue) {

        // Get array attribute
        JsArrayString array = null;
        if (isAttached()) {
            array = getStringArrayAttribute(getElement(), option.getName());
        } else {
            String value = attributeMixin.getAttribute(option.getDataAttribute());
            if (value != null && !value.isEmpty()) {
                array = JsonUtils.safeEval(value);
            }
        }

        // Attribute not set
        if (array == null) {
            return defaultValue;
        }

        // Put array to list
        List<String> list = new ArrayList<String>(array.length());
        for (int i = 0; i < array.length(); i++) {
            list.add(array.get(i));
        }
        return list;
    }
 
Example 6
Source Project: proarc   Source File: JsonTokenizer.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static JSONValue parse(String token) {
    try {
        if (JsonUtils.safeToEval(token)) {
            JSONValue jsonv = JSONParser.parseStrict(token);
            return jsonv;
        }
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, token, ex);
    }
    return null;
}
 
Example 7
Source Project: swellrt   Source File: WebServerOperationExecutor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected <O extends ServiceOperation.Options> String toJson(O options) {
  if (options != null) {
    if (options instanceof JavaScriptObject) {
      return JsonUtils.stringify((JavaScriptObject) options);
    }
  }
  return null;
}
 
Example 8
Source Project: swellrt   Source File: WebModelFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object parseJsonObject(String json) {
  if (json != null)
    return JsonUtils.<JavaScriptObject> safeEval(json);

  return null;
}
 
Example 9
Source Project: swellrt   Source File: WebModelFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String serializeJsonObject(Object o) {

  if (isJsPrimitive(o)) {
    return o.toString();
  } else if (o instanceof JavaScriptObject) {
    return JsonUtils.stringify((JavaScriptObject) o);
  }

  throw new IllegalStateException("Object can't be serialized to JSON");

}
 
Example 10
Source Project: swellrt   Source File: SJsonFactoryWeb.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String serialize(SJsonObject object) {

  if (object instanceof SJsonObjectWeb) {
    SJsonObjectWeb jow = (SJsonObjectWeb) object;
    return JsonUtils.stringify(jow.getJsoView());
  }

  return null;
}
 
Example 11
Source Project: gwt-ol   Source File: GeoJsonTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testWriteGeoJSON() {

        injectUrlAndTest(() -> {
            String geoJson = geoJsonFormat.writeFeatures(OLTestUtils.createLineFeatures(), null);
            assertNotNull(geoJson);

            java.lang.Object geoJsonObject = JsonUtils.safeEval(geoJson);
            assertNotNull(geoJsonObject);
        });

    }
 
Example 12
Source Project: gwtbootstrap3-extras   Source File: SliderBase.java    License: Apache License 2.0 5 votes vote down vote up
private void updateSliderForNumberArray(SliderOption option, List<Double> value) {
    JsArrayNumber array = JavaScriptObject.createArray().cast();
    for (Double val : value) {
        array.push(val);
    }
    if (isAttached()) {
        setAttribute(getElement(), option.getName(), array);
        refresh();
    } else {
        String arrayStr = JsonUtils.stringify(array);
        attributeMixin.setAttribute(option.getDataAttribute(), arrayStr);
    }
}
 
Example 13
Source Project: gwtbootstrap3-extras   Source File: SliderBase.java    License: Apache License 2.0 5 votes vote down vote up
private void updateSliderForStringArray(SliderOption option, List<String> value) {
    JsArrayString array = JavaScriptObject.createArray().cast();
    for (String val : value) {
        array.push(val);
    }
    if (isAttached()) {
        setAttribute(getElement(), option.getName(), array);
        refresh();
    } else {
        String arrayStr = JsonUtils.stringify(array);
        attributeMixin.setAttribute(option.getDataAttribute(), arrayStr);
    }
}
 
Example 14
Source Project: swellrt   Source File: WebServerOperationExecutor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected OperationError parseServiceError(String json) {
  return (OperationError) JsonUtils.safeEval(json);
}
 
Example 15
Source Project: requestor   Source File: OverlaySerdes.java    License: Apache License 2.0 4 votes vote down vote up
protected <T extends JavaScriptObject> T eval(String response) {
    return USE_SAFE_EVAL ? JsonUtils.<T>safeEval(response) : JsonUtils.<T>unsafeEval(response);
}
 
Example 16
Source Project: gwt-jackson   Source File: FastJsonWriter.java    License: Apache License 2.0 4 votes vote down vote up
private void string(String value) {
  out.append(JsonUtils.escapeValue(value));
}
 
Example 17
Source Project: gwtbootstrap3-extras   Source File: Range.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Converts the given string to a range instance.<br>
 * <br>
 * Useful when using UiBinder.
 *
 * @param value
 * @return
 */
public static Range fromString(String value) {
    if (value == null || value.isEmpty())
        return null;
    JsArrayNumber array = JsonUtils.safeEval(value);
    return new Range(array);
}
 
Example 18
Source Project: gwtbootstrap3-extras   Source File: SelectBase.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Sets the window padding to top, right, bottom, and right sides. This
 * is useful in cases where the window has areas that the drop-down menu
 * should not cover - for instance a fixed header.
 *
 * @param top
 * @param right
 * @param bottom
 * @param left
 */
public void setWindowPaddingTopRightBottomLeft(final int top, final int right,
        final int bottom, final int left) {
    JsArrayNumber array = JavaScriptObject.createArray(4).cast();
    array.push(top);
    array.push(right);
    array.push(bottom);
    array.push(left);
    attrMixin.setAttribute(WINDOW_PADDING, JsonUtils.stringify(array));
}
 
Example 19
Source Project: requestor   Source File: JsonObjectSerdes.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Performs evaluation of serialized response obeying the #useSafeEval configuration.
 * <p/>
 *
 * If #useSafeEval is {@code true} then the eval is performed using {@link JsonUtils#safeEval},
 * otherwise then content will be loosely evaluated by {@link JsonUtils#unsafeEval}.
 *
 * @param response The serialized content
 *
 * @return The converted JavaScriptObject
 */
protected JavaScriptObject eval(String response) {
    return useSafeEval() ? JsonUtils.safeEval(response) : JsonUtils.unsafeEval(response);
}