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

Last change on this file since 2450 was 2450, checked in by jrm21, 23 years ago

now accepts the "-title_sub" option, a regexp to remove when automatically
extracting title from text.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
RevLine 
[585]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
[1244]26# creates simple single-level document. Adds Title metadata
27# of first line of text (up to 100 characters long).
[585]28
29package TEXTPlug;
30
[1435]31use BasPlug;
[2450]32use parsargv;
[585]33
[2450]34
[585]35sub BEGIN {
[1435]36 @ISA = ('BasPlug');
[585]37}
38
[2450]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
[585]49sub new {
50 my ($class) = @_;
[1435]51 my $self = new BasPlug ($class, @_);
[585]52
[2450]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
[585]62 return bless $self, $class;
63}
64
[1244]65sub get_default_process_exp {
[585]66 my $self = shift (@_);
67
[1244]68 return q^(?i)\.te?xt$^;
[585]69}
70
[1244]71# do plugin specific processing of doc_obj
72sub process {
[585]73 my $self = shift (@_);
[1244]74 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
[1424]75 my $outhandle = $self->{'outhandle'};
76
77 print $outhandle "TEXTPlug: processing $file\n"
[1244]78 if $self->{'verbosity'} > 1;
79
[585]80 my $cursection = $doc_obj->get_top_section();
[1244]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'}) {
[2450]86 my ($title) = $$textref;
87 $title =~ /^\s+/s;
88 if (defined $self->{'title_sub'}) {$title =~ s/$self->{'title_sub'}//;}
89 $title =~ /^\s*([^\n]*)/s; $title=$1;
[1244]90 if (length($title) > 100) {
[2450]91 $title = substr ($title, 0, 100) . "...";
[585]92 }
[1244]93 $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
[585]94 }
[2085]95
96 # we need to escape the escape character, or else mg will convert into
97 # eg literal newlines, instead of leaving the text as '\n'
98 $$textref =~ s/\\/\\\\/g;
99
[1244]100 # insert preformat tags and add text to document object
101 $doc_obj->add_utf8_text($cursection, "<pre>\n$$textref\n</pre>");
[585]102
[1244]103 return 1;
[585]104}
105
1061;
107
108
109
110
111
112
113
114
115
116
117
Note: See TracBrowser for help on using the repository browser.