1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # RTFPlugin.pm -- plugin for importing Rich Text Format files.
|
---|
4 | #
|
---|
5 | # A component of the Greenstone digital library software
|
---|
6 | # from the New Zealand Digital Library Project at the
|
---|
7 | # University of Waikato, New Zealand.
|
---|
8 | #
|
---|
9 | # Copyright (C) 2001 New Zealand Digital Library Project
|
---|
10 | #
|
---|
11 | # This program is free software; you can redistribute it and/or modify
|
---|
12 | # it under the terms of the GNU General Public License as published by
|
---|
13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
14 | # (at your option) any later version.
|
---|
15 | #
|
---|
16 | # This program is distributed in the hope that it will be useful,
|
---|
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | # GNU General Public License for more details.
|
---|
20 | #
|
---|
21 | # You should have received a copy of the GNU General Public License
|
---|
22 | # along with this program; if not, write to the Free Software
|
---|
23 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | #
|
---|
25 | ###########################################################################
|
---|
26 |
|
---|
27 | package RTFPlugin;
|
---|
28 |
|
---|
29 | use ConvertBinaryFile;
|
---|
30 | use strict;
|
---|
31 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
32 |
|
---|
33 | sub BEGIN {
|
---|
34 | @RTFPlugin::ISA = ('ConvertBinaryFile');
|
---|
35 | }
|
---|
36 |
|
---|
37 | # currently only converts to HTML
|
---|
38 | my $convert_to_list =
|
---|
39 | [ { 'name' => "html",
|
---|
40 | 'desc' => "{ConvertBinaryFile.convert_to.html}" } ];
|
---|
41 |
|
---|
42 | my $arguments =
|
---|
43 | [ { 'name' => "convert_to",
|
---|
44 | 'desc' => "{ConvertBinaryFile.convert_to}",
|
---|
45 | 'type' => "enum",
|
---|
46 | 'reqd' => "yes",
|
---|
47 | 'list' => $convert_to_list,
|
---|
48 | 'deft' => "html" },
|
---|
49 | { 'name' => "process_exp",
|
---|
50 | 'desc' => "{BasePlugin.process_exp}",
|
---|
51 | 'type' => "regexp",
|
---|
52 | 'deft' => &get_default_process_exp(),
|
---|
53 | 'reqd' => "no" },
|
---|
54 | { 'name' => "description_tags",
|
---|
55 | 'desc' => "{HTMLPlugin.description_tags}",
|
---|
56 | 'type' => "flag" }
|
---|
57 | ];
|
---|
58 |
|
---|
59 | my $options = { 'name' => "RTFPlugin",
|
---|
60 | 'desc' => "{RTFPlugin.desc}",
|
---|
61 | 'abstract' => "no",
|
---|
62 | 'inherits' => "yes",
|
---|
63 | 'srcreplaceable' => "yes", # Source docs in rtf can be replaced with GS-generated html
|
---|
64 | 'args' => $arguments };
|
---|
65 |
|
---|
66 | sub new {
|
---|
67 | my ($class) = shift (@_);
|
---|
68 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
69 | push(@$pluginlist, $class);
|
---|
70 |
|
---|
71 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
72 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
73 |
|
---|
74 | my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
75 |
|
---|
76 | if ($self->{'info_only'}) {
|
---|
77 | # don't worry about any options etc
|
---|
78 | return bless $self, $class;
|
---|
79 | }
|
---|
80 |
|
---|
81 | $self->{'file_type'} = "RTF";
|
---|
82 |
|
---|
83 | # set convert_to_plugin and convert_to_ext
|
---|
84 | $self->set_standard_convert_settings();
|
---|
85 | my $secondary_plugin_name = $self->{'convert_to_plugin'};
|
---|
86 | my $secondary_plugin_options = $self->{'secondary_plugin_options'};
|
---|
87 |
|
---|
88 | if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
|
---|
89 | $secondary_plugin_options->{$secondary_plugin_name} = [];
|
---|
90 | }
|
---|
91 | my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
|
---|
92 |
|
---|
93 | push(@$specific_options, "-file_rename_method", "none");
|
---|
94 | push(@$specific_options, "-extract_language") if $self->{'extract_language'};
|
---|
95 | if ($secondary_plugin_name eq "TextPlugin") {
|
---|
96 | push(@$specific_options, "-input_encoding", "utf8");
|
---|
97 | }
|
---|
98 | elsif ($secondary_plugin_name eq "HTMLPlugin") {
|
---|
99 | push(@$specific_options, "-description_tags") if $self->{'description_tags'};
|
---|
100 | push(@$specific_options, "-processing_tmp_files");
|
---|
101 | }
|
---|
102 |
|
---|
103 | $self = bless $self, $class;
|
---|
104 |
|
---|
105 | $self->load_secondary_plugins($class,$secondary_plugin_options, $hashArgOptLists);
|
---|
106 |
|
---|
107 | return $self;
|
---|
108 | }
|
---|
109 |
|
---|
110 | sub get_default_process_exp {
|
---|
111 | my $self = shift (@_);
|
---|
112 | return q^(?i)\.rtf$^;
|
---|
113 | }
|
---|
114 |
|
---|
115 | 1;
|
---|