01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.http.server.repository;
07:
08: import static javax.servlet.http.HttpServletResponse.SC_OK;
09:
10: import java.io.IOException;
11: import java.io.OutputStream;
12: import java.util.Map;
13:
14: import javax.servlet.http.HttpServletRequest;
15: import javax.servlet.http.HttpServletResponse;
16:
17: import org.openrdf.query.resultio.BooleanQueryResultFormat;
18: import org.openrdf.query.resultio.BooleanQueryResultWriter;
19: import org.openrdf.query.resultio.BooleanQueryResultWriterFactory;
20:
21: /**
22: * View used to render boolean query results. Renders results in a format
23: * specified using a parameter or Accept header.
24: *
25: * @author Arjohn Kampman
26: */
27: public class BooleanQueryResultView extends QueryResultView {
28:
29: private static final BooleanQueryResultView INSTANCE = new BooleanQueryResultView();
30:
31: public static BooleanQueryResultView getInstance() {
32: return INSTANCE;
33: }
34:
35: private BooleanQueryResultView() {
36: }
37:
38: public String getContentType() {
39: return null;
40: }
41:
42: @SuppressWarnings("unchecked")
43: public void render(Map model, HttpServletRequest request,
44: HttpServletResponse response) throws IOException {
45: BooleanQueryResultWriterFactory brWriterFactory = (BooleanQueryResultWriterFactory) model
46: .get(FACTORY_KEY);
47: BooleanQueryResultFormat brFormat = brWriterFactory
48: .getBooleanQueryResultFormat();
49:
50: response.setStatus(SC_OK);
51: setContentType(response, brFormat);
52: setContentDisposition(model, response, brFormat);
53:
54: OutputStream out = response.getOutputStream();
55: try {
56: BooleanQueryResultWriter qrWriter = brWriterFactory
57: .getWriter(out);
58: boolean value = (Boolean) model.get(QUERY_RESULT_KEY);
59: qrWriter.write(value);
60: } finally {
61: out.close();
62: }
63: }
64: }
|