BaseParser.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // System.Web.UI.BaseParser.cs
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Gonzalo Paniagua Javier ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc. (http://www.ximian.com)
  9. //
  10. using System;
  11. using System.Collections;
  12. using System.IO;
  13. using System.Web;
  14. using System.Web.Compilation;
  15. using System.Web.Configuration;
  16. using System.Web.Util;
  17. namespace System.Web.UI
  18. {
  19. public class BaseParser
  20. {
  21. HttpContext context;
  22. string baseDir;
  23. string baseVDir;
  24. ILocation location;
  25. CompilationConfiguration compilationConfig;
  26. internal string MapPath (string path)
  27. {
  28. return MapPath (path, true);
  29. }
  30. internal string MapPath (string path, bool allowCrossAppMapping)
  31. {
  32. if (context == null)
  33. throw new HttpException ("context is null!!");
  34. return context.Request.MapPath (path, BaseVirtualDir, allowCrossAppMapping);
  35. }
  36. internal string PhysicalPath (string path)
  37. {
  38. if (Path.DirectorySeparatorChar != '/')
  39. path = path.Replace ('/', '\\');
  40. return Path.Combine (BaseDir, path);
  41. }
  42. internal bool GetBool (Hashtable hash, string key, bool deflt)
  43. {
  44. string val = hash [key] as string;
  45. if (val == null)
  46. return deflt;
  47. hash.Remove (key);
  48. bool result = false;
  49. if (String.Compare (val, "true", true) == 0)
  50. result = true;
  51. else if (String.Compare (val, "false", true) != 0)
  52. ThrowParseException ("Invalid value for " + key);
  53. return result;
  54. }
  55. internal static string GetString (Hashtable hash, string key, string deflt)
  56. {
  57. string val = hash [key] as string;
  58. if (val == null)
  59. return deflt;
  60. hash.Remove (key);
  61. return val;
  62. }
  63. internal void ThrowParseException (string message)
  64. {
  65. throw new ParseException (location, message);
  66. }
  67. internal void ThrowParseException (string message, Exception inner)
  68. {
  69. throw new ParseException (location, message, inner);
  70. }
  71. internal ILocation Location {
  72. get { return location; }
  73. set { location = value; }
  74. }
  75. internal HttpContext Context {
  76. get { return context; }
  77. set { context = value; }
  78. }
  79. internal string BaseDir {
  80. get {
  81. if (baseDir == null)
  82. baseDir = MapPath (BaseVirtualDir, false);
  83. return baseDir;
  84. }
  85. }
  86. internal virtual string BaseVirtualDir {
  87. get {
  88. if (baseVDir == null)
  89. baseVDir = UrlUtils.GetDirectory (context.Request.FilePath);
  90. return baseVDir;
  91. }
  92. set { baseVDir = value; }
  93. }
  94. internal CompilationConfiguration CompilationConfig {
  95. get {
  96. if (compilationConfig == null)
  97. compilationConfig = CompilationConfiguration.GetInstance (context);
  98. return compilationConfig;
  99. }
  100. }
  101. }
  102. }