[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 |
|
---|
[3540] | 29 | # 12/05/02 Added usage datastructure - John Thompson
|
---|
| 30 |
|
---|
[585] | 31 | package TEXTPlug;
|
---|
| 32 |
|
---|
[1435] | 33 | use BasPlug;
|
---|
[2450] | 34 | use parsargv;
|
---|
[585] | 35 |
|
---|
[2450] | 36 |
|
---|
[585] | 37 | sub BEGIN {
|
---|
[1435] | 38 | @ISA = ('BasPlug');
|
---|
[585] | 39 | }
|
---|
| 40 |
|
---|
[4744] | 41 | my $arguments =
|
---|
| 42 | [ { 'name' => "process_exp",
|
---|
[4873] | 43 | 'desc' => "{BasPlug.process_exp}",
|
---|
[6408] | 44 | 'type' => "regexp",
|
---|
[4744] | 45 | 'deft' => &get_default_process_exp(),
|
---|
| 46 | 'reqd' => "no" } ,
|
---|
| 47 | { 'name' => "title_sub",
|
---|
[4873] | 48 | 'desc' => "{TEXTPlug.title_sub}",
|
---|
[6408] | 49 | 'type' => "regexp",
|
---|
[4744] | 50 | 'deft' => "",
|
---|
| 51 | 'reqd' => "no" } ];
|
---|
[3540] | 52 |
|
---|
| 53 | my $options = { 'name' => "TEXTPlug",
|
---|
[5680] | 54 | 'desc' => "{TEXTPlug.desc}",
|
---|
[6408] | 55 | 'abstract' => "no",
|
---|
[4744] | 56 | 'inherits' => "yes",
|
---|
| 57 | 'args' => $arguments };
|
---|
[3540] | 58 |
|
---|
[2450] | 59 |
|
---|
[585] | 60 | sub new {
|
---|
[10218] | 61 | my ($class) = shift (@_);
|
---|
| 62 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 63 | push(@$pluginlist, $class);
|
---|
[3540] | 64 |
|
---|
[10218] | 65 | if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
|
---|
| 66 | if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
|
---|
[2450] | 67 |
|
---|
[10218] | 68 | my $self = (defined $hashArgOptLists)? new BasPlug($pluginlist,$inputargs,$hashArgOptLists): new BasPlug($pluginlist,$inputargs);
|
---|
[2450] | 69 |
|
---|
[585] | 70 | return bless $self, $class;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[1244] | 73 | sub get_default_process_exp {
|
---|
[585] | 74 | my $self = shift (@_);
|
---|
| 75 |
|
---|
[1244] | 76 | return q^(?i)\.te?xt$^;
|
---|
[585] | 77 | }
|
---|
| 78 |
|
---|
[1244] | 79 | # do plugin specific processing of doc_obj
|
---|
| 80 | sub process {
|
---|
[585] | 81 | my $self = shift (@_);
|
---|
[6332] | 82 | my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
[1424] | 83 | my $outhandle = $self->{'outhandle'};
|
---|
| 84 |
|
---|
[6332] | 85 | print STDERR "<Processing n='$file' p='TEXTPlug'>\n" if ($gli);
|
---|
[1424] | 86 | print $outhandle "TEXTPlug: processing $file\n"
|
---|
[1244] | 87 | if $self->{'verbosity'} > 1;
|
---|
| 88 |
|
---|
[585] | 89 | my $cursection = $doc_obj->get_top_section();
|
---|
[1244] | 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'}) {
|
---|
[2450] | 94 | my ($title) = $$textref;
|
---|
| 95 | $title =~ /^\s+/s;
|
---|
[3037] | 96 | if (defined $self->{'title_sub'} &&
|
---|
[3540] | 97 | $self->{'title_sub'}) {$title =~ s/$self->{'title_sub'}//;}
|
---|
[2450] | 98 | $title =~ /^\s*([^\n]*)/s; $title=$1;
|
---|
[1244] | 99 | if (length($title) > 100) {
|
---|
[2450] | 100 | $title = substr ($title, 0, 100) . "...";
|
---|
[585] | 101 | }
|
---|
[3732] | 102 | $title =~ s/\[/[/g;
|
---|
| 103 | $title =~ s/\[/]/g;
|
---|
| 104 | $title =~ s/\</</g;
|
---|
| 105 | $title =~ s/\>/>/g;
|
---|
[1244] | 106 | $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
|
---|
[585] | 107 | }
|
---|
[8121] | 108 | # Add FileFormat metadata
|
---|
| 109 | $doc_obj->add_metadata($cursection, "FileFormat", "TEXT");
|
---|
| 110 |
|
---|
[2085] | 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'
|
---|
[3932] | 114 | $$textref =~ s/\\/\\\\/g; # macro language
|
---|
| 115 | $$textref =~ s/_/\\_/g; # macro language
|
---|
[2667] | 116 | $$textref =~ s/</</g;
|
---|
| 117 | $$textref =~ s/>/>/g;
|
---|
[2085] | 118 |
|
---|
[1244] | 119 | # insert preformat tags and add text to document object
|
---|
| 120 | $doc_obj->add_utf8_text($cursection, "<pre>\n$$textref\n</pre>");
|
---|
[585] | 121 |
|
---|
[1244] | 122 | return 1;
|
---|
[585] | 123 | }
|
---|
| 124 |
|
---|
| 125 | 1;
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 |
|
---|