@Override public Object createMap() { return new JSONObject(); }
@Override public void setProperty(final Object obj, final Object key, final Object value) { Object v = value == null ? JSONObject.NULL : value; if (isMap(obj)) { ((JSONObject) obj).put(key.toString(), v); } }
@Test public void an_object_can_be_read() { JSONObject book = using(TAPESTRY_JSON_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[0]"); assertThat(book.get("author").toString()).isEqualTo("Nigel Rees"); }
public JSONObject toJSON() { JSONObject result = new JSONObject("message", message, "severity", severity.name().toLowerCase(), "markup", markup ); if (duration == Duration.TRANSIENT) { result.put("transient", true); } if (duration.persistent) { result.put("id", id); } return result; } }
final String metaValue = componentModel.getMeta(InternalConstants.PUBLISH_COMPONENT_EVENTS_META); final JSONArray componentEvents = new JSONArray(metaValue); final JSONObject events = new JSONObject(); final String existingValue = element.getAttribute(COMPONENT_EVENTS_ATTRIBUTE_NAME); final JSONObject existing = new JSONObject(existingValue); for (String key : existing.keys()) { events.put(key, existing.get(key)); JSONObject event = new JSONObject(); event.put(PUBLISH_COMPONENT_EVENTS_URL_PROPERTY, containerResources.createEventLink(eventName).toString()); events.put(eventName, event); element.forceAttributes(TapestryConstants.COMPONENT_EVENTS_ATTRIBUTE_NAME, events.toString());
/** * Merge obj1 with obj2. Obj2 has predominance. * * @param obj1 * @param obj2 * @return null if obj1 is null. Else return obj1 merged with obj2 */ public final static JSONObject merge(JSONObject obj1, JSONObject obj2) { if (obj1 == null) return null; if (obj2 == null) return obj1; for (String key : obj2.keys()) { obj1.put(key, obj2.get(key)); } return null; }
public String getInitialization() { Locale locale = threadLocale.getLocale(); JSONObject spec = new JSONObject(); DateFormatSymbols symbols = new DateFormatSymbols(locale); spec.put("months", new JSONArray((Object[]) symbols.getMonths())); StringBuilder days = new StringBuilder(); String[] weekdays = symbols.getWeekdays(); Calendar c = Calendar.getInstance(locale); int firstDay = c.getFirstDayOfWeek(); // DatePicker needs them in order from monday to sunday. for (int i = Calendar.MONDAY; i <= Calendar.SATURDAY; i++) { days.append(weekdays[i].substring(0, 1)); } days.append(weekdays[Calendar.SUNDAY].substring(0, 1)); spec.put("days", days.toString().toLowerCase(locale)); // jQuery DatePicker widget expects 0 to be sunday. Calendar defines SUNDAY as 1, MONDAY as 2, etc. spec.put("firstDay", firstDay-1); // set language spec.put("language", locale.getLanguage()); // TODO: Skip localization if locale is English? return String.format("Tapestry.DateField.initLocalization(%s);", spec.toString(compactJSON)); }
public void processResultValue(URL value) throws IOException { JSONObject response = new JSONObject(); response.in(InternalConstants.PARTIAL_KEY).put("redirectURL", value.toExternalForm() ); masterProcessor.processResultValue(response); } }
JSONObject object = new JSONObject(); object.put("libraryName", libraryName); object.put("rootPackage", libraryMapping.getRootPackage()); JSONObject infoJsonObject = new JSONObject(); putIfNotNull("description", info.getDescription(), infoJsonObject); putIfNotNull("homepage", info.getHomepageUrl(), infoJsonObject); infoJsonObject.accumulate("tags", tag); object.put("info", infoJsonObject); addClasses("mixins", filter(componentClassResolver.getMixinNames()), Type.MIXIN, info, object); return new TextStreamResponse("text/javascript", object.toString());
private String buildRequireJSConfig(List<ModuleConfigurationCallback> callbacks) { // This is the part that can vary from one request to another, based on the capabilities of the client. JSONObject config = baseConfig.copy().put("baseUrl", getBaseURL()); // TAP5-2196: allow changes to the configuration in a per-request basis. for (ModuleConfigurationCallback callback : callbacks) { config = callback.configure(config); assert config != null; } // This part gets written out before any libraries are loaded (including RequireJS). return String.format("var require = %s;\n", config.toString(compactJSON)); }
Object onAutocomplete() { JSONObject json = new JSONObject(request.getParameter("data")); JSONObject extra = (json.length()>1) ? new JSONObject(json.getString(EXTRA_NAME)) : new JSONObject(); String input = json.getString(PARAM_NAME); final Holder<List> matchesHolder = Holder.create(); // Default it to an empty list. matchesHolder.put(Collections.emptyList()); ComponentEventCallback<List> callback = new ComponentEventCallback<List>() { public boolean handleResult(List result) { matchesHolder.put(result); return true; } }; Object[] params = extra.length()==0 ? new Object[] {input} : new Object[] {input, extra}; resources.triggerEvent(EventConstants.PROVIDE_COMPLETIONS, params, callback); ContentType contentType = responseRenderer.findContentType(this); return new TextStreamResponse(contentType.toString(), generateResponseJSON(matchesHolder.get()).toString()); }
/** * Prints the JSONObject using the session. * * @since 5.2.0 */ @Override void print(JSONPrintSession session) { session.printSymbol('{'); session.indent(); boolean comma = false; for (String key : keys()) { if (comma) session.printSymbol(','); session.newline(); session.printQuoted(key); session.printSymbol(':'); printValue(session, nameValuePairs.get(key)); comma = true; } session.outdent(); if (comma) session.newline(); session.printSymbol('}'); }
JSONObject parameters = new JSONObject(RequestConstants.FORM_CLIENTID_PARAMETER, formSupport.getClientId(), RequestConstants.FORM_COMPONENTID_PARAMETER, formSupport.getFormComponentId()); parameters.toString(compactJSON));
@Override public Collection<String> getPropertyKeys(final Object obj) { return ((JSONObject) obj).keys(); }
((JSONObject) value).print(session); return; String printValue = numberToString((Number) value); session.print(printValue); return;
@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."); } }
javaScriptSupport.addScript(InitializationPriority.LATE,"%s('%s').tapestryZone('option',{opt: %s});", jQueryAlias, theSelector, defaultParamsObject.toString(compact));
public Void perform() throws IOException { // This is a complex area as we are trying to keep public and private services properly // separated, and trying to keep stateless and stateful (i.e., perthread scope) services // separated. So we inform the stateful queue service what it needs to do here ... String pageName = (String) request.getAttribute(InternalConstants.PAGE_NAME_ATTRIBUTE_NAME); if (pageName == null) { throw new IllegalStateException("The active page name has not been specified."); } MarkupWriter writer = factory.newPartialMarkupWriter(pageName); // ... and here, the pipeline eventually reaches the PRQ to let it render the root render command. partialMarkupRenderer.renderMarkup(writer, reply); PrintWriter pw = response.getPrintWriter(contentType.toString()); reply.print(pw, compactJSON); pw.close(); return null; } });