source: trunk/gsdl/perllib/plugins/TEXTPlug.pm@ 3517

Last change on this file since 3517 was 3037, checked in by jrm21, 22 years ago

title_sub seems to always get defined by parsargv, so we test that it is
non-empty as well as defined before doing s/;

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1###########################################################################
2#
3# TEXTPlug.pm -- simple text plugin
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26# creates simple single-level document. Adds Title metadata
27# of first line of text (up to 100 characters long).
28
29package TEXTPlug;
30
31use BasPlug;
32use parsargv;
33
34
35sub BEGIN {
36 @ISA = ('BasPlug');
37}
38
39sub print_usage {
40 print STDERR "\n usage: plugin TEXTPlug [options]\n\n";
41 print STDERR " options:\n";
42 print STDERR " -title_sub\t Substitution expression to modify string stored as Title.\n";
43 print STDERR "\t\t Used by, for example, PSPlug to remove \"Page 1\" etc from\n";
44 print STDERR "\t\t text used as the title.\n";
45
46 print STDERR "\n";
47}
48
49sub new {
50 my ($class) = @_;
51 my $self = new BasPlug ($class, @_);
52
53 if (!parsargv::parse(\@_,
54 q^title_sub/.*/^, \$self->{'title_sub'},
55 "allow_extra_options")) {
56 print STDERR "\nIncorrect options passed to TEXTPlug, check your collect.cfg configuration file\n";
57 &print_usage();
58 die "\n";
59 }
60
61
62 return bless $self, $class;
63}
64
65sub get_default_process_exp {
66 my $self = shift (@_);
67
68 return q^(?i)\.te?xt$^;
69}
70
71# do plugin specific processing of doc_obj
72sub process {
73 my $self = shift (@_);
74 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
75 my $outhandle = $self->{'outhandle'};
76
77 print $outhandle "TEXTPlug: processing $file\n"
78 if $self->{'verbosity'} > 1;
79
80 my $cursection = $doc_obj->get_top_section();
81
82 # get title metadata
83 # (don't need to get title if it has been passed
84 # in from another plugin)
85 if (!defined $metadata->{'Title'}) {
86 my ($title) = $$textref;
87 $title =~ /^\s+/s;
88 if (defined $self->{'title_sub'} &&
89 $self->{'title_sub'}) {$title =~ s/$self->{'title_sub'}//;}
90 $title =~ /^\s*([^\n]*)/s; $title=$1;
91 if (length($title) > 100) {
92 $title = substr ($title, 0, 100) . "...";
93 }
94 $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
95 }
96
97 # we need to escape the escape character, or else mg will convert into
98 # eg literal newlines, instead of leaving the text as '\n'
99 $$textref =~ s/\\/\\\\/g;
100 $$textref =~ s/</&lt;/g;
101 $$textref =~ s/>/&gt;/g;
102
103 # insert preformat tags and add text to document object
104 $doc_obj->add_utf8_text($cursection, "<pre>\n$$textref\n</pre>");
105
106 return 1;
107}
108
1091;
110
111
112
113
114
115
116
117
118
119
120
Note: See TracBrowser for help on using the repository browser.