**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Web / System.Web.UI / BaseParser.cs
blobe01bd6faf07270bb8834972747ded92b5e0ce121
1 //
2 // System.Web.UI.BaseParser.cs
3 //
4 // Authors:
5 // Duncan Mak (duncan@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //
8 // (C) 2002 Ximian, Inc. (http://www.ximian.com)
9 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System;
33 using System.Collections;
34 using System.IO;
35 using System.Web;
36 using System.Web.Compilation;
37 using System.Web.Configuration;
38 using System.Web.Util;
40 namespace System.Web.UI
42 public class BaseParser
44 HttpContext context;
45 string baseDir;
46 string baseVDir;
47 ILocation location;
48 CompilationConfiguration compilationConfig;
50 internal string MapPath (string path)
52 return MapPath (path, true);
55 internal string MapPath (string path, bool allowCrossAppMapping)
57 if (context == null)
58 throw new HttpException ("context is null!!");
60 return context.Request.MapPath (path, BaseVirtualDir, allowCrossAppMapping);
63 internal string PhysicalPath (string path)
65 if (Path.DirectorySeparatorChar != '/')
66 path = path.Replace ('/', '\\');
68 return Path.Combine (BaseDir, path);
71 internal bool GetBool (Hashtable hash, string key, bool deflt)
73 string val = hash [key] as string;
74 if (val == null)
75 return deflt;
77 hash.Remove (key);
79 bool result = false;
80 if (String.Compare (val, "true", true) == 0)
81 result = true;
82 else if (String.Compare (val, "false", true) != 0)
83 ThrowParseException ("Invalid value for " + key);
85 return result;
88 internal static string GetString (Hashtable hash, string key, string deflt)
90 string val = hash [key] as string;
91 if (val == null)
92 return deflt;
94 hash.Remove (key);
95 return val;
98 internal void ThrowParseException (string message)
100 throw new ParseException (location, message);
103 internal void ThrowParseException (string message, Exception inner)
105 throw new ParseException (location, message, inner);
108 internal ILocation Location {
109 get { return location; }
110 set { location = value; }
113 internal HttpContext Context {
114 get { return context; }
115 set { context = value; }
118 internal string BaseDir {
119 get {
120 if (baseDir == null)
121 baseDir = MapPath (BaseVirtualDir, false);
123 return baseDir;
127 internal virtual string BaseVirtualDir {
128 get {
129 if (baseVDir == null)
130 baseVDir = UrlUtils.GetDirectory (context.Request.FilePath);
132 return baseVDir;
135 set { baseVDir = value; }
138 internal CompilationConfiguration CompilationConfig {
139 get {
140 if (compilationConfig == null)
141 compilationConfig = CompilationConfiguration.GetInstance (context);
143 return compilationConfig;