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)
12 using System.Collections;
15 using System.Web.Compilation;
16 using System.Web.Configuration;
17 using System.Web.Util;
19 namespace System.Web.UI
21 public class BaseParser
27 CompilationConfiguration compilationConfig;
29 internal string MapPath (string path)
31 return MapPath (path, true);
34 internal string MapPath (string path, bool allowCrossAppMapping)
37 throw new HttpException ("context is null!!");
39 return context.Request.MapPath (path, BaseVirtualDir, allowCrossAppMapping);
42 internal string PhysicalPath (string path)
44 if (Path.DirectorySeparatorChar != '/')
45 path = path.Replace ('/', '\\');
47 return Path.Combine (BaseDir, path);
50 internal bool GetBool (Hashtable hash, string key, bool deflt)
52 string val = hash [key] as string;
59 if (String.Compare (val, "true", true) == 0)
61 else if (String.Compare (val, "false", true) != 0)
62 ThrowParseException ("Invalid value for " + key);
67 internal static string GetString (Hashtable hash, string key, string deflt)
69 string val = hash [key] as string;
77 internal void ThrowParseException (string message)
79 throw new ParseException (location, message);
82 internal void ThrowParseException (string message, Exception inner)
84 throw new ParseException (location, message, inner);
87 internal ILocation Location {
88 get { return location; }
89 set { location = value; }
92 internal HttpContext Context {
93 get { return context; }
94 set { context = value; }
97 internal string BaseDir {
100 baseDir = MapPath (BaseVirtualDir, false);
106 internal virtual string BaseVirtualDir {
108 if (baseVDir == null)
109 baseVDir = UrlUtils.GetDirectory (context.Request.FilePath);
114 set { baseVDir = value; }
117 internal CompilationConfiguration CompilationConfig {
119 if (compilationConfig == null)
120 compilationConfig = CompilationConfiguration.GetInstance (context);
122 return compilationConfig;