4 // Copyright (C) 2004 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.
29 using System
.Collections
;
37 namespace Beagle
.Filters
{
39 public abstract class FilterOle
: Beagle
.Daemon
.Filter
{
45 protected virtual void ExtractMetaData (Gsf
.Input sum_stream
,
50 protected virtual void OpenStorage (FileInfo info
) {}
52 protected Infile file
;
53 protected DocMetaData sumMeta
= null;
54 protected DocMetaData docSumMeta
= null;
55 protected string FileName
;
57 override protected void DoOpen (FileInfo info
)
61 Input input
= new InputStdio (info
.FullName
);
63 input
= input
.Uncompress();
64 file
= new InfileMSOle (input
);
66 if (input
== null || file
== null) {
67 Logger
.Log
.Error ("Unable to open [{0}] ",info
.FullName
);
68 Console
.WriteLine ("input/file is null");
74 } catch (Exception e
) {
75 Logger
.Log
.Error ("Unable to open "+info
.FullName
);
76 Console
.WriteLine ("{0}", e
.Message
);
82 void PullMetaData (Gsf
.Input sum_stream
, Gsf
.Input doc_stream
)
88 sumMeta
= new DocMetaData ();
89 if (sum_stream
!= null)
90 Msole
.MetadataRead (sum_stream
, sumMeta
);
92 Logger
.Log
.Warn ("SummaryInformationStream not found in {0}", FileName
);
94 docSumMeta
= new DocMetaData ();
95 if (doc_stream
!= null)
96 Msole
.MetadataRead (doc_stream
, docSumMeta
);
98 Logger
.Log
.Warn ("DocumentSummaryInformationStream not found in {0}", FileName
);
100 if (sumMeta
!= null) {
101 prop
= sumMeta
.Lookup ("dc:title");
103 str
= prop
.Val
as string;
104 if (str
!= null && str
.Length
> 0)
105 AddProperty (Beagle
.Property
.New ("dc:title", str
));
108 prop
= sumMeta
.Lookup ("dc:subject");
110 str
= prop
.Val
as string;
111 if (str
!= null && str
.Length
> 0)
112 AddProperty (Beagle
.Property
.New ("dc:subject", str
));
115 prop
= sumMeta
.Lookup ("dc:description");
117 str
= prop
.Val
as string;
118 if (str
!= null && str
.Length
> 0)
119 AddProperty (Beagle
.Property
.New ("dc:description", str
));
122 prop
= sumMeta
.Lookup ("gsf:keywords");
124 str
= prop
.Val
as string;
125 if (str
!= null && str
.Length
> 0)
126 AddProperty (Beagle
.Property
.New ("fixme:keywords", str
));
129 prop
= sumMeta
.Lookup ("gsf:creator");
131 str
= prop
.Val
as string;
132 if (str
!= null && str
.Length
> 0)
133 AddProperty (Beagle
.Property
.New ("fixme:author", str
));
136 prop
= sumMeta
.Lookup ("gsf:last-saved-by");
138 str
= prop
.Val
as string;
139 if (str
!= null && str
.Length
> 0)
140 AddProperty (Beagle
.Property
.New ("fixme:last-saved-by", str
));
143 prop
= sumMeta
.Lookup ("gsf:generator");
145 str
= prop
.Val
as string;
146 if (str
!= null && str
.Length
> 0)
147 AddProperty (Beagle
.Property
.New ("fixme:generator", str
));
150 prop
= sumMeta
.Lookup ("gsf:template");
152 str
= prop
.Val
as string;
153 if (str
!= null && str
.Length
> 0)
154 AddProperty (Beagle
.Property
.New ("fixme:template", str
));
157 if (docSumMeta
!= null) {
159 prop
= docSumMeta
.Lookup ("gsf:company");
161 str
= prop
.Val
as string;
162 if (str
!= null && str
.Length
> 0)
163 AddProperty (Beagle
.Property
.New ("fixme:company", str
));
166 prop
= docSumMeta
.Lookup ("gsf:category");
168 str
= prop
.Val
as string;
169 if (str
!= null && str
.Length
> 0)
170 AddProperty (Beagle
.Property
.New ("fixme:category", str
));
174 ExtractMetaData (sum_stream
, doc_stream
);
177 override protected void DoPullProperties ()
179 Input sum_stream
= null;
180 Input doc_stream
= null;
191 sum_stream
= file
.ChildByName ("\u0005SummaryInformation");
192 doc_stream
= file
.ChildByName ("\u0005DocumentSummaryInformation");
194 PullMetaData (sum_stream
, doc_stream
);
195 } catch (Exception e
) {
196 Logger
.Log
.Error ("Exception occurred duing DoPullProperties.");
197 Logger
.Log
.Error (e
);
203 FIXME: Uncomment this when Shutdown() is
205 override protected void DoClose ()
207 Gsf.Global.Shutdown ();
211 // FIXME: These are utility functions and can be useful
212 // outside this filter as well.
213 public static int GetInt32 (byte [] data
, int offset
) {
214 return data
[offset
] + (data
[offset
+ 1] << 8) + (data
[offset
+ 2] << 16) + (data
[offset
+ 3] << 24);
216 public static int GetInt16 (byte [] data
, int offset
) {
217 return data
[offset
] + (data
[offset
+ 1] << 8);