Changeset 22515

Show
Ignore:
Timestamp:
27.07.2010 16:07:18 (9 years ago)
Author:
kjdon
Message:

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

Location:
main/trunk/greenstone2/perllib/plugins
Files:
2 modified

Legend:

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

    r21958 r22515  
    3131use strict; 
    3232no strict 'refs'; # allow filehandles to be variables and viceversa 
     33no strict 'subs'; 
     34use gsprintf 'gsprintf'; 
    3335 
     36#sub BEGIN { 
     37#    @ExcelPlugin::ISA = ('ConvertBinaryFile'); 
     38#} 
     39 
     40# @ISA dynamically configured to be either OpenOfficeConverter or ConvertBinaryFile 
     41 
     42# do not initialise these variables 
     43my $openoffice_ext_installed; 
     44my $openoffice_ext_working; 
    3445sub BEGIN { 
    35     @ExcelPlugin::ISA = ('ConvertBinaryFile'); 
     46    eval("require OpenOfficeConverter"); 
     47    if ($@) { 
     48    # Useful debugging statement if there is a syntax error in OpenOfficeConverter   
     49    #print STDERR "$@\n"; 
     50    @ExcelPlugin::ISA = ('ConvertBinaryFile'); 
     51    $openoffice_ext_installed = 0; 
     52    $openoffice_ext_working = 0; 
     53    } 
     54    else { 
     55    # Successfully found 
     56    $openoffice_ext_installed = 1; 
     57    # now check whether it can run soffice 
     58    if ($OpenOfficeConverter::openoffice_conversion_available) { 
     59        @ExcelPlugin::ISA = ('OpenOfficeConverter'); 
     60        $openoffice_ext_working = 1; 
     61         
     62    } else { 
     63        @ExcelPlugin::ISA = ('ConvertBinaryFile'); 
     64        $openoffice_ext_working = 0; 
     65    } 
     66    } 
    3667} 
    3768 
     
    4374    'deft' => &get_default_process_exp() } 
    4475      ]; 
     76 
     77my $opt_openoffice_args =  
     78    [ { 'name' => "openoffice_scripting", 
     79    'desc' => "{OpenOfficeConverter.openoffice_scripting}", 
     80    'type' => "flag", 
     81    'reqd' => "no" } ]; 
     82 
    4583 
    4684my $options = { 'name'     => "ExcelPlugin", 
     
    5593    my ($pluginlist,$inputargs,$hashArgOptLists) = @_; 
    5694    push(@$pluginlist, $class); 
     95     
     96    #my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists); 
     97    if ($openoffice_ext_installed) { 
     98    print STDERR "ExcelPlugin: OpenOffice Extension to Greenstone detected\n"; 
     99    if ($openoffice_ext_working) { 
     100        print STDERR "... and it appears to be working\n"; 
     101    } else { 
     102        print STDERR "... but it appears to be broken\n"; 
     103        &gsprintf(STDERR, "OpenOfficeConverter: {OpenOfficeConverter.noconversionavailable} ({OpenOfficeConverter.$OpenOfficeConverter::no_openoffice_conversion_reason})\n"); 
     104    } 
     105    } 
     106 
     107    if ($openoffice_ext_working) { 
     108    push(@$arguments,@$opt_openoffice_args); 
     109    }     
    57110 
    58111    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments}); 
    59112    push(@{$hashArgOptLists->{"OptList"}},$options); 
    60      
    61     my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists); 
     113 
     114    my $self = {}; 
     115 
     116    if ($openoffice_ext_working) { 
     117    $self = new OpenOfficeConverter($pluginlist, $inputargs, $hashArgOptLists); 
     118    } 
     119    else { 
     120    $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists); 
     121    } 
    62122 
    63123    if ($self->{'info_only'}) { 
     
    66126    } 
    67127 
     128    my $outhandle = $self->{'outhandle'}; 
     129 
    68130    $self->{'filename_extension'} = "xls"; 
    69131    $self->{'file_type'} = "Excel"; 
    70132 
     133    $self->{'convert_options'} = "-openoffice_scripting" if $self->{'openoffice_scripting'}; 
     134 
     135    # other options for HTML if using open office??? 
    71136    my $secondary_plugin_options = $self->{'secondary_plugin_options'}; 
    72137    if (!defined $secondary_plugin_options->{'HTMLPlugin'}) { 
  • main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm

    r21958 r22515  
    3232use strict; 
    3333no strict 'refs'; # allow filehandles to be variables and viceversa 
    34  
     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; 
    3546sub BEGIN { 
    36     @PowerPointPlugin::ISA = ('ConvertBinaryFile'); 
     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    } 
    3768} 
    3869 
    39 my $convert_to_list = 
     70my $windows_convert_to_list = 
    4071    [ { 'name' => "auto", 
    4172    'desc' => "{ConvertBinaryFile.convert_to.auto}" }, 
     
    6091      ]; 
    6192 
     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 
    62112my $options = { 'name'     => "PowerPointPlugin", 
    63113        'desc'     => "{PowerPointPlugin.desc}", 
     
    72122    push(@$pluginlist, $class); 
    73123 
     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 
    74134    if ($ENV{'GSDLOS'} =~ m/^windows$/i) { 
    75     my $ws_arg =[{ 'name' => "convert_to", 
    76                'desc' => "{ConvertBinaryFile.convert_to}", 
    77                'type' => "enum", 
    78                'reqd' => "yes", 
    79                'list' => $convert_to_list,  
    80                'deft' => "html" }, 
    81              { 'name' => "windows_scripting", 
    82                'desc' => "{PowerPointPlugin.windows_scripting}", 
    83                'type' => "flag", 
    84                'reqd' => "no" } 
    85              ]; 
    86     push(@$arguments,@$ws_arg); 
    87     } 
    88      
     135    push(@$arguments,@$opt_windows_args); 
     136    } 
     137    if ($openoffice_ext_working) { 
     138    push(@$arguments,@$opt_openoffice_args); 
     139    }     
     140 
    89141    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments}); 
    90142    push(@{$hashArgOptLists->{"OptList"}},$options); 
    91143 
    92144 
    93     my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists); 
     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    } 
    94153  
    95154    if ($self->{'info_only'}) { 
     
    98157    } 
    99158 
     159    my $outhandle = $self->{'outhandle'}; 
     160 
    100161    $self->{'filename_extension'} = "ppt"; 
    101162    $self->{'file_type'} = "PPT"; 
    102163 
     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     
    103171    #these are passed through to gsConvert.pl by ConvertBinaryFile.pm 
    104172    $self->{'convert_options'} = "-windows_scripting" if $self->{'windows_scripting'}; 
     173    $self->{'convert_options'} = "-openoffice_scripting" if $self->{'openoffice_scripting'}; 
    105174    my $secondary_plugin_options = $self->{'secondary_plugin_options'}; 
    106175