- Timestamp:
- 2010-08-17T12:14:00+12:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/plugins/WordPlugin.pm
r22611 r22641 25 25 package WordPlugin; 26 26 27 use ConvertBinaryFile;27 use OOConvertBinaryFile; 28 28 29 29 … … 33 33 use gsprintf 'gsprintf'; 34 34 35 # @ISA dynamically configured to be either OpenOfficeConverter or ConvertBinaryFile36 37 # do not initialise these variables38 my $openoffice_ext_installed;39 my $openoffice_ext_working;40 35 sub BEGIN { 41 eval("require OpenOfficeConverter"); 42 if ($@) { 43 # Useful debugging statement if there is a syntax error in OpenOfficeConverter: 44 print STDERR "$@\n"; 45 #@WordPlugin::ISA = ('ConvertBinaryFile'); 46 $openoffice_ext_installed = 0; 47 $openoffice_ext_working = 0; 48 } 49 else { 50 # Successfully found 51 $openoffice_ext_installed = 1; 52 # now check whether it can run soffice 53 if ($OpenOfficeConverter::openoffice_conversion_available) { 54 #@WordPlugin::ISA = ('OpenOfficeConverter'); 55 $openoffice_ext_working = 1; 56 57 } else { 58 #@WordPlugin::ISA = ('ConvertBinaryFile'); 59 $openoffice_ext_working = 0; 60 } 61 } 62 63 if ($openoffice_ext_working) { 64 @WordPlugin::ISA = ('ConvertBinaryFile', 'OpenOfficeConverter'); 65 } else { 66 @WordPlugin::ISA = ('ConvertBinaryFile'); 67 } 36 @WordPlugin::ISA = ('OOConvertBinaryFile'); 68 37 } 69 38 … … 85 54 'reqd' => "no" } ]; 86 55 87 my $opt_openoffice_args =88 [ { 'name' => "openoffice_scripting",89 'desc' => "{OpenOfficeConverter.openoffice_scripting}",90 'type' => "flag",91 'reqd' => "no" } ];92 93 56 my $opt_office_args = [ { 'name' => "metadata_fields", 94 57 'desc' => "{WordPlugin.metadata_fields}", … … 138 101 push(@$pluginlist, $class); 139 102 140 if ($openoffice_ext_installed) {141 print STDERR "WordPlugin: OpenOffice Extension to Greenstone detected\n";142 if ($openoffice_ext_working) {143 print STDERR "... and it appears to be working\n";144 } else {145 print STDERR "... but it appears to be broken\n";146 &gsprintf(STDERR, "OpenOfficeConverter: {OpenOfficeConverter.noconversionavailable} ({OpenOfficeConverter.$OpenOfficeConverter::no_openoffice_conversion_reason})\n");147 }148 }149 150 103 my $office_capable = 0; 151 104 if ($ENV{'GSDLOS'} =~ m/^windows$/i) { … … 153 106 $office_capable = 1; 154 107 } 155 if ($openoffice_ext_working) { 156 push(@$arguments,@$opt_openoffice_args); 108 if ($OOConvertBinaryFile::openoffice_ext_working) { 157 109 $office_capable = 1; 158 110 } … … 165 117 push(@{$hashArgOptLists->{"OptList"}},$options); 166 118 167 my $self = {}; 168 if ($openoffice_ext_working) { 169 170 #$self = new OpenOfficeConverter($pluginlist, $inputargs, $hashArgOptLists); 171 my $ooc_self = new OpenOfficeConverter($pluginlist, $inputargs, $hashArgOptLists); 172 my $cbf_self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists); 173 $self = BasePlugin::merge_inheritance($ooc_self, $cbf_self); 174 } 175 else { 176 $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists); 177 } 119 my $self = new OOConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists); 178 120 179 121 if ($self->{'info_only'}) { … … 195 137 print $outhandle "Warning: Cannot have -windows_scripting and -openoffice_scripting\n"; 196 138 print $outhandle " on at the same time. Defaulting to -windows_scripting\n"; 139 $self->{'openoffice_scripting'} = 0; 197 140 } 198 141 else { 199 $self->{'convert_options'} = "-openoffice_scripting";200 142 $self->{'office_scripting'} = 1; 201 143 } … … 211 153 } 212 154 213 $self = bless $self, $class;214 # if we use the merge inheritance above, need to bless self before calling a method.215 155 # set convert_to_plugin and convert_to_ext 216 156 $self->set_standard_convert_settings(); … … 263 203 } 264 204 265 #$self = bless $self, $class;266 205 $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists); 267 206 268 return bless $self; 269 } 270 271 sub init { 272 my $self = shift (@_); 273 my ($verbosity, $outhandle, $failhandle) = @_; 274 275 $self->SUPER::init($verbosity,$outhandle,$failhandle); 276 if ($openoffice_ext_working) { 277 $self->OpenOfficeConverter::init(); 278 } 279 } 280 281 sub deinit { 282 # called only once, after all plugin passes have been done 283 my ($self) = @_; 284 285 if ($openoffice_ext_working) { 286 $self->OpenOfficeConverter::deinit(); 287 } 288 $self->SUPER::deinit(); 207 return bless $self, $class; 289 208 } 290 209 291 210 sub get_default_process_exp { 292 211 my $self = shift (@_); 293 if ($ openoffice_ext_working) {212 if ($OOConvertBinaryFile::openoffice_ext_working) { 294 213 return q^(?i)\.(doc|dot|docx|odt)$^; 295 214 } … … 297 216 } 298 217 299 # if we are using open office, we use OpenOfficeConverter's convert method, otherwise fall back to ConvertBinaryFile method.300 sub tmp_area_convert_file {301 my $self = shift (@_);302 my ($output_ext, $input_filename, $textref) = @_;303 304 if ($openoffice_ext_working && $self->{'openoffice_scripting'}) {305 my ($result, $result_str, $new_filename) = $self->OpenOfficeConverter::convert($input_filename, $output_ext);306 if ($result != 0) {307 return $new_filename;308 }309 my $outhandle=$self->{'outhandle'};310 print $outhandle "Open Office Conversion error\n";311 print $outhandle $result_str;312 return "";313 }314 else {315 return $self->ConvertBinaryFile::tmp_area_convert_file(@_);316 }317 }318 218 sub convert_post_process_old 319 219 {
Note:
See TracChangeset
for help on using the changeset viewer.