source: main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm@ 22632

Last change on this file since 22632 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:keywords set to Author Date Id Revision
File size: 6.9 KB
RevLine 
[2981]1###########################################################################
2#
[17722]3# PowerPointPlugin.pm -- plugin for importing Microsoft PowerPoint files.
[2981]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
[17722]28package PowerPointPlugin;
[2981]29
[15872]30use ConvertBinaryFile;
31
[10254]32use strict;
33no strict 'refs'; # allow filehandles to be variables and viceversa
[22515]34no strict 'subs';
35use gsprintf 'gsprintf';
[2981]36
[22515]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;
[2981]42sub BEGIN {
[22515]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 }
[2981]64}
65
[22515]66my $windows_convert_to_list =
[10466]67 [ { 'name' => "auto",
[15872]68 'desc' => "{ConvertBinaryFile.convert_to.auto}" },
[10466]69 { 'name' => "html",
[15872]70 'desc' => "{ConvertBinaryFile.convert_to.html}" },
[10466]71 { 'name' => "text",
[15872]72 'desc' => "{ConvertBinaryFile.convert_to.text}" },
[10466]73 { 'name' => "pagedimg_jpg",
[15872]74 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_jpg}" },
[10466]75 { 'name' => "pagedimg_gif",
[15872]76 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_gif}" },
[10466]77 { 'name' => "pagedimg_png",
[15872]78 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_png}" }
[10466]79 ];
80
[6408]81my $arguments =
82 [ { 'name' => "process_exp",
[15872]83 'desc' => "{BasePlugin.process_exp}",
[6408]84 'type' => "regexp",
85 'reqd' => "no",
[10275]86 'deft' => &get_default_process_exp()}
[6408]87 ];
88
[22515]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
[17722]108my $options = { 'name' => "PowerPointPlugin",
[17744]109 'desc' => "{PowerPointPlugin.desc}",
[6408]110 'abstract' => "no",
[11679]111 'inherits' => "yes",
[15114]112 'srcreplaceable' => "yes", # Source docs in PPT format can be replaced with GS-generated html
[6408]113 'args' => $arguments };
[4744]114
[2981]115sub new {
[10218]116 my ($class) = shift (@_);
117 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
118 push(@$pluginlist, $class);
[2981]119
[22515]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
[10275]130 if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
[22515]131 push(@$arguments,@$opt_windows_args);
[10275]132 }
[22515]133 if ($openoffice_ext_working) {
134 push(@$arguments,@$opt_openoffice_args);
135 }
136
[15872]137 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
138 push(@{$hashArgOptLists->{"OptList"}},$options);
[10218]139
[10427]140
[22515]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 }
[10275]149
[10580]150 if ($self->{'info_only'}) {
151 # don't worry about any options etc
152 return bless $self, $class;
153 }
154
[15872]155 $self->{'filename_extension'} = "ppt";
156 $self->{'file_type'} = "PPT";
157
[22597]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
[22515]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
[15872]176 #these are passed through to gsConvert.pl by ConvertBinaryFile.pm
[10491]177 $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'};
[22515]178 $self->{'convert_options'} = "-openoffice_scripting" if $self->{'openoffice_scripting'};
[22597]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'};
[10275]184 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
[10218]185
[22597]186 if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
187 $secondary_plugin_options->{$secondary_plugin_name} = [];
[10275]188 }
[22597]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>");
[18406]197 }
[22597]198 elsif ($secondary_plugin_name eq "PagedImagePlugin") {
199 push(@$specific_options, "-processing_tmp_files");
[21958]200 #is this true??
[22597]201 push(@$specific_options,"-input_encoding", "utf8");
[15903]202 }
[2981]203
[10275]204 $self = bless $self, $class;
205
[10427]206 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
[10275]207 return $self;
[2981]208}
209
210sub get_default_process_exp {
211 my $self = shift (@_);
212 return q^(?i)\.ppt$^;
213}
[10275]214
[2981]2151;
[10275]216
Note: See TracBrowser for help on using the repository browser.