%@ WebHandler Language="c#" class="Mono.Website.Handlers.MonodocHandler" %> <%@ Assembly name="monodoc" %> // // Mono.Web.Handlers.MonodocHandler. // // Authors: // Ben Maurer (bmaurer@users.sourceforge.net) // // (C) 2003 Ben Maurer // using System; using System.Collections; using System.IO; using System.Text; using System.Web; using System.Web.UI; using System.Text.RegularExpressions; using System.Xml; using System.Xml.Xsl; using Monodoc; namespace Mono.Website.Handlers { public class MonodocHandler : IHttpHandler { static RootTree help_tree; static MonodocHandler () { help_tree = RootTree.LoadTree (); } void IHttpHandler.ProcessRequest (HttpContext context) { string link = (string) context.Request.Params["link"]; if (link == null) link = "root:"; if (link.StartsWith ("source-id:") && (link.EndsWith (".gif") || link.EndsWith (".jpeg") || link.EndsWith (".jpg") || link.EndsWith(".png"))) { switch (link.Substring (link.LastIndexOf ('.') + 1)) { case "gif": context.Response.ContentType = "image/gif"; break; case "jpeg": case "jpg": context.Response.ContentType = "image/jpeg"; break; case "png": context.Response.ContentType = "image/png"; break; default: throw new Exception ("Internal error"); } Stream s = help_tree.GetImage (link); if (s == null) throw new HttpException (404, "File not found"); Copy (s, context.Response.OutputStream); return; } Node n; string content = help_tree.RenderUrl (link, out n); PrintDocs (content, context); } void Copy (Stream input, Stream output) { const int BUFFER_SIZE=8192; // 8k buf byte [] buffer = new byte [BUFFER_SIZE]; int len; while ( (len = input.Read (buffer, 0, BUFFER_SIZE)) > 0) output.Write (buffer, 0, len); output.Flush(); } string requestPath; void PrintDocs (string content, HttpContext ctx) { Node n; ctx.Response.Write (@"