PageParser.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // System.Web.UI.PageParser
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. using System;
  10. using System.Collections;
  11. using System.Text;
  12. using System.Web;
  13. using System.Web.Compilation;
  14. using System.Web.Util;
  15. namespace System.Web.UI
  16. {
  17. public sealed class PageParser : TemplateControlParser
  18. {
  19. bool enableSessionState = true;
  20. bool readonlySessionState;
  21. string responseEncoding;
  22. string contentType;
  23. int codepage = -1;
  24. // FIXME: this is here just for DesignTimeTemplateParser. Anything to do?
  25. internal PageParser ()
  26. {
  27. }
  28. internal PageParser (string virtualPath, string inputFile, HttpContext context)
  29. {
  30. Context = context;
  31. BaseVirtualDir = UrlUtils.GetDirectory (virtualPath);
  32. InputFile = inputFile;
  33. AddApplicationAssembly ();
  34. }
  35. public static IHttpHandler GetCompiledPageInstance (string virtualPath,
  36. string inputFile,
  37. HttpContext context)
  38. {
  39. PageParser pp = new PageParser (virtualPath, inputFile, context);
  40. IHttpHandler h = (IHttpHandler) pp.GetCompiledInstance ();
  41. return h;
  42. }
  43. internal override void ProcessMainAttributes (Hashtable atts)
  44. {
  45. string enabless = GetString (atts, "EnableSessionState", null);
  46. if (enabless != null) {
  47. readonlySessionState = (String.Compare (enabless, "readonly", true) == 0);
  48. if (readonlySessionState == true || String.Compare (enabless, "true", true) == 0) {
  49. enableSessionState = true;
  50. } else if (String.Compare (enabless, "false", true) == 0) {
  51. enableSessionState = false;
  52. } else {
  53. ThrowParseException ("Invalid value for EnableSessionState: " + enabless);
  54. }
  55. }
  56. string cp = GetString (atts, "CodePage", null);
  57. if (cp != null) {
  58. if (responseEncoding != null)
  59. ThrowParseException ("CodePage and ResponseEncoding are " +
  60. "mutually exclusive.");
  61. int codepage = 0;
  62. try {
  63. codepage = (int) UInt32.Parse (cp);
  64. } catch {
  65. ThrowParseException ("Invalid value for CodePage: " + cp);
  66. }
  67. try {
  68. Encoding.GetEncoding (codepage);
  69. } catch {
  70. ThrowParseException ("Unsupported codepage: " + cp);
  71. }
  72. }
  73. responseEncoding = GetString (atts, "ResponseEncoding", null);
  74. if (responseEncoding != null) {
  75. if (codepage != -1)
  76. ThrowParseException ("CodePage and ResponseEncoding are " +
  77. "mutually exclusive.");
  78. try {
  79. Encoding.GetEncoding (responseEncoding);
  80. } catch {
  81. ThrowParseException ("Unsupported encoding: " + responseEncoding);
  82. }
  83. }
  84. contentType = GetString (atts, "ContentType", null);
  85. // Ignored by now
  86. GetString (atts, "Buffer", null);
  87. GetString (atts, "ClientTarget", null);
  88. GetString (atts, "Culture", null);
  89. GetString (atts, "EnableViewStateMac", null);
  90. GetString (atts, "ErrorPage", null);
  91. GetString (atts, "LCID", null);
  92. GetString (atts, "Trace", null);
  93. GetString (atts, "TraceMode", null);
  94. GetString (atts, "UICulture", null);
  95. GetBool (atts, "ValidateRequest", true);
  96. base.ProcessMainAttributes (atts);
  97. }
  98. protected override Type CompileIntoType ()
  99. {
  100. AspGenerator generator = new AspGenerator (this);
  101. return generator.GetCompiledType ();
  102. }
  103. internal bool EnableSessionState {
  104. get { return enableSessionState; }
  105. }
  106. internal bool ReadOnlySessionState {
  107. get { return readonlySessionState; }
  108. }
  109. internal override Type DefaultBaseType
  110. {
  111. get {
  112. return typeof (Page);
  113. }
  114. }
  115. internal override string DefaultDirectiveName
  116. {
  117. get {
  118. return "page";
  119. }
  120. }
  121. internal string ResponseEncoding {
  122. get { return responseEncoding; }
  123. }
  124. internal string ContentType {
  125. get { return contentType; }
  126. }
  127. internal int CodePage {
  128. get { return codepage; }
  129. }
  130. }
  131. }