@PathVariable final String appId,
@RequestParam(value = "pretty", defaultValue = "false") final boolean pretty,
@RequestParam(value = "jsonp", defaultValue = "") final String jsonpCallback,
final HttpServletResponse capabilitiesResponse) throws ServletException,
IOException, JSONException {
MapPrinter printer;
try {
printer = this.printerFactory.create(appId);
} catch (NoSuchAppException e) {
error(capabilitiesResponse, e.getMessage(), HttpStatus.NOT_FOUND);
return;
}
setContentType(capabilitiesResponse, jsonpCallback);
final Writer writer;
final ByteArrayOutputStream prettyPrintBuffer = new ByteArrayOutputStream();
if (pretty) {
writer = new OutputStreamWriter(prettyPrintBuffer, Constants.DEFAULT_CHARSET);
} else {
writer = capabilitiesResponse.getWriter();
}
try {
if (!pretty && !Strings.isNullOrEmpty(jsonpCallback)) {
writer.append(jsonpCallback + "(");
}
JSONWriter json = new JSONWriter(writer);
try {
json.object();
{
json.key(JSON_APP).value(appId);
printer.printClientConfig(json);
}
{
json.key("formats");
Set<String> formats = printer.getOutputFormatsNames();
json.array();
for (String format : formats) {
json.value(format);
}
json.endArray();