2 // System.Web.UI.SimpleWebHandlerParser
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
11 using System.Collections;
15 using System.Web.Compilation;
17 namespace System.Web.UI
19 public abstract class SimpleWebHandlerParser
30 protected SimpleWebHandlerParser (HttpContext context, string virtualPath, string physicalPath)
32 this.context = context;
33 this.vPath = virtualPath;
34 this.physPath = physicalPath;
35 GetDirectiveAndContent ();
38 private void GetDirectiveAndContent ()
40 StreamReader reader = new StreamReader (File.OpenRead (physPath));
42 bool directiveFound = false;
43 StringBuilder content = new StringBuilder ();
45 while ((line = reader.ReadLine ()) != null) {
46 string trimmed = line.Trim ();
47 if (!directiveFound && trimmed != String.Empty)
50 if (!directiveFound) {
51 ParseDirective (trimmed);
52 directiveFound = true;
56 content.Append (line + "\n");
57 content.Append (reader.ReadToEnd ());
60 this.program = content.ToString ();
64 private void ParseDirective (string line)
66 MemoryStream st = new MemoryStream (Encoding.Default.GetBytes (line));
67 AspParser parser = new AspParser (physPath, st);
69 ArrayList elems = parser.Elements;
71 throw new ApplicationException ("Error looking for WebService directive.");
73 Directive directive = elems [0] as Directive;
74 if (directive == null)
75 throw new ApplicationException ("Error looking for WebService directive.");
77 if (0 != String.Compare (directive.TagID, DefaultDirectiveName, false))
78 throw new ApplicationException ("Expecting @WebService. Got: " +
81 TagAttributes ta = directive.Attributes;
82 className = ta ["class"] as string;
83 if (className == null)
84 throw new ApplicationException ("No Class attribute found.");
86 string d = ta ["debug"] as string;
88 debug = Convert.ToBoolean (d);
90 language = ta ["language"] as string;
91 if (language != null) {
92 if (0 != String.Compare (language, "C#", false))
93 throw new ApplicationException ("Only C# language is supported.");
96 codeBehind = ta ["codebehind"] as string;
97 if (codeBehind != null) {
98 string ext = Path.GetExtension (codeBehind);
99 if (0 != String.Compare (ext, "cs", false) &&
100 0 != String.Compare (ext, "dll", false))
101 throw new ApplicationException ("Unknown file type in CodeBehind.");
106 protected abstract string DefaultDirectiveName { get; }
108 internal HttpContext Context
115 internal string VirtualPath
122 internal string PhysicalPath
129 internal string ClassName
140 internal string CodeBehind
162 internal string Language
173 internal string Program