4 // Copyright (C) 2005 Novell, Inc.
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
31 using System
.Threading
;
36 using ICSharpCode
.SharpZipLib
.Zip
;
38 namespace Beagle
.Filters
{
40 public class FilterMonodoc
: Filter
{
42 ZipFile archive
= null;
44 public FilterMonodoc ()
46 AddSupportedFlavor (FilterFlavor
.NewFromMimeType ("application/monodoc"));
47 // FIXME: Autoconf to find the monodoc prefix
48 AddSupportedFlavor (new FilterFlavor ("file:///usr/lib/monodoc/sources/*", ".zip", null, 0));
51 override protected void DoOpen (FileInfo file
)
54 archive
= new ZipFile (file
.FullName
);
55 } catch (Exception e
) {
56 Logger
.Log
.Error ("Error while filtering Monodoc archive: {0}", e
);
61 override protected void DoPullProperties ()
63 if (archive
== null) {
68 foreach (ZipEntry entry
in archive
) {
69 if (entry
.Name
.IndexOf (".") != -1)
72 XmlDocument document
= new XmlDocument ();
73 document
.Load (archive
.GetInputStream (entry
));
75 XmlNode type
= document
.SelectSingleNode ("/Type");
80 Indexable type_indexable
= TypeNodeToIndexable (type
, FileInfo
);
81 AddChildIndexable (type_indexable
);
83 foreach(XmlNode member
in type
.SelectNodes ("Members/Member")) {
84 Indexable member_indexable
= MemberNodeToIndexable (member
,
86 type
.Attributes
["FullName"].Value
);
87 AddChildIndexable (member_indexable
);
91 // If we've successfully crawled the file but haven't
92 // found any indexables, we shouldn't consider it
93 // successfull at all.
94 if (ChildIndexables
.Count
== 0) {
102 static private Indexable
TypeNodeToIndexable (XmlNode node
, FileInfo file
)
104 Indexable indexable
= new Indexable (UriFu
.PathToFileUri (file
+ "#T:" + node
.Attributes
["FullName"].Value
));
106 indexable
.MimeType
= "text/html";
107 indexable
.HitType
= "MonodocEntry";
109 indexable
.AddProperty (Property
.NewUnsearched ("fixme:type", "type"));
110 indexable
.AddProperty (Property
.NewUnsearched ("fixme:name", "T:" + node
.Attributes
["FullName"].Value
));
112 StringReader reader
= new StringReader (node
.SelectSingleNode ("Docs").InnerXml
);
113 indexable
.SetTextReader (reader
);
118 static private Indexable
MemberNodeToIndexable(XmlNode node
, FileInfo file
, string parentName
)
120 char memberType
= MemberTypeToChar (node
.SelectSingleNode ("MemberType").InnerText
);
121 StringBuilder memberFullName
= new StringBuilder ();
123 memberFullName
.Append (memberType
+ ":"+ parentName
);
125 if (memberType
!= 'C')
126 memberFullName
.Append ("." + node
.Attributes
["MemberName"].Value
);
128 if (memberType
== 'C' || memberType
== 'M' || memberType
== 'E') {
129 memberFullName
.Append ("(");
132 foreach (XmlNode parameter
in node
.SelectNodes ("Parameters/Parameter")) {
133 if (!inside
) inside
= true; else memberFullName
.Append(",");
134 memberFullName
.Append (parameter
.Attributes
["Type"].Value
);
137 memberFullName
.Append (")");
140 Indexable indexable
= new Indexable (UriFu
.PathToFileUri (file
+ "#" + memberFullName
));
142 indexable
.MimeType
= "text/html";
143 indexable
.HitType
= "MonodocEntry";
145 indexable
.AddProperty (Property
.NewUnsearched ("fixme:type", node
.SelectSingleNode ("MemberType").InnerText
.ToLower ()));
146 indexable
.AddProperty (Property
.New ("fixme:name", memberFullName
.ToString ()));
148 StringReader reader
= new StringReader (node
.SelectSingleNode ("Docs").InnerXml
);
149 indexable
.SetTextReader (reader
);
154 static private char MemberTypeToChar (string memberType
)
156 switch (memberType
) {