Changeset 10276


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

Add a read_into_doc_obj() for enabling secondary_pluging function. Also, a numer of minor modifications
to identify undefined variable or text file contains no text.

File:
1 edited

Legend:

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

    r10254 r10276  
    228228    if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
    229229    if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
    230 
     230   
    231231    my $self = (defined $hashArgOptLists)? new XMLPlug($pluginlist,$inputargs,$hashArgOptLists): new XMLPlug($pluginlist,$inputargs);
    232232
     
    256256    my $section = shift (@_); #the current section
    257257    my $rotate = shift (@_); # whether to rotate the image or not
    258 
     258    $rotate = 0 unless defined $rotate;
     259   
    259260    my $top=0;
    260261    if ($section eq $doc_obj->get_top_section()) {
     
    279280    my $converted = 0;
    280281    my $rotated=0;
     282
    281283    if ($converttotype ne "" && $filename !~ /$converttotype$/) {
    282284    $converted=1;
     
    528530# include directories
    529531
    530 sub read {
     532sub read_into_doc_obj {
    531533    my $self = shift (@_);
    532534    my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
    533535    my $outhandle   = $self->{'outhandle'};
    534536    my $smart_block = $self->{'smart_block'};
    535 
     537   
    536538    my $filename = &util::filename_cat($base_dir, $file);
    537 
     539   
    538540    if ($self->associate_with($file,$filename,$metadata)) {
    539541    # a form of smart block
     
    541543    return 0; # blocked
    542544    }
    543 
     545   
    544546    if ($smart_block) {
    545547    if (defined $self->{'file_blocks'}->{$filename} && $self->{'file_blocks'}->{$filename} == 1){
     
    557559   
    558560    print $outhandle "PagedImgPlug processing \"$filename\"\n"
    559         if $self->{'verbosity'} > 1;
     561    if $self->{'verbosity'} > 1;
    560562    print STDERR "<Processing n='$file' p='PagedImgPlug'>\n" if ($gli);
    561 
     563   
    562564    # here we need to decide if we have an old text .item file, or a new xml
    563565    # .item file - for now the test is if the first non-empty line is
     
    572574    }
    573575    chomp $line;
    574     if ($line =~ /^<PagedDocument/) {
     576    if ($line =~ /<PagedDocument/) {
    575577    $xml_version = 1;
    576578    }
    577579    close ITEMFILE;
     580    #print STDERR "xml version = $xml_version\n";
    578581    my $doc_obj;
    579582    if ($xml_version) {
    580 
    581583    $file =~ s/^[\/\\]+//; # $file often begins with / so we'll tidy it up
    582584    $self->{'file'} = $file;
     
    644646    my $section = $doc_obj->get_top_section();
    645647    $self->extra_metadata ($doc_obj, $section, $metadata);
    646 
    647     # do plugin specific processing of doc_obj - don't need this unless
    648     # something inherits from PagedImgPlug
     648    #my $text="";
     649    # do plugin specific processing of doc_obj
    649650    #unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) {
    650 #   print STDERR "<ProcessingError n='$file'>\n" if ($gli);
    651 #   return -1;
    652 #    }
    653 
     651    #print STDERR "<ProcessingError n='$file'>\n" if ($gli);
     652    #return -1;
     653    #}
    654654    # do any automatic metadata extraction
    655655    $self->auto_extract_metadata ($doc_obj);
    656656
    657     # process the document
    658     $processor->process($doc_obj);
    659 
     657    $self->{'num_processed'}++;
     658    return (1,$doc_obj);
     659}
     660
     661sub read
     662{
     663    my $self = shift (@_);
     664    my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
     665
     666    my ($process_status,$doc_obj) = $self->read_into_doc_obj(@_);
     667
     668    if ((defined $process_status) && ($process_status == 1)) {
     669    # process the document
     670    $processor->process($doc_obj);
     671
     672    #if(defined($self->{'places_filename'})){
     673    #    &util::rm($self->{'places_filename'});
     674    #    $self->{'places_filename'} = undef;
     675    #}
     676    #$self->{'num_processed'} ++;
     677    undef $doc_obj;
     678    }
     679   
    660680    # clean up temporary files - we do this here instead of in 
    661681    # process_image becuase associated files aren't actually copied
     
    663683    if (defined $self->{'tmp_filename1'} &&
    664684    -e $self->{'tmp_filename1'}) {
    665       &util::rm($self->{'tmp_filename1'})
     685    &util::rm($self->{'tmp_filename1'})
    666686    }
    667687    if (defined $self->{'tmp_filename2'} &&
    668688    -e $self->{'tmp_filename2'}) {
    669       &util::rm($self->{'tmp_filename2'})
     689    &util::rm($self->{'tmp_filename2'})
    670690    }
    671691    if (defined $self->{'tmp_filename3'} &&
     
    673693      &util::rm($self->{'tmp_filename3'})
    674694    }
    675 
    676     $self->{'num_processed'}++;
    677 
    678     return 1;
     695    # if process_status == 1, then the file has been processed.
     696    return $process_status;
    679697}
    680698
     
    699717    }
    700718    my ($txtfile) = $_{'txtfile'};
    701     if (defined($txtfile)) {
     719    if (defined($txtfile)&& $txtfile ne "") {
    702720        $self->process_text ($self->{'base_dir'}.$txtfile, $txtfile, $doc_obj, $self->{'current_section'});
    703721    } else {
     
    793811    # set the gsdlthistype metadata to Paged - this ensures this document will
    794812    # be treated as a Paged doc, even if Titles are not numeric
    795    
    796813    $doc_obj->set_utf8_metadata_element ($topsection, "gsdlthistype", "Paged");
    797814    } else {
     
    862879    # Do encoding stuff
    863880    my ($language, $encoding) = $self->textcat_get_language_encoding ($fullpath);
    864  
     881
    865882    my $text="";
    866883    &BasPlug::read_file($self, $fullpath, $encoding, $language, \$text);
Note: See TracChangeset for help on using the changeset viewer.