Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Adapters / ServerUtilityAdapter.cs
blob8f828d741436a137a1f4abd521efb43a76f37da1
1 // Copyright 2004-2008 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.Adapters
17 using System;
18 using System.Web;
19 using Castle.MonoRail.Framework;
21 /// <summary>
22 /// Adapts the ASP.Net HttpServerUtility to MonoRail's interface for the same service.
23 /// </summary>
24 public class ServerUtilityAdapter : IServerUtility
26 private readonly HttpServerUtility server;
28 /// <summary>
29 /// Initializes a new instance of the <see cref="ServerUtilityAdapter"/> class.
30 /// </summary>
31 /// <param name="server">The server.</param>
32 public ServerUtilityAdapter(HttpServerUtility server)
34 this.server = server;
37 /// <summary>
38 /// HTML encodes a string and returns the encoded string.
39 /// </summary>
40 /// <param name="content">The text string to HTML encode.</param>
41 /// <returns>The HTML encoded text.</returns>
42 public String HtmlEncode(String content)
44 return server.HtmlEncode(content);
47 /// <summary>
48 /// Escapes JavaScript with Url encoding and returns the encoded string.
49 /// </summary>
50 /// <remarks>
51 /// Converts quotes, single quotes and CR/LFs to their representation as an escape character.
52 /// </remarks>
53 /// <param name="content">The text to URL encode and escape JavaScript within.</param>
54 /// <returns>The URL encoded and JavaScript escaped text.</returns>
55 public String JavaScriptEscape(String content)
57 // TODO: Replace by a regular expression, which should be much more efficient
59 return content.Replace("\"", "\\\"").Replace("\r", "").Replace("\n", "\\n").Replace("'","\\'");
62 /// <summary>
63 /// URL encodes a string and returns the encoded string.
64 /// </summary>
65 /// <param name="content">The text to URL encode.</param>
66 /// <returns>The URL encoded text.</returns>
67 public String UrlEncode(String content)
69 return server.UrlEncode(content);
72 /// <summary>
73 /// URL decodes a string and returns the decoded string.
74 /// </summary>
75 /// <param name="content">The text to URL decode.</param>
76 /// <returns>The URL decoded text.</returns>
77 public String UrlDecode(String content)
79 return server.UrlDecode(content);
82 /// <summary>
83 /// URL encodes the path portion of a URL string and returns the encoded string.
84 /// </summary>
85 /// <param name="content">The text to URL encode.</param>
86 /// <returns>The URL encoded text.</returns>
87 public String UrlPathEncode(String content)
89 return server.UrlPathEncode(content);
92 /// <summary>
93 /// Returns the physical path for the
94 /// specified virtual path.
95 /// </summary>
96 /// <param name="virtualPath">The virtual path.</param>
97 /// <returns>The mapped path</returns>
98 public String MapPath(String virtualPath)
100 return server.MapPath(virtualPath);