Ignore:
Timestamp:
2008-06-05T09:29:32+12:00 (16 years ago)
Author:
kjdon
Message:

plugin overhaul: plugins renamed to xxPlugin, and in some cases the names are made more sensible. They now use the new base plugins. Hopefully we have better code reuse. Some of the plugins still need work done as I didn't want to spend another month doing this before committing it. Alos, I haven't really tested anything yet...

File:
1 edited

Legend:

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

    r15865 r15872  
    11###########################################################################
    22#
    3 # PDFPlug.pm -- reasonably with-it pdf plugin
     3# PDFPlugin.pm -- reasonably with-it pdf plugin
    44# A component of the Greenstone digital library software
    55# from the New Zealand Digital Library Project at the
     
    2323#
    2424###########################################################################
    25 package PDFPlug;
    26 
    27 use ConvertToPlug;
     25package PDFPlugin;
     26
     27use ConvertBinaryFile;
     28use ReadTextFile;
    2829use unicode;
    2930use strict;
     
    3132
    3233sub BEGIN {
    33     @PDFPlug::ISA = ('ConvertToPlug');
     34    @PDFPlugin::ISA = ('ConvertBinaryFile', 'ReadTextFile');
    3435}
    3536
    3637my $convert_to_list =
    3738    [ { 'name' => "auto",
    38     'desc' => "{ConvertToPlug.convert_to.auto}" },
     39    'desc' => "{ConvertBinaryFile.convert_to.auto}" },
    3940      { 'name' => "html",
    40     'desc' => "{ConvertToPlug.convert_to.html}" },
     41    'desc' => "{ConvertBinaryFile.convert_to.html}" },
    4142      { 'name' => "text",
    42     'desc' => "{ConvertToPlug.convert_to.text}" },
     43    'desc' => "{ConvertBinaryFile.convert_to.text}" },
    4344      { 'name' => "pagedimg_jpg",
    44     'desc' => "{ConvertToPlug.convert_to.pagedimg_jpg}"},
     45    'desc' => "{ConvertBinaryFile.convert_to.pagedimg_jpg}"},
    4546      { 'name' => "pagedimg_gif",
    46     'desc' => "{ConvertToPlug.convert_to.pagedimg_gif}"},
     47    'desc' => "{ConvertBinaryFile.convert_to.pagedimg_gif}"},
    4748      { 'name' => "pagedimg_png",
    48     'desc' => "{ConvertToPlug.convert_to.pagedimg_png}"},
     49    'desc' => "{ConvertBinaryFile.convert_to.pagedimg_png}"},
    4950      ];
    5051
     
    5354    [
    5455     { 'name' => "convert_to",
    55        'desc' => "{ConvertToPlug.convert_to}",
     56       'desc' => "{ConvertBinaryFile.convert_to}",
    5657       'type' => "enum",
    5758       'reqd' => "yes",
     
    5960       'deft' => "html" },   
    6061     { 'name' => "process_exp",
    61        'desc' => "{BasPlug.process_exp}",
     62       'desc' => "{BasePlugin.process_exp}",
    6263       'type' => "regexp",
    6364       'deft' => &get_default_process_exp(),
    6465       'reqd' => "no" },
    6566     { 'name' => "block_exp",
    66        'desc' => "{BasPlug.block_exp}",
     67       'desc' => "{BasePlugin.block_exp}",
    6768       'type' => "regexp",
    6869       'deft' => &get_default_block_exp() },
    6970     { 'name' => "metadata_fields",
    70        'desc' => "{HTMLPlug.metadata_fields}",
     71       'desc' => "{HTMLPlugin.metadata_fields}",
    7172       'type' => "string",
    7273       'deft' => "" },
    7374     { 'name' => "noimages",
    74        'desc' => "{PDFPlug.noimages}",
     75       'desc' => "{PDFPlugin.noimages}",
    7576       'type' => "flag" },
    7677     { 'name' => "allowimagesonly",
    77        'desc' => "{PDFPlug.allowimagesonly}",
     78       'desc' => "{PDFPlugin.allowimagesonly}",
    7879       'type' => "flag" },
    7980     { 'name' => "complex",
    80        'desc' => "{PDFPlug.complex}",
     81       'desc' => "{PDFPlugin.complex}",
    8182       'type' => "flag" },
    8283     { 'name' => "nohidden",
    83        'desc' => "{PDFPlug.nohidden}",
     84       'desc' => "{PDFPlugin.nohidden}",
    8485       'type' => "flag" },
    8586     { 'name' => "zoom",
    86        'desc' => "{PDFPlug.zoom}",
     87       'desc' => "{PDFPlugin.zoom}",
    8788       'deft' => "2",
    8889       'range' => "1,3", # actually the range is 0.5-3
    8990       'type' => "int" },
    9091     { 'name' => "use_sections",
    91        'desc' => "{PDFPlug.use_sections}",
     92       'desc' => "{PDFPlugin.use_sections}",
    9293       'type' => "flag" },
    9394     { 'name' => "description_tags",
    94        'desc' => "{HTMLPlug.description_tags}",
     95       'desc' => "{HTMLPlugin.description_tags}",
    9596       'type' => "flag" }
    9697     ];
    9798
    98 my $options = { 'name'     => "PDFPlug",
    99         'desc'     => "{PDFPlug.desc}",
     99my $options = { 'name'     => "PDFPlugin",
     100        'desc'     => "{PDFPlugin.desc}",
    100101        'abstract' => "no",
    101102        'inherits' => "yes",
     
    111112    push(@$inputargs,'^(Page\s+\d+)?(\s*1\s+)?');
    112113
    113     if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
    114     if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
     114    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
     115    push(@{$hashArgOptLists->{"OptList"}},$options);
    115116
    116117    my @arg_array = @$inputargs;
    117     my $self = new ConvertToPlug($pluginlist, $inputargs, $hashArgOptLists);
     118    my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
    118119   
    119120    if ($self->{'info_only'}) {
     
    122123    }
    123124
    124     # these are passed through to gsConvert.pl by ConvertToPlug.pm
     125    $self->{'filename_extension'} = "pdf";
     126    $self->{'file_type'} = "PDF";
     127
     128    # these are passed through to gsConvert.pl by ConvertBinaryFile.pm
    125129    my $zoom = $self->{"zoom"};
    126130    $self->{'convert_options'} = "-pdf_zoom $zoom";
     
    132136    my $secondary_plugin_options = $self->{'secondary_plugin_options'};
    133137
    134     if (!defined $secondary_plugin_options->{'HTMLPlug'}) {
    135     $secondary_plugin_options->{'HTMLPlug'} = [];
    136     }
    137     if (!defined $secondary_plugin_options->{'TEXTPlug'}) {
    138     $secondary_plugin_options->{'TEXTPlug'} = [];
     138    if (!defined $secondary_plugin_options->{'HTMLPlugin'}) {
     139    $secondary_plugin_options->{'HTMLPlugin'} = [];
     140    }
     141    if (!defined $secondary_plugin_options->{'TextPlugin'}) {
     142    $secondary_plugin_options->{'TextPlugin'} = [];
    139143    }
    140144    if (defined $self->{'convert_to'} && $self->{'convert_to'} =~ /pagedimg.*/i) {
    141     if (!defined $secondary_plugin_options->{'PagedImgPlug'}){
    142         $secondary_plugin_options->{'PagedImgPlug'} = [];
    143         my $pagedimg_options = $secondary_plugin_options->{'PagedImgPlug'};
     145    if (!defined $secondary_plugin_options->{'PagedImagePlugin'}){
     146        $secondary_plugin_options->{'PagedImagePlugin'} = [];
     147        my $pagedimg_options = $secondary_plugin_options->{'PagedImagePlugin'};
    144148        push(@$pagedimg_options, "-title_sub", '^(Page\s+\d+)?(\s*1\s+)?');
    145149    }
    146150    }
    147     my $html_options = $secondary_plugin_options->{'HTMLPlug'};
    148     my $text_options = $secondary_plugin_options->{'TEXTPlug'};
    149     my $pagedimg_options = $secondary_plugin_options->{'PagedImgPlug'};
     151    my $html_options = $secondary_plugin_options->{'HTMLPlugin'};
     152    my $text_options = $secondary_plugin_options->{'TextPlugin'};
     153    my $pagedimg_options = $secondary_plugin_options->{'PagedImagePlugin'};
    150154   
    151155    if ($self->{'input_encoding'} eq "auto") {
     
    227231    && $self->{'converted_to'} eq "HTML") {
    228232
    229     print $outhandle "PDFPlug: Calculating sections...\n";
     233    print $outhandle "PDFPlugin: Calculating sections...\n";
    230234
    231235    # we have "<a name=1></a>" etc for each page
     
    236240
    237241    if (scalar (@sections) == 1) { #only one section - no split!
    238         print $outhandle "PDFPlug: warning - no sections found\n";
     242        print $outhandle "PDFPlugin: warning - no sections found\n";
    239243    } else {
    240244        $top_section .= shift @sections; # keep HTML header etc as top_section
     
    274278        $title = " "; # get rid of the undefined warning in next line
    275279        }
    276         my $newsection = "<!-- from PDFPlug -->\n<!-- <Section>\n";
     280        my $newsection = "<!-- from PDFPlugin -->\n<!-- <Section>\n";
    277281        $newsection .= "<Metadata name=\"Title\">" . $title
    278282        . "</Metadata>\n--><p>\n";
     
    296300sub process {
    297301    my $self = shift (@_);
    298     my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
     302    my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
    299303
    300304    my $result = $self->process_type("pdf",$base_dir,$file,$doc_obj);
Note: See TracChangeset for help on using the changeset viewer.