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 ();
56 chmFile
.Load(info
.FullName
);
57 } catch (Exception e
) {
58 Logger
.Log
.Warn (e
, "Could not load {0}:", info
.Name
);
63 chmFile
.ParseContents (FilterFileContents
);
66 public void FilterFileContents(TextReader text
) {
68 HtmlDocument doc
= new HtmlDocument ();
69 doc
.StreamMode
= true;
70 doc
.ReportNode
+= HandleNodeEvent
;
77 Logger
.Log
.Warn (e
, "Error parsing file contents");
78 //Console.WriteLine (e.Message);
79 //Console.WriteLine (e.StackTrace);
85 override protected void DoPullProperties()
87 AddProperty (Beagle
.Property
.New ("dc:title", chmFile
.Title
));
90 override protected void DoPull()
95 override protected void DoClose()
100 override protected void RegisterSupportedTypes()
102 AddSupportedFlavor (FilterFlavor
.NewFromMimeType ("application/x-chm"));