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

Last change on this file since 7243 was 6408, checked in by jmt12, 20 years ago

Added two new attributes for script arguments. HiddenGLI controls whether the argument will be visible at all in GLI, while ModeGLI defines the lowest detail mode under which the argument will be visible (only really for import and buildcol). Also ensured that the scripts were reporting their correct default process expressions, and further refined argument types by adding the catagory regexp for any regular expression (which can then be hidden under lower detail modes in GLI)

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.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
29# 12/05/02 Added usage datastructure - John Thompson
30
31package TEXTPlug;
32
33use BasPlug;
34use parsargv;
35
36
37sub BEGIN {
38 @ISA = ('BasPlug');
39}
40
41my $arguments =
42 [ { 'name' => "process_exp",
43 'desc' => "{BasPlug.process_exp}",
44 'type' => "regexp",
45 'deft' => &get_default_process_exp(),
46 'reqd' => "no" } ,
47 { 'name' => "title_sub",
48 'desc' => "{TEXTPlug.title_sub}",
49 'type' => "regexp",
50 'deft' => "",
51 'reqd' => "no" } ];
52
53my $options = { 'name' => "TEXTPlug",
54 'desc' => "{TEXTPlug.desc}",
55 'abstract' => "no",
56 'inherits' => "yes",
57 'args' => $arguments };
58
59# sub print_usage {
60# print STDERR "\n usage: plugin TEXTPlug [options]\n\n";
61# print STDERR " options:\n";
62# print STDERR " -title_sub\t Substitution expression to modify string stored as Title.\n";
63# print STDERR "\t\t Used by, for example, PSPlug to remove \"Page 1\" etc from\n";
64# print STDERR "\t\t text used as the title.\n";
65
66# print STDERR "\n";
67# }
68
69sub new {
70 my ($class) = @_;
71 my $self = new BasPlug ($class, @_);
72 $self->{'plugin_type'} = "TEXTPlug";
73 # 14-05-02 To allow for proper inheritance of arguments - John Thompson
74 my $option_list = $self->{'option_list'};
75 push( @{$option_list}, $options );
76
77 if (!parsargv::parse(\@_,
78 q^title_sub/.*/^, \$self->{'title_sub'},
79 "allow_extra_options")) {
80 print STDERR "\nIncorrect options passed to TEXTPlug, check your collect.cfg configuration file\n";
81 $self->print_txt_usage(""); # Use default resource bundle
82 die "\n";
83 }
84
85
86 return bless $self, $class;
87}
88
89sub get_default_process_exp {
90 my $self = shift (@_);
91
92 return q^(?i)\.te?xt$^;
93}
94
95# do plugin specific processing of doc_obj
96sub process {
97 my $self = shift (@_);
98 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
99 my $outhandle = $self->{'outhandle'};
100
101 print STDERR "<Processing n='$file' p='TEXTPlug'>\n" if ($gli);
102 print $outhandle "TEXTPlug: processing $file\n"
103 if $self->{'verbosity'} > 1;
104
105 my $cursection = $doc_obj->get_top_section();
106
107 # get title metadata
108 # (don't need to get title if it has been passed
109 # in from another plugin)
110 if (!defined $metadata->{'Title'}) {
111 my ($title) = $$textref;
112 $title =~ /^\s+/s;
113 if (defined $self->{'title_sub'} &&
114 $self->{'title_sub'}) {$title =~ s/$self->{'title_sub'}//;}
115 $title =~ /^\s*([^\n]*)/s; $title=$1;
116 if (length($title) > 100) {
117 $title = substr ($title, 0, 100) . "...";
118 }
119 $title =~ s/\[/&#91;/g;
120 $title =~ s/\[/&#93;/g;
121 $title =~ s/\</&#60;/g;
122 $title =~ s/\>/&#62;/g;
123 $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
124 }
125
126 # we need to escape the escape character, or else mg will convert into
127 # eg literal newlines, instead of leaving the text as '\n'
128 $$textref =~ s/\\/\\\\/g; # macro language
129 $$textref =~ s/_/\\_/g; # macro language
130 $$textref =~ s/</&lt;/g;
131 $$textref =~ s/>/&gt;/g;
132
133 # insert preformat tags and add text to document object
134 $doc_obj->add_utf8_text($cursection, "<pre>\n$$textref\n</pre>");
135
136 return 1;
137}
138
1391;
140
141
142
143
144
145
146
147
148
149
150
Note: See TracBrowser for help on using the repository browser.