root/main/trunk/greenstone2/perllib/plugins/RTFPlugin.pm @ 22597

Revision 22597, 3.7 KB (checked in by kjdon, 9 years ago)

code tidy up. rearranged how convertbinaryfile plugins set up their secondary plugins - now only set up the options for the one they are using. all subclass specific code moved out of convertbinaryfile.new into the appropriate plugin file.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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
27package RTFPlugin;
28
29use ConvertBinaryFile;
30use strict;
31no strict 'refs'; # allow filehandles to be variables and viceversa
32
33sub BEGIN {
34    @RTFPlugin::ISA = ('ConvertBinaryFile');
35}
36
37# currently only converts to HTML
38my $convert_to_list =
39    [ { 'name' => "html",
40    'desc' => "{ConvertBinaryFile.convert_to.html}" } ];
41
42my $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
59my $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
66sub 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->{'filename_extension'} = "rtf";
82    $self->{'file_type'} = "RTF";
83
84    # set convert_to_plugin and convert_to_ext
85    $self->ConvertBinaryFile::set_standard_convert_settings();
86    my $secondary_plugin_name = $self->{'convert_to_plugin'};
87    my $secondary_plugin_options = $self->{'secondary_plugin_options'};
88
89    if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
90    $secondary_plugin_options->{$secondary_plugin_name} = [];
91    }
92    my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
93   
94    push(@$specific_options, "-file_rename_method", "none");
95    push(@$specific_options, "-extract_language") if $self->{'extract_language'};
96    if ($secondary_plugin_name eq "TextPlugin") {
97    push(@$specific_options, "-input_encoding", "utf8");
98    }
99    elsif ($secondary_plugin_name eq "HTMLPlugin") {
100    push(@$specific_options, "-description_tags") if $self->{'description_tags'};
101    push(@$specific_options, "-processing_tmp_files");
102    }
103
104    $self = bless $self, $class;
105
106    $self->load_secondary_plugins($class,$secondary_plugin_options, $hashArgOptLists);
107
108    return $self;
109}
110
111sub get_default_process_exp {
112    my $self = shift (@_);
113    return q^(?i)\.rtf$^;
114}
115
1161;
Note: See TracBrowser for help on using the browser.