jsinterop.base.Js Java Examples
The following examples show how to use
jsinterop.base.Js.
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 File: JsStringArrayReader.java From domino-jackson with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public String[] readArray(JsonReader reader) { JsArray<JsString> jsArray = new JsArray<>(); reader.beginArray(); while (JsonToken.END_ARRAY != reader.peek()) { if (JsonToken.NULL == reader.peek()) { reader.skipValue(); jsArray.push(null); } else { jsArray.push((JsString) Js.cast(reader.nextString())); } } reader.endArray(); return reinterpretCast(jsArray); }
Example #2
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 6 votes |
/** * Initialize a specified plain object with the specified property values. For example, * $(new MyJsPlainObj(), "a",1, "b","somevalue) is eqivalent to the following javascript * { a: 1, b: "somevalue" } * * @param <O> The type of plain object * @param jsPlainObj The object to initialize * @param fieldValues a set of 1 or more (field name, value) pairs * @return The initialzed plain object */ @JsOverlay public static <O> O $(O jsPlainObj, Object ...fieldValues) { String fieldName = null; for(Object f : fieldValues) { if (fieldName == null) fieldName = (String)f; else { Js.asPropertyMap(jsPlainObj).set(fieldName, f); fieldName = null; } } return jsPlainObj; }
Example #3
Source File: NaluPluginCoreWeb.java From nalu with Apache License 2.0 | 5 votes |
public static void addPopStateHandler(RouteChangeHandler handler, String contextPath) { DomGlobal.window.onpopstate = e -> { String newUrl; if (PropertyFactory.get() .isUsingHash()) { Location location = Js.uncheckedCast(DomGlobal.location); newUrl = location.getHash(); } else { PopStateEvent event = (PopStateEvent) e; newUrl = (String) event.state; if (Objects.isNull(newUrl) || newUrl.trim() .length() == 0) { newUrl = PropertyFactory.get() .getStartRoute(); } } // remove leading '/' if (newUrl.length() > 1) { if (newUrl.startsWith("/")) { newUrl = newUrl.substring(1); } } // remove contextPath if (!Objects.isNull(contextPath)) { if (newUrl.length() > contextPath.length()) { newUrl = newUrl.substring(contextPath.length()); } } NaluPluginCoreWeb.handleChange(handler, newUrl); return null; }; }
Example #4
Source File: NaluPluginCoreWeb.java From nalu with Apache License 2.0 | 5 votes |
public static void addOnHashChangeHandler(RouteChangeHandler handler) { DomGlobal.window.onhashchange = e -> { String newUrl; Location location = Js.uncheckedCast(DomGlobal.location); newUrl = location.getHash(); NaluPluginCoreWeb.handleChange(handler, newUrl); return null; }; }
Example #5
Source File: BaseJsNumberArrayReader.java From domino-jackson with Apache License 2.0 | 5 votes |
JsArray<JsNumber> readNumberArray(JsonReader reader){ JsArray<JsNumber> jsArray = new JsArray<>(); reader.beginArray(); while (JsonToken.END_ARRAY != reader.peek()) { if (JsonToken.NULL == reader.peek()) { reader.skipValue(); jsArray.push(null); } else { jsArray.push((JsNumber) Js.cast(reader.nextInt())); } } reader.endArray(); return jsArray; }
Example #6
Source File: RequestResourceBuilder.java From autorest with Apache License 2.0 | 5 votes |
private @Nullable <T> T decode(XMLHttpRequest ctx) { try { String text = ctx.response.asString(); return text == null || text.isEmpty() ? null : Js.cast(Global.JSON.parse(text)); } catch (Throwable e) { throw new ResponseFormatException("Parsing response error", e); } }
Example #7
Source File: StringMap.java From gwt-interop-utils with MIT License | 4 votes |
/** * Removes all entries from this map */ @JsOverlay default void clear() { Js.asPropertyMap(this).forEach((key) -> delete(key)); }
Example #8
Source File: GwtReact.java From gwt-react with MIT License | 4 votes |
public static ReactElement castAsReactElement(Array<? extends ReactElement> children) { return Js.uncheckedCast(children); }
Example #9
Source File: GwtReact.java From gwt-react with MIT License | 4 votes |
public static ReactElement castAsReactElement(ReactElementChildren children) { return Js.uncheckedCast(children); }
Example #10
Source File: GwtReact.java From gwt-react with MIT License | 4 votes |
public static ReactElement stringLiteral(String value) { return Js.uncheckedCast(value); }
Example #11
Source File: NaluPluginCoreWeb.java From nalu with Apache License 2.0 | 4 votes |
@SuppressWarnings("StringSplitter") public static void getContextPath(ShellConfiguration shellConfiguration) { if (PropertyFactory.get() .isUsingHash()) { return; } Location location = Js.uncheckedCast(DomGlobal.location); String pathName = location.getPathname(); if (pathName.startsWith("/") && pathName.length() > 1) { pathName = pathName.substring(1); } if (pathName.contains(".")) { if (pathName.contains("/")) { pathName = pathName.substring(0, pathName.lastIndexOf("/")); StringBuilder context = new StringBuilder(); for (String partOfContext : pathName.split("/")) { Optional<String> optional = shellConfiguration.getShells() .stream() .map(ShellConfig::getRoute) .filter(f -> f.equals("/" + partOfContext)) .findAny(); if (optional.isPresent()) { break; } else { if (context.length() > 0) { context.append("/"); } context.append(partOfContext); } } PropertyFactory.get() .setContextPath(context.toString()); } else { PropertyFactory.get() .setContextPath(""); } } PropertyFactory.get() .setContextPath(""); }
Example #12
Source File: JsIntegerArrayReader.java From domino-jackson with Apache License 2.0 | 4 votes |
private static int[] reinterpretCast(JsArray<JsNumber> value) { JsNumber[] sliced = value.slice(); return Js.uncheckedCast(sliced); }
Example #13
Source File: JsStringArrayReader.java From domino-jackson with Apache License 2.0 | 4 votes |
private static String[] reinterpretCast(JsArray<JsString> value) { JsString[] sliced = value.slice(); return Js.uncheckedCast(sliced); }
Example #14
Source File: JsDoubleArrayReader.java From domino-jackson with Apache License 2.0 | 4 votes |
private static double[] reinterpretCast(JsArray<JsNumber> value) { JsNumber[] sliced = value.slice(); return Js.uncheckedCast(sliced); }
Example #15
Source File: JsShortArrayReader.java From domino-jackson with Apache License 2.0 | 4 votes |
private static short[] reinterpretCast(JsArray<JsNumber> value) { JsNumber[] sliced = value.slice(); return Js.uncheckedCast(sliced); }
Example #16
Source File: OLUtil.java From gwt-ol with Apache License 2.0 | 3 votes |
/** * Adds an item to the array. * * @param array array (will be changed) * @param item item to add * @return array including the item */ @SuppressWarnings("unchecked") public static <T> T[] pushItem(T[] array, T item) { JsArray<T> jsArray = Js.cast(array); jsArray.push(item); return array; }
Example #17
Source File: OLUtil.java From gwt-ol with Apache License 2.0 | 2 votes |
/** * Combines two arrays. * * @param array1 first array * @param array2 second array * @return combined array */ public static <T> T[] concatArrays(T[] array1, T[] array2) { JsArray<T> jsArray = Js.cast(array1); return jsArray.concat(array2); }
Example #18
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Set the specified property on this plain object. The property will be added if it doesn't * currently exist * * @param prop The property to set * @param <V> The type of value to set * @param v The value to set the property to */ @JsOverlay final public <V> void set(String prop, V v) { Js.asPropertyMap(this).set(prop, v); }
Example #19
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Set the specified property on this plain object. The property will be added if it doesn't * currently exist * * @param prop The property to set * @param v The value to set the property to */ @JsOverlay final public void set(String prop, String v) { Js.asPropertyMap(this).set(prop, v); }
Example #20
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Set the specified property on this plain object. The property will be added if it doesn't * currently exist * * @param prop The property to set * @param v The value to set the property to */ @JsOverlay final public void set(String prop, boolean v) { Js.asPropertyMap(this).set(prop, v); }
Example #21
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Set the specified property on this plain object. The property will be added if it doesn't * currently exist * * @param prop The property to set * @param v The value to set the property to */ @JsOverlay final public void set(String prop, double v) { Js.asPropertyMap(this).set(prop, v); }
Example #22
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Set the specified property on this plain object. The property will be added if it doesn't * currently exist * * @param prop The property to set * @param v The value to set the property to */ @JsOverlay final public void set(String prop, int v) { Js.asPropertyMap(this).set(prop, v); }
Example #23
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Return an Object parameter from this plain object. NOTE this method is NOT type safe. If * you access a property that isn't an Object you will get an undefined result. Also if you * access a property that does not exist you will get an undefined error * * @param prop The property to access * @param <O> The Object property value * @return The Object property value */ @JsOverlay final public <O> O getObj(String prop) { return Js.uncheckedCast(Js.asPropertyMap(this).get(prop)); }
Example #24
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Return an String parameter from this plain object. NOTE this method is NOT type safe. If you access * a property that isn't an String you will get an undefined result. Also if you access a property * that does not exist you will get an undefined error * * @param prop The property to access * @return The String property value */ @JsOverlay final public String getStr(String prop) { return Js.asPropertyMap(this).getAny(prop).asString(); }
Example #25
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Return an boolean parameter from this plain object. NOTE this method is NOT type safe. If you access * a property that isn't a boolean you will get an undefined result. Also if you access a property * that does not exist you will get an undefined error * * @param prop The property to access * @return The boolean property value */ @JsOverlay final public boolean getBool(String prop) { return Js.asPropertyMap(this).getAny(prop).asBoolean(); }
Example #26
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Return a double parameter from this plain object. NOTE this method is NOT type safe. If you access * a property that isn't a double you will get an undefined result. Also if you access a property * that does not exist you will get an undefined error * * @param prop The property to access * @return The double property value */ @JsOverlay final public double getDbl(String prop) { return Js.asPropertyMap(this).getAny(prop).asDouble(); }
Example #27
Source File: JsPlainObj.java From gwt-interop-utils with MIT License | 2 votes |
/** * Return an int parameter from this plain object. NOTE this is method is NOT type safe. If if you access * a property that isn't an int you will get an undefined result. Also if you access a property * that does not exist you will get an undefined error * * @param prop The property to access * @return The integer property value */ @JsOverlay final public int getInt(String prop) { return Js.asPropertyMap(this).getAny(prop).asInt(); }