1
// Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
22 /// Handles the service of static files (usually js files)
24 public class ResourceFileHandler
: IHttpHandler
26 private readonly UrlInfo urlInfo
;
27 private readonly IStaticResourceRegistry staticResourceRegistry
;
30 /// Initializes a new instance of the <see cref="ResourceFileHandler"/> class.
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
;
41 /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
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"];
52 name
= urlInfo
.Action
;
57 if (!staticResourceRegistry
.Exists(name
, location
, version
))
59 context
.Response
.StatusCode
= 404;
65 string content
= staticResourceRegistry
.GetResource(name
, location
, version
, out mimeType
);
67 context
.Response
.ContentType
= mimeType
;
68 context
.Response
.Write(content
);
72 context
.Response
.StatusCode
= 500;
79 /// Gets a value indicating whether another request can use the <see cref="T:System.Web.IHttpHandler"/> instance.
82 /// <returns>true if the <see cref="T:System.Web.IHttpHandler"/> instance is reusable; otherwise, false.</returns>
83 public bool IsReusable