Changeset 22641

Show
Ignore:
Timestamp:
17.08.2010 12:14:00 (9 years ago)
Author:
kjdon
Message:

now inherits from OOConvertBinaryFile. still a couple of things to iron out

Files:
1 modified

Legend:

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

    r22611 r22641  
    2525package WordPlugin; 
    2626 
    27 use ConvertBinaryFile; 
     27use OOConvertBinaryFile; 
    2828 
    2929 
     
    3333use gsprintf 'gsprintf'; 
    3434 
    35 # @ISA dynamically configured to be either OpenOfficeConverter or ConvertBinaryFile 
    36  
    37 # do not initialise these variables 
    38 my $openoffice_ext_installed; 
    39 my $openoffice_ext_working; 
    4035sub 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'); 
    6837} 
    6938 
     
    8554               'reqd' => "no" } ]; 
    8655 
    87 my $opt_openoffice_args =  
    88     [ { 'name' => "openoffice_scripting", 
    89     'desc' => "{OpenOfficeConverter.openoffice_scripting}", 
    90     'type' => "flag", 
    91     'reqd' => "no" } ]; 
    92  
    9356my $opt_office_args = [ { 'name' => "metadata_fields", 
    9457              'desc' => "{WordPlugin.metadata_fields}", 
     
    138101    push(@$pluginlist, $class); 
    139102 
    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      
    150103    my $office_capable = 0; 
    151104    if ($ENV{'GSDLOS'} =~ m/^windows$/i) { 
     
    153106    $office_capable = 1; 
    154107    } 
    155     if ($openoffice_ext_working) { 
    156     push(@$arguments,@$opt_openoffice_args); 
     108    if ($OOConvertBinaryFile::openoffice_ext_working) { 
    157109    $office_capable = 1; 
    158110    } 
     
    165117    push(@{$hashArgOptLists->{"OptList"}},$options); 
    166118 
    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); 
    178120 
    179121    if ($self->{'info_only'}) { 
     
    195137        print $outhandle "Warning: Cannot have -windows_scripting and -openoffice_scripting\n"; 
    196138        print $outhandle "         on at the same time.  Defaulting to -windows_scripting\n"; 
     139        $self->{'openoffice_scripting'} = 0; 
    197140    } 
    198141    else { 
    199         $self->{'convert_options'} = "-openoffice_scripting"; 
    200142        $self->{'office_scripting'} = 1; 
    201143    } 
     
    211153    }  
    212154 
    213     $self = bless $self, $class; 
    214     # if we use the merge inheritance above, need to bless self before calling a method. 
    215155    # set convert_to_plugin and convert_to_ext 
    216156    $self->set_standard_convert_settings(); 
     
    263203    } 
    264204 
    265     #$self = bless $self, $class; 
    266205    $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists); 
    267206 
    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; 
    289208} 
    290209 
    291210sub get_default_process_exp { 
    292211    my $self = shift (@_); 
    293     if ($openoffice_ext_working) { 
     212    if ($OOConvertBinaryFile::openoffice_ext_working) { 
    294213    return q^(?i)\.(doc|dot|docx|odt)$^; 
    295214    } 
     
    297216} 
    298217 
    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 } 
    318218sub convert_post_process_old 
    319219{