2 // A provider to display man pages
5 // Johannes Roith <johannes@roith.de>
6 // Jonathan Pryor <jpryor@novell.com>
8 // (C) 2008 Novell, Inc.
15 using System
.Collections
.Generic
;
17 namespace Monodoc
.Providers
19 public class ManProvider
: Provider
23 public ManProvider (string[] handbookTocFiles
)
25 tocFiles
= handbookTocFiles
;
28 if (!File
.Exists (tocFiles
[0]))
29 throw new FileNotFoundException (String
.Format ("The table of contents, `{0}' does not exist", tocFiles
[0]));
32 public override void PopulateTree (Tree tree
)
34 foreach(string TocFile
in tocFiles
) {
35 XmlDocument doc
= new XmlDocument();
38 XmlNodeList nodeList
= doc
.GetElementsByTagName("manpage");
39 Node nodeToAddChildrenTo
= tree
.RootNode
;
40 var storage
= nodeToAddChildrenTo
.Tree
.HelpSource
.Storage
;
42 foreach (XmlNode node
in nodeList
) {
44 XmlAttribute name
= node
.Attributes
["name"];
45 XmlAttribute page
= node
.Attributes
["page"];
47 if (name
== null || page
== null) continue;
49 if (!File
.Exists (page
.Value
))
52 string target
= "man:" + name
.Value
;
53 nodeToAddChildrenTo
.CreateNode (name
.Value
, target
);
55 if (File
.Exists (page
.Value
))
56 using (var file
= File
.OpenRead (page
.Value
))
57 storage
.Store (name
.Value
, file
);
62 public override void CloseTree (HelpSource hs
, Tree tree
)
67 public class ManHelpSource
: HelpSource
69 const string ManPrefix
= "man:";
70 Dictionary
<string, Node
> nodesMap
;
72 public ManHelpSource (string base_file
, bool create
) : base (base_file
, create
)
74 nodesMap
= Tree
.RootNode
.ChildNodes
.ToDictionary (n
=> n
.Element
);
77 // Since man always has a flat tree and rather small amount of item
78 // we store them in a dictionary
79 public override Node
MatchNode (string url
)
82 return nodesMap
.TryGetValue (url
, out result
) ? result
: null;
85 public override DocumentType
GetDocumentTypeForId (string id
)
87 return id
== "root:" ? DocumentType
.TocXml
: DocumentType
.Man
;
90 public override bool IsGeneratedContent (string id
)
95 public override string GetText (string url
)
97 return TreeDumper
.ExportToTocXml (Tree
.RootNode
, "Mono Documentation Library", "Available man pages:");
100 protected override string UriPrefix
{