Changeset 22565

Show
Ignore:
Timestamp:
04.08.2010 14:01:35 (10 years ago)
Author:
kjdon
Message:

removed block exp. now it scans the item file to work out which files to block

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/PagedImagePlugin.pm

    r22349 r22565  
    157157    'deft' => &get_default_process_exp(), 
    158158    'reqd' => "no" }, 
    159       { 'name' => "block_exp", 
    160     'desc' => "{BasePlugin.block_exp}", 
    161     'type' => "string", 
    162     'deft' => &get_default_block_exp(), 
    163     'reqd' => "no" }, 
    164159      { 'name' => "title_sub", 
    165160    'desc' => "{HTMLPlugin.title_sub}", 
     
    248243 
    249244 
    250 # want to block everything except the .item ones  
    251 # but instead we will block images and txt files 
    252 sub get_default_block_exp { 
    253     my $self = shift (@_); 
    254      
    255     return q^(?i)(\.jpe?g|\.gif|\.png|\.tif?f|\.te?xt|\.html?|~)$^ 
    256 ###    return q^(?i)(\.jpe?g|\.gif|\.png|\.tif?f|\.te?xt|\.html?|\.css|\.opd|\.pdf|~)$^ 
    257 } 
    258  
    259  
    260245# want to use BasePlugin's version of this, not ReadXMLFile's 
    261246sub can_process_this_file { 
    262247    my $self = shift(@_); 
    263      
    264248    return $self->BasePlugin::can_process_this_file(@_); 
     249} 
     250 
     251# instead of a block exp, now we scan the file and record all text and img files mentioned there for blocking. 
     252sub store_block_files 
     253{ 
     254    my $self = shift (@_); 
     255    my ($filename_full_path, $block_hash) = @_; 
     256 
     257    my $xml_version = $self->is_xml_item_file($filename_full_path); 
     258     
     259    # do we need to do this? if we do it here, then don't need to do it later 
     260    $self->tidy_item_file($filename_full_path); 
     261 
     262    my ($dir, $file) = $filename_full_path =~ /^(.*?)([^\/\\]*)$/; 
     263    if ($xml_version) { 
     264 
     265    # do something 
     266    $self->scan_xml_for_files_to_block($filename_full_path, $dir, $block_hash); 
     267    } else { 
     268     
     269    $self->scan_item_for_files_to_block($filename_full_path, $dir, $block_hash); 
     270    } 
     271     
    265272} 
    266273 
     
    294301    my $xml_version = $self->is_xml_item_file($filename_full_path); 
    295302 
    296     $self->tidy_item_file($filename_full_path); 
     303    # have done this already in store_block_files 
     304    #$self->tidy_item_file($filename_full_path); 
    297305     
    298306    my $doc_obj; 
     
    552560} 
    553561 
     562sub scan_xml_for_files_to_block 
     563{ 
     564    my $self = shift (@_); 
     565    my ($filename_full_path, $dir, $block_hash) = @_; 
     566 
     567    open (ITEMFILE, $filename_full_path) || die "couldn't open $filename_full_path to work out which files to block\n"; 
     568    my $line = ""; 
     569    while (defined ($line = <ITEMFILE>)) { 
     570    next unless $line =~ /\w/; 
     571 
     572    if ($line =~ /imgfile=\"([^\"]+)\"/) { 
     573        $block_hash->{'file_blocks'}->{$dir.$1} = 1; 
     574    } 
     575    if ($line =~ /txtfile=\"([^\"]+)\"/) { 
     576        $block_hash->{'file_blocks'}->{$dir.$1} = 1; 
     577    } 
     578    } 
     579    close ITEMFILE; 
     580     
     581} 
     582 
     583sub scan_item_for_files_to_block 
     584{ 
     585    my $self = shift (@_); 
     586    my ($filename_full_path, $dir, $block_hash) = @_; 
     587 
     588    open (ITEMFILE, $filename_full_path) || die "couldn't open $filename_full_path to work out which files to block\n"; 
     589    my $line = ""; 
     590    while (defined ($line = <ITEMFILE>)) { 
     591    next unless $line =~ /\w/; 
     592    chomp $line; 
     593    next if $line =~ /^#/; # ignore comment lines 
     594    next if ($line =~ /^<([^>]*)>\s*(.*?)\s*$/); # ignore metadata lines  
     595    # line should be like page:imagefilename:textfilename:r  
     596    $line =~ s/^\s+//; #remove space at the front 
     597    $line =~ s/\s+$//; #remove space at the end 
     598    my ($pagenum, $imgname, $txtname, $rotate) = split /:/, $line; 
     599         
     600    # find the image file if there is one 
     601    if (defined $imgname && $imgname ne "") { 
     602        $block_hash->{'file_blocks'}->{$dir.$imgname}=1; 
     603    } 
     604    # find the text file if there is one 
     605    if (defined $txtname && $txtname ne "") { 
     606        $block_hash->{'file_blocks'}->{$dir.$txtname} = 1; 
     607    } 
     608    } 
     609    close ITEMFILE; 
     610 
     611} 
    554612 
    555613sub process_item { 
     
    661719    $text = $1; 
    662720 
    663     # insert preformat tags and add text to document object 
     721    # add text to document object 
    664722    $doc_obj->add_utf8_text($cursection, "$text"); 
    665723    }