Refactored the Kernel registration fluent interface to be more readable, better suppo...
[castle.git] / MonoRail / Castle.MonoRail.Framework / Adapters / ResponseAdapter.cs
blob2c1554d14aa932697eda98d8dd7e6d3b95940efa
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Adapters
17 using System;
18 using System.IO;
19 using System.Web;
20 using Castle.MonoRail.Framework;
21 using Internal;
22 using Routing;
23 using Services;
25 /// <summary>
26 /// Adapts the <see cref="IResponse"/> to
27 /// an <see cref="HttpResponse"/> instance.
28 /// </summary>
29 public class ResponseAdapter : BaseResponse
31 private readonly HttpResponse response;
33 /// <summary>
34 /// Initializes a new instance of the <see cref="ResponseAdapter"/> class.
35 /// </summary>
36 /// <param name="currentUrl">The current URL.</param>
37 /// <param name="urlBuilder">The URL builder.</param>
38 /// <param name="serverUtility">The server utility.</param>
39 /// <param name="routeMatch">The route match.</param>
40 /// <param name="response">The response.</param>
41 public ResponseAdapter(HttpResponse response, UrlInfo currentUrl,
42 IUrlBuilder urlBuilder, IServerUtility serverUtility,
43 RouteMatch routeMatch) : base(currentUrl, urlBuilder, serverUtility, routeMatch)
45 this.response = response;
48 /// <summary>
49 /// Gets the caching policy (expiration time, privacy,
50 /// vary clauses) of a Web page.
51 /// </summary>
52 public override HttpCachePolicy CachePolicy
54 get { return response.Cache; }
55 set { throw new NotImplementedException(); }
58 /// <summary>
59 /// Sets the Cache-Control HTTP header to Public or Private.
60 /// </summary>
61 public override string CacheControlHeader
63 get { return response.CacheControl; }
64 set { response.CacheControl = value; }
67 /// <summary>
68 /// Gets or sets the HTTP character set of the output stream.
69 /// </summary>
70 public override string Charset
72 get { return response.Charset; }
73 set { response.Charset = value; }
76 /// <summary>
77 /// Gets or sets the status code.
78 /// </summary>
79 /// <value>The status code.</value>
80 public override int StatusCode
82 get { return response.StatusCode; }
83 set { response.StatusCode = value; }
86 /// <summary>
87 /// Gets or sets the status code.
88 /// </summary>
89 /// <value>The status code.</value>
90 public override string StatusDescription
92 get { return response.StatusDescription; }
93 set { response.StatusDescription = value; }
96 /// <summary>
97 /// Gets or sets the content type.
98 /// </summary>
99 /// <value>The type of the content.</value>
100 public override string ContentType
102 get { return response.ContentType; }
103 set { response.ContentType = value; }
106 /// <summary>
107 /// Appends the header.
108 /// </summary>
109 /// <param name="name">The name.</param>
110 /// <param name="headerValue">The header value.</param>
111 public override void AppendHeader(string name, string headerValue)
113 response.AppendHeader(name, headerValue);
116 /// <summary>
117 /// Gets the output.
118 /// </summary>
119 /// <value>The output.</value>
120 public override TextWriter Output
122 get { return response.Output; }
123 set { throw new NotImplementedException(); }
126 /// <summary>
127 /// Gets the output stream.
128 /// </summary>
129 /// <value>The output stream.</value>
130 public override Stream OutputStream
132 get { return response.OutputStream; }
135 /// <summary>
136 /// Writes the buffer to the browser
137 /// </summary>
138 /// <param name="buffer">The buffer.</param>
139 public override void BinaryWrite(byte[] buffer)
141 response.BinaryWrite(buffer);
144 /// <summary>
145 /// Writes the stream to the browser
146 /// </summary>
147 /// <param name="stream">The stream.</param>
148 public override void BinaryWrite(Stream stream)
150 byte[] buffer = new byte[stream.Length];
152 stream.Read(buffer, 0, buffer.Length);
154 BinaryWrite(buffer);
157 /// <summary>
158 /// Clears the response (only works if buffered)
159 /// </summary>
160 public override void Clear()
162 response.Clear();
165 /// <summary>
166 /// Clears the response content (only works if buffered).
167 /// </summary>
168 public override void ClearContent()
170 response.ClearContent();
173 /// <summary>
174 /// Writes the specified string.
175 /// </summary>
176 /// <param name="s">The string.</param>
177 public override void Write(string s)
179 response.Write(s);
182 /// <summary>
183 /// Writes the specified obj.
184 /// </summary>
185 /// <param name="obj">The obj.</param>
186 public override void Write(object obj)
188 response.Write(obj);
191 /// <summary>
192 /// Writes the specified char.
193 /// </summary>
194 /// <param name="ch">The char.</param>
195 public override void Write(char ch)
197 response.Write(ch);
200 /// <summary>
201 /// Writes the specified buffer.
202 /// </summary>
203 /// <param name="buffer">The buffer.</param>
204 /// <param name="index">The index.</param>
205 /// <param name="count">The count.</param>
206 public override void Write(char[] buffer, int index, int count)
208 response.Write(buffer, index, count);
211 /// <summary>
212 /// Writes the file.
213 /// </summary>
214 /// <param name="fileName">Name of the file.</param>
215 public override void WriteFile(string fileName)
217 response.WriteFile(fileName);
220 /// <summary>
221 /// Gets a value indicating whether this instance is client connected.
222 /// </summary>
223 /// <value>
224 /// <c>true</c> if this instance is client connected; otherwise, <c>false</c>.
225 /// </value>
226 public override bool IsClientConnected
228 get { return response.IsClientConnected; }
231 /// <summary>
232 /// Gets a value indicating whether the response sent a redirect.
233 /// </summary>
234 /// <value><c>true</c> if was redirected; otherwise, <c>false</c>.</value>
235 public override bool WasRedirected
237 get { return redirected; }
240 /// <summary>
241 /// Redirects to the specified url
242 /// </summary>
243 /// <param name="url">An relative or absolute URL to redirect the client to</param>
244 /// <param name="endProcess">if set to <c>true</c>, sends the redirect and
245 /// kills the current request process.</param>
246 public override void RedirectToUrl(string url, bool endProcess)
248 redirected = true;
249 response.Redirect(url, endProcess);
252 /// <summary>
253 /// Creates the cookie.
254 /// </summary>
255 /// <param name="cookie">The cookie.</param>
256 public override void CreateCookie(HttpCookie cookie)
258 response.Cookies.Add(cookie);