| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- using System;
- using System.IO;
- using System.Diagnostics;
- using System.Web.UI;
- using System.Reflection;
- namespace Helper {
- public class HtmlWriter : HtmlTextWriter {
- bool full_trace;
- TextWriter output;
- int call_count;
- int NextIndex ()
- {
- return call_count++;
- }
- public HtmlWriter (TextWriter writer) : this (writer, DefaultTabString)
- {
- }
-
- public HtmlWriter (TextWriter writer, string tabString) : base (writer, tabString)
- {
- full_trace = (Environment.GetEnvironmentVariable ("HTMLWRITER_FULLTRACE") == "yes");
- string file = Environment.GetEnvironmentVariable ("HTMLWRITER_FILE");
- Console.WriteLine ("file: '{0}' (null? {1})", file, file == null);
- if (file != null && file != "") {
- output = new StreamWriter (new FileStream (file, FileMode.OpenOrCreate | FileMode.Append));
- Console.WriteLine ("Sending log to '{0}'.", file);
- } else {
- output = Console.Out;
- }
- }
- void WriteTrace (StackTrace trace)
- {
- int n = trace.FrameCount;
- for (int i = 0; i < n; i++) {
- StackFrame frame = trace.GetFrame (i);
- Type type = frame.GetMethod ().DeclaringType;
- string ns = type.Namespace;
- if (ns != "Helper" && !ns.StartsWith ("System.Web.UI"))
- break;
- output.Write ("\t{0}.{1}", type.Name, frame);
- }
- output.WriteLine ();
- }
- public override void AddAttribute (HtmlTextWriterAttribute key, string value, bool fEncode)
- {
- output.WriteLine ("{0:###0} AddAttribute ({1}, {2}, {3}))", NextIndex (), key, value, fEncode);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.AddAttribute (key, value, fEncode);
- }
-
- public override void AddAttribute (string name, string value, bool fEncode)
- {
- output.WriteLine ("{0:###0} AddAttribute ({1}, {2}, {3}))", NextIndex (), name, value, fEncode);
- if (full_trace)
- WriteTrace (new StackTrace ());
- if (fEncode)
- ; // FIXME
- base.AddAttribute (name, value, (HtmlTextWriterAttribute) 0);
- }
-
- protected override void AddAttribute (string name, string value, HtmlTextWriterAttribute key)
- {
- output.WriteLine ("{0:###0} AddAttribute ({1}, {2}, {3}))", NextIndex (), name, value, key);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.AddAttribute (name, value, key);
- }
-
- protected override void AddStyleAttribute (string name, string value, HtmlTextWriterStyle key)
- {
- output.WriteLine ("{0:###0} AddStyleAttribute ({1}, {2}, {3}))", NextIndex (), name, value, key);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.AddStyleAttribute (name, value, key);
- }
-
- public override void Close ()
- {
- output.WriteLine ("{0:###0} Close ()", NextIndex ());
- if (full_trace)
- WriteTrace (new StackTrace ());
- if (output != Console.Out)
- output.Close ();
- base.Close ();
- }
- protected override string EncodeAttributeValue (HtmlTextWriterAttribute attrKey, string value)
- {
- output.WriteLine ("{0:###0} EncodeAttributeValue ({1}, {2})", NextIndex (), attrKey, value);
- if (full_trace)
- WriteTrace (new StackTrace ());
- return base.EncodeAttributeValue (attrKey, value);
- }
-
- protected override void FilterAttributes ()
- {
- output.WriteLine ("{0:###0} FilterAttributes ()", NextIndex ());
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.FilterAttributes ();
- }
-
- public override void Flush ()
- {
- output.WriteLine ("{0:###0} Flush ()", NextIndex ());
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.Flush ();
- }
- protected override HtmlTextWriterTag GetTagKey (string tagName)
- {
- output.WriteLine ("{0:###0} GetTagKey ({1})", NextIndex (), tagName);
- if (full_trace)
- WriteTrace (new StackTrace ());
- return base.GetTagKey (tagName);
- }
- protected override string GetTagName (HtmlTextWriterTag tagKey)
- {
- output.WriteLine ("{0:###0} GetTagName ({1})", NextIndex (), tagKey);
- if (full_trace)
- WriteTrace (new StackTrace ());
- return base.GetTagName (tagKey);
- }
-
- protected override bool OnAttributeRender (string name, string value, HtmlTextWriterAttribute key)
- {
- output.WriteLine ("{0:###0} OnAttributeRender ({1}, {2}, {3})", NextIndex (), name, value, key);
- if (full_trace)
- WriteTrace (new StackTrace ());
- return base.OnAttributeRender (name, value, key);
- }
-
- protected override bool OnStyleAttributeRender (string name, string value, HtmlTextWriterStyle key)
- {
- output.WriteLine ("{0:###0} OnStyleAttributeRender ({1}, {2}, {3})", NextIndex (), name, value, key);
- if (full_trace)
- WriteTrace (new StackTrace ());
- return base.OnStyleAttributeRender (name, value, key);
- }
-
- protected override bool OnTagRender (string name, HtmlTextWriterTag key)
- {
- output.WriteLine ("{0:###0} OnTagRender ({1}, {2})", NextIndex (), name, key);
- if (full_trace)
- WriteTrace (new StackTrace ());
- return base.OnTagRender (name, key);
- }
-
-
- protected override void OutputTabs ()
- {
- output.WriteLine ("{0:###0} OutputTabs ()", NextIndex ());
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.OutputTabs ();
- }
-
- protected override string RenderAfterContent ()
- {
- output.WriteLine ("{0:###0} RenderAfterContent ()", NextIndex ());
- if (full_trace)
- WriteTrace (new StackTrace ());
- return null;
- }
-
- protected override string RenderAfterTag ()
- {
- output.WriteLine ("{0:###0} RenderAfterTag ()", NextIndex ());
- if (full_trace)
- WriteTrace (new StackTrace ());
- return null;
- }
-
- protected override string RenderBeforeContent ()
- {
- output.WriteLine ("{0:###0} RenderBeforeContent ()", NextIndex ());
- if (full_trace)
- WriteTrace (new StackTrace ());
- return null;
- }
-
- protected override string RenderBeforeTag ()
- {
- output.WriteLine ("{0:###0} RenderBeforeTag ()", NextIndex ());
- if (full_trace)
- WriteTrace (new StackTrace ());
- return null;
- }
- public override void RenderBeginTag (string tagName)
- {
- output.WriteLine ("{0:###0} RenderBeginTag ({1})", NextIndex (), tagName);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.RenderBeginTag (tagName);
- }
-
- public override void RenderBeginTag (HtmlTextWriterTag tagKey)
- {
- output.WriteLine ("{0:###0} RenderBeginTag ({1})", NextIndex (), tagKey);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.RenderBeginTag (tagKey);
- }
- public override void RenderEndTag ()
- {
- output.WriteLine ("{0:###0} RenderEndTag ()", NextIndex ());
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.RenderEndTag ();
- }
-
- public override void WriteAttribute (string name, string value, bool fEncode)
- {
- output.WriteLine ("{0:###0} WriteAttribute ({1}, {2}, {3})", NextIndex (), name, value, fEncode);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.WriteAttribute (name, value, fEncode);
- }
-
-
- public override void WriteBeginTag (string tagName)
- {
- output.WriteLine ("{0:###0} WriteBeginTag ({1})", NextIndex (), tagName);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.WriteBeginTag (tagName);
- }
-
- public override void WriteEndTag (string tagName)
- {
- output.WriteLine ("{0:###0} WriteEndTag ({1})", NextIndex (), tagName);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.WriteEndTag (tagName);
- }
-
- public override void WriteFullBeginTag (string tagName)
- {
- output.WriteLine ("{0:###0} WriteFullBeginTag ({1})", NextIndex (), tagName);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.WriteFullBeginTag (tagName);
- }
-
- public override void WriteStyleAttribute (string name, string value, bool fEncode)
- {
- output.WriteLine ("{0:###0} WriteStyleAttribute ({1}, {2}, {3})", NextIndex (), name, value, fEncode);
- if (full_trace)
- WriteTrace (new StackTrace ());
- base.WriteStyleAttribute (name, value, fEncode);
- }
- }
- }
|