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

Last change on this file since 12169 was 12169, checked in by mdewsnip, 18 years ago

Tidied up that horrible long line in the new() function of every plugin.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 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;
34
35use strict;
36no strict 'refs'; # allow filehandles to be variables and viceversa
37
38sub BEGIN {
39 @TEXTPlug::ISA = ('BasPlug');
40}
41
42my $arguments =
43 [ { 'name' => "process_exp",
44 'desc' => "{BasPlug.process_exp}",
45 'type' => "regexp",
46 'deft' => &get_default_process_exp(),
47 'reqd' => "no" } ,
48 { 'name' => "title_sub",
49 'desc' => "{TEXTPlug.title_sub}",
50 'type' => "regexp",
51 'deft' => "",
52 'reqd' => "no" } ];
53
54my $options = { 'name' => "TEXTPlug",
55 'desc' => "{TEXTPlug.desc}",
56 'abstract' => "no",
57 'inherits' => "yes",
58 'args' => $arguments };
59
60
61sub new {
62 my ($class) = shift (@_);
63 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
64 push(@$pluginlist, $class);
65
66 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
67 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
68
69 my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);
70
71 return bless $self, $class;
72}
73
74sub get_default_process_exp {
75 my $self = shift (@_);
76
77 return q^(?i)\.te?xt$^;
78}
79
80# do plugin specific processing of doc_obj
81sub process {
82 my $self = shift (@_);
83 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
84 my $outhandle = $self->{'outhandle'};
85
86 print STDERR "<Processing n='$file' p='TEXTPlug'>\n" if ($gli);
87 print $outhandle "TEXTPlug: processing $file\n"
88 if $self->{'verbosity'} > 1;
89
90 my $cursection = $doc_obj->get_top_section();
91 # get title metadata
92 # (don't need to get title if it has been passed
93 # in from another plugin)
94 if (!defined $metadata->{'Title'}) {
95 my ($title) = $$textref;
96 $title =~ /^\s+/s;
97 if (defined $self->{'title_sub'} &&
98 $self->{'title_sub'}) {$title =~ s/$self->{'title_sub'}//;}
99 $title =~ /^\s*([^\n]*)/s; $title=$1;
100 if (length($title) > 100) {
101 $title = substr ($title, 0, 100) . "...";
102 }
103 $title =~ s/\[/&#91;/g;
104 $title =~ s/\[/&#93;/g;
105 $title =~ s/\</&#60;/g;
106 $title =~ s/\>/&#62;/g;
107 $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
108 }
109 # Add FileFormat metadata
110 $doc_obj->add_metadata($cursection, "FileFormat", "TEXT");
111
112
113 # we need to escape the escape character, or else mg will convert into
114 # eg literal newlines, instead of leaving the text as '\n'
115 $$textref =~ s/\\/\\\\/g; # macro language
116 $$textref =~ s/_/\\_/g; # macro language
117 $$textref =~ s/</&lt;/g;
118 $$textref =~ s/>/&gt;/g;
119
120 # insert preformat tags and add text to document object
121 $doc_obj->add_utf8_text($cursection, "<pre>\n$$textref\n</pre>");
122
123 return 1;
124}
125
1261;
127
128
129
130
131
132
133
134
135
136
137
Note: See TracBrowser for help on using the repository browser.