source: main/trunk/greenstone2/perllib/plugins/RTFPlugin.pm@ 22597

Last change on this file since 22597 was 22597, checked in by kjdon, 14 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
File size: 3.7 KB
RevLine 
[2564]1###########################################################################
2#
[15872]3# RTFPlugin.pm -- plugin for importing Rich Text Format files.
[2564]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
[15872]27package RTFPlugin;
[3540]28
[15872]29use ConvertBinaryFile;
[10254]30use strict;
31no strict 'refs'; # allow filehandles to be variables and viceversa
[2564]32
33sub BEGIN {
[15872]34 @RTFPlugin::ISA = ('ConvertBinaryFile');
[2564]35}
36
[22597]37# currently only converts to HTML
38my $convert_to_list =
39 [ { 'name' => "html",
40 'desc' => "{ConvertBinaryFile.convert_to.html}" } ];
41
[4744]42my $arguments =
[22597]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",
[15872]50 'desc' => "{BasePlugin.process_exp}",
[6408]51 'type' => "regexp",
[4744]52 'deft' => &get_default_process_exp(),
[10514]53 'reqd' => "no" },
54 { 'name' => "description_tags",
[15872]55 'desc' => "{HTMLPlugin.description_tags}",
[10514]56 'type' => "flag" }
57];
[3540]58
[15872]59my $options = { 'name' => "RTFPlugin",
60 'desc' => "{RTFPlugin.desc}",
[6408]61 'abstract' => "no",
[3540]62 'inherits' => "yes",
[15114]63 'srcreplaceable' => "yes", # Source docs in rtf can be replaced with GS-generated html
[3540]64 'args' => $arguments };
65
66sub new {
[10218]67 my ($class) = shift (@_);
68 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
69 push(@$pluginlist, $class);
[3540]70
[15872]71 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
72 push(@{$hashArgOptLists->{"OptList"}},$options);
[10425]73
[15872]74 my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
[10218]75
[10580]76 if ($self->{'info_only'}) {
77 # don't worry about any options etc
78 return bless $self, $class;
79 }
80
[15872]81 $self->{'filename_extension'} = "rtf";
82 $self->{'file_type'} = "RTF";
83
[22597]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'};
[10425]87 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
[22597]88
89 if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
90 $secondary_plugin_options->{$secondary_plugin_name} = [];
[10425]91 }
[22597]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");
[10425]98 }
[22597]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 }
[10425]103
[10272]104 $self = bless $self, $class;
105
[10425]106 $self->load_secondary_plugins($class,$secondary_plugin_options, $hashArgOptLists);
[10272]107
108 return $self;
[3540]109}
110
[2564]111sub get_default_process_exp {
112 my $self = shift (@_);
113 return q^(?i)\.rtf$^;
114}
[2785]115
[2564]1161;
Note: See TracBrowser for help on using the repository browser.