Java Code Examples for elemental.json.JsonArray#getArray()
The following examples show how to use
elemental.json.JsonArray#getArray() .
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: UidlRequestHandler.java From flow with Apache License 2.0 | 6 votes |
private String removeHashInChange(JsonArray change) { if (change.length() < 3 || !change.get(2).getType().equals(JsonType.ARRAY)) { return null; } JsonArray value = change.getArray(2); if (value.length() < 2 || !value.get(1).getType().equals(JsonType.OBJECT)) { return null; } JsonObject location = value.getObject(1); if (!location.hasKey(LOCATION)) { return null; } String url = location.getString(LOCATION); Matcher match = URL_PATTERN.matcher(url); if (match.find()) { location.put(LOCATION, match.group(1)); } return url; }
Example 2
Source File: UidlRequestHandler.java From flow with Apache License 2.0 | 6 votes |
private String removeHashInRpc(JsonArray rpc) { if (rpc.length() != 4 || !rpc.get(1).getType().equals(JsonType.STRING) || !rpc.get(2).getType().equals(JsonType.STRING) || !rpc.get(3).getType().equals(JsonType.ARRAY) || !"com.vaadin.shared.extension.javascriptmanager.ExecuteJavaScriptRpc" .equals(rpc.getString(1)) || !"executeJavaScript".equals(rpc.getString(2))) { return null; } JsonArray scripts = rpc.getArray(3); for (int j = 0; j < scripts.length(); j++) { String exec = scripts.getString(j); Matcher match = HASH_PATTERN.matcher(exec); if (match.find()) { // replace JS with a noop scripts.set(j, ";"); return match.group(1); } } return null; }
Example 3
Source File: ExecuteJavaScriptProcessor.java From flow with Apache License 2.0 | 5 votes |
/** * Executes invocations received from the server. * * @param invocations * a JSON containing invocation data */ public void execute(JsonArray invocations) { for (int i = 0; i < invocations.length(); i++) { JsonArray invocation = invocations.getArray(i); handleInvocation(invocation); } }
Example 4
Source File: SimpleElementBindingStrategy.java From flow with Apache License 2.0 | 5 votes |
private static boolean resolveDebounces(Node element, String debouncerId, JsonArray debounceList, Consumer<String> command) { boolean atLeastOneEager = false; for (int i = 0; i < debounceList.length(); i++) { // [timeout, phase1, phase2, ...] JsonArray debounceSettings = debounceList.getArray(i); double timeout = debounceSettings.getNumber(0); if (timeout == 0) { atLeastOneEager = true; continue; } JsSet<String> phases = JsCollections.set(); for (int j = 1; j < debounceSettings.length(); j++) { phases.add(debounceSettings.getString(j)); } boolean eager = Debouncer.getOrCreate(element, debouncerId, timeout) .trigger(phases, command); atLeastOneEager |= eager; } return atLeastOneEager; }
Example 5
Source File: GwtPolymerModelTest.java From flow with Apache License 2.0 | 5 votes |
private void assertUpdateListValues(StateNode nodeWithList) { Binder.bind(node, element); Reactive.flush(); List<String> newList = Arrays.asList("1", "2", "3"); fillNodeWithListItems(nodeWithList, newList); Reactive.flush(); JsonArray argumentsArray = WidgetUtil.crazyJsCast( WidgetUtil.getJsProperty(element, "argumentsArray")); // Since `fillNodeWithListItems` makes separate `add` call for every // element in newList, we will be having // the same number of `splice` calls. assertEquals(newList.size(), argumentsArray.length()); for (int i = 0; i < newList.size(); i++) { JsonArray arguments = argumentsArray.getArray(i); assertEquals(4, arguments.length()); String path = arguments.getString(0); int start = (int) arguments.getNumber(1); int deleteCount = (int) arguments.getNumber(2); String items = arguments.getString(3); assertEquals(MODEL_PROPERTY_NAME + "." + LIST_PROPERTY_NAME, path); assertEquals(i, start); assertEquals(0, deleteCount); assertEquals(newList.get(i), items); } }
Example 6
Source File: RootImpl.java From serverside-elements with Apache License 2.0 | 5 votes |
public void handleCallback(JsonArray arguments) { JsonArray attributeChanges = arguments.getArray(1); for (int i = 0; i < attributeChanges.length(); i++) { JsonArray attributeChange = attributeChanges.getArray(i); int id = (int) attributeChange.getNumber(0); String attribute = attributeChange.getString(1); JsonValue value = attributeChange.get(2); NodeImpl target = idToNode.get(Integer.valueOf(id)); if (value.getType() == JsonType.NULL) { target.node.removeAttr(attribute); } else { target.node.attr(attribute, value.asString()); } } JsonArray callbacks = arguments.getArray(0); for (int i = 0; i < callbacks.length(); i++) { JsonArray call = callbacks.getArray(i); int elementId = (int) call.getNumber(0); int cid = (int) call.getNumber(1); JsonArray params = call.getArray(2); ElementImpl element = (ElementImpl) idToNode .get(Integer.valueOf(elementId)); if (element == null) { System.out.println(cid + " detached?"); return; } JavaScriptFunction callback = element.getCallback(cid); callback.call(params); } }
Example 7
Source File: DomEventTest.java From flow with Apache License 2.0 | 4 votes |
private <T extends ComponentEvent<Component>> void assertSettings( Class<T> eventType, String expectedFilter, int expectedTimeout, DebouncePhase... expectedPhases) { JsonObject settings = getEventSettings(eventType); if (expectedFilter == null) { Assert.assertArrayEquals(new String[0], settings.keys()); return; } Assert.assertArrayEquals(new String[] { expectedFilter }, settings.keys()); if (expectedTimeout == 0 && expectedPhases.length == 0) { Assert.assertEquals( "There should be a boolean instead of empty phase list", JsonType.BOOLEAN, settings.get(expectedFilter).getType()); boolean isFilter = settings.getBoolean(expectedFilter); Assert.assertTrue("Expression should be used as a filter", isFilter); return; } JsonArray filterSettings = settings.getArray(expectedFilter); Assert.assertEquals(1, filterSettings.length()); JsonArray filterSetting = filterSettings.getArray(0); Assert.assertEquals("Debunce timeout should be as expected", expectedTimeout, (int) filterSetting.getNumber(0)); Assert.assertEquals("Number of phases should be as expected", expectedPhases.length, filterSetting.length() - 1); for (int i = 0; i < expectedPhases.length; i++) { String expectedIdentifier = expectedPhases[i].getIdentifier(); Assert.assertEquals(expectedIdentifier, filterSetting.getString(i + 1)); } }
Example 8
Source File: ElementIntegration.java From serverside-elements with Apache License 2.0 | 4 votes |
private void getDom(JsonArray arguments) { int id = (int) arguments.getNumber(0); JsonArray hierarchy = arguments.getArray(1); root.synchronize(id, hierarchy); }