2 // Mainsoft.Web.Hosting.IncludeHelperServlet
5 // Eyal Alaluf (eyala@mainsoft.com)
7 // (C) 2006 Mainsoft Co. (http://www.mainsoft.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
36 using javax.servlet.http;
38 namespace Mainsoft.Web.Hosting
41 /// <para>This class supports the Framework infrastructure and is not intended to be used directly from your code.</para>
43 public class IncludeHelperServlet : HttpServlet
45 public IncludeHelperServlet()
49 override protected void service(HttpServletRequest req, HttpServletResponse resp)
51 string servletPath = ServletIncludeUtils.getServletPath(req);
52 TextWriter writer = (TextWriter)ServletIncludeUtils.getTextWriter(req);
53 RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(servletPath);
54 HttpServletResponseWrapper wrapper = new AspxResponseWrapper(resp, writer);
55 dispatcher.include(req, wrapper);
58 sealed class AspxResponseWrapper : HttpServletResponseWrapper
60 public AspxResponseWrapper(HttpServletResponse resp, TextWriter writer) : base (resp)
62 jwriter = new PrintWriter(new JavaWriterFromTextWriter(writer));
65 public override PrintWriter getWriter()
70 readonly PrintWriter jwriter;
73 sealed class JavaWriterFromTextWriter : Writer
75 public JavaWriterFromTextWriter(TextWriter writer)
80 public override void flush()
85 public override void write(char[] buffer, int offset, int count)
87 writer.Write(buffer, offset, count);
90 public override void write(String s)
95 public override void write(string s, int start, int count)
97 if (start == 0 && count == s.Length)
100 writer.Write(s.Substring(start, count));
103 public override void close()
105 // Ignore close as we don't own here the writer.
108 readonly TextWriter writer;
113 namespace System.Web.GH
116 /// <para>This class supports the Framework infrastructure and is not intended to be used directly from your code.</para>
118 public class IncludeHelperServlet : Mainsoft.Web.Hosting.IncludeHelperServlet