1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # ConvertToPlug.pm -- plugin that inherits from HTML or TEXT Plug, depending
|
---|
4 | # on plugin argument convert_to
|
---|
5 | #
|
---|
6 | # A component of the Greenstone digital library software
|
---|
7 | # from the New Zealand Digital Library Project at the
|
---|
8 | # University of Waikato, New Zealand.
|
---|
9 | #
|
---|
10 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or modify
|
---|
13 | # it under the terms of the GNU General Public License as published by
|
---|
14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
15 | # (at your option) any later version.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful,
|
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | # GNU General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, write to the Free Software
|
---|
24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | #
|
---|
26 | ###########################################################################
|
---|
27 |
|
---|
28 | # The plugin is inherited by such plugins as WordPlug and PDFPlug.
|
---|
29 | # It facilitates the conversion of these document types to either HTML
|
---|
30 | # or TEXT by setting up variable that instruct ConvertToBasPlug
|
---|
31 | # how to work.
|
---|
32 |
|
---|
33 | # It works by dynamically inheriting HTMLPlug or TEXTPlug based on
|
---|
34 | # the plugin argument 'convert_to'. If the argument is not present,
|
---|
35 | # the default is to inherit HTMLPlug.
|
---|
36 |
|
---|
37 |
|
---|
38 | package ConvertToPlug;
|
---|
39 |
|
---|
40 | use HTMLPlug;
|
---|
41 | use TEXTPlug;
|
---|
42 |
|
---|
43 | sub BEGIN {
|
---|
44 | @ISA = ('HTMLPlug', 'TEXTPlug');
|
---|
45 | }
|
---|
46 |
|
---|
47 | use strict;
|
---|
48 |
|
---|
49 | sub print_usage {
|
---|
50 | my ($plugin_name) = @_;
|
---|
51 |
|
---|
52 | print STDERR "\n usage: plugin $plugin_name [options]\n\n";
|
---|
53 | print STDERR " options:\n";
|
---|
54 | print STDERR " -convert_to (html|text) plugin converts to TEXT or HTML\n";
|
---|
55 | print STDERR " (default html)\n";
|
---|
56 | }
|
---|
57 |
|
---|
58 | sub parse_args
|
---|
59 | {
|
---|
60 | my $class = shift (@_);
|
---|
61 | my ($args) = @_;
|
---|
62 |
|
---|
63 | my $plugin_name = $class;
|
---|
64 | $plugin_name =~ s/\.pm$//;
|
---|
65 |
|
---|
66 | my $generate_format;
|
---|
67 | if (!parsargv::parse($args,
|
---|
68 | q^convert_to/(html|text)/html^, \$generate_format,
|
---|
69 | "allow_extra_options")) {
|
---|
70 |
|
---|
71 | print STDERR "\nIncorrect options passed to $plugin_name, ";
|
---|
72 | print STDERR "check your collect.cfg configuration file\n";
|
---|
73 | &print_usage($plugin_name);
|
---|
74 | die "\n";
|
---|
75 | }
|
---|
76 |
|
---|
77 | return ($plugin_name,$generate_format);
|
---|
78 | }
|
---|
79 |
|
---|
80 | sub new {
|
---|
81 | my $class = shift (@_);
|
---|
82 |
|
---|
83 | my ($plugin_name,$generate_format) = $class->parse_args(\@_);
|
---|
84 |
|
---|
85 | my $self;
|
---|
86 |
|
---|
87 | if ($generate_format eq "text")
|
---|
88 | {
|
---|
89 | $self = new TEXTPlug ($class, @_);
|
---|
90 | }
|
---|
91 | else
|
---|
92 | {
|
---|
93 | $self = new HTMLPlug ($class, @_);
|
---|
94 | }
|
---|
95 |
|
---|
96 | return bless $self, $class;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | # do plugin specific processing of doc_obj for HTML type
|
---|
101 | sub process_type {
|
---|
102 | my $self = shift (@_);
|
---|
103 | my ($doc_ext, $textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
|
---|
104 |
|
---|
105 | my $conv_filename = $self->{'conv_filename'};
|
---|
106 | my $tmp_dirname = File::Basename::dirname($conv_filename);
|
---|
107 | my $tmp_tailname = File::Basename::basename($conv_filename);
|
---|
108 |
|
---|
109 | my $convert_to = $self->{'convert_to'};
|
---|
110 | my $ret_val;
|
---|
111 |
|
---|
112 | if ($convert_to eq "TEXT")
|
---|
113 | {
|
---|
114 | $ret_val = TEXTPlug::process($self,$textref,$pluginfo,
|
---|
115 | $tmp_dirname,$tmp_tailname,
|
---|
116 | $metadata,$doc_obj);
|
---|
117 | }
|
---|
118 | else
|
---|
119 | {
|
---|
120 | $ret_val = HTMLPlug::process($self,$textref,$pluginfo,
|
---|
121 | $tmp_dirname,$tmp_tailname,
|
---|
122 | $metadata,$doc_obj);
|
---|
123 | }
|
---|
124 |
|
---|
125 | # associate original file with doc object
|
---|
126 | my $cursection = $doc_obj->get_top_section();
|
---|
127 | my $filename = &util::filename_cat($base_dir,$file);
|
---|
128 | $doc_obj->associate_file($filename, "doc.$doc_ext", undef, $cursection);
|
---|
129 |
|
---|
130 | $doc_obj->add_utf8_metadata ($cursection, "srcicon", "_icon".$doc_ext."_");
|
---|
131 | $doc_obj->add_utf8_metadata ($cursection, "srcdoc", "doc.$doc_ext");
|
---|
132 |
|
---|
133 | # my $doclink = '<a href=_httpcollection_/index/assoc/[archivedir]/doc.$doc_ext>';
|
---|
134 | # $doc_obj->add_utf8_metadata ($cursection, "srclink", $doclink);
|
---|
135 | $doc_obj->add_utf8_metadata ($cursection, "/srclink", "</a>");
|
---|
136 |
|
---|
137 | return $ret_val;
|
---|
138 | }
|
---|
139 |
|
---|
140 | 1;
|
---|