1 // Copyright 2004-2008 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
.Adapters
19 using Castle
.MonoRail
.Framework
;
22 /// Adapts the ASP.Net HttpServerUtility to MonoRail's interface for the same service.
24 public class ServerUtilityAdapter
: IServerUtility
26 private readonly HttpServerUtility server
;
29 /// Initializes a new instance of the <see cref="ServerUtilityAdapter"/> class.
31 /// <param name="server">The server.</param>
32 public ServerUtilityAdapter(HttpServerUtility server
)
38 /// HTML encodes a string and returns the encoded string.
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
);
48 /// Escapes JavaScript with Url encoding and returns the encoded string.
51 /// Converts quotes, single quotes and CR/LFs to their representation as an escape character.
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("'","\\'");
63 /// URL encodes a string and returns the encoded string.
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
);
73 /// URL decodes a string and returns the decoded string.
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
);
83 /// URL encodes the path portion of a URL string and returns the encoded string.
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
);
93 /// Returns the physical path for the
94 /// specified virtual path.
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
);