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

Revision 22597, 6.9 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:keywords set to Author Date Id Revision
Line 
1###########################################################################
2#
3# PowerPointPlugin.pm -- plugin for importing Microsoft PowerPoint files.
4#  (currently only versions 95 and 97)
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) 2002 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
28package PowerPointPlugin;
29
30use ConvertBinaryFile;
31
32use strict;
33no strict 'refs'; # allow filehandles to be variables and viceversa
34no strict 'subs';
35use gsprintf 'gsprintf';
36
37# @ISA dynamically configured to be either OpenOfficeConverter or ConvertBinaryFile
38
39# do not initialise these variables
40my $openoffice_ext_installed;
41my $openoffice_ext_working;
42sub BEGIN {
43    eval("require OpenOfficeConverter");
44    if ($@) {
45    # Useful debugging statement if there is a syntax error in OpenOfficeConverter 
46    #print STDERR "$@\n";
47    @PowerPointPlugin::ISA = ('ConvertBinaryFile');
48    $openoffice_ext_installed = 0;
49    $openoffice_ext_working = 0;
50    }
51    else {
52    # Successfully found
53    $openoffice_ext_installed = 1;
54    # now check whether it can run soffice
55    if ($OpenOfficeConverter::openoffice_conversion_available) {
56        @PowerPointPlugin::ISA = ('OpenOfficeConverter');
57        $openoffice_ext_working = 1;
58       
59    } else {
60        @PowerPointPlugin::ISA = ('ConvertBinaryFile');
61        $openoffice_ext_working = 0;
62    }
63    }
64}
65
66my $windows_convert_to_list =
67    [ { 'name' => "auto",
68    'desc' => "{ConvertBinaryFile.convert_to.auto}" },
69      { 'name' => "html",
70    'desc' => "{ConvertBinaryFile.convert_to.html}" },
71      { 'name' => "text",
72    'desc' => "{ConvertBinaryFile.convert_to.text}" },
73      { 'name' => "pagedimg_jpg",
74    'desc' => "{ConvertBinaryFile.convert_to.pagedimg_jpg}" },
75      { 'name' => "pagedimg_gif",
76    'desc' => "{ConvertBinaryFile.convert_to.pagedimg_gif}" },
77      { 'name' => "pagedimg_png",
78    'desc' => "{ConvertBinaryFile.convert_to.pagedimg_png}" }
79      ];
80
81my $arguments =
82    [ { 'name' => "process_exp",
83    'desc' => "{BasePlugin.process_exp}",
84    'type' => "regexp",
85    'reqd' => "no",
86    'deft' => &get_default_process_exp()}
87      ];
88
89my $opt_windows_args =
90    [ { 'name' => "convert_to",
91    'desc' => "{ConvertBinaryFile.convert_to}",
92    'type' => "enum",
93    'reqd' => "yes",
94    'list' => $windows_convert_to_list,
95    'deft' => "html" },
96      { 'name' => "windows_scripting",
97    'desc' => "{PowerPointPlugin.windows_scripting}",
98    'type' => "flag",
99    'reqd' => "no" }
100      ];
101
102my $opt_openoffice_args =
103    [ { 'name' => "openoffice_scripting",
104    'desc' => "{OpenOfficeConverter.openoffice_scripting}",
105    'type' => "flag",
106    'reqd' => "no" } ];
107
108my $options = { 'name'     => "PowerPointPlugin",
109        'desc'     => "{PowerPointPlugin.desc}",
110        'abstract' => "no",
111        'inherits' => "yes",
112        'srcreplaceable' => "yes", # Source docs in PPT format can be replaced with GS-generated html
113            'args'     => $arguments };
114
115sub new {
116    my ($class) = shift (@_);
117    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
118    push(@$pluginlist, $class);
119
120    if ($openoffice_ext_installed) {
121    print STDERR "PowerPointPlugin: OpenOffice Extension to Greenstone detected\n";
122    if ($openoffice_ext_working) {
123        print STDERR "... and it appears to be working\n";
124    } else {
125        print STDERR "... but it appears to be broken\n";
126        &gsprintf(STDERR, "OpenOfficeConverter: {OpenOfficeConverter.noconversionavailable} ({OpenOfficeConverter.$OpenOfficeConverter::no_openoffice_conversion_reason})\n");
127    }
128    }
129
130    if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
131    push(@$arguments,@$opt_windows_args);
132    }
133    if ($openoffice_ext_working) {
134    push(@$arguments,@$opt_openoffice_args);
135    }   
136
137    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
138    push(@{$hashArgOptLists->{"OptList"}},$options);
139
140
141    my $self = {};
142
143    if ($openoffice_ext_working) {
144    $self = new OpenOfficeConverter($pluginlist, $inputargs, $hashArgOptLists);
145    }
146    else {
147    $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
148    }
149 
150    if ($self->{'info_only'}) {
151    # don't worry about any options etc
152    return bless $self, $class;
153    }
154
155    $self->{'filename_extension'} = "ppt";
156    $self->{'file_type'} = "PPT";
157
158    if ($self->{'convert_to'} eq "auto") {
159    if ($self->{'windows_scripting'}) {
160        $self->{'convert_to'} = "pagedimg_jpg";
161    }
162    else {
163        $self->{'convert_to'} = "html";
164    }
165    }
166
167   my $outhandle = $self->{'outhandle'};
168
169    # can't have windows_scripting and openoffice_scripting at the same time
170    if ($self->{'windows_scripting'} && $self->{'openoffice_scripting'}) {
171    print $outhandle "Warning: Cannot have -windows_scripting and -openoffice_scripting\n";
172    print $outhandle "         on at the same time.  Defaulting to -windows_scripting\n";
173    $self->{'openoffice_scripting'} = 0;
174    }
175   
176    #these are passed through to gsConvert.pl by ConvertBinaryFile.pm
177    $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'};
178    $self->{'convert_options'} = "-openoffice_scripting" if $self->{'openoffice_scripting'};
179
180    # set convert_to_plugin and convert_to_ext
181    $self->ConvertBinaryFile::set_standard_convert_settings();
182
183    my $secondary_plugin_name = $self->{'convert_to_plugin'};
184    my $secondary_plugin_options = $self->{'secondary_plugin_options'};
185
186    if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
187    $secondary_plugin_options->{$secondary_plugin_name} = [];
188    }
189    my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
190
191    push(@$specific_options, "-file_rename_method", "none");
192    push(@$specific_options, "-extract_language") if $self->{'extract_language'};
193
194    if ($secondary_plugin_name eq "HTMLPlugin") {
195    push(@$specific_options, "-processing_tmp_files");
196    push(@$specific_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
197    }
198    elsif ($secondary_plugin_name eq "PagedImagePlugin") {
199    push(@$specific_options, "-processing_tmp_files");
200    #is this true??
201    push(@$specific_options,"-input_encoding", "utf8");
202    }
203
204    $self = bless $self, $class;
205
206    $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
207    return $self;
208}
209
210sub get_default_process_exp {
211    my $self = shift (@_);
212    return q^(?i)\.ppt$^;
213}
214
2151;
216
Note: See TracBrowser for help on using the browser.