Changeset 1446


Ignore:
Timestamp:
2000-08-25T13:05:54+12:00 (24 years ago)
Author:
paynter
Message:

Major overhauls; works with the new gsConvert.pl instead of gs2text/gs2html.

File:
1 edited

Legend:

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

    r1435 r1446  
    3838package ConvertToPlug;
    3939
     40use BasPlug;
    4041use HTMLPlug;
    4142use TEXTPlug;
    4243
    4344sub BEGIN {
    44     @ISA = ('HTMLPlug', 'TEXTPlug');
     45    @ISA = ('HTMLPlug');
     46#    @ISA = ('HTMLPlug', 'TEXTPlug');
     47#    @ISA = ('BasPlug'); #, 'HTMLPlug', 'TEXTPlug');
    4548}
    4649
     
    8083sub new {
    8184    my $class = shift (@_);
    82    
    8385    my ($plugin_name,$generate_format) = $class->parse_args(\@_);
    84 
    8586    my $self;
    8687
     
    9697    $self->{'convert_to'} = "HTML";
    9798    $self->{'convert_to_ext'} = "html";
     99
     100    $self->{'rename_assoc_files'} = 1;
     101    $self->{'metadata_fields'} .= ",GENERATOR";
    98102    }
    99103
     
    103107
    104108
    105 # Run conversion utility on the input file.  Output files generated in
    106 # collection specific 'tmp' directory. 
    107 # The collection tmp area is used to convert Word, PDF etc documents into
    108 # another format (such as text or HTML) suitable for reading and indexing
     109# Run conversion utility on the input file. 
     110#
     111# The conversion takes place in a collection specific 'tmp' directory so
     112# that we don't accidentally damage the input.
     113#
     114# The desired output type is indicated by $output_ext.  This is usually
     115# something like "html" or "word", but can be "best" (or the empty string)
     116# to indicate that the conversion utility should do the best it can.
    109117
    110118sub tmp_area_convert_file {
    111119    my $self = shift (@_);
    112120    my ($output_ext,$input_filename, $textref) = @_;
     121
     122    my $convert_to = $self->{'convert_to'};
    113123
    114124    # softlink to collection tmp dir
     
    122132    = File::Basename::fileparse($input_filename,'\..+');
    123133    my $tmp_filename = &util::filename_cat($tmp_dirname,"$tailname$suffix");
    124 
    125134    # Remove any white space from filename -- no risk of name collision, and
    126     # makes latter conversion by utils simpler
     135    # makes later conversion by utils simpler
    127136    $tmp_filename =~ s/\s+//g;
    128137
    129138    &util::soft_link($input_filename,$tmp_filename);
    130 
    131     my $output_filename
    132     = &util::filename_cat($tmp_dirname,"$tailname.$output_ext");
    133     $output_filename =~ s/\s+//g;
    134139
    135140    my $verbosity = $self->{'verbosity'};
    136141    if ($verbosity>0)
    137142    {
    138     print STDERR "Converting $tailname$suffix to $self->{'convert_to'}\n";
    139     }
    140    
    141     # run either gs2txt.pl or gs2html.pl to peform the requested conversion
    142     if (system("gs2$output_ext.pl -verbose $verbosity \"$tmp_filename\"")>0)
    143     {
    144     print STDERR "Warning: unable to convert to $output_ext format\n";
     143    print STDERR "Converting $tailname$suffix to $convert_to format\n";
     144    }
     145   
     146    # Execute the conversion command and get the type of the result,
     147    # making sure the converter gives us the appropriate output type
     148    my $output_type = lc($convert_to);
     149    my $cmd = "gsConvert.pl -verbose $verbosity -output $output_type \"$tmp_filename\"";
     150    $output_type = `$cmd`;
     151
     152    # Check STDERR here
     153
     154    chomp $output_type;
     155    if ($output_type eq "fail") {
     156    print STDERR "Could not convert $tailname$suffix to $convert_to format\n";
     157    exit 1;
    145158    }
    146159
    147160    # remove symbolic link to original file
    148161    &util::rm($tmp_filename);
     162
     163    # store the *actual* output type and return the output filename
     164    $self->{'convert_to_ext'} = $output_type;
     165    my $output_filename = $tmp_filename;
     166    $output_filename =~ s/$suffix$/.$output_type/;
    149167
    150168    return $output_filename;
     
    207225    if ($convert_to eq "TEXT")
    208226    {
     227
    209228    $ret_val = TEXTPlug::process($self,$textref,$pluginfo,
    210229                     $tmp_dirname,$tmp_tailname,
Note: See TracChangeset for help on using the changeset viewer.