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

Last change on this file since 7362 was 7362, checked in by kjdon, 20 years ago

plugin read functions now return 'undef' - didn't recognise, '-1' - recognised but had an error during processing, '0' - blocked or didn't process but don't pass it on to other plugins, or 'num_docs' processed. this emables a bit better error reporting about what has happened to each file

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 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
60sub new {
61 my ($class) = @_;
62 my $self = new BasPlug ($class, @_);
63 $self->{'plugin_type'} = "TEXTPlug";
64 # 14-05-02 To allow for proper inheritance of arguments - John Thompson
65 my $option_list = $self->{'option_list'};
66 push( @{$option_list}, $options );
67
68 if (!parsargv::parse(\@_,
69 q^title_sub/.*/^, \$self->{'title_sub'},
70 "allow_extra_options")) {
71 print STDERR "\nIncorrect options passed to TEXTPlug, check your collect.cfg configuration file\n";
72 $self->print_txt_usage(""); # Use default resource bundle
73 die "\n";
74 }
75
76
77 return bless $self, $class;
78}
79
80sub get_default_process_exp {
81 my $self = shift (@_);
82
83 return q^(?i)\.te?xt$^;
84}
85
86# do plugin specific processing of doc_obj
87sub process {
88 my $self = shift (@_);
89 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
90 my $outhandle = $self->{'outhandle'};
91
92 print STDERR "<Processing n='$file' p='TEXTPlug'>\n" if ($gli);
93 print $outhandle "TEXTPlug: processing $file\n"
94 if $self->{'verbosity'} > 1;
95
96 my $cursection = $doc_obj->get_top_section();
97 return undef; # an error
98 # get title metadata
99 # (don't need to get title if it has been passed
100 # in from another plugin)
101 if (!defined $metadata->{'Title'}) {
102 my ($title) = $$textref;
103 $title =~ /^\s+/s;
104 if (defined $self->{'title_sub'} &&
105 $self->{'title_sub'}) {$title =~ s/$self->{'title_sub'}//;}
106 $title =~ /^\s*([^\n]*)/s; $title=$1;
107 if (length($title) > 100) {
108 $title = substr ($title, 0, 100) . "...";
109 }
110 $title =~ s/\[/&#91;/g;
111 $title =~ s/\[/&#93;/g;
112 $title =~ s/\</&#60;/g;
113 $title =~ s/\>/&#62;/g;
114 $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
115 }
116
117 # we need to escape the escape character, or else mg will convert into
118 # eg literal newlines, instead of leaving the text as '\n'
119 $$textref =~ s/\\/\\\\/g; # macro language
120 $$textref =~ s/_/\\_/g; # macro language
121 $$textref =~ s/</&lt;/g;
122 $$textref =~ s/>/&gt;/g;
123
124 # insert preformat tags and add text to document object
125 $doc_obj->add_utf8_text($cursection, "<pre>\n$$textref\n</pre>");
126
127 return 1;
128}
129
1301;
131
132
133
134
135
136
137
138
139
140
141
Note: See TracBrowser for help on using the repository browser.