Changeset 10352


Ignore:
Timestamp:
2005-07-29T14:25:23+12:00 (19 years ago)
Author:
chi
Message:

Change the pagedimg_png,jpg,gif (hyphen to underscore) setting in -convert_to

File:
1 edited

Legend:

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

    r10278 r10352  
    3131# secondary_plugins to devide which format to 'convert_to'. If the argument is
    3232# not present, the default is to inherit auto.
    33 
    34 
    3533package ConvertToPlug;
    3634
     
    4543
    4644sub BEGIN {
    47     @ISA = ('BasPlug');
     45    @ConvertToPlug::ISA = ('BasPlug');
    4846}
    4947
     
    5553      { 'name' => "text",
    5654    'desc' => "{ConvertToPlug.convert_to.text}" },
    57       { 'name' => "pagedimg-jpg",
    58     'desc' => "{ConvertToPlug.convert_to.pagedimg-jpg"},
    59       { 'name' => "pagedimg-gif",
    60     'desc' => "{ConvertToPlug.convert_to.pagedimg-gif"},
    61       { 'name' => "pagedimg-png",
    62     'desc' => "{ConvertToPlug.convert_to.pagedimg-png"},
     55      { 'name' => "pagedimg_jpg",
     56    'desc' => "{ConvertToPlug.convert_to.pagedimg_jpg}"},
     57      { 'name' => "pagedimg_gif",
     58    'desc' => "{ConvertToPlug.convert_to.pagedimg_gif}"},
     59      { 'name' => "pagedimg_png",
     60    'desc' => "{ConvertToPlug.convert_to.pagedimg_png}"},
    6361      ];
    6462
     
    7068    'list' => $convert_to_list,
    7169    'deft' => "html" },
     70      { 'name' => "title_sub",
     71    'desc' => "{HTMLPlug.title_sub}",
     72    'type' => "string",
     73    #'type' => "regexp",
     74    'deft' => "" },
    7275      { 'name' => "use_strings",
    7376    'desc' => "{ConvertToPlug.use_strings}",
     
    9194        'args'     => $arguments };
    9295
    93 
    9496sub findType
    9597{
     
    118120
    119121    my @convert_to_list = split(",",$self->{'convert_to'});
    120    
    121122    $secondary_plugins = {};
    122123
     
    125126    my $plugin_class = $convert_to."Plug";
    126127    my $plugin_package = $plugin_class.".pm";
     128
    127129    require $plugin_package;
    128130
     
    152154
    153155    my $self = {};
     156
     157    my $plugin_class ="";
     158   
     159    if ($strConvertTo =~ /pagedimg.*/i){
     160    $plugin_class = "PagedImg"."Plug";
     161    } else {
     162    $plugin_class = uc($strConvertTo)."Plug";
     163    }
     164   
     165    my $plugin_package = $plugin_class.".pm";
     166    require $plugin_package;
     167   
     168    # call its constructor with extra options that we've worked out!
     169    my $arglist = $plugin_options->{$plugin_class};
     170    $self = (defined $hashArgOptLists)? new $plugin_class($pluginlist,$inputargs,$hashArgOptLists): new $plugin_class($pluginlist,$inputargs);
     171
     172
    154173    if ($strConvertTo eq "text")
    155174    {
    156     $self = (defined $hashArgOptLists)? new TEXTPlug($pluginlist,$inputargs,$hashArgOptLists): new TEXTPlug($pluginlist,$inputargs);
     175    #$self = (defined $hashArgOptLists)? new TEXTPlug($pluginlist,$inputargs,$hashArgOptLists): new TEXTPlug($pluginlist,$inputargs);
    157176    $self->{'convert_to'} = "TEXT";
    158177    $self->{'convert_to_ext'} = "txt";
     
    162181    }
    163182    elsif ($strConvertTo =~ /pagedimg.*/i){
    164     $self = (defined $hashArgOptLists)? new PagedImgPlug($pluginlist,$inputargs,$hashArgOptLists): new PagedImgPlug($pluginlist,$inputargs);
     183    #$self = (defined $hashArgOptLists)? new PagedImgPlug($pluginlist,$inputargs,$hashArgOptLists): new PagedImgPlug($pluginlist,$inputargs);
    165184    $self->{'convert_to'} = "PagedImg";
    166     #$self->{'convert_to'} = $strConvertTo;
    167185    my $convert_to_ext = $strConvertTo;
    168     $convert_to_ext =~ s/.*\-(.*)/$1/i;
     186    $convert_to_ext =~ s/.*\_(.*)/$1/i;
    169187    if ($convert_to_ext eq "gif"){
    170188        $self->{'convert_to_ext'} = "gif";
     
    179197    } else {
    180198    # HTML or auto
    181     $self = (defined $hashArgOptLists)? new HTMLPlug($pluginlist,$inputargs,$hashArgOptLists): new HTMLPlug($pluginlist,$inputargs);
     199    #$self = (defined $hashArgOptLists)? new HTMLPlug($pluginlist,$inputargs,$hashArgOptLists): new HTMLPlug($pluginlist,$inputargs);
    182200    $self->{'convert_to'} = "HTML";
    183201    $self->{'convert_to_ext'} = "html";
     
    219237}
    220238
    221 
    222239sub convert_post_process
    223240{
     
    239256    my $self = shift (@_);
    240257    my ($output_ext, $input_filename, $textref) = @_;
    241 
     258   
    242259    my $outhandle = $self->{'outhandle'};
    243260    my $convert_to = $self->{'convert_to'};
    244261    my $failhandle = $self->{'failhandle'};
    245262    my $convert_to_ext = $self->{'convert_to_ext'};
    246 
     263   
    247264    # softlink to collection tmp dir
    248265    my $tmp_dirname
     
    273290    my $output_type="";
    274291    if ($convert_to =~ m/PagedImg/i) {
    275     $output_type = lc($convert_to)."-".lc($convert_to_ext);
     292    $output_type = lc($convert_to)."_".lc($convert_to_ext);
    276293    } else {
    277294    $output_type = lc($convert_to);
     
    290307
    291308    # remove symbolic link to original file
    292     #&util::rm($tmp_filename);
     309    &util::rm($tmp_filename);
    293310
    294311    # Check STDERR here
     
    312329    # store the *actual* output type and return the output filename
    313330    # it's possible we requested conversion to html, but only to text succeeded
    314     $self->{'convert_to_ext'} = $output_type;
     331    #$self->{'convert_to_ext'} = $output_type;
    315332    if ($output_type =~ /html/i) {
    316333    $self->{'converted_to'} = "HTML";
     
    323340    my $output_filename = $tmp_filename;
    324341    if ($output_type =~ /item/i) {
    325     $output_filename = $tmp_dirname . "\\$tailname\\" . $tailname . ".$output_type";
     342    # running under windows
     343    if ($ENV{'GSDLOS'} =~ /^windows$/i) {
     344        $output_filename = $tmp_dirname . "\\$tailname\\" . $tailname . ".$output_type";
     345    } else {
     346        $output_filename = $tmp_dirname . "\/$tailname\/" . $tailname . ".$output_type";
     347    }
    326348    } else {
    327349    $output_filename =~ s/$suffix$/.$output_type/;
     
    337359    my $tmp_dirname
    338360    = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "tmp");
    339     #&util::rm_r($tmp_dirname);
     361    &util::rm_r($tmp_dirname);
    340362    &util::mk_dir($tmp_dirname);
    341363}
     
    347369    my $self = shift (@_);
    348370    my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
    349 #    if ($self->is_recursive()) {
    350 #        die "BasPlug::read function must be implemented in sub-class for recursive plugins\n";
    351 #    }
     371    #if ($self->is_recursive()) {
     372    #   die "BasPlug::read function must be implemented in sub-class for recursive plugins\n";
     373    # }
    352374
    353375    my $outhandle = $self->{'outhandle'};
    354 
     376   
    355377    my ($block_status,$filename) = $self->read_block(@_);
    356378    return $block_status if ((!defined $block_status) || ($block_status==0));
    357379    $file = $self->read_tidy_file($file);
    358 
     380   
    359381    my $output_ext = $self->{'convert_to_ext'};
    360     my $conv_filename = $self->tmp_area_convert_file($output_ext, $filename);
     382
     383    my $conv_filename = "";
     384    $conv_filename = $self->tmp_area_convert_file($output_ext, $filename);
     385
    361386    if ("$conv_filename" eq "") {return 0;} # allows continue on errors
    362387    if (! -e "$conv_filename") {return 0;} # allows continue on errors
     
    367392    my $secondary_plugins =  $self->{'secondary_plugins'};
    368393    my $num_secondary_plugins = scalar(keys %$secondary_plugins);
     394
    369395    if ($num_secondary_plugins == 0) {
    370396    print $outhandle "Warning: No secondary plugin to use in conversion.  Skipping $file\n";
     
    380406   
    381407    my $secondary_plugin = $secondary_plugins->{$plugin_name};
    382    
     408
    383409    # note: metadata is not carried on to the next level
    384410    my ($rv,$doc_obj)
     
    400426    my ($filemeta) = $file =~ /([^\\\/]+)$/;
    401427    $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Source", &ghtml::dmsafe($filemeta));
     428
    402429    $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
    403430    $doc_obj->set_utf8_metadata_element($doc_obj->get_top_section(), "FileSize", (-s $filename));
    404    
     431
    405432    # do plugin specific processing of doc_obj
    406433    unless (defined ($self->process(undef, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli))) {
     
    414441    # process the document
    415442    $processor->process($doc_obj);
    416 ##    $self->cleanup_tmp_area();
     443    ##$self->cleanup_tmp_area();
    417444
    418445    $self->{'num_processed'} ++;
Note: See TracChangeset for help on using the changeset viewer.