Ignore:
Timestamp:
2010-08-10T14:31:53+12:00 (14 years ago)
Author:
kjdon
Message:

code tidy up. rearranged how convertbinaryfile plugins set up their secondary plugins - now only set up the options for the one they are using. all subclass specific code moved out of convertbinaryfile.new into the appropriate plugin file.

File:
1 edited

Legend:

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

    r22504 r22597  
    9595    my ($class,$input_args,$hashArgOptLists) = @_;
    9696
    97     my @convert_to_list = split(",",$self->{'convert_to'});
     97    my @convert_to_list = split(",",$self->{'convert_to_plugin'});
    9898    my $secondary_plugins = {};
    9999    # find the plugin
     
    101101    foreach my $convert_to (@convert_to_list) {
    102102    # load in "convert_to" plugin package
    103     my $plugin_class = $convert_to."Plugin";
     103    my $plugin_class = $convert_to;
    104104    my $plugin_package = $plugin_class.".pm";
    105105
     
    143143
    144144    my $self = new AutoExtractMetadata($pluginlist, $inputargs, $hashArgOptLists);
    145    
    146     if ($self->{'info_only'}) {
    147     # don't worry about any options etc
    148     return bless $self, $class;
    149     }
    150 
    151     my $convert_to_type = $self->{'convert_to'};
    152     if (!defined $convert_to_type || $convert_to_type eq "") {
    153     $convert_to_type = "auto";
    154     }
    155     my $windows_scripting = $self->{'windows_scripting'};
    156     $windows_scripting = 0 unless defined $windows_scripting;
    157     if ($classPluginName eq "PDFPlugin") {
    158     if ($convert_to_type eq "text" &&
    159         $ENV{'GSDLOS'} =~ /^windows$/i) {
    160         print STDERR "Windows does not support pdf to text. PDFs will be converted to HTML instead\n";
    161         $convert_to_type = "html";
    162     }
    163     } elsif ($classPluginName eq "WordPlugin") {
    164     if (($windows_scripting && $ENV{'GSDLOS'} =~ /^windows$/i && $convert_to_type =~ /^(html|auto)$/) || defined $self->{'openoffice_scripting'}) {
    165         # we use structured HTML, not normal html
    166         $convert_to_type = "structuredhtml";
    167     }
    168     } elsif ($classPluginName eq "PowerPointPlugin") {
    169     if ($windows_scripting && $ENV{'GSDLOS'} =~ /^windows$/i && $convert_to_type eq "auto") {
    170         # we use paged img
    171         $convert_to_type = "pagedimg_jpg";
    172     }
    173     } elsif ($classPluginName eq "PostScriptPlugin") {
    174     if ($convert_to_type eq "auto") {
    175         # we use text
    176         $convert_to_type = "text";
    177     }
    178     }
    179    
    180     if ($convert_to_type eq "auto") {
    181     # choose html for now - should choose a format based on doc type
    182     $convert_to_type = "html";
    183     }
    184    
    185     if ($convert_to_type eq "html") {
    186     $self->{'convert_to'} = "HTML";
     145   
     146    return bless $self, $class;
     147}
     148
     149# should be called by subclasses after checking and setting
     150# $self->{'convert_to'}
     151sub set_standard_convert_settings {
     152    my $self =shift (@_);
     153   
     154    my $convert_to = $self->{'convert_to'};
     155    if ($convert_to eq "auto") {
     156    $convert_to = "html";
     157    $self->{'convert_to'} = "html";
     158    }
     159
     160    if ($convert_to eq "html") {
     161    $self->{'convert_to_plugin'} = "HTMLPlugin";
    187162    $self->{'convert_to_ext'} = "html";
    188     } elsif ($convert_to_type eq "text") {
    189     $self->{'convert_to'} = "Text";
     163    } elsif ($convert_to eq "text") {
     164    $self->{'convert_to_plugin'} = "TextPlugin";
    190165    $self->{'convert_to_ext'} = "txt";
    191     } elsif ($convert_to_type eq "structuredhtml") {
    192     $self->{'convert_to'} = "StructuredHTML";
     166    } elsif ($convert_to eq "structuredhtml") {
     167    $self->{'convert_to_plugin'} = "StructuredHTMLPlugin";
    193168    $self->{'convert_to_ext'} = "html";
    194     } elsif ($convert_to_type =~ /^pagedimg/) {
    195     $self->{'convert_to'} = "PagedImage";
    196     my ($convert_to_ext) = $convert_to_type =~ /pagedimg\_(jpg|gif|png)/i;
     169    } elsif ($convert_to =~ /^pagedimg/) {
     170    $self->{'convert_to_plugin'} = "PagedImagePlugin";
     171    my ($convert_to_ext) = $convert_to =~ /pagedimg\_(jpg|gif|png)/i;
    197172    $convert_to_ext = 'jpg' unless defined $convert_to_ext;
    198173    $self->{'convert_to_ext'} = $convert_to_ext;
    199174    }
    200    
    201     return bless $self, $class;
    202 }
    203 
    204 
     175
     176}
    205177sub init {
    206178    my $self = shift (@_);
     
    316288    # Execute the conversion command and get the type of the result,
    317289    # making sure the converter gives us the appropriate output type
    318     my $output_type="";
    319     if ($convert_to =~ m/PagedImage/i) {
    320     $output_type = lc($convert_to)."_".lc($convert_to_ext);
    321     } else {
    322     $output_type = lc($convert_to);
    323     }
     290    my $output_type=$self->{'convert_to'};
     291#    if ($convert_to =~ m/PagedImage/i) {
     292#   $output_type = lc($convert_to)."_".lc($convert_to_ext);
     293#    } else {
     294#   $output_type = lc($convert_to);
     295#    }
    324296
    325297    my $cmd = "perl -S gsConvert.pl -verbose $verbosity ";
     
    331303    }
    332304    $cmd .= "-errlog \"$errlog\" -output $output_type \"$tmp_filename\"";
    333 
     305    print STDERR "calling cmd $cmd\n";
    334306    $output_type = `$cmd`;
    335307
Note: See TracChangeset for help on using the changeset viewer.