Ignore:
Timestamp:
2005-07-06T15:27:45+12:00 (19 years ago)
Author:
kjdon
Message:

Jeffrey's new parsing modifications, committed approx 6 July, 15.16

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/ConvertToPlug.pm

    r9853 r10218  
    6565    'desc' => "{ConvertToPlug.use_strings}",
    6666    'type' => "flag",
    67     'reqd' => "no" } ];
     67    'reqd' => "no" },
     68      { 'name' => "extract_keyphrases",
     69    'desc' => "{BasPlug.extract_keyphrases}",
     70    'type' => "flag",
     71    'reqd' => "no",
     72    'hiddengli' => "yes" },
     73      { 'name' => "extract_keyphrase_options",
     74    'desc' => "{BasPlug.extract_keyphrase_options}",
     75    'type' => "string",
     76    'reqd' => "no",
     77    'hiddengli' => "yes" } ];
    6878
    6979my $options = { 'name'     => "ConvertToPlug",
     
    7383        'args'     => $arguments };
    7484
    75 sub parse_args
     85
     86sub findType
    7687{
    77     my $class = shift (@_);
    78     my ($args) = @_;
    79 
    80     my $plugin_name = $class;
    81     $plugin_name =~ s/\.pm$//;
    82 
    83     my $newargs = {};
    84 
    85     if (!parsargv::parse($args, 
    86              q^extract_keyphrases^, \$newargs->{'kea'}, #with extra options (undocumented)
    87              q^extract_keyphrase_options/.*/^, \$newargs->{'kea_options'}, #no extra options (undocumented)
    88              q^convert_to/(html|text)/html^, \$newargs->{'generate_format'},
    89              q^use_strings^, \$newargs->{'use_strings'},
    90              "allow_extra_options")) {
    91 
    92     print STDERR "\nIncorrect options passed to $plugin_name, ";
    93     print STDERR "check your collect.cfg configuration file\n";
    94     $self->print_txt_usage("");  # Use default resource bundle
    95     die "\n";
    96     }
    97    
    98     return ($plugin_name, $newargs);
     88    my ($inputargs) = @_;
     89   
     90    for(my $intCounter = 0; $intCounter < scalar(@{$inputargs}) ; $intCounter++)
     91    {
     92    if($inputargs->[$intCounter] eq "-convert_to")
     93    {
     94        if($inputargs->[$intCounter+1] eq "text" || $inputargs->[$intCounter+1] eq "html")
     95        {
     96        return $inputargs->[$intCounter+1];
     97        }
     98        else {return "html";}
     99    }
     100    }
     101    return "html";
    99102}
    100103
    101104sub new {
    102     my $class = shift (@_);
    103     if ($class eq "ConvertToPlug" && defined $_[0]) {$class = shift (@_);}
    104     my $self;
    105     # parsargv::parse might modify the list, so we do this by creating a copy
    106     # of the argument list.
    107     my @arglist = @_;
    108     my ($plugin_name, $args) = $class->parse_args(\@_);
    109 
    110     if ($class eq "PDFPlug" && $args->{'generate_format'} eq "text" &&
     105    my ($class) = shift (@_);
     106    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
     107    push(@$pluginlist, $class);
     108    my $classPluginName = (defined $pluginlist->[0]) ? $pluginlist->[0] : $class;
     109    my $strConvertTo = findType($inputargs);
     110
     111    if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
     112    if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
     113
     114    if ($classPluginName eq "PDFPlug" && $strConvertTo eq "text" &&
    111115    $ENV{'GSDLOS'} =~ /^windows$/i) {
    112116    print STDERR "Windows does not support pdf to text. PDFs will be converted to HTML instead\n";
    113     $args->{'generate_format'} = "html";
    114     }
    115 
    116     if ($args->{'generate_format'} eq "text")
     117    $strConvertTo = "html";
     118    }
     119
     120    my $self = {};
     121    if ($strConvertTo eq "text")
    117122    {
    118     $self = new TEXTPlug ($class, @arglist);
     123    $self = (defined $hashArgOptLists)? new TEXTPlug($pluginlist,$inputargs,$hashArgOptLists): new TEXTPlug($pluginlist,$inputargs);
    119124    $self->{'convert_to'} = "TEXT";
    120125    $self->{'convert_to_ext'} = "txt";
     
    122127    else
    123128    {
    124     $self = new HTMLPlug ($class, @arglist);
     129    $self = (defined $hashArgOptLists)? new HTMLPlug($pluginlist,$inputargs,$hashArgOptLists): new HTMLPlug($pluginlist,$inputargs);
    125130    $self->{'convert_to'} = "HTML";
    126131    $self->{'convert_to_ext'} = "html";
     
    130135    }
    131136
    132     # 14-05-02 To allow for proper inheritance of arguments - John Thompson
    133     my $option_list = $self->{'option_list'};
    134     push( @{$option_list}, $options );
    135 
    136     foreach my $key (keys %$args) {
    137       $self->{$key} = $args->{$key};
    138     }
    139  
    140137    return bless $self, $class;
    141138}
     
    273270
    274271    my $outhandle = $self->{'outhandle'};
    275 
     272   
    276273    my $filename = $file;
    277274    $filename = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/;
     
    296293
    297294    my $output_ext = $self->{'convert_to_ext'};
     295   
    298296    my $conv_filename = $self->tmp_area_convert_file($output_ext, $filename);
    299297
Note: See TracChangeset for help on using the changeset viewer.