Changeset 22507

Show
Ignore:
Timestamp:
26.07.2010 15:43:40 (10 years ago)
Author:
kjdon
Message:

some moving around and tidying up of code

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/WordPlugin.pm

    r22505 r22507  
    3030use strict; 
    3131no strict 'refs'; # allow filehandles to be variables and viceversa 
    32  
     32no strict 'subs'; 
     33use gsprintf 'gsprintf'; 
    3334 
    3435# @ISA dynamically configured to be either OpenOfficeConverter or ConvertBinaryFile 
     36 
     37# do not initialise these variables 
     38my $openoffice_ext_installed; 
     39my $openoffice_ext_working; 
     40sub 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} 
    3563 
    3664my $arguments = 
     
    104132    push(@$pluginlist, $class); 
    105133 
    106     my $openoffice_ext_installed; 
    107     eval("require OpenOfficeConverter"); 
    108     if ($@) { 
    109     # Useful debugging statement if there is a syntax error in OpenOfficeConverter   
    110      #print STDERR "$@\n"; 
    111  
    112     push(@WordPlugin::ISA,"ConvertBinaryFile"); 
    113     $openoffice_ext_installed = 0; 
    114     } 
    115     else { 
    116     # Successfully found 
     134    if ($openoffice_ext_installed) { 
    117135    print STDERR "WordPlugin: OpenOffice Extension to Greenstone detected\n"; 
    118     push(@WordPlugin::ISA,"OpenOfficeConverter"); 
    119     $openoffice_ext_installed = 1; 
    120     } 
    121  
     136    if ($openoffice_ext_working) { 
     137        print STDERR "... and it appears to be working\n"; 
     138    } else { 
     139        print STDERR "... but it appears to be broken\n"; 
     140        &gsprintf(STDERR, "OpenOfficeConverter: {OpenOfficeConverter.noconversionavailable} ({OpenOfficeConverter.$OpenOfficeConverter::no_openoffice_conversion_reason})\n"); 
     141    } 
     142    } 
     143     
     144    my $office_capable = 0; 
    122145    if ($ENV{'GSDLOS'} =~ m/^windows$/i) { 
    123146    push(@$arguments,@$opt_windows_args); 
     147    $office_capable = 1; 
     148    } 
     149    if ($openoffice_ext_working) { 
     150    push(@$arguments,@$opt_openoffice_args); 
     151    $office_capable = 1; 
     152    } 
     153    # these office args apply to windows scripting or to openoffice scripting 
     154    if ($office_capable) { 
    124155    push(@$arguments,@$opt_office_args); 
    125156    } 
    126     elsif ($openoffice_ext_installed) { 
    127     push(@$arguments,@$opt_openoffice_args); 
    128     push(@$arguments,@$opt_office_args); 
    129     } 
    130  
     157     
    131158    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments}); 
    132159    push(@{$hashArgOptLists->{"OptList"}},$options); 
     
    135162    my $outhandle; 
    136163 
    137     if ($openoffice_ext_installed) { 
     164    if ($openoffice_ext_working) { 
     165     
    138166    $self = new OpenOfficeConverter($pluginlist, $inputargs, $hashArgOptLists); 
    139167    $outhandle = $self->{'outhandle'}; 
    140168 
    141     if ($self->{'openoffice_conversion_available'}) { 
    142         print $outhandle "WordPlugin: OpenOffice scripting functionality available\n"; 
    143  
    144         # Override default process expression 
    145         $self->{'process_exp'} = q^(?i)\.(doc|dot|docx|odt)$^; 
    146  
    147         if ($self->{'openoffice_scripting'}) { 
    148         print $outhandle "WordPlugin: Activating OpenOffice scripting functionality\n"; 
    149         } 
    150     } 
    151     else { 
    152         print $outhandle "WordPlugin: Unable to run 'soffice'\n"; 
    153         print $outhandle "WordPlugin: Defaulting to ConvertBinaryFile inheritence\n"; 
    154     } 
    155169    } 
    156170    else { 
     
    266280sub get_default_process_exp { 
    267281    my $self = shift (@_); 
    268  
     282    if ($openoffice_ext_working) { 
     283    return q^(?i)\.(doc|dot|docx|odt)$^; 
     284    } 
    269285    return q^(?i)\.(doc|dot)$^; 
    270286}