source: main/trunk/greenstone2/perllib/plugins/UnknownPlugin.pm@ 21764

Last change on this file since 21764 was 21760, checked in by kjdon, 14 years ago

srclink now generated dynamically at runtime. instead of storing srclink metadata, we store srclink_file metadata, which can be a value (doc.doc) or a metadata format element (eg [SourceFile]).

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1###########################################################################
2#
3# UnknownPlugin.pm -- Plugin for files you know about but Greenstone doesn't
4#
5# A component of the Greenstone digital library software from the New
6# Zealand Digital Library Project at the University of Waikato, New
7# Zealand.
8#
9# Copyright (C) 2001 Gordon W. Paynter
10# Copyright (C) 2001 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful, but
18# WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20# General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28# UnknownPlugin - a plugin for unknown files
29
30# This is a simple Plugin for importing files in formats that
31# Greenstone doesn't know anything about. A fictional document will
32# be created for every such file, and the file itself will be passed
33# to Greenstone as the "associated file" of the document.
34
35# Here's an example where it is useful: I have a collection of
36# pictures that include a couple of quicktime movie files with names
37# like DCP_0163.MOV. Rather than write a new plugin for quicktime
38# movies, I add this line to the collection configuration file:
39
40# plugin UnknownPlugin -process_exp "*.MOV" -assoc_field "movie"
41
42# A document is created for each movie, with the associated movie
43# file's name in the "movie" metadata field. In the collection's
44# format strings, I use the {If} macro to output different text for
45# each type of file, like this:
46
47# {If}{[movie],<HTML for displaying movie>}{If}{[Image],<HTML for displaying image>}
48
49# You can also add extra metadata, such as the Title, Subject, and
50# Duration, with metadata.xml files and RecPlug. (If you want to use
51# UnknownPlugin with more than one type of file, you will have to add
52# some sort of distinguishing metadata in this way.)
53
54
55
56package UnknownPlugin;
57
58use BasePlugin;
59
60use strict;
61no strict 'refs'; # allow filehandles to be variables and viceversa
62
63sub BEGIN {
64 @UnknownPlugin::ISA = ('BasePlugin');
65}
66
67my $arguments =
68 [ { 'name' => "assoc_field",
69 'desc' => "{UnknownPlugin.assoc_field}",
70 'type' => "string",
71 'deft' => "",
72 'reqd' => "no" },
73 { 'name' => "file_format",
74 'desc' => "{UnknownPlugin.file_format}",
75 'type' => "string",
76 'deft' => "",
77 'reqd' => "no" },
78 { 'name' => "mime_type",
79 'desc' => "{UnknownPlugin.mime_type}",
80 'type' => "string",
81 'deft' => "",
82 'reqd' => "no" },
83 { 'name' => "srcicon",
84 'desc' => "{UnknownPlugin.srcicon}",
85 'type' => "string",
86 'deft' => "iconunknown",
87 'reqd' => "no" },
88 { 'name' => "process_extension",
89 'desc' => "{UnknownPlugin.process_extension}",
90 'type' => "string",
91 'deft' => "",
92 'reqd' => "no" } ];
93
94my $options = { 'name' => "UnknownPlugin",
95 'desc' => "{UnknownPlugin.desc}",
96 'abstract' => "no",
97 'inherits' => "yes",
98 'args' => $arguments };
99
100
101sub new {
102 my ($class) = shift (@_);
103 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
104 push(@$pluginlist, $class);
105
106 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
107 push(@{$hashArgOptLists->{"OptList"}},$options);
108
109 my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
110
111 # "-process_extension" is a simpler alternative to -process_exp for non-regexp people
112 if (!$self->{'process_exp'} && $self->{'process_extension'}) {
113 $self->{'process_exp'} = "\\." . $self->{'process_extension'} . "\$";
114 }
115
116 return bless $self, $class;
117}
118
119
120sub process {
121 my $self = shift (@_);
122 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
123
124 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
125 my $outhandle = $self->{'outhandle'};
126 my $verbosity = $self->{'verbosity'};
127
128 # check the filename is okay - do we need this??
129 if ($filename_full_path eq "" || $filename_no_path eq "") {
130 print $outhandle "UnknownPlugin: couldn't process \"$filename_no_path\"\n";
131 return undef;
132 }
133
134 # Add the file as an associated file ...
135 my $section = $doc_obj->get_top_section();
136 my $file_format = $self->{'file_format'} || "unknown";
137 my $mime_type = $self->{'mime_type'} || "unknown/unknown";
138 my $assoc_field = $self->{'assoc_field'} || "unknown_file";
139
140 # The assocfilename is the url-encoded version of the utf8 filename
141 my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
142
143 $doc_obj->associate_file($filename_full_path, $assoc_file, $mime_type, $section);
144 $doc_obj->add_metadata ($section, "FileFormat", $file_format);
145 $doc_obj->add_metadata ($section, "MimeType", $mime_type);
146 $doc_obj->add_utf8_metadata ($section, $assoc_field, $doc_obj->get_source()); # Source metadata is already in utf8
147
148 #$doc_obj->add_metadata ($section, "srclink",
149# "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
150 $doc_obj->add_metadata ($section, "srclink_file", "[SourceFile]");
151 $doc_obj->add_metadata ($section, "srcicon", "_".$self->{'srcicon'}."_");
152 #$doc_obj->add_metadata ($section, "/srclink", "</a>");
153
154 # we have no text - add dummy text and NoText metadata
155 $self->add_dummy_text($doc_obj, $section);
156
157 return 1;
158}
159
160
1611;
162
163
164
165
166
167
168
169
170
171
172
Note: See TracBrowser for help on using the repository browser.