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 // 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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
33 using System
.Collections
;
36 using System
.Web
.Compilation
;
37 using System
.Web
.Configuration
;
38 using System
.Web
.Util
;
40 namespace System
.Web
.UI
42 public class BaseParser
48 CompilationConfiguration compilationConfig
;
50 internal string MapPath (string path
)
52 return MapPath (path
, true);
55 internal string MapPath (string path
, bool allowCrossAppMapping
)
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;
80 if (String
.Compare (val
, "true", true) == 0)
82 else if (String
.Compare (val
, "false", true) != 0)
83 ThrowParseException ("Invalid value for " + key
);
88 internal static string GetString (Hashtable hash
, string key
, string deflt
)
90 string val
= hash
[key
] as string;
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
{
121 baseDir
= MapPath (BaseVirtualDir
, false);
127 internal virtual string BaseVirtualDir
{
129 if (baseVDir
== null)
130 baseVDir
= UrlUtils
.GetDirectory (context
.Request
.FilePath
);
135 set { baseVDir = value; }
138 internal CompilationConfiguration CompilationConfig
{
140 if (compilationConfig
== null)
141 compilationConfig
= CompilationConfiguration
.GetInstance (context
);
143 return compilationConfig
;