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

Last change on this file since 10218 was 10218, checked in by kjdon, 19 years ago

Jeffrey's new parsing modifications, committed approx 6 July, 15.16

  • 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;
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) = shift (@_);
62 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
63 push(@$pluginlist, $class);
64
65 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
66 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
67
68 my $self = (defined $hashArgOptLists)? new BasPlug($pluginlist,$inputargs,$hashArgOptLists): new BasPlug($pluginlist,$inputargs);
69
70 return bless $self, $class;
71}
72
73sub get_default_process_exp {
74 my $self = shift (@_);
75
76 return q^(?i)\.te?xt$^;
77}
78
79# do plugin specific processing of doc_obj
80sub process {
81 my $self = shift (@_);
82 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
83 my $outhandle = $self->{'outhandle'};
84
85 print STDERR "<Processing n='$file' p='TEXTPlug'>\n" if ($gli);
86 print $outhandle "TEXTPlug: processing $file\n"
87 if $self->{'verbosity'} > 1;
88
89 my $cursection = $doc_obj->get_top_section();
90 # get title metadata
91 # (don't need to get title if it has been passed
92 # in from another plugin)
93 if (!defined $metadata->{'Title'}) {
94 my ($title) = $$textref;
95 $title =~ /^\s+/s;
96 if (defined $self->{'title_sub'} &&
97 $self->{'title_sub'}) {$title =~ s/$self->{'title_sub'}//;}
98 $title =~ /^\s*([^\n]*)/s; $title=$1;
99 if (length($title) > 100) {
100 $title = substr ($title, 0, 100) . "...";
101 }
102 $title =~ s/\[/&#91;/g;
103 $title =~ s/\[/&#93;/g;
104 $title =~ s/\</&#60;/g;
105 $title =~ s/\>/&#62;/g;
106 $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
107 }
108 # Add FileFormat metadata
109 $doc_obj->add_metadata($cursection, "FileFormat", "TEXT");
110
111
112 # we need to escape the escape character, or else mg will convert into
113 # eg literal newlines, instead of leaving the text as '\n'
114 $$textref =~ s/\\/\\\\/g; # macro language
115 $$textref =~ s/_/\\_/g; # macro language
116 $$textref =~ s/</&lt;/g;
117 $$textref =~ s/>/&gt;/g;
118
119 # insert preformat tags and add text to document object
120 $doc_obj->add_utf8_text($cursection, "<pre>\n$$textref\n</pre>");
121
122 return 1;
123}
124
1251;
126
127
128
129
130
131
132
133
134
135
136
Note: See TracBrowser for help on using the repository browser.