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

Last change on this file since 22515 was 22515, checked in by kjdon, 14 years ago

added open office support for PowerPoint and Excel plugins. followed WordPlugin example

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