1 //
2 // System.Web.UI.Adapters.PageAdapter
3 //
4 // Author:
5 //	Dick Porter  <dick@ximian.com>
6 //
7 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.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 
29 using System.Web.UI;
30 using System.Web.UI.WebControls;
31 using System.Collections;
32 using System.Collections.Specialized;
33 
34 namespace System.Web.UI.Adapters
35 {
36 	public abstract class PageAdapter : ControlAdapter
37 	{
PageAdapter()38 		protected PageAdapter ()
39 		{
40 		}
41 
PageAdapter(Page p)42 		internal PageAdapter (Page p) : base (p)
43 		{
44 		}
45 
46 		public virtual StringCollection CacheVaryByHeaders {
47 			get { return null; }
48 		}
49 
50 		public virtual StringCollection CacheVaryByParams {
51 			get { return null; }
52 		}
53 
54 		protected string ClientState
55 		{
56 			get {
57 				return Page.GetSavedViewState ();
58 			}
59 		}
60 
DeterminePostBackMode()61 		public virtual NameValueCollection DeterminePostBackMode ()
62 		{
63 			return Page.DeterminePostBackMode ();
64 		}
65 
GetRadioButtonsByGroup(string groupName)66 		public virtual ICollection GetRadioButtonsByGroup (string groupName)
67 		{
68 			if (radio_button_group == null)
69 				return new ArrayList();
70 			ArrayList radioButtons = (ArrayList) radio_button_group [groupName];
71 			if (radioButtons == null)
72 				return new ArrayList();
73 			return radioButtons;
74 		}
75 
GetStatePersister()76 		public virtual PageStatePersister GetStatePersister ()
77 		{
78 			return new HiddenFieldPageStatePersister ((Page)Control);
79 		}
80 
RegisterRadioButton(RadioButton radioButton)81 		public virtual void RegisterRadioButton (RadioButton radioButton)
82 		{
83 			if (radio_button_group == null)
84 				radio_button_group = new ListDictionary();
85 			ArrayList radioButtons = (ArrayList) radio_button_group [radioButton.GroupName];
86 			if (radioButtons == null)
87 				radio_button_group [radioButton.GroupName] = radioButtons = new ArrayList();
88 			if (!radioButtons.Contains(radioButton))
89 				radioButtons.Add(radioButton);
90 		}
91 
RenderBeginHyperlink(HtmlTextWriter writer, string targetUrl, bool encodeUrl, string softkeyLabel)92 		public virtual void RenderBeginHyperlink (HtmlTextWriter writer,
93 							  string targetUrl,
94 							  bool encodeUrl,
95 							  string softkeyLabel)
96 		{
97 			InternalRenderBeginHyperlink (writer, targetUrl, encodeUrl, softkeyLabel, null);
98 		}
99 
RenderBeginHyperlink(HtmlTextWriter writer, string targetUrl, bool encodeUrl, string softkeyLabel, string accessKey)100 		public virtual void RenderBeginHyperlink (HtmlTextWriter writer,
101 							  string targetUrl,
102 							  bool encodeUrl,
103 							  string softkeyLabel,
104 							  string accessKey)
105 		{
106 			if (accessKey != null && accessKey.Length > 1)
107 				throw new ArgumentOutOfRangeException("accessKey");
108 			InternalRenderBeginHyperlink (writer, targetUrl, encodeUrl, softkeyLabel, accessKey);
109 		}
110 
InternalRenderBeginHyperlink(HtmlTextWriter w, string targetUrl, bool encodeUrl, string softKeyLabel, string accessKey)111 		void InternalRenderBeginHyperlink (HtmlTextWriter w,
112 						   string targetUrl,
113 						   bool encodeUrl,
114 						   string softKeyLabel,
115 						   string accessKey)
116 		{
117 			w.AddAttribute (HtmlTextWriterAttribute.Href, targetUrl, encodeUrl);
118 			if (accessKey != null)
119 				w.AddAttribute (HtmlTextWriterAttribute.Accesskey, accessKey);
120 			w.RenderBeginTag (HtmlTextWriterTag.A);
121 		}
122 
123 
RenderEndHyperlink(HtmlTextWriter writer)124 		public virtual void RenderEndHyperlink (HtmlTextWriter writer)
125 		{
126 			writer.RenderEndTag();
127 		}
128 
RenderPostBackEvent(HtmlTextWriter writer, string target, string argument, string softkeyLabel, string text)129 		public virtual void RenderPostBackEvent (HtmlTextWriter writer,
130 							 string target,
131 							 string argument,
132 							 string softkeyLabel,
133 							 string text)
134 		{
135 			RenderPostBackEvent (writer, target, argument, softkeyLabel, text, Page.Request.FilePath, null, true);
136 		}
137 
RenderPostBackEvent(HtmlTextWriter writer, string target, string argument, string softkeyLabel, string text, string postUrl, string accessKey)138 		public virtual void RenderPostBackEvent (HtmlTextWriter writer,
139 							 string target,
140 							 string argument,
141 							 string softkeyLabel,
142 							 string text,
143 							 string postUrl,
144 							 string accessKey)
145 		{
146 			RenderPostBackEvent (writer, target, argument, softkeyLabel, text, postUrl, accessKey, true);
147 		}
148 
RenderPostBackEvent(HtmlTextWriter writer, string target, string argument, string softkeyLabel, string text, string postUrl, string accessKey, bool encode)149 		protected void RenderPostBackEvent (HtmlTextWriter writer,
150 						    string target,
151 						    string argument,
152 						    string softkeyLabel,
153 						    string text,
154 						    string postUrl,
155 						    string accessKey,
156 						    bool encode)
157 		{
158 			string url = String.Format ("{0}?__VIEWSTATE={1}&__EVENTTARGET={2}&__EVENTARGUMENT={3}&__PREVIOUSPAGE={4}",
159 				postUrl, HttpUtility.UrlEncode (Page.GetSavedViewState ()), target, argument, Page.Request.FilePath);
160 			RenderBeginHyperlink (writer, url, encode, softkeyLabel, accessKey);
161 			writer.Write(text);
162 			RenderEndHyperlink(writer);
163 		}
164 
TransformText(string text)165 		public virtual string TransformText (string text)
166 		{
167 			return text;
168 		}
169 
GetPostBackFormReference(string formId)170 		protected internal virtual string GetPostBackFormReference (string formId)
171 		{
172 			return String.Format("document.forms['{0}']", formId);
173 		}
174 
175 		ListDictionary radio_button_group;
176 	}
177 }
178 
179