@Override public Object createArray() { return new JSONArray(); }
@Override public void setArrayIndex(final Object array, final int index, final Object newValue) { Object v = newValue == null ? JSONObject.NULL : newValue; JSONArray list = (JSONArray) array; list.put(index, v); }
@Override public int length(final Object obj) { if (obj instanceof JSONArray) { return ((JSONArray) obj).length(); } else if (obj instanceof JSONObject) { return ((JSONObject) obj).length(); } else { throw new IllegalArgumentException("Cannot determine length of " + obj + ", unsupported type."); } }
/** * Transforms the matches into a JSONArray * * @return JSONArray of available responses */ protected JSONArray generateResponseJSON(List matches) { JSONArray array = new JSONArray(); for (Object o : matches) { if (o instanceof JSONObject) array.put(o); else array.put(o.toString()); } return array; } }
public void addInitialization(InitializationPriority priority, String moduleName, String functionName, JSONArray arguments) { assert priority != null; assert InternalUtils.isNonBlank(moduleName); String name = functionName == null ? moduleName : moduleName + ":" + functionName; if ((arguments == null || arguments.length() == 0)) { if (pureInits.contains(name)) { // A degenerate case is a pure init added repeatedly with different priorities. That isn't handled: // the first priority wins. return; } pureInits.add(name); InternalUtils.addToMapList(inits, priority, name); } else { JSONArray init = new JSONArray(); init.put(name); init.putAll(arguments); InternalUtils.addToMapList(inits, priority, init); } initCount++; }
private void addPublishEventInfo(Flow<EventHandlerMethod> eventHandlerMethods, MutableComponentModel model) { JSONArray publishEvents = new JSONArray(); for (EventHandlerMethod eventHandlerMethod : eventHandlerMethods) { if (eventHandlerMethod.publishEvent != null) { publishEvents.put(eventHandlerMethod.eventType.toLowerCase()); } } // If we do have events to publish, we apply the mixin and pass // event information to it. if (publishEvents.length() > 0) { model.addMixinClassName(PublishServerSideEvents.class.getName(), "after:*"); model.setMeta(InternalConstants.PUBLISH_COMPONENT_EVENTS_META, publishEvents.toString()); } }
@Override protected void processSubmission(String controlName) { String parameterValue = request.getParameter(controlName); JSONArray values = new JSONArray(parameterValue); // Use a couple of local variables to cut down on access via bindings Collection<Object> selected = this.selected; selected.clear(); ValueEncoder encoder = this.encoder; // TODO: Validation error if the model does not contain a value. int count = values.length(); for (int i = 0; i < count; i++) { String value = values.getString(i); Object objectValue = encoder.toValue(value); selected.add(objectValue); } putPropertyNameIntoBeanValidationContext("selected"); try { fieldValidationSupport.validate(selected, resources, validate); this.selected = selected; } catch (final ValidationException e) { validationTracker.recordError(this, e.getMessage()); } removePropertyNameFromBeanValidationContext(); }
array.checkedPut(value); } else { JSONArray array = new JSONArray(); array.checkedPut(current); array.checkedPut(value); nameValuePairs.put(name, array);
@Override public Object getArrayIndex(final Object obj, final int idx) { return ((JSONArray) obj).get(idx); }
private boolean selected(String clientId, String elementName) { // Case #1: via JavaScript, the client id is passed up. String raw = request.getParameter(Form.SUBMITTING_ELEMENT_ID); if (InternalUtils.isNonBlank(raw) && new JSONArray(raw).getString(0).equals(clientId)) { return true; } // Case #2: No JavaScript, look for normal semantic (non-null value for the element's name). // If configured as an image submit, look for a value for the x position. Ah, the ugliness // of HTML. String name = image == null ? elementName : elementName + ".x"; String value = request.getParameter(name); return value != null; }
/** * Create a new array, and adds all values fro the iterable to the array (using {@link #putAll(Iterable)}. * * This is implemented as a static method so as not to break the semantics of the existing {@link #JSONArray(Object...)} constructor. * Adding a constructor of type Iterable would change the meaning of <code>new JSONArray(new JSONArray())</code>. * * @param iterable * collection ot value to include, or null * @since 5.4 */ public static JSONArray from(Iterable<?> iterable) { return new JSONArray().putAll(iterable); }
/** * Commits changes, adding one or more keys to the reply. * * @param reply * JSON Object to be sent to client */ public void commit(JSONObject reply) { if (libraryURLs.length() > 0) { reply.in(InternalConstants.PARTIAL_KEY).put("libraries", libraryURLs); } if (stylesheets.length() > 0) { reply.in(InternalConstants.PARTIAL_KEY).put("stylesheets", stylesheets); } List<?> inits = initsManager.getSortedInits(); if (inits.size() > 0) { reply.in(InternalConstants.PARTIAL_KEY).put("inits", JSONArray.from(inits)); } } }
public void addInitializerCall(InitializationPriority priority, String functionName, JSONArray parameter) { // TAP5-2300: In 5.3, a JSONArray implied an array of method arguments, so unwrap and add // functionName to the arguments List parameterList = new ArrayList(parameter.length() + 1); parameterList.add(functionName); parameterList.addAll(parameter.toList()); createInitializer(priority).with(parameterList.toArray()); }
/** * Returns an array containing the string names in this object. This method * returns null if this object contains no mappings. * * @return the names. */ public JSONArray names() { return nameValuePairs.isEmpty() ? null : JSONArray.from(nameValuePairs.keySet()); }
public void processResultValue(JSONArray value) throws IOException { PrintWriter pw = response.getPrintWriter(contentType.toString()); value.print(pw, compactJSON); pw.close(); } }
array.checkedPut(value); } else { JSONArray array = new JSONArray(); array.checkedPut(current); array.checkedPut(value); nameValuePairs.put(name, array);