public Status asStatus(boolean verbose) { Response.Status response = Response.status(getStatus()); if (verbose) { StringBuilder buffer = new StringBuilder(); Formatting.renderStyleSheet(buffer); buffer.append("<div class=\"juzu\">"); buffer.append("<h1>Oups something went wrong</h1>"); // Use getCause as it can be overriden with subclasses Throwable c = getCause(); if (c != null) { Formatting.renderThrowable(null, buffer, c); } else { // Use getMessage as it can be overriden with subclasses String m = getHtmlMessage(); buffer.append(m); } buffer.append("</div>"); response = response.content(buffer).withMimeType("text/html"); } return response; }
return Response.ok(result.toString()).with(PropertyType.MIME_TYPE, "application/json"); } else { if (file != null && file.getContentType().contains("png")) {
set("eventsDisplayedList", eventsDisplayedList). set("tasksDisplayedList", tasksDisplayedList). set("date_act", dateLabel).ok().withCharset(Tools.UTF_8);
parameters.put(GettingStartedUtils.SHOW, Isshow.toString()); if ((isChange) || ("true".equals(reload))) { return gettingStartedList.ok(parameters).withCharset(Tools.UTF_8);
result = new Response.Content(status.getCode(), wrapper);
result = new Response.Content(status.getCode(), wrapper);
return Response.ok(result.toString()).with(PropertyType.MIME_TYPE, "application/json");
/** * return the object data contains the url of logo and the bar navigation * * @param httpContext * @return Resource */ @Ajax @Resource public Response.Content getResource(HttpContext httpContext) { JSONObject json = new JSONObject(); String style = "Dark"; if (settingService.get(Context.GLOBAL, Scope.GLOBAL, BAR_NAVIGATION_STYLE_KEY) != null) { style = (String) settingService.get(Context.GLOBAL, Scope.GLOBAL, BAR_NAVIGATION_STYLE_KEY) .getValue(); } try { json.put("error", "0"); json.put("style", style); json.put("logoUrl", getLogoUrl(httpContext, true)); } catch (JSONException ex) { if (LOG.isErrorEnabled()) { LOG.error("Can not put json value", ex); } } return Response.ok(json.toString()).with(PropertyType.MIME_TYPE, "application/json"); }
@Override public Response handle(Stage.Unmarshalling argument) { Response result = argument.invoke(); Request request = argument.getRequest(); if (request.getPhase() == Phase.VIEW) { if (result instanceof Response.Content) { final Collection<Chunk.Property<String>> bar = foo(request.getHandler().getMethod(), Collections.<Chunk.Property<String>>emptyList()); Response.Status status = (Response.Status)result; if ((bar.size() > 0)) { status = new Response.Content(status.getCode(), new StreamableDecorator(status.streamable()) { @Override protected void sendHeader(Stream consumer) { for (Chunk.Property<String> asset : bar) { consumer.provide(asset); } } }); result = status; } } } return result; } }
@Ajax @Resource public Response.Content setting() throws Exception { calendarDisplayedList.clear(); calendarNonDisplayedList.clear(); String username = RequestContext.getCurrentInstance().getRemoteUser(); String defaultCalendarLabel = "Default"; Iterator itr1 = getAllCal(username).iterator(); while (itr1.hasNext()) { org.exoplatform.calendar.service.Calendar c = (org.exoplatform.calendar.service.Calendar) itr1.next(); if(c.getGroups()==null) { if (c.getId().equals(Utils.getDefaultCalendarId(username)) && c.getName().equals(calendarService_.getDefaultCalendarName())) { c.setName(defaultCalendarLabel); } } if (CalendarPortletUtils.contains(nonDisplayedCalendarList, c.getId())) { calendarNonDisplayedList.add(c); } else { calendarDisplayedList.add(c); } } return setting.with().set("displayedCalendar", calendarDisplayedList). set("nonDisplayedCalendar", calendarNonDisplayedList).ok().withCharset(Tools.UTF_8); }
@Override public Response handle(Stage.Unmarshalling argument) { Response result = argument.invoke(); Request request = argument.getRequest(); if (request.getPhase() == Phase.VIEW) { if (result instanceof Response.Content) { final Collection<Chunk.Property<String>> bar = foo(request.getHandler().getMethod(), Collections.<Chunk.Property<String>>emptyList()); Response.Status status = (Response.Status)result; if ((bar.size() > 0)) { status = new Response.Content(status.getCode(), new StreamableDecorator(status.streamable()) { @Override protected void sendHeader(Stream consumer) { for (Chunk.Property<String> asset : bar) { consumer.provide(asset); } } }); result = status; } } } return result; } }
/** * Parse the header into an {@link Element} and set it on the response as an header tag. This method * expects well formed XML, the parsed Element will be translated into markup according to the * response content type when the response will be written to the document. * * @param header the header string to parse * @return this object * @throws ParserConfigurationException any ParserConfigurationException * @throws SAXException any SAXException */ public Content withHeaderTag(String header) throws ParserConfigurationException, SAXException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbf.newDocumentBuilder(); try { Document doc = builder.parse(new InputSource(new StringReader(header))); Element elt = doc.getDocumentElement(); return withHeaderTag(elt); } catch (IOException e) { // Let's save user from IOException at least throw new UndeclaredIOException(e); } }
/** * Parse the header into an {@link Element} and set it on the response as an header tag. This method * expects well formed XML, the parsed Element will be translated into markup according to the * response content type when the response will be written to the document. * * @param header the header string to parse * @return this object * @throws ParserConfigurationException any ParserConfigurationException * @throws SAXException any SAXException */ public Content withHeaderTag(String header) throws ParserConfigurationException, SAXException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbf.newDocumentBuilder(); try { Document doc = builder.parse(new InputSource(new StringReader(header))); Element elt = doc.getDocumentElement(); return withHeaderTag(elt); } catch (IOException e) { // Let's save user from IOException at least throw new UndeclaredIOException(e); } }
public Status asStatus(boolean verbose) { Response.Status response = Response.status(getStatus()); if (verbose) { StringBuilder buffer = new StringBuilder(); Formatting.renderStyleSheet(buffer); buffer.append("<div class=\"juzu\">"); buffer.append("<h1>Oups something went wrong</h1>"); // Use getCause as it can be overriden with subclasses Throwable c = getCause(); if (c != null) { Formatting.renderThrowable(null, buffer, c); } else { // Use getMessage as it can be overriden with subclasses String m = getHtmlMessage(); buffer.append(m); } buffer.append("</div>"); response = response.content(buffer).withMimeType("text/html"); } return response; }
@Ajax @Resource public Response saveSender(String name, String email) { JSON data = new JSON(); data.set("name", name); data.set("email",email); if(name != null && name.length() > 0 && NotificationUtils.isValidEmailAddresses(email)) { settingService.set(org.exoplatform.commons.api.settings.data.Context.GLOBAL, Scope.GLOBAL, NotificationPluginUtils.NOTIFICATION_SENDER_NAME, SettingValue.create(name)); settingService.set(org.exoplatform.commons.api.settings.data.Context.GLOBAL, Scope.GLOBAL, NotificationPluginUtils.NOTIFICATION_SENDER_EMAIL, SettingValue.create(email)); data.set("status","OK"); } else { data.set("status","NOK"); } return Response.ok(data.toString()).withMimeType("application/json"); }
@Ajax @Resource public Response saveActivePlugin(String pluginId, String inputs) { JSON data = new JSON(); try { Map<String, String> datas = parserParams(inputs); for (String channelId : datas.keySet()) { pluginSettingService.saveActivePlugin(channelId, pluginId, Boolean.valueOf(datas.get(channelId))); } data.set("status", "ok"); data.set("result", datas); } catch (Exception e) { LOG.error("Failed to save settings", e); data.set("status", "false"); data.set("error", "Exception: " + e.getMessage()); } return Response.ok(data.toString()).withMimeType("application/json"); }
public Content content(Streamable s) { return new Content(code, properties, s); }
public Content withTitle(String title) { return with(PropertyType.TITLE, title); }
public Content withTitle(String title) { return with(PropertyType.TITLE, title); }
public static Content content(int code, Streamable content) { return new Content(code, content); }