Changeset 1435

Show
Ignore:
Timestamp:
21.08.2000 14:58:48 (19 years ago)
Author:
davidb
Message:

Rearrangement of ConvertTo? inheritence so HTMLPlug and TextPlug? do not need
to know anything about the conversion process.

Location:
trunk/gsdl/perllib/plugins
Files:
3 modified

Legend:

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

    r1420 r1435  
    8888    { 
    8989    $self = new TEXTPlug ($class, @_); 
     90    $self->{'convert_to'} = "TEXT"; 
     91    $self->{'convert_to_ext'} = "txt"; 
    9092    } 
    9193    else 
    9294    { 
    9395    $self = new HTMLPlug ($class, @_); 
     96    $self->{'convert_to'} = "HTML"; 
     97    $self->{'convert_to_ext'} = "html"; 
    9498    } 
    9599 
    96100    return bless $self, $class; 
    97101} 
     102 
     103 
     104 
     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 
     110sub tmp_area_convert_file { 
     111    my $self = shift (@_); 
     112    my ($output_ext,$input_filename, $textref) = @_; 
     113 
     114    # softlink to collection tmp dir 
     115    my $colname = &util::use_collection(); 
     116    my $tmp_dirname  
     117    = &util::filename_cat($ENV{'GSDLHOME'},"collect",$colname,"tmp"); 
     118    &util::mk_dir($tmp_dirname) if (!-e $tmp_dirname); 
     119 
     120    # derive tmp filename from input filename 
     121    my ($tailname,$dirname,$suffix) 
     122    = File::Basename::fileparse($input_filename,'\..+'); 
     123    my $tmp_filename = &util::filename_cat($tmp_dirname,"$tailname$suffix"); 
     124 
     125    # Remove any white space from filename -- no risk of name collision, and 
     126    # makes latter conversion by utils simpler 
     127    $tmp_filename =~ s/\s+//g;  
     128 
     129    &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;  
     134 
     135    my $verbosity = $self->{'verbosity'}; 
     136    if ($verbosity>0) 
     137    { 
     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"; 
     145    } 
     146 
     147    # remove symbolic link to original file 
     148    &util::rm($tmp_filename); 
     149 
     150    return $output_filename; 
     151} 
     152 
     153 
     154# Remove collection specific tmp directory and all its contents. 
     155 
     156sub cleanup_tmp_area { 
     157    my $self = shift (@_); 
     158 
     159    my $colname = &util::use_collection(); 
     160    my $tmp_dirname  
     161    = &util::filename_cat($ENV{'GSDLHOME'},"collect",$colname,"tmp"); 
     162    &util::rm_r($tmp_dirname); 
     163    &util::mk_dir($tmp_dirname); 
     164} 
     165 
    98166 
    99167 
     
    155223    $doc_obj->associate_file($filename, "doc.$doc_ext", undef, $cursection); 
    156224 
     225    my $doclink = "<a href=_httpcollection_/index/assoc/[archivedir]/doc.$doc_ext>"; 
     226    $doc_obj->add_utf8_metadata ($cursection, "srclink",  $doclink);  
    157227    $doc_obj->add_utf8_metadata ($cursection, "srcicon",  "_icon".$doc_ext."_");  
    158     $doc_obj->add_utf8_metadata ($cursection, "srcdoc",  "doc.$doc_ext");  
    159  
    160 #   my $doclink = '<a href=_httpcollection_/index/assoc/[archivedir]/doc.$doc_ext>'; 
    161 #   $doc_obj->add_utf8_metadata ($cursection, "srclink",  $doclink);  
    162228    $doc_obj->add_utf8_metadata ($cursection, "/srclink", "</a>");  
    163229 
  • trunk/gsdl/perllib/plugins/HTMLPlug.pm

    r1431 r1435  
    3838package HTMLPlug; 
    3939 
    40 use ConvertToBasPlug; 
     40use BasPlug; 
    4141use ghtml; 
    4242use util; 
     
    4444 
    4545sub BEGIN { 
    46     @ISA = ('ConvertToBasPlug'); 
     46    @ISA = ('BasPlug'); 
    4747} 
    4848 
     
    7272sub new { 
    7373    my $class = shift (@_); 
    74     my $self = new ConvertToBasPlug ($class, @_); 
     74    my $self = new BasPlug ($class, @_); 
    7575 
    7676    if (!parsargv::parse(\@_,  
     
    9393    $self->{'dir_num'} = 0; 
    9494    $self->{'file_num'} = 0; 
    95  
    96     $self->{'convert_to'} = "HTML"; 
    97     $self->{'convert_to_ext'} = "html"; 
    9895 
    9996    return bless $self, $class; 
  • trunk/gsdl/perllib/plugins/TEXTPlug.pm

    r1424 r1435  
    2929package TEXTPlug; 
    3030 
    31 use ConvertToBasPlug; 
     31use BasPlug; 
    3232 
    3333sub BEGIN { 
    34     @ISA = ('ConvertToBasPlug'); 
     34    @ISA = ('BasPlug'); 
    3535} 
    3636 
    3737sub new { 
    3838    my ($class) = @_; 
    39     my $self = new ConvertToBasPlug ($class, @_); 
    40  
    41     $self->{'convert_to'} = "TEXT"; 
    42     $self->{'convert_to_ext'} = "txt"; 
     39    my $self = new BasPlug ($class, @_); 
    4340 
    4441    return bless $self, $class;