merged Sys.Web.Services 2.0 support in my branch:
[mono.git] / mcs / class / System.Web / Test / tools / HtmlWriter.cs
1 using System;
2 using System.IO;
3 using System.Diagnostics;
4 using System.Web.UI;
5 using System.Reflection;
6
7 namespace Helper {
8         public class HtmlWriter : HtmlTextWriter {
9                 bool full_trace;
10                 TextWriter output;
11                 int call_count;
12
13                 int NextIndex ()
14                 {
15                         return call_count++;
16                 }
17
18                 public HtmlWriter (TextWriter writer) : this (writer, DefaultTabString)
19                 {
20                 }
21         
22                 public HtmlWriter (TextWriter writer, string tabString) : base (writer, tabString)
23                 {
24                         full_trace = (Environment.GetEnvironmentVariable ("HTMLWRITER_FULLTRACE") == "yes");
25                         string file = Environment.GetEnvironmentVariable ("HTMLWRITER_FILE");
26                         Console.WriteLine ("file: '{0}' (null? {1})", file, file == null);
27                         if (file != null && file != "") {
28                                 output = new StreamWriter (new FileStream (file, FileMode.OpenOrCreate | FileMode.Append));
29                                 Console.WriteLine ("Sending log to '{0}'.", file);
30                         } else {
31                                 output = Console.Out;
32                         }
33                 }
34
35                 void WriteTrace (StackTrace trace)
36                 {
37                         int n = trace.FrameCount;
38                         for (int i = 0; i < n; i++) {
39                                 StackFrame frame = trace.GetFrame (i);
40                                 Type type = frame.GetMethod ().DeclaringType;
41                                 string ns = type.Namespace;
42                                 if (ns != "Helper" && !ns.StartsWith ("System.Web.UI"))
43                                         break;
44                                 output.Write ("\t{0}.{1}", type.Name, frame);
45                         }
46                         output.WriteLine ();
47                 }
48
49                 public override void AddAttribute (HtmlTextWriterAttribute key, string value, bool fEncode)
50                 {
51                         output.WriteLine ("{0:###0} AddAttribute ({1}, {2}, {3}))", NextIndex (), key, value, fEncode);
52                         if (full_trace)
53                                 WriteTrace (new StackTrace ());
54
55                         base.AddAttribute (key, value, fEncode);
56                 }
57                 
58                 public override void AddAttribute (string name, string value, bool fEncode)
59                 {
60                         output.WriteLine ("{0:###0} AddAttribute ({1}, {2}, {3}))", NextIndex (), name, value, fEncode);
61                         if (full_trace)
62                                 WriteTrace (new StackTrace ());
63
64                         if (fEncode)
65                                 ; // FIXME
66
67                         base.AddAttribute (name, value, (HtmlTextWriterAttribute) 0);
68                 }
69                 
70                 protected override void AddAttribute (string name, string value, HtmlTextWriterAttribute key)
71                 {
72                         output.WriteLine ("{0:###0} AddAttribute ({1}, {2}, {3}))", NextIndex (), name, value, key);
73                         if (full_trace)
74                                 WriteTrace (new StackTrace ());
75
76                         base.AddAttribute (name, value, key);
77                 }
78                 
79                 protected override void AddStyleAttribute (string name, string value, HtmlTextWriterStyle key)
80                 {
81                         output.WriteLine ("{0:###0} AddStyleAttribute ({1}, {2}, {3}))", NextIndex (), name, value, key);
82                         if (full_trace)
83                                 WriteTrace (new StackTrace ());
84
85                         base.AddStyleAttribute (name, value, key);
86                 }
87                 
88                 public override void Close ()
89                 {
90                         output.WriteLine ("{0:###0} Close ()", NextIndex ());
91                         if (full_trace)
92                                 WriteTrace (new StackTrace ());
93
94                         if (output != Console.Out)
95                                 output.Close ();
96                         base.Close ();  
97                 }
98
99                 protected override string EncodeAttributeValue (HtmlTextWriterAttribute attrKey, string value)
100                 {
101                         output.WriteLine ("{0:###0} EncodeAttributeValue ({1}, {2})", NextIndex (), attrKey, value);
102                         if (full_trace)
103                                 WriteTrace (new StackTrace ());
104
105                         return base.EncodeAttributeValue (attrKey, value);
106                 }
107                 
108                 protected override void FilterAttributes ()
109                 {
110                         output.WriteLine ("{0:###0} FilterAttributes ()", NextIndex ());
111                         if (full_trace)
112                                 WriteTrace (new StackTrace ());
113
114                         base.FilterAttributes ();
115                 }
116         
117                 public override void Flush ()
118                 {
119                         output.WriteLine ("{0:###0} Flush ()", NextIndex ());
120                         if (full_trace)
121                                 WriteTrace (new StackTrace ());
122
123                         base.Flush ();
124                 }
125
126                 protected override HtmlTextWriterTag GetTagKey (string tagName) 
127                 {
128                         output.WriteLine ("{0:###0} GetTagKey ({1})", NextIndex (), tagName);
129                         if (full_trace)
130                                 WriteTrace (new StackTrace ());
131
132                         return base.GetTagKey (tagName);
133                 }
134
135                 protected override string GetTagName (HtmlTextWriterTag tagKey)
136                 {
137                         output.WriteLine ("{0:###0} GetTagName ({1})", NextIndex (), tagKey);
138                         if (full_trace)
139                                 WriteTrace (new StackTrace ());
140
141                         return base.GetTagName (tagKey);
142                 }
143                 
144                 protected override bool OnAttributeRender (string name, string value, HtmlTextWriterAttribute key)
145                 {
146                         output.WriteLine ("{0:###0} OnAttributeRender ({1}, {2}, {3})", NextIndex (), name, value, key);
147                         if (full_trace)
148                                 WriteTrace (new StackTrace ());
149
150                         return base.OnAttributeRender (name, value, key);
151                 }
152                 
153                 protected override bool OnStyleAttributeRender (string name, string value, HtmlTextWriterStyle key)
154                 {
155                         output.WriteLine ("{0:###0} OnStyleAttributeRender ({1}, {2}, {3})", NextIndex (), name, value, key);
156                         if (full_trace)
157                                 WriteTrace (new StackTrace ());
158
159                         return base.OnStyleAttributeRender (name, value, key);
160                 }
161                 
162                 protected override bool OnTagRender (string name, HtmlTextWriterTag key)
163                 {
164                         output.WriteLine ("{0:###0} OnTagRender ({1}, {2})", NextIndex (), name, key);
165                         if (full_trace)
166                                 WriteTrace (new StackTrace ());
167
168                         return base.OnTagRender (name, key);
169                 }
170                 
171         
172                 protected override void OutputTabs ()
173                 {
174                         output.WriteLine ("{0:###0} OutputTabs ()", NextIndex ());
175                         if (full_trace)
176                                 WriteTrace (new StackTrace ());
177
178                         base.OutputTabs ();
179                 }
180         
181                 protected override string RenderAfterContent ()
182                 {
183                         output.WriteLine ("{0:###0} RenderAfterContent ()", NextIndex ());
184                         if (full_trace)
185                                 WriteTrace (new StackTrace ());
186
187                         return null;
188                 }
189                 
190                 protected override string RenderAfterTag ()
191                 {
192                         output.WriteLine ("{0:###0} RenderAfterTag ()", NextIndex ());
193                         if (full_trace)
194                                 WriteTrace (new StackTrace ());
195
196                         return null;
197                 }
198                 
199                 protected override string RenderBeforeContent ()
200                 {
201                         output.WriteLine ("{0:###0} RenderBeforeContent ()", NextIndex ());
202                         if (full_trace)
203                                 WriteTrace (new StackTrace ());
204
205                         return null;
206                 }
207                         
208                 protected override string RenderBeforeTag ()
209                 {
210                         output.WriteLine ("{0:###0} RenderBeforeTag ()", NextIndex ());
211                         if (full_trace)
212                                 WriteTrace (new StackTrace ());
213
214                         return null;
215                 }
216
217                 public override void RenderBeginTag (string tagName)
218                 {
219                         output.WriteLine ("{0:###0} RenderBeginTag ({1})", NextIndex (), tagName);
220                         if (full_trace)
221                                 WriteTrace (new StackTrace ());
222
223                         base.RenderBeginTag (tagName);
224                 }
225                 
226                 public override void RenderBeginTag (HtmlTextWriterTag tagKey)
227                 {
228                         output.WriteLine ("{0:###0} RenderBeginTag ({1})", NextIndex (), tagKey);
229                         if (full_trace)
230                                 WriteTrace (new StackTrace ());
231
232                         base.RenderBeginTag (tagKey);
233                 }
234
235                 public override void RenderEndTag ()
236                 {
237                         output.WriteLine ("{0:###0} RenderEndTag ()", NextIndex ());
238                         if (full_trace)
239                                 WriteTrace (new StackTrace ());
240
241                         base.RenderEndTag ();
242                 }
243                 
244                 public override void WriteAttribute (string name, string value, bool fEncode)
245                 {
246                         output.WriteLine ("{0:###0} WriteAttribute ({1}, {2}, {3})", NextIndex (), name, value, fEncode);
247                         if (full_trace)
248                                 WriteTrace (new StackTrace ());
249
250                         base.WriteAttribute (name, value, fEncode);
251                 }
252                 
253         
254                 public override void WriteBeginTag (string tagName)
255                 {
256                         output.WriteLine ("{0:###0} WriteBeginTag ({1})", NextIndex (), tagName);
257                         if (full_trace)
258                                 WriteTrace (new StackTrace ());
259
260                         base.WriteBeginTag (tagName);
261                 }
262                 
263                 public override void WriteEndTag (string tagName)
264                 {
265                         output.WriteLine ("{0:###0} WriteEndTag ({1})", NextIndex (), tagName);
266                         if (full_trace)
267                                 WriteTrace (new StackTrace ());
268
269                         base.WriteEndTag (tagName);
270                 }
271                 
272                 public override void WriteFullBeginTag (string tagName)
273                 {
274                         output.WriteLine ("{0:###0} WriteFullBeginTag ({1})", NextIndex (), tagName);
275                         if (full_trace)
276                                 WriteTrace (new StackTrace ());
277
278                         base.WriteFullBeginTag (tagName);
279                 }
280                         
281                 public override void WriteStyleAttribute (string name, string value, bool fEncode)
282                 {
283                         output.WriteLine ("{0:###0} WriteStyleAttribute ({1}, {2}, {3})", NextIndex (), name, value, fEncode);
284                         if (full_trace)
285                                 WriteTrace (new StackTrace ());
286
287                         base.WriteStyleAttribute (name, value, fEncode);
288                 }
289         }
290 }
291