4 // Copyright (C) 2004 Novell, Inc.
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in all
16 // 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 FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 using System
.Collections
;
37 class ExtractContentTool
{
39 static bool tokenize
= false;
40 static bool show_children
= false;
42 // FIXME: We don't display structural breaks
43 static void DisplayContent (string line
)
47 string [] parts
= line
.Split (' ');
48 for (int i
= 0; i
< parts
.Length
; ++i
) {
49 string part
= parts
[i
].Trim ();
51 Console
.WriteLine ("{0}", part
);
55 Console
.WriteLine (line
);
59 static bool first_indexable
= true;
61 static void Display (Indexable indexable
)
63 if (!first_indexable
) {
65 Console
.WriteLine ("-----------------------------------------");
68 first_indexable
= false;
70 Console
.WriteLine ("Filename: " + indexable
.Uri
);
72 if (indexable
.MimeType
!= null)
73 Console
.WriteLine ("MimeType: " + indexable
.MimeType
);
77 if (! FilterFactory
.FilterIndexable (indexable
, out filter
))
78 Console
.WriteLine ("No filter!");
81 Console
.WriteLine ("Filter: {0}", filter
);
85 if (filter
!= null && filter
.ChildIndexables
!= null && filter
.ChildIndexables
.Count
> 0) {
86 Console
.WriteLine ("Child indexables:");
88 foreach (Indexable i
in filter
.ChildIndexables
)
89 Console
.WriteLine (" {0}", i
.Uri
);
97 foreach (Beagle
.Property prop
in indexable
.Properties
) {
99 Console
.WriteLine ("Properties:");
102 Console
.WriteLine (" {0} = {1}", prop
.Key
, prop
.Value
);
105 Console
.WriteLine ();
107 if (indexable
.NoContent
)
112 reader
= indexable
.GetTextReader ();
113 if (reader
!= null) {
116 while ((line
= reader
.ReadLine ()) != null) {
118 Console
.WriteLine ("Content:");
121 DisplayContent (line
);
125 Console
.WriteLine ("(no content)");
127 Console
.WriteLine ();
130 reader
= indexable
.GetHotTextReader ();
131 if (reader
!= null) {
134 while ((line
= reader
.ReadLine ()) != null) {
136 Console
.WriteLine ("HotContent:");
139 DisplayContent (line
);
143 Console
.WriteLine ("(no hot content)");
145 Console
.WriteLine ();
148 if (show_children
&& filter
!= null && filter
.ChildIndexables
!= null) {
149 foreach (Indexable i
in filter
.ChildIndexables
) {
151 i
.DeleteContent
= true;
158 static void PrintUsage ()
160 Console
.WriteLine ("beagle-extract-content: Extracts filtered data from a file.");
161 Console
.WriteLine ("Copyright (C) 2004-2005 Novell, Inc.");
162 Console
.WriteLine ();
163 Console
.WriteLine ("Usage: beagle-extract-content [OPTIONS] file [file ...]");
164 Console
.WriteLine ();
165 Console
.WriteLine ("Options:");
166 Console
.WriteLine (" --tokenize\t\tTokenize the text before printing");
167 Console
.WriteLine (" --show-children\tShow filtering information for items created by filters");
168 Console
.WriteLine (" --help\t\tShow this message");
169 Console
.WriteLine ();
172 static int Main (string[] args
)
174 Logger
.DefaultEcho
= true;
175 Logger
.DefaultLevel
= LogLevel
.Debug
;
177 if (Array
.IndexOf (args
, "--help") != -1) {
182 if (Array
.IndexOf (args
, "--tokenize") != -1)
185 if (Array
.IndexOf (args
, "--show-children") != -1)
186 show_children
= true;
188 foreach (string arg
in args
) {
191 if (arg
.Substring (0, 2) == "--")
194 Uri uri
= UriFu
.PathToFileUri (arg
);
195 Indexable indexable
= new Indexable (uri
);
199 } catch (Exception e
) {
200 Console
.WriteLine ("Unable to filter {0}: {1}", uri
, e
.Message
);