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
)
92 sumMeta
= new DocMetaData ();
93 if (sum_stream
!= null)
94 Msole
.MetadataRead (sum_stream
, sumMeta
);
96 Logger
.Log
.Warn ("SummaryInformationStream not found in {0}", FileName
);
98 docSumMeta
= new DocMetaData ();
99 if (doc_stream
!= null)
100 Msole
.MetadataRead (doc_stream
, docSumMeta
);
102 Logger
.Log
.Warn ("DocumentSummaryInformationStream not found in {0}", FileName
);
104 if (sumMeta
!= null) {
105 prop
= sumMeta
.Lookup ("dc:title");
107 AddProperty (Beagle
.Property
.New ("dc:title", prop
.Val
as string));
109 prop
= sumMeta
.Lookup ("dc:subject");
111 AddProperty (Beagle
.Property
.New ("dc:subject", prop
.Val
as string));
113 prop
= sumMeta
.Lookup ("dc:description");
115 AddProperty (Beagle
.Property
.New ("dc:description", prop
.Val
as string));
117 prop
= sumMeta
.Lookup ("gsf:keywords");
119 AddProperty (Beagle
.Property
.New ("fixme:keywords", prop
.Val
as string));
121 prop
= sumMeta
.Lookup ("gsf:creator");
123 AddProperty (Beagle
.Property
.New ("fixme:author", prop
.Val
as string));
125 prop
= sumMeta
.Lookup ("gsf:last-saved-by");
127 AddProperty (Beagle
.Property
.New ("fixme:last-saved-by", prop
.Val
as string));
129 prop
= sumMeta
.Lookup ("gsf:generator");
131 AddProperty (Beagle
.Property
.New ("fixme:generator", prop
.Val
as string));
133 prop
= sumMeta
.Lookup ("gsf:template");
135 AddProperty (Beagle
.Property
.New ("fixme:template", prop
.Val
as string));
138 if (docSumMeta
!= null) {
139 prop
= docSumMeta
.Lookup ("gsf:company");
141 AddProperty (Beagle
.Property
.New ("fixme:company", prop
.Val
as string));
143 prop
= docSumMeta
.Lookup ("gsf:category");
145 AddProperty (Beagle
.Property
.New ("fixme:category", prop
.Val
as string));
148 ExtractMetaData (sum_stream
, doc_stream
);
153 if (docSumMeta
!= null)
154 docSumMeta
.Dispose ();
157 override protected void DoPullProperties ()
159 Input sum_stream
= null;
160 Input doc_stream
= null;
168 sum_stream
= file
.ChildByName ("\u0005SummaryInformation");
169 doc_stream
= file
.ChildByName ("\u0005DocumentSummaryInformation");
171 PullMetaData (sum_stream
, doc_stream
);
172 } catch (Exception e
) {
173 Logger
.Log
.Error (e
, "Exception occurred duing DoPullProperties.");
176 if (sum_stream
!= null)
177 sum_stream
.Dispose ();
178 if (doc_stream
!= null)
179 doc_stream
.Dispose ();
183 override protected void DoClose ()
188 Log
.Debug ("File should be closed now or very shortly.");
190 // FIXME: Uncomment this when Shutdown() is available in gsf#
191 // Gsf.Global.Shutdown ();
194 // FIXME: These are utility functions and can be useful
195 // outside this filter as well.
196 public static uint GetInt32 (byte [] data
, int offset
) {
197 return (uint)(data
[offset
] + (data
[offset
+ 1] << 8) + (data
[offset
+ 2] << 16) + (data
[offset
+ 3] << 24));
199 public static ushort GetInt16 (byte [] data
, int offset
) {
200 return (ushort)(data
[offset
] + (data
[offset
+ 1] << 8));