[Mono-docs-list] Monodoc aspx .1

Ben Maurer bmaurer@users.sourceforge.net
12 Jul 2003 20:23:56 -0500


--=-KQ2V2FeNEA0bu/xmVj+A
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hello everyone,
After a long day of hacking, I have finished up a beta version of a web
based monodoc.

Here are the things that we can do so far: 
      * View pages from all providers 
      * View images 
      * Navigate links
One issue that I know about is that in the url root:/monohb, only if you
refresh the page does the output i want come out. Also, if you view that
page with --html, it comes up the way I don't want it. I need to debug
this. Also, I realize I have to support regular http links/images. I
will do that soon.

Ok, now for the `how do I install that'

      * Install jluke's patch [Mono-docs-list] path fix for provider.cs 
      * Install the two patches I have attached. (this is a workaround
        for a bug in the runtime with threading). 
      * Create a directory for xsp to work in 
      * move browser.exe in that bin/. also cp that file to browser.dll
        (this is a hack that we will fix) 
      * Compile the attached .cs file, /r:browser.exe. Make sure to
        replace /devel/install with your own path. 
      * register the provider in web.config. The following will work
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <customErrors mode="Off" />
	<authentication mode= "Forms" />

	<httpHandlers>
		<add verb="*" path="*.mdoc"
type="Mono.Website.Handlers.MonodocHandler,Mono.Website" />
	</httpHandlers> 

	</system.web>
</configuration>
      * Visit the page in xsp


Enjoy!

-- Ben

--=-KQ2V2FeNEA0bu/xmVj+A
Content-Disposition: attachment; filename=monodocasp.patch
Content-Type: text/x-patch; name=monodocasp.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

Index: ChangeLog
===================================================================
RCS file: /cvs/public/monodoc/browser/ChangeLog,v
retrieving revision 1.46
diff -u -r1.46 ChangeLog
--- ChangeLog	11 Jul 2003 02:00:07 -0000	1.46
+++ ChangeLog	13 Jul 2003 01:24:20 -0000
@@ -1,3 +1,9 @@
+2003-07-12  Ben Maurer <bmaurer@users.sourceforge.net>
+	* browser.cs: Added support for visiting nodes from the root tree.
+	* ecma-provider.cs: Render the root: url with a list of namespaces
+	* provider.cs: Send the root:/xxx to the help sources. Handle
+	root:
+
 2003-07-10  Ben Maurer <bmaurer@users.sourceforge.net>
 
 	* mono-ecma.xsl: Don't generate the excess monodoc namespaces.
Index: browser.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/browser.cs,v
retrieving revision 1.37
diff -u -r1.37 browser.cs
--- browser.cs	11 Jul 2003 00:13:10 -0000	1.37
+++ browser.cs	13 Jul 2003 01:24:20 -0000
@@ -529,10 +529,16 @@
 
 		public override void Go ()
 		{
+			string res;
 			Node x;
 			
-			string res = n.tree.HelpSource.GetText (url, out x);
-			((Browser)browser).Render (res, n, url);
+			// The root tree has no help source
+			if (n.tree.HelpSource != null)
+				res = n.tree.HelpSource.GetText (url, out x);
+			else
+				res = ((RootTree)n.tree).RenderUrl (url, out x);
+					
+			browser.Render (res, n, url);
 		}
 	}
 
@@ -554,23 +560,25 @@
 
 		if (tree_view.Selection.GetSelected (out model, ref iter)){
 			Node n = (Node) iter_to_node [iter];
-
-			if (n.tree.HelpSource == null)
-				return;
-
-			string url = n.URL;
 			
-			//
-			// Try the tree-based urls first.
-			//
+			string url = n.URL;
 			Node match;
-			string s = n.tree.HelpSource.GetText (url, out match);
-			if (s != null){
-				((Browser)browser).Render (s, null, url);
-				browser.history.AppendHistory (new NodePageVisit (browser, n, url));
-				return;
+			string s;
+			
+			if (n.tree.HelpSource != null)
+			{
+				//
+				// Try the tree-based urls first.
+				//
+				
+				s = n.tree.HelpSource.GetText (url, out match);
+				if (s != null){
+					((Browser)browser).Render (s, null, url);
+					browser.history.AppendHistory (new NodePageVisit (browser, n, url));
+					return;
+				}
 			}
-
+			
 			//
 			// Try the url resolver next
 			//
Index: ecma-provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/ecma-provider.cs,v
retrieving revision 1.51
diff -u -r1.51 ecma-provider.cs
--- ecma-provider.cs	10 Jul 2003 16:34:32 -0000	1.51
+++ ecma-provider.cs	13 Jul 2003 01:24:21 -0000
@@ -384,6 +384,17 @@
 	public override string GetText (string url, out Node match_node)
 	{
 		match_node = null;
+		
+		if (url == "root:")
+		{
+			StringBuilder sb = new StringBuilder ();
+			
+			foreach (Node ns_node in Tree.Nodes)
+				sb.AppendFormat ("<a href='{0}'>{1}</a></br>", ns_node.Element, ns_node.Element.Substring (2));				
+				
+			return sb.ToString ();
+		}
+		
 		if (url.StartsWith ("ecma:"))
 			return GetTextFromUrl (url);
 
Index: monohb-provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/monohb-provider.cs,v
retrieving revision 1.4
diff -u -r1.4 monohb-provider.cs
--- monohb-provider.cs	18 Jun 2003 13:24:57 -0000	1.4
+++ monohb-provider.cs	13 Jul 2003 01:24:21 -0000
@@ -20,7 +20,7 @@
 			string cssClass = ((XmlElement)node).GetAttribute("class");
 			if (cssClass != null && (cssClass == "topframe" || cssClass == "navbar" || cssClass == "copyright"))
 			{
-				node.RemoveAll();
+				node.ParentNode.RemoveChild (node);
 			}
                                                                                 
 		}
@@ -53,7 +53,7 @@
 		bodynode.RemoveChild(firstheading);
 
 	bodynode.InnerXml =	"<table width=\"100%\">" +
-			"<tr bgcolor=\"#b0c4dae\"><td><i></i>Mono Handbook<h3>" + headinginner + "</h3></td></tr></table><p />" +
+			"<tr bgcolor=\"#b0c4de\"><td><i></i>Mono Handbook<h3>" + headinginner + "</h3></td></tr></table><p />" +
 	bodynode.InnerXml;
 }
 catch {
@@ -117,6 +117,8 @@
 
 		}
 	}
-		return docToProcess;
+		XmlDocument ret = new XmlDocument ();
+		ret.LoadXml (docToProcess.GetElementsByTagName("body")[0].OuterXml);
+		return ret;
 	}
 }
Index: provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/provider.cs,v
retrieving revision 1.34
diff -u -r1.34 provider.cs
--- provider.cs	11 Jul 2003 00:13:10 -0000	1.34
+++ provider.cs	13 Jul 2003 01:24:21 -0000
@@ -641,6 +641,7 @@
 				if (hs == null)
 					continue;
 				root.help_sources.Add (hs);
+				root.name_to_hs [path] = hs;
 
 				Node parent = (Node) root.name_to_node [path];
 				if (parent == null){
@@ -661,6 +662,7 @@
 	// Maintains the name to node mapping
 	//
 	Hashtable name_to_node = new Hashtable ();
+	Hashtable name_to_hs = new Hashtable ();
 	
 	void Populate (Node parent, XmlNodeList xml_node_list)
 	{
@@ -678,7 +680,7 @@
 			}
 			string name = e.InnerText;
 
-			Node n = parent.LookupNode (label, name);
+			Node n = parent.LookupNode (label, "root:/" + name);
 			n.EnsureNodes ();
 			name_to_node [name] = n;
 			XmlNodeList children = xml_node.SelectNodes ("./node");
@@ -812,7 +814,20 @@
 	///    URL.
 	/// </summary>
 	public string RenderUrl (string url, out Node match_node)
-	{
+	{	
+		if (url.StartsWith ("root:"))
+		{
+			match_node = null;
+			if (url == "root:") {
+				StringBuilder sb = new StringBuilder ("<h1>Welcome to Monodoc</h1>");
+				foreach (Node n in Nodes)
+					sb.AppendFormat ("<a href='{0}'>{1}</a></br>", n.Element, n.Caption);
+				return sb.ToString ();
+				
+			} else
+				return ((HelpSource)name_to_hs [url.Substring (6)]).GetText ("root:", out match_node);
+		}
+		
 		if (url.StartsWith ("source-id:")){
 			string rest = url.Substring (10);
 			int p = rest.IndexOf (":");
Index: xhtml-provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/xhtml-provider.cs,v
retrieving revision 1.11
diff -u -r1.11 xhtml-provider.cs
--- xhtml-provider.cs	26 Jun 2003 19:12:02 -0000	1.11
+++ xhtml-provider.cs	13 Jul 2003 01:24:21 -0000
@@ -55,6 +55,27 @@
 	public override string GetText (string url, out Node match_node)
 	{
 		match_node = null;
+		
+		if (url == "root:") {
+			StringBuilder sb = new StringBuilder ();
+			foreach (Node n in Tree.Nodes) {
+				if (n.IsLeaf) { 
+					sb.AppendFormat ("<a href='{0}'>{1}</a></br>", 
+						n.Element.Replace ("source-id:NNN", "source-id:" + SourceID), 
+						n.Caption);
+				} else {
+					sb.AppendFormat ("<h2>{0}</h2>", n.Caption);
+					foreach (Node subNode in n.Nodes) {
+						sb.AppendFormat ("<a href='{0}'>{1}</a></br>", 
+							subNode.Element.Replace ("source-id:NNN", "source-id:" + SourceID), 
+							subNode.Caption);
+					}
+				}
+			}
+			
+			return sb.ToString ();
+		}
+		
 		if (url.IndexOf (XHTML_PREFIX) > -1)
 			return GetTextFromUrl (url);
 
@@ -227,7 +248,7 @@
 			
 			XmlDocument processedDoc = ProcessContent(newdoc);
 			XmlDocument docForMonodoc = RewriteLinks(processedDoc, url);
-			return docForMonodoc.InnerXml;
+			return docForMonodoc.DocumentElement.InnerXml; // get rid of <body>
 		}
 
 		else if (s != null && (fname.EndsWith (".gif") || fname.EndsWith (".jpeg") || fname.EndsWith (".jpg")  || fname.EndsWith(".png")))

--=-KQ2V2FeNEA0bu/xmVj+A
Content-Disposition: attachment; filename=XmlUrlResolver.cs.patch
Content-Type: text/x-patch; name=XmlUrlResolver.cs.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

Index: XmlUrlResolver.cs
===================================================================
RCS file: /cvs/public/mcs/class/System.XML/System.Xml/XmlUrlResolver.cs,v
retrieving revision 1.7
diff -u -r1.7 XmlUrlResolver.cs
--- XmlUrlResolver.cs	19 Jun 2003 20:00:43 -0000	1.7
+++ XmlUrlResolver.cs	13 Jul 2003 01:24:58 -0000
@@ -42,6 +42,9 @@
 		[MonoTODO("Use Credentials; Uri must be absolute.")]
 		public override object GetEntity (Uri absoluteUri, string role, Type ofObjectToReturn)
 		{
+			if (absoluteUri.Scheme == "file")
+				return new FileStream (absoluteUri.LocalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
+
 			// (MS documentation says) parameter role isn't used yet.
 			Stream s = null;
 			using (s) {

--=-KQ2V2FeNEA0bu/xmVj+A
Content-Disposition: attachment; filename=MonodocHandler.cs
Content-Type: text/plain; name=MonodocHandler.cs; charset=UTF-8
Content-Transfer-Encoding: 7bit

//
// 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.Xml;
using System.Xml.Xsl;

namespace Mono.Website.Handlers
{
	public class MonodocHandler : IHttpHandler
	{
		static RootTree help_tree;
		static MonodocHandler ()
		{
			help_tree = RootTree.LoadTree ("/devel/install/lib/monodoc/");
		}

		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 ("WTF!?!!?!");
				}
				
				Stream s = help_tree.GetImage (link);
				
				if (s == null)
					throw new HttpException (404, "File not found");
				
				Copy (s, context.Response.OutputStream);
				return;
			}
			
			PrintDocs (link, context);
		}
		
		
		
		void Copy (Stream input, Stream output)
		{
			const int BUFFER_SIZE=1024; // 1k 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();
		}
		
		void PrintDocs (string url, HttpContext ctx)
		{
			Node n;
			
			
			ctx.Response.Write (@"
<html>
<head>
<script>
<!--
function load ()
{
	objs = document.getElementsByTagName('a');
	for (i = 0; i < objs.length; i++)
	{
		objs[i].href = '" + ctx.Request.Path + @"?link=' + objs[i].href;
	}
			
	objs = document.getElementsByTagName('img');
	for (i = 0; i < objs.length; i++)
	{
		objs[i].src = '" + ctx.Request.Path + @"?link=' + objs[i].src;
	}
}
-->
</script>
<title>Mono Documentation</title>
</head>
<body onLoad='load()'>

			");
			
			ctx.Response.Write (help_tree.RenderUrl (url, out n));
		
			ctx.Response.Write (@"
			</body>
</html>");
		}

		bool IHttpHandler.IsReusable
		{
			get {
				return true;
			}
		}

	}
}
--=-KQ2V2FeNEA0bu/xmVj+A--