source: gsdl/trunk/perllib/plugins/UnknownPlugin.pm@ 16961

Last change on this file since 16961 was 16961, checked in by ak19, 16 years ago

Fixed a bug introduced in last commit

  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
RevLine 
[2883]1###########################################################################
2#
[15872]3# UnknownPlugin.pm -- Plugin for files you know about but Greenstone doesn't
[2883]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
[15872]28# UnknownPlugin - a plugin for unknown files
[2883]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
[15872]40# plugin UnknownPlugin -process_exp "*.MOV" -assoc_field "movie"
[2883]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
[15872]51# UnknownPlugin with more than one type of file, you will have to add
[2883]52# some sort of distinguishing metadata in this way.)
53
54
55
[15872]56package UnknownPlugin;
[2883]57
[15872]58use BasePlugin;
[2883]59
[10254]60use strict;
61no strict 'refs'; # allow filehandles to be variables and viceversa
[2883]62
63sub BEGIN {
[15872]64 @UnknownPlugin::ISA = ('BasePlugin');
[2883]65}
66
[4744]67my $arguments =
68 [ { 'name' => "assoc_field",
[15872]69 'desc' => "{UnknownPlugin.assoc_field}",
[4744]70 'type' => "string",
71 'deft' => "",
[9427]72 'reqd' => "no" },
[7504]73 { 'name' => "file_format",
[15872]74 'desc' => "{UnknownPlugin.file_format}",
[4744]75 'type' => "string",
76 'deft' => "",
[7504]77 'reqd' => "no" },
78 { 'name' => "mime_type",
[15872]79 'desc' => "{UnknownPlugin.mime_type}",
[7504]80 'type' => "string",
81 'deft' => "",
[9427]82 'reqd' => "no" },
[10985]83 { 'name' => "srcicon",
[15872]84 'desc' => "{UnknownPlugin.srcicon}",
[10985]85 'type' => "string",
86 'deft' => "iconunknown",
87 'reqd' => "no" },
[9427]88 { 'name' => "process_extension",
[15872]89 'desc' => "{UnknownPlugin.process_extension}",
[9427]90 'type' => "string",
91 'deft' => "",
[4744]92 'reqd' => "no" } ];
93
[15872]94my $options = { 'name' => "UnknownPlugin",
95 'desc' => "{UnknownPlugin.desc}",
[6408]96 'abstract' => "no",
[4744]97 'inherits' => "yes",
98 'args' => $arguments };
99
[2883]100
101sub new {
[10218]102 my ($class) = shift (@_);
103 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
104 push(@$pluginlist, $class);
[4744]105
[15918]106 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
107 push(@{$hashArgOptLists->{"OptList"}},$options);
[2883]108
[15872]109 my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
[10218]110
[9427]111 # "-process_extension" is a simpler alternative to -process_exp for non-regexp people
112 if (!$self->{'process_exp'} && $self->{'process_extension'}) {
[9706]113 $self->{'process_exp'} = "\\." . $self->{'process_extension'} . "\$";
[9427]114 }
[2883]115
116 return bless $self, $class;
117}
118
119
[15872]120sub process {
121 my $self = shift (@_);
122 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
[2883]123
[16392]124 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
[15872]125 my $outhandle = $self->{'outhandle'};
[2883]126 my $verbosity = $self->{'verbosity'};
127
[15872]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 }
[2883]133
134 # Add the file as an associated file ...
135 my $section = $doc_obj->get_top_section();
[7504]136 my $file_format = $self->{'file_format'} || "unknown";
137 my $mime_type = $self->{'mime_type'} || "unknown/unknown";
[2883]138 my $assoc_field = $self->{'assoc_field'} || "unknown_file";
139
[16953]140 # The assocfilename is the url-encoded version of the utf8 filename
[16961]141 my $assoc_file = $self->{'doc_object'}->get_assocfile_from_sourcefile();
[16953]142
143 $doc_obj->associate_file($filename_full_path, $assoc_file, $mime_type, $section);
[7504]144 $doc_obj->add_metadata ($section, "FileFormat", $file_format);
[10594]145 $doc_obj->add_metadata ($section, "MimeType", $mime_type);
[15872]146 $doc_obj->add_metadata ($section, $assoc_field, $filename_full_path);
[2883]147
[6214]148 $doc_obj->add_metadata ($section, "srclink",
[11834]149 "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[$assoc_field]\">");
[10985]150 $doc_obj->add_metadata ($section, "srcicon", "_".$self->{'srcicon'}."_");
[6214]151 $doc_obj->add_metadata ($section, "/srclink", "</a>");
152
[15872]153 # we have no text - add dummy text and NoText metadata
154 $self->add_dummy_text($doc_obj, $section);
[14117]155
[2883]156 return 1;
157}
158
159
1601;
161
162
163
164
165
166
167
168
169
170
171
Note: See TracBrowser for help on using the repository browser.