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

Last change on this file since 22709 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
Line 
1###########################################################################
2#
3# PowerPointPlugin.pm -- plugin for importing Microsoft PowerPoint files.
4# (basic version supports versions 95 and 97)
5# (through OpenOffice extension, supports all contempoary formats)
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
29package PowerPointPlugin;
30
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33no strict 'subs';
34
35use gsprintf 'gsprintf';
36
37use AutoloadConverterScripting;
38
39@PowerPointPlugin::ISA = ('AutoloadConverterScripting');
40
41
42my $windows_convert_to_list =
43 [ { 'name' => "auto",
44 'desc' => "{ConvertBinaryFile.convert_to.auto}" },
45 { 'name' => "html",
46 'desc' => "{ConvertBinaryFile.convert_to.html}" },
47 { 'name' => "text",
48 'desc' => "{ConvertBinaryFile.convert_to.text}" },
49 { 'name' => "pagedimg_jpg",
50 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_jpg}" },
51 { 'name' => "pagedimg_gif",
52 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_gif}" },
53 { 'name' => "pagedimg_png",
54 'desc' => "{ConvertBinaryFile.convert_to.pagedimg_png}" }
55 ];
56
57my $arguments =
58 [ { 'name' => "process_exp",
59 'desc' => "{BasePlugin.process_exp}",
60 'type' => "regexp",
61 'reqd' => "no",
62 'deft' => "&get_default_process_exp(\$self)", # delayed (see below)
63 }
64 ];
65
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
79my $options = { 'name' => "PowerPointPlugin",
80 'desc' => "{PowerPointPlugin.desc}",
81 'abstract' => "no",
82 'inherits' => "yes",
83 'srcreplaceable' => "yes", # Source docs in PPT format can be replaced with GS-generated html
84 'args' => $arguments };
85
86sub new {
87 my ($class) = shift (@_);
88 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
89 push(@$pluginlist, $class);
90
91 if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
92 push(@$arguments,@$opt_windows_args);
93 }
94
95 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
96 push(@{$hashArgOptLists->{"OptList"}},$options);
97
98
99 my $self
100 = new AutoloadConverterScripting("OpenOfficeConverter",
101 $pluginlist, $inputargs,
102 $hashArgOptLists);
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
132
133 if ($self->{'info_only'}) {
134 # don't worry about any options etc
135 return bless $self, $class;
136 }
137
138 $self->{'filename_extension'} = "ppt";
139 $self->{'file_type'} = "PPT";
140
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
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
159 #these are passed through to gsConvert.pl by ConvertBinaryFile.pm
160 $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'};
161
162 # set convert_to_plugin and convert_to_ext
163 $self->set_standard_convert_settings();
164
165 my $secondary_plugin_name = $self->{'convert_to_plugin'};
166 my $secondary_plugin_options = $self->{'secondary_plugin_options'};
167
168 if (!defined $secondary_plugin_options->{$secondary_plugin_name}) {
169 $secondary_plugin_options->{$secondary_plugin_name} = [];
170 }
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>");
179 }
180 elsif ($secondary_plugin_name eq "PagedImagePlugin") {
181 push(@$specific_options, "-processing_tmp_files");
182 #is this true??
183 push(@$specific_options,"-input_encoding", "utf8");
184 }
185
186 $self = bless $self, $class;
187
188 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
189 return $self;
190}
191
192sub get_default_process_exp {
193 my $self = shift (@_);
194
195 if ($self->{'scripting_ext_working'}) {
196 return q^(?i)\.(ppt|pptx|odp)$^;
197 }
198
199 return q^(?i)\.ppt$^;
200}
201
2021;
203
Note: See TracBrowser for help on using the repository browser.