2 // FilterChm.cs : Trivial implementation of a CHM filter.
4 // Copyright (C) 2005,2006 Miguel Cabrera <mfcabrera@gmail.com>
7 // Permission is hereby granted, free of charge, to any person obtaining a
8 // copy of this software and associated documentation files (the "Software"),
9 // to deal in the Software without restriction, including without limitation
10 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 // and/or sell copies of the Software, and to permit persons to whom the
12 // Software is furnished to do so, subject to the following conditions:
14 // The above copyright notice and this permission notice shall be included in
15 // all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 // DEALINGS IN THE SOFTWARE.
27 using System
.Collections
;
30 using HtmlAgilityPack
;
35 namespace Beagle
.Filters
{
37 public class FilterChm
: FilterHtml
{
41 public FilterChm () : base()
44 RegisterSupportedTypes ();
49 override protected void DoOpen (FileInfo info
)
52 chmFile
= new ChmFile ();
57 chmFile
.Load(info
.FullName
);
62 Logger
.Log
.Warn ("Could not load {0}: {1}", info
.Name
, e
.Message
);
69 chmFile
.ParseContents (FilterFileContents
);
75 public void FilterFileContents(TextReader text
) {
77 HtmlDocument doc
= new HtmlDocument ();
78 doc
.StreamMode
= true;
79 doc
.ReportNode
+= HandleNodeEvent
;
86 Logger
.Log
.Warn ("Error parsing file contents: {0}",e
.Message
);
87 //Console.WriteLine (e.Message);
88 //Console.WriteLine (e.StackTrace);
94 override protected void DoPullProperties()
97 if(chmFile
.Title
!= "")
98 AddProperty (Beagle
.Property
.New ("dc:title", chmFile
.Title
));
103 override protected void DoPull()
112 override protected void DoClose()
118 override protected void RegisterSupportedTypes()
120 AddSupportedFlavor (FilterFlavor
.NewFromMimeType ("application/x-chm"));