Page.jvm.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //
  2. // System.Web.UI.Page.jvm.cs
  3. //
  4. // Authors:
  5. // Eyal Alaluf ([email protected])
  6. //
  7. // (C) 2006 Mainsoft Co. (http://www.mainsoft.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using [email protected];
  29. using javax.servlet.http;
  30. using System.Collections.Specialized;
  31. using System.Globalization;
  32. using System.Web.Hosting;
  33. using System.Web.J2EE;
  34. using System.ComponentModel;
  35. namespace System.Web.UI
  36. {
  37. public partial class Page
  38. {
  39. const string PageNamespaceKey = "__PAGENAMESPACE";
  40. const string RenderPageMark = "vmw.render.page=";
  41. const string ActionPageMark = "vmw.action.page=";
  42. static readonly string NextActionPageKey = PortletInternalUtils.NextActionPage;
  43. static readonly string NextRenderPageKey = PortletInternalUtils.NextRenderPage;
  44. bool _emptyPortletNamespace = false;
  45. string _PortletNamespace = null;
  46. bool _renderResponseInit = false;
  47. IPortletRenderResponse _renderResponse = null;
  48. internal string PortletNamespace
  49. {
  50. get {
  51. if (_emptyPortletNamespace)
  52. return null;
  53. if (_PortletNamespace == null) {
  54. IPortletResponse portletResponse = null;
  55. if (Context != null) {
  56. string usePortletNamespace = J2EEUtils.GetInitParameterByHierarchy (Context.Servlet.getServletConfig (), "mainsoft.use.portlet.namespace");
  57. if (usePortletNamespace == null || Boolean.Parse(usePortletNamespace))
  58. portletResponse = Context.ServletResponse as IPortletResponse;
  59. }
  60. if (portletResponse != null)
  61. _PortletNamespace = portletResponse.getNamespace ();
  62. else if (_requestValueCollection != null && _requestValueCollection [PageNamespaceKey] != null)
  63. _PortletNamespace = _requestValueCollection [PageNamespaceKey];
  64. _emptyPortletNamespace = _PortletNamespace == null;
  65. }
  66. return _PortletNamespace;
  67. }
  68. }
  69. internal string theForm {
  70. get {
  71. return "theForm" + PortletNamespace;
  72. }
  73. }
  74. bool _isMultiForm = false;
  75. bool _isMultiFormInited = false;
  76. internal bool IsMultiForm {
  77. get {
  78. if (!_isMultiFormInited) {
  79. Mainsoft.Web.Configuration.PagesSection pageSection = (Mainsoft.Web.Configuration.PagesSection) System.Web.Configuration.WebConfigurationManager.GetSection ("mainsoft.web/pages");
  80. if (pageSection != null)
  81. _isMultiForm = pageSection.MultiForm;
  82. _isMultiFormInited = true;
  83. }
  84. return _isMultiForm;
  85. }
  86. }
  87. internal bool IsPortletRender
  88. {
  89. get {
  90. return RenderResponse != null;
  91. }
  92. }
  93. internal bool IsGetBack {
  94. get {
  95. return IsPostBack && IsPortletRender &&
  96. (0 == String.Compare (Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase));
  97. }
  98. }
  99. internal IPortletRenderResponse RenderResponse
  100. {
  101. get {
  102. if (!_renderResponseInit)
  103. if (Context != null) {
  104. _renderResponse = Context.ServletResponse as IPortletRenderResponse;
  105. _renderResponseInit = true;
  106. }
  107. return _renderResponse;
  108. }
  109. }
  110. public string CreateRenderUrl (string url)
  111. {
  112. if (RenderResponse != null)
  113. return RenderResponse.createRenderURL (url);
  114. if (PortletNamespace == null)
  115. return url;
  116. string internalUrl = RemoveAppPathIfInternal (url);
  117. if (internalUrl == null)
  118. return url;
  119. PostBackOptions options = new PostBackOptions (this);
  120. options.ActionUrl = RenderPageMark + internalUrl;
  121. options.RequiresJavaScriptProtocol = true;
  122. return ClientScript.GetPostBackEventReference (options);
  123. }
  124. public string CreateActionUrl (string url)
  125. {
  126. if (url.StartsWith (RenderPageMark, StringComparison.Ordinal) || url.StartsWith (ActionPageMark, StringComparison.Ordinal))
  127. return url;
  128. if (RenderResponse != null)
  129. return RenderResponse.createActionURL (url);
  130. if (PortletNamespace == null)
  131. return url;
  132. Uri requestUrl = Request.Url;
  133. string internalUrl = RemoveAppPathIfInternal (url);
  134. if (internalUrl == null)
  135. return url;
  136. return ActionPageMark + internalUrl;
  137. }
  138. private string RemoveAppPathIfInternal (string url)
  139. {
  140. Uri reqUrl = Request.Url;
  141. string appPath = Request.ApplicationPath;
  142. string currPage = Request.CurrentExecutionFilePath;
  143. if (currPage.StartsWith (appPath, StringComparison.InvariantCultureIgnoreCase))
  144. currPage = currPage.Substring (appPath.Length);
  145. return PortletInternalUtils.mapPathIfInternal (url, reqUrl.Host, reqUrl.Port, reqUrl.Scheme, appPath, currPage);
  146. }
  147. internal bool OnSaveStateCompleteForPortlet ()
  148. {
  149. if (PortletNamespace != null) {
  150. ClientScript.RegisterHiddenField (PageNamespaceKey, PortletNamespace);
  151. ClientScript.RegisterHiddenField (NextActionPageKey, "");
  152. ClientScript.RegisterHiddenField (NextRenderPageKey, "");
  153. }
  154. IPortletActionResponse resp = Context.ServletResponse as IPortletActionResponse;
  155. IPortletActionRequest req = Context.ServletRequest as IPortletActionRequest;
  156. if (req == null)
  157. return false;
  158. // When redirecting don't save the page viewstate and hidden fields
  159. if (resp.isRedirected ())
  160. return true;
  161. if (IsPostBack && 0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
  162. resp.setRenderParameter ("__VIEWSTATE", GetSavedViewState ());
  163. if (ClientScript.hiddenFields != null)
  164. foreach (string key in ClientScript.hiddenFields.Keys)
  165. resp.setRenderParameter (key, (string) ClientScript.hiddenFields [key]);
  166. if (is_validated && Validators.Count > 0) {
  167. string validatorsState = GetValidatorsState ();
  168. #if DEBUG
  169. Console.WriteLine ("__VALIDATORSSTATE: " + validatorsState);
  170. #endif
  171. if (!String.IsNullOrEmpty (validatorsState))
  172. resp.setRenderParameter ("__VALIDATORSSTATE", validatorsState);
  173. }
  174. }
  175. // Stop processing only if we are handling processAction. If we
  176. // are handling a postback from render then fall through.
  177. return req.processActionOnly ();
  178. }
  179. string GetValidatorsState () {
  180. bool [] validatorsState = new bool [Validators.Count];
  181. bool isValid = true;
  182. for (int i = 0; i < Validators.Count; i++) {
  183. IValidator val = Validators [i];
  184. if (!val.IsValid)
  185. isValid = false;
  186. else
  187. validatorsState [i] = true;
  188. }
  189. if (isValid)
  190. return null;
  191. return GetFormatter ().Serialize (validatorsState);
  192. }
  193. void RestoreValidatorsState () {
  194. string validatorsStateSerialized = Request.Form ["__VALIDATORSSTATE"];
  195. if (String.IsNullOrEmpty (validatorsStateSerialized))
  196. return;
  197. is_validated = true;
  198. bool [] validatorsState = (bool []) GetFormatter ().Deserialize (validatorsStateSerialized);
  199. for (int i = 0; i < Math.Min (validatorsState.Length, Validators.Count); i++) {
  200. IValidator val = Validators [i];
  201. val.IsValid = validatorsState [i];
  202. }
  203. }
  204. }
  205. }