}
private void doSingleView(HttpServletRequest request, HttpServletResponse response, String format, String type, String id) throws ApiRequestException
{
try {
SenateResponse sr = Application.getLucene().search("otype:"+type+" AND oid:\""+id+"\"", 0, 1, null, false);
ApiHelper.buildSearchResultList(sr);
if (format.equals("json")) {
response.setContentType("application/json");
// Writing directly to the output stream here currently makes UTF8 errors.
response.getWriter().write(new Api2JsonConverter().toString(sr));
}
else if (format.equals("jsonp")) {
String callback = request.getParameter("callback");
if (callback != null && callback != "") {
PrintWriter out = response.getWriter();
response.setContentType("application/javascript");
out.write(callback+"("+new Api2JsonConverter().toString(sr)+");");
}
else {
throw new ApiRequestException("callback parameter required for jsonp queries.");
}
}
else if (format.equals("xml")) {
response.setContentType("application/xml");
new Api2XmlConverter().write(sr, response.getOutputStream());
}
else if (format.equals("pdf")) {
if (sr.getResults().size() == 0) {
throw new ApiRequestException("No matching document could be found.");
}
response.setContentType("application/pdf");
PDFConverter.write(sr.getResults().get(0).object, response.getOutputStream());
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new ApiRequestException("internal server error.", e);