01: package com.icesoft.faces.webapp.http.common.standard;
02:
03: import com.icesoft.faces.webapp.http.common.Response;
04: import com.icesoft.faces.webapp.http.common.ResponseHandler;
05:
06: import java.io.IOException;
07: import java.io.StringWriter;
08: import java.io.Writer;
09:
10: public abstract class FixedSizeContentHandler implements
11: ResponseHandler {
12: private String mimeType;
13: private String characterSet;
14:
15: protected FixedSizeContentHandler(String mimeType,
16: String characterSet) {
17: this .mimeType = mimeType;
18: this .characterSet = characterSet;
19: }
20:
21: public abstract void writeTo(Writer writer) throws IOException;
22:
23: public void respond(Response response) throws Exception {
24: StringWriter writer = new StringWriter();
25: writeTo(writer);
26: writer.write("\n\n");
27: byte[] content = writer.getBuffer().toString().getBytes(
28: characterSet);
29: response.setHeader("Content-Type", mimeType + "; charset="
30: + characterSet);
31: response.setHeader("Content-Length", content.length);
32: response.writeBody().write(content);
33: }
34: }
|