Page.jvm.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. internal bool IsMultiForm {
  75. get {
  76. Mainsoft.Web.Configuration.PagesSection pageSection = (Mainsoft.Web.Configuration.PagesSection) System.Web.Configuration.WebConfigurationManager.GetSection ("mainsoft.web/pages");
  77. if (pageSection != null)
  78. return pageSection.MultiForm;
  79. return false;
  80. }
  81. }
  82. internal bool IsPortletRender
  83. {
  84. get {
  85. return RenderResponse != null;
  86. }
  87. }
  88. internal bool IsGetBack {
  89. get {
  90. return IsPostBack && IsPortletRender &&
  91. (0 == String.Compare (Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase));
  92. }
  93. }
  94. internal IPortletRenderResponse RenderResponse
  95. {
  96. get {
  97. if (!_renderResponseInit)
  98. if (Context != null) {
  99. _renderResponse = Context.ServletResponse as IPortletRenderResponse;
  100. _renderResponseInit = true;
  101. }
  102. return _renderResponse;
  103. }
  104. }
  105. public string CreateRenderUrl (string url)
  106. {
  107. if (RenderResponse != null)
  108. return RenderResponse.createRenderURL (url);
  109. if (PortletNamespace == null)
  110. return url;
  111. string internalUrl = RemoveAppPathIfInternal (url);
  112. if (internalUrl == null)
  113. return url;
  114. PostBackOptions options = new PostBackOptions (this);
  115. options.ActionUrl = RenderPageMark + internalUrl;
  116. options.RequiresJavaScriptProtocol = true;
  117. return ClientScript.GetPostBackEventReference (options);
  118. }
  119. public string CreateActionUrl (string url)
  120. {
  121. if (url.StartsWith (RenderPageMark, StringComparison.Ordinal) || url.StartsWith (ActionPageMark, StringComparison.Ordinal))
  122. return url;
  123. if (RenderResponse != null)
  124. return RenderResponse.createActionURL (url);
  125. if (PortletNamespace == null)
  126. return url;
  127. Uri requestUrl = Request.Url;
  128. string internalUrl = RemoveAppPathIfInternal (url);
  129. if (internalUrl == null)
  130. return url;
  131. return ActionPageMark + internalUrl;
  132. }
  133. private string RemoveAppPathIfInternal (string url)
  134. {
  135. Uri reqUrl = Request.Url;
  136. string appPath = Request.ApplicationPath;
  137. string currPage = Request.CurrentExecutionFilePath;
  138. if (currPage.StartsWith (appPath, StringComparison.InvariantCultureIgnoreCase))
  139. currPage = currPage.Substring (appPath.Length);
  140. return PortletInternalUtils.mapPathIfInternal (url, reqUrl.Host, reqUrl.Port, reqUrl.Scheme, appPath, currPage);
  141. }
  142. internal bool OnSaveStateCompleteForPortlet ()
  143. {
  144. if (PortletNamespace != null) {
  145. ClientScript.RegisterHiddenField (PageNamespaceKey, PortletNamespace);
  146. ClientScript.RegisterHiddenField (NextActionPageKey, "");
  147. ClientScript.RegisterHiddenField (NextRenderPageKey, "");
  148. }
  149. IPortletActionResponse resp = Context.ServletResponse as IPortletActionResponse;
  150. IPortletActionRequest req = Context.ServletRequest as IPortletActionRequest;
  151. if (req == null)
  152. return false;
  153. // When redirecting don't save the page viewstate and hidden fields
  154. if (resp.isRedirected ())
  155. return true;
  156. if (IsPostBack && 0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
  157. resp.setRenderParameter ("__VIEWSTATE", GetSavedViewState ());
  158. if (ClientScript.hiddenFields != null)
  159. foreach (string key in ClientScript.hiddenFields.Keys)
  160. resp.setRenderParameter (key, (string) ClientScript.hiddenFields [key]);
  161. }
  162. // Stop processing only if we are handling processAction. If we
  163. // are handling a postback from render then fall through.
  164. return req.processActionOnly ();
  165. }
  166. }
  167. }