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

Last change on this file since 22853 was 22709, checked in by davidb, 14 years ago

Fixed up -process_exp so it now dynamically configures itself properly, based on whether OpenOfficeConverter is found or not

  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
RevLine 
[2981]1###########################################################################
2#
[17722]3# PowerPointPlugin.pm -- plugin for importing Microsoft PowerPoint files.
[22709]4# (basic version supports versions 95 and 97)
5# (through OpenOffice extension, supports all contempoary formats)
[2981]6#
7# A component of the Greenstone digital library software
8# from the New Zealand Digital Library Project at the
9# University of Waikato, New Zealand.
10#
11# Copyright (C) 2002 New Zealand Digital Library Project
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2 of the License, or
16# (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#
27###########################################################################
28
[17722]29package PowerPointPlugin;
[2981]30
[10254]31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
[22515]33no strict 'subs';
[22705]34
[22515]35use gsprintf 'gsprintf';
[2981]36
[22705]37use AutoloadConverterScripting;
[2981]38
[22705]39@PowerPointPlugin::ISA = ('AutoloadConverterScripting');
40
41
[22515]42my $windows_convert_to_list =
[10466]43 [ { 'name' => "auto",
[15872]44 'desc' => "{ConvertBinaryFile.convert_to.auto}" },
[10466]45 { 'name' => "html",
[15872]46 'desc' => "{ConvertBinaryFile.convert_to.html}" },
[10466]47 { 'name' => "text",
[15872]48 'desc' => "{ConvertBinaryFile.convert_to.text}" },
[10466]49 { 'name' => "pagedimg_jpg",
[15872]50 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_jpg}" },
[10466]51 { 'name' => "pagedimg_gif",
[15872]52 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_gif}" },
[10466]53 { 'name' => "pagedimg_png",
[15872]54 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_png}" }
[10466]55 ];
56
[6408]57my $arguments =
58 [ { 'name' => "process_exp",
[15872]59 'desc' => "{BasePlugin.process_exp}",
[6408]60 'type' => "regexp",
61 'reqd' => "no",
[22709]62 'deft' => "&get_default_process_exp(\$self)", # delayed (see below)
63 }
[6408]64 ];
65
[22515]66my $opt_windows_args =
67 [ { 'name' => "convert_to",
68 'desc' => "{ConvertBinaryFile.convert_to}",
69 'type' => "enum",
70 'reqd' => "yes",
71 'list' => $windows_convert_to_list,
72 'deft' => "html" },
73 { 'name' => "windows_scripting",
74 'desc' => "{PowerPointPlugin.windows_scripting}",
75 'type' => "flag",
76 'reqd' => "no" }
77 ];
78
[17722]79my $options = { 'name' => "PowerPointPlugin",
[17744]80 'desc' => "{PowerPointPlugin.desc}",
[6408]81 'abstract' => "no",
[11679]82 'inherits' => "yes",
[15114]83 'srcreplaceable' => "yes", # Source docs in PPT format can be replaced with GS-generated html
[6408]84 'args' => $arguments };
[4744]85
[2981]86sub new {
[10218]87 my ($class) = shift (@_);
88 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
89 push(@$pluginlist, $class);
[2981]90
[10275]91 if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
[22515]92 push(@$arguments,@$opt_windows_args);
[10275]93 }
[22515]94
[15872]95 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
96 push(@{$hashArgOptLists->{"OptList"}},$options);
[10218]97
[10427]98
[22705]99 my $self
100 = new AutoloadConverterScripting("OpenOfficeConverter",
101 $pluginlist, $inputargs,
102 $hashArgOptLists);
[22709]103
104
105 # plugin's process_exp can only be correctly determined once autoloading
106 # has taken place
107 my $plug_options = $self->{'option_list'}->[0];
108 my $plug_args = $plug_options->{'args'};
109
110 foreach my $a (@$plug_args) {
111 # consider changing this to search for all values that are
112 # tagged as 'deft-delayed' = 1 ?!?
113
114 if ($a->{'name'} eq "process_exp") {
115 my $eval_expr = $a->{'deft'};
116 $a->{'deft'} = eval "$eval_expr";
117
118 # Now see if process_exp needs updating
119 my $process_exp = $self->{'process_exp'};
120 if (!$self->{'info_only'} && ($process_exp eq $eval_expr)) {
121 # process_exp is only defined if not 'info_only'
122 #
123 # if it does exist and it equals the unevaluated $eval_expr
124 # then it was set to the default (rather than overriden by
125 # the collect.cfg file)
126
127 $self->{'process_exp'} = $a->{'deft'};
128 }
129 }
130 }
131
[10275]132
[10580]133 if ($self->{'info_only'}) {
134 # don't worry about any options etc
135 return bless $self, $class;
136 }
137
[15872]138 $self->{'filename_extension'} = "ppt";
139 $self->{'file_type'} = "PPT";
140
[22597]141 if ($self->{'convert_to'} eq "auto") {
142 if ($self->{'windows_scripting'}) {
143 $self->{'convert_to'} = "pagedimg_jpg";
144 }
145 else {
146 $self->{'convert_to'} = "html";
147 }
148 }
149
150 my $outhandle = $self->{'outhandle'};
151
[22515]152 # can't have windows_scripting and openoffice_scripting at the same time
153 if ($self->{'windows_scripting'} && $self->{'openoffice_scripting'}) {
154 print $outhandle "Warning: Cannot have -windows_scripting and -openoffice_scripting\n";
155 print $outhandle " on at the same time. Defaulting to -windows_scripting\n";
156 $self->{'openoffice_scripting'} = 0;
157 }
158
[15872]159 #these are passed through to gsConvert.pl by ConvertBinaryFile.pm
[10491]160 $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'};
[22597]161
162 # set convert_to_plugin and convert_to_ext
[22640]163 $self->set_standard_convert_settings();
[22597]164
165 my $secondary_plugin_name = $self->{'convert_to_plugin'};
[10275]166 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
[10218]167
[22597]168 if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
169 $secondary_plugin_options->{$secondary_plugin_name} = [];
[10275]170 }
[22597]171 my $specific_options = $secondary_plugin_options->{$secondary_plugin_name};
172
173 push(@$specific_options, "-file_rename_method", "none");
174 push(@$specific_options, "-extract_language") if $self->{'extract_language'};
175
176 if ($secondary_plugin_name eq "HTMLPlugin") {
177 push(@$specific_options, "-processing_tmp_files");
178 push(@$specific_options,"-metadata_fields","Title,GENERATOR,date,author<Creator>");
[18406]179 }
[22597]180 elsif ($secondary_plugin_name eq "PagedImagePlugin") {
181 push(@$specific_options, "-processing_tmp_files");
[21958]182 #is this true??
[22597]183 push(@$specific_options,"-input_encoding", "utf8");
[15903]184 }
[2981]185
[10275]186 $self = bless $self, $class;
187
[10427]188 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
[10275]189 return $self;
[2981]190}
191
192sub get_default_process_exp {
193 my $self = shift (@_);
[22709]194
195 if ($self->{'scripting_ext_working'}) {
196 return q^(?i)\.(ppt|pptx|odp)$^;
197 }
198
[2981]199 return q^(?i)\.ppt$^;
200}
[10275]201
[2981]2021;
[10275]203
Note: See TracBrowser for help on using the repository browser.