**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web / System.Web.Handlers / AssemblyResourceLoader.cs
blob2e089b2e5cc8e61bbb7bc47a5cce6fe9b4221011
1 //
2 // System.Web.Handlers.AssemblyResourceLoader
3 //
4 // Authors:
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 //
7 // (C) 2003 Ben Maurer
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Web;
32 using System.Web.UI;
33 using System.Reflection;
34 using System.IO;
36 namespace System.Web.Handlers {
37 [MonoTODO ("Should we cache stuff?")]
38 #if NET_2_0
39 public
40 #else
41 internal // since this is in the .config file, we need to support it, since we dont have versoned support.
42 #endif
43 class AssemblyResourceLoader : IHttpHandler {
45 internal static string GetResourceUrl (Type type, string resourceName)
47 return "WebResource.axd?assembly="
48 + HttpUtility.UrlEncode (type.Assembly.GetName ().FullName)
49 + "&resource="
50 + HttpUtility.UrlEncode (resourceName);
54 [MonoTODO ("Substitution not implemented")]
55 void System.Web.IHttpHandler.ProcessRequest (HttpContext context)
57 #if NET_2_0
58 string resourceName = context.Request.QueryString ["resource"];
59 Assembly assembly = Assembly.Load (context.Request.QueryString ["assembly"]);
61 bool found = false;
62 foreach (WebResourceAttribute wra in assembly.GetCustomAttributes (typeof (WebResourceAttribute), false)) {
63 if (wra.WebResource == resourceName) {
64 context.Response.ContentType = wra.ContentType;
66 if (wra.PerformSubstitution)
67 throw new NotImplementedException ("Substitution not implemented");
69 found = true;
70 break;
73 if (!found)
74 return;
76 Stream s = assembly.GetManifestResourceStream (resourceName);
78 byte [] buf = new byte [1024];
79 Stream output = context.Response.OutputStream;
80 int c;
81 do {
82 c = s.Read (buf, 0, 1024);
83 output.Write (buf, 0, c);
84 } while (c > 0);
85 #endif
88 bool System.Web.IHttpHandler.IsReusable { get { return true; } }