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
)
62 Input input
= new InputStdio (info
.FullName
);
65 Input uncompressed_input
= input
.Uncompress();
67 file
= new InfileMSOle (uncompressed_input
);
68 uncompressed_input
.Dispose ();
71 if (input
== null || file
== null) {
72 Logger
.Log
.Error ("Unable to open [{0}] ",info
.FullName
);
73 Console
.WriteLine ("input/file is null");
79 } catch (Exception e
) {
80 Logger
.Log
.Error ("Unable to open "+info
.FullName
);
81 Console
.WriteLine ("{0}", e
.Message
);
87 void PullMetaData (Gsf
.Input sum_stream
, Gsf
.Input doc_stream
)
93 sumMeta
= new DocMetaData ();
94 if (sum_stream
!= null)
95 Msole
.MetadataRead (sum_stream
, sumMeta
);
97 Logger
.Log
.Warn ("SummaryInformationStream not found in {0}", FileName
);
99 docSumMeta
= new DocMetaData ();
100 if (doc_stream
!= null)
101 Msole
.MetadataRead (doc_stream
, docSumMeta
);
103 Logger
.Log
.Warn ("DocumentSummaryInformationStream not found in {0}", FileName
);
105 if (sumMeta
!= null) {
106 prop
= sumMeta
.Lookup ("dc:title");
108 str
= prop
.Val
as string;
109 if (str
!= null && str
.Length
> 0)
110 AddProperty (Beagle
.Property
.New ("dc:title", str
));
113 prop
= sumMeta
.Lookup ("dc:subject");
115 str
= prop
.Val
as string;
116 if (str
!= null && str
.Length
> 0)
117 AddProperty (Beagle
.Property
.New ("dc:subject", str
));
120 prop
= sumMeta
.Lookup ("dc:description");
122 str
= prop
.Val
as string;
123 if (str
!= null && str
.Length
> 0)
124 AddProperty (Beagle
.Property
.New ("dc:description", str
));
127 prop
= sumMeta
.Lookup ("gsf:keywords");
129 str
= prop
.Val
as string;
130 if (str
!= null && str
.Length
> 0)
131 AddProperty (Beagle
.Property
.New ("fixme:keywords", str
));
134 prop
= sumMeta
.Lookup ("gsf:creator");
136 str
= prop
.Val
as string;
137 if (str
!= null && str
.Length
> 0)
138 AddProperty (Beagle
.Property
.New ("fixme:author", str
));
141 prop
= sumMeta
.Lookup ("gsf:last-saved-by");
143 str
= prop
.Val
as string;
144 if (str
!= null && str
.Length
> 0)
145 AddProperty (Beagle
.Property
.New ("fixme:last-saved-by", str
));
148 prop
= sumMeta
.Lookup ("gsf:generator");
150 str
= prop
.Val
as string;
151 if (str
!= null && str
.Length
> 0)
152 AddProperty (Beagle
.Property
.New ("fixme:generator", str
));
155 prop
= sumMeta
.Lookup ("gsf:template");
157 str
= prop
.Val
as string;
158 if (str
!= null && str
.Length
> 0)
159 AddProperty (Beagle
.Property
.New ("fixme:template", str
));
162 if (docSumMeta
!= null) {
164 prop
= docSumMeta
.Lookup ("gsf:company");
166 str
= prop
.Val
as string;
167 if (str
!= null && str
.Length
> 0)
168 AddProperty (Beagle
.Property
.New ("fixme:company", str
));
171 prop
= docSumMeta
.Lookup ("gsf:category");
173 str
= prop
.Val
as string;
174 if (str
!= null && str
.Length
> 0)
175 AddProperty (Beagle
.Property
.New ("fixme:category", str
));
179 ExtractMetaData (sum_stream
, doc_stream
);
184 if (docSumMeta
!= null)
185 docSumMeta
.Dispose ();
188 override protected void DoPullProperties ()
190 Input sum_stream
= null;
191 Input doc_stream
= null;
202 sum_stream
= file
.ChildByName ("\u0005SummaryInformation");
203 doc_stream
= file
.ChildByName ("\u0005DocumentSummaryInformation");
205 PullMetaData (sum_stream
, doc_stream
);
206 } catch (Exception e
) {
207 Logger
.Log
.Error (e
, "Exception occurred duing DoPullProperties.");
210 if (sum_stream
!= null)
211 sum_stream
.Dispose ();
212 if (doc_stream
!= null)
213 doc_stream
.Dispose ();
217 override protected void DoClose ()
222 Log
.Debug ("File should be closed now or very shortly.");
224 // FIXME: Uncomment this when Shutdown() is available in gsf#
225 // Gsf.Global.Shutdown ();
228 // FIXME: These are utility functions and can be useful
229 // outside this filter as well.
230 public static uint GetInt32 (byte [] data
, int offset
) {
231 return (uint)(data
[offset
] + (data
[offset
+ 1] << 8) + (data
[offset
+ 2] << 16) + (data
[offset
+ 3] << 24));
233 public static ushort GetInt16 (byte [] data
, int offset
) {
234 return (ushort)(data
[offset
] + (data
[offset
+ 1] << 8));