2 // System.Web.UI.BaseParser.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // (C) 2002 Ximian, Inc. (http://www.ximian.com)
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.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.
31 using System.Collections;
33 using System.Security.Permissions;
34 using System.Web.Compilation;
35 using System.Web.Configuration;
36 using System.Web.Util;
38 namespace System.Web.UI
41 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
43 public class BaseParser
50 CompilationConfiguration compilationConfig;
53 internal string MapPath (string path)
55 return MapPath (path, true);
58 internal string MapPath (string path, bool allowCrossAppMapping)
61 throw new HttpException ("context is null!!");
63 return context.Request.MapPath (path, BaseVirtualDir, allowCrossAppMapping);
66 internal string PhysicalPath (string path)
68 if (Path.DirectorySeparatorChar != '/')
69 path = path.Replace ('/', '\\');
71 return Path.Combine (BaseDir, path);
74 internal bool GetBool (Hashtable hash, string key, bool deflt)
76 string val = hash [key] as string;
83 if (String.Compare (val, "true", true) == 0)
85 else if (String.Compare (val, "false", true) != 0)
86 ThrowParseException ("Invalid value for " + key);
91 internal static string GetString (Hashtable hash, string key, string deflt)
93 string val = hash [key] as string;
101 internal void ThrowParseException (string message, params object[] parms)
103 throw new ParseException (location, String.Format (message, parms));
106 internal void ThrowParseException (string message, Exception inner, params object[] parms)
108 throw new ParseException (location, String.Format (message, parms), inner);
111 internal ILocation Location {
112 get { return location; }
113 set { location = value; }
116 internal HttpContext Context {
117 get { return context; }
118 set { context = value; }
121 internal string BaseDir {
124 baseDir = MapPath (BaseVirtualDir, false);
130 internal virtual string BaseVirtualDir {
132 if (baseVDir == null)
133 baseVDir = UrlUtils.GetDirectory (context.Request.FilePath);
139 if (VirtualPathUtility.IsRooted (value))
140 baseVDir = VirtualPathUtility.ToAbsolute (value);
147 internal CompilationSection CompilationConfig {
149 return WebConfigurationManager.GetSection ("system.web/compilation") as CompilationSection;
154 internal CompilationConfiguration CompilationConfig {
156 if (compilationConfig == null)
157 compilationConfig = CompilationConfiguration.GetInstance (context);
159 return compilationConfig;