[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 |
|
---|
| 29 | package TEXTPlug;
|
---|
| 30 |
|
---|
[1435] | 31 | use BasPlug;
|
---|
[585] | 32 |
|
---|
| 33 | sub BEGIN {
|
---|
[1435] | 34 | @ISA = ('BasPlug');
|
---|
[585] | 35 | }
|
---|
| 36 |
|
---|
| 37 | sub new {
|
---|
| 38 | my ($class) = @_;
|
---|
[1435] | 39 | my $self = new BasPlug ($class, @_);
|
---|
[585] | 40 |
|
---|
| 41 | return bless $self, $class;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
[1244] | 44 | sub get_default_process_exp {
|
---|
[585] | 45 | my $self = shift (@_);
|
---|
| 46 |
|
---|
[1244] | 47 | return q^(?i)\.te?xt$^;
|
---|
[585] | 48 | }
|
---|
| 49 |
|
---|
[1244] | 50 | # do plugin specific processing of doc_obj
|
---|
| 51 | sub process {
|
---|
[585] | 52 | my $self = shift (@_);
|
---|
[1244] | 53 | my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
|
---|
[1424] | 54 | my $outhandle = $self->{'outhandle'};
|
---|
| 55 |
|
---|
| 56 | print $outhandle "TEXTPlug: processing $file\n"
|
---|
[1244] | 57 | if $self->{'verbosity'} > 1;
|
---|
| 58 |
|
---|
[585] | 59 | my $cursection = $doc_obj->get_top_section();
|
---|
[1244] | 60 |
|
---|
| 61 | # get title metadata
|
---|
| 62 | # (don't need to get title if it has been passed
|
---|
| 63 | # in from another plugin)
|
---|
| 64 | if (!defined $metadata->{'Title'}) {
|
---|
[1729] | 65 | my ($title) = $$textref =~ /^\s*([^\n]*)/;
|
---|
[1244] | 66 | if (length($title) > 100) {
|
---|
| 67 | $title = substr ($title, 0, 100);
|
---|
[585] | 68 | }
|
---|
[1244] | 69 | $doc_obj->add_utf8_metadata ($cursection, "Title", $title);
|
---|
[585] | 70 | }
|
---|
| 71 |
|
---|
[1244] | 72 | # insert preformat tags and add text to document object
|
---|
| 73 | $doc_obj->add_utf8_text($cursection, "<pre>\n$$textref\n</pre>");
|
---|
[585] | 74 |
|
---|
[1244] | 75 | return 1;
|
---|
[585] | 76 | }
|
---|
| 77 |
|
---|
| 78 | 1;
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 |
|
---|