2007-08-05 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / Mainsoft.Web / Mainsoft.Web.Hosting / IncludeHelperServlet.cs
1 //
2 // Mainsoft.Web.Hosting.IncludeHelperServlet
3 //
4 // Authors:
5 //      Eyal Alaluf (eyala@mainsoft.com)
6 //
7 // (C) 2006 Mainsoft Co. (http://www.mainsoft.com)
8 //
9
10 //
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.
29 //
30
31 using System;
32 using System.IO;
33 using System.Web.UI;
34 using java.io;
35 using javax.servlet;
36 using javax.servlet.http;
37 using vmw.@internal.j2ee;
38
39 namespace Mainsoft.Web.Hosting
40 {
41         /// <summary>\r
42         /// <para>This class supports the Framework infrastructure and is not intended to be used directly from your code.</para>\r
43         /// </summary>
44         public class IncludeHelperServlet : HttpServlet
45         {
46                 public IncludeHelperServlet()
47                 {
48                 }
49
50                 override public void init(ServletConfig config)
51                 {
52                         base.init(config);
53                 }
54
55                 override protected void service(HttpServletRequest req, HttpServletResponse resp)
56                 {
57                         string servletPath = ServletIncludeUtils.getServletPath(req);
58                         TextWriter writer = (TextWriter)ServletIncludeUtils.getTextWriter(req);
59                         RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(servletPath);
60                         HttpServletResponseWrapper wrapper = new AspxResponseWrapper(resp, writer);
61                         dispatcher.include(req, wrapper);
62                 }
63
64                 override public void destroy()
65                 {
66                         base.destroy();
67                 }
68
69                 class AspxResponseWrapper : HttpServletResponseWrapper 
70                 {
71                         public AspxResponseWrapper(HttpServletResponse resp, TextWriter writer) : base (resp)
72                         {
73                                 jwriter = new PrintWriter(new JavaWriterFromTextWriter(writer));
74                         }
75
76                         public override PrintWriter getWriter()
77                         {
78                                 return jwriter;
79                         }
80
81                         PrintWriter jwriter;
82                 }
83
84                 class JavaWriterFromTextWriter : Writer
85                 {
86                         public JavaWriterFromTextWriter(TextWriter writer)
87                         {
88                                 this.writer = writer;
89                         }
90
91                         public override void flush()
92                         {
93                                 writer.Flush ();
94                         }
95
96                         public override void write(char[] buffer, int offset, int count)
97                         {
98                                 writer.Write(buffer, offset, count);
99                         }
100
101                         public override void write(String s)
102                         {
103                                 writer.Write(s);
104                         }
105
106                         public override void write(string s, int start, int count)
107                         {
108                                 if (start == 0 && count == s.Length)
109                                         writer.Write(s);
110                                 else
111                                         writer.Write(s.Substring(start, count));
112                         }
113
114                         public override void close()
115                         {
116                                 // Ignore close as we don't own here the writer.
117                         }
118
119                         TextWriter writer;
120                 }
121         }
122 }
123
124 namespace System.Web.GH
125 {
126         /// <summary>\r
127         /// <para>This class supports the Framework infrastructure and is not intended to be used directly from your code.</para>\r
128         /// </summary>
129         public class IncludeHelperServlet : Mainsoft.Web.Hosting.IncludeHelperServlet
130         {
131         }
132
133 }