1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.abstracthorizon.danube.tapestry;
15
16 import java.io.IOException;
17 import java.io.OutputStream;
18 import java.io.PrintWriter;
19
20 import org.abstracthorizon.danube.http.HTTPConnection;
21 import org.abstracthorizon.danube.http.Status;
22
23 import org.apache.tapestry.util.ContentType;
24 import org.apache.tapestry.web.WebResponse;
25
26
27
28
29
30
31 public class DanubeResponse implements WebResponse {
32
33
34 protected HTTPConnection connection;
35
36
37 protected boolean needReset = false;
38
39
40
41
42
43 public DanubeResponse(HTTPConnection connection) {
44 this.connection = connection;
45 }
46
47
48
49
50
51
52 public OutputStream getOutputStream(ContentType contentType) throws IOException {
53 connection.getResponseHeaders().putOnly("Content-Type", contentType.getMimeType());
54 return (OutputStream)connection.adapt(OutputStream.class);
55 }
56
57
58
59
60
61 public PrintWriter getPrintWriter(ContentType contentType) throws IOException {
62 if (needReset) {
63 connection.reset();
64 }
65 needReset = true;
66 connection.getRequestHeaders().putOnly("Content-Type", contentType.getMimeType());
67 return (PrintWriter)connection.adapt(PrintWriter.class);
68 }
69
70
71
72
73
74
75 public String encodeURL(String url) {
76 return url;
77 }
78
79
80
81
82 public void reset() {
83 connection.reset();
84 }
85
86
87
88
89
90 public void setContentLength(int len) {
91 connection.getResponseHeaders().putOnly("Content-Length", Integer.toString(len));
92 }
93
94
95
96
97
98 public String getNamespace() {
99 return "";
100 }
101
102
103
104
105
106
107 public void setDateHeader(String name, long date) {
108
109 }
110
111
112
113
114
115
116 public void setHeader(String name, String value) {
117 connection.getRequestHeaders().putOnly(name, value);
118 }
119
120
121
122
123
124
125 public void setIntHeader(String name, int i) {
126 connection.getRequestHeaders().putOnly(name, Integer.toString(i));
127 }
128
129
130
131
132
133 public void setStatus(int code) {
134
135 Status status = new Status(Integer.toString(code), Integer.toString(code));
136 connection.setResponseStatus(status);
137 }
138
139
140
141
142
143
144
145 public void sendError(int code, String msg) throws IOException {
146 Status status = new Status(Integer.toString(code), msg);
147 connection.setResponseStatus(status);
148
149 }
150
151 }