Added non-generic registration interface to IKernel and IWindsor to accommodate dynam...
[castle.git] / MonoRail / Castle.MonoRail.Framework / ResourceFileHandler.cs
blobe3ad0c454dc2bec7df7284c333224c35a946275b
1 // Copyright 2004-2007 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
17 using System;
18 using System.Web;
19 using Services;
21 /// <summary>
22 /// Handles the service of static files (usually js files)
23 /// </summary>
24 public class ResourceFileHandler : IHttpHandler
26 private readonly UrlInfo urlInfo;
27 private readonly IStaticResourceRegistry staticResourceRegistry;
29 /// <summary>
30 /// Initializes a new instance of the <see cref="ResourceFileHandler"/> class.
31 /// </summary>
32 /// <param name="urlInfo">The URL info.</param>
33 /// <param name="staticResourceRegistry">The static resource registry.</param>
34 public ResourceFileHandler(UrlInfo urlInfo, IStaticResourceRegistry staticResourceRegistry)
36 this.urlInfo = urlInfo;
37 this.staticResourceRegistry = staticResourceRegistry;
40 /// <summary>
41 /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
42 /// </summary>
43 /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
44 public void ProcessRequest(HttpContext context)
46 string name = context.Request.QueryString["name"];
47 string location = context.Request.QueryString["location"];
48 string version = context.Request.QueryString["version"];
50 if (name == null)
52 name = urlInfo.Action;
55 try
57 if (!staticResourceRegistry.Exists(name, location, version))
59 context.Response.StatusCode = 404;
61 return;
64 string mimeType;
65 string content = staticResourceRegistry.GetResource(name, location, version, out mimeType);
67 context.Response.ContentType = mimeType;
68 context.Response.Write(content);
70 catch(Exception)
72 context.Response.StatusCode = 500;
74 throw;
78 /// <summary>
79 /// Gets a value indicating whether another request can use the <see cref="T:System.Web.IHttpHandler"/> instance.
80 /// </summary>
81 /// <value></value>
82 /// <returns>true if the <see cref="T:System.Web.IHttpHandler"/> instance is reusable; otherwise, false.</returns>
83 public bool IsReusable
85 get { return false; }