Ignore:
Timestamp:
2006-10-27T13:41:01+13:00 (18 years ago)
Author:
kjdon
Message:

Moved all printing stuff out of doc.pm.
docprint now prints a GA representation of a doc obj - use &docprint::get_section_xml instead of $doc_obj->buffer_section_xml or $doc_obj->output_section.
Most of the code has been moved into plugouts, except for the bit thats gone to docprint.pm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugouts/BasPlugout.pm

    r13064 r13172  
    4141
    4242my $arguments = [
    43       { 'name' => "group_size",
     43       { 'name' => "group_size",
    4444    'desc' => "{BasPlugout.group_size}",
    4545    'type' => "int",
     
    7373    'type' => "flag",
    7474    'reqd' => "no", 
    75         'hiddengli' => "no"}                   
     75        'hiddengli' => "no"},
     76       { 'name' => "debug",
     77     'desc' => "{BasPlugout.debug}",
     78     'type' => "flag",
     79     'reqd' => "no",
     80     'hiddengli' => "yes"}
    7681];
    7782
     
    483488    # copy all the associated files, add this information as metadata
    484489    # to the document
    485         print STDERR "Writing associated files to $doc_dir\n";
     490        print $outhandle "Writing associated files to $doc_dir\n";
    486491    $self->process_assoc_files ($doc_obj, $doc_dir);
    487492    }
    488493
    489494    # save this document
    490     $doc_obj->output_section('BasPlugout::GROUPPROCESS', $doc_obj->get_top_section());
     495    my $section_text = &docprint::get_section_xml($doc_obj,$doc_obj->get_top_section());
     496    print GROUPPROCESS $section_text;
    491497
    492498    $self->{'gs_count'}++;
     
    717723}
    718724
     725
    719726#the subclass should implement this method if is_group method could return 1.
    720727sub close_group_output{
     
    727734}
    728735
     736my $dc_set = { Title => 1,       
     737           Creator => 1,
     738           Subject => 1,
     739           Description => 1,
     740           Publisher => 1,
     741           Contributor => 1,
     742           Date => 1,
     743           Type => 1,
     744           Format => 1,
     745           Identifier => 1,
     746           Source => 1,
     747           Language => 1,
     748           Relation => 1,
     749           Coverage => 1,
     750           Rights => 1};
     751
     752
     753# returns an XML representation of the dublin core metadata
     754# if dc meta is not found, try ex mete
     755sub get_dc_metadata {
     756    my $self = shift(@_);
     757    my ($doc_obj, $section, $version) = @_;
     758   
     759    # build up string of dublin core metadata
     760    $section="" unless defined $section;
     761   
     762    my $section_ptr = $doc_obj->_lookup_section($section);
     763    return "" unless defined $section_ptr;
     764
     765
     766    my $explicit_dc = {};
     767    my $explicit_ex = {};
     768
     769    my $all_text="";
     770    foreach my $data (@{$section_ptr->{'metadata'}}){
     771    my $escaped_value = &docprint::escape_text($data->[1]);
     772    if ($data->[0]=~ m/^dc\./) {
     773        $data->[0] =~ tr/[A-Z]/[a-z]/;
     774
     775        $data->[0] =~ m/^dc\.(.*)/;
     776        my $dc_element =  $1;
     777
     778        if (!defined $explicit_dc->{$dc_element}) {
     779        $explicit_dc->{$dc_element} = [];
     780        }
     781        push(@{$explicit_dc->{$dc_element}},$escaped_value);
     782
     783        if (defined $version && ($version eq "oai_dc")) {
     784        $all_text .= "   <dc:$dc_element>$escaped_value</dc:$dc_element>\n";
     785        }
     786        else {
     787        # qualifier???
     788        $all_text .= '   <dcvalue element="'. $dc_element.'">'. $escaped_value. "</dcvalue>\n";
     789        }
     790
     791    }
     792    elsif (($data->[0] =~ m/^ex\./) || ($data->[0] !~ m/\./)) {
     793        $data->[0] =~ m/^(ex\.)?(.*)/;
     794        my $ex_element =  $2;
     795        my $lc_ex_element = lc($ex_element);
     796
     797        if (defined $dc_set->{$ex_element}) {
     798        if (!defined $explicit_ex->{$lc_ex_element}) {
     799            $explicit_ex->{$lc_ex_element} = [];
     800        }
     801        push(@{$explicit_ex->{$lc_ex_element}},$escaped_value);
     802        }
     803    }
     804    }
     805
     806    # go through dc_set and for any element *not* defined in explicit_dc
     807    # that do exist in explicit_ex, add it in as metadata
     808    foreach my $k ( keys %$dc_set ) {
     809    my $lc_k = lc($k);
     810
     811    if (!defined $explicit_dc->{$lc_k}) {
     812        if (defined $explicit_ex->{$lc_k}) {
     813
     814        foreach my $v (@{$explicit_ex->{$lc_k}}) {
     815            my $dc_element    = $lc_k;
     816            my $escaped_value = $v;
     817
     818            if (defined $version && ($version eq "oai_dc")) {
     819            $all_text .= "   <dc:$dc_element>$escaped_value</dc:$dc_element>\n";
     820            }
     821            else {
     822            $all_text .= '   <dcvalue element="'. $dc_element.'">'. $escaped_value. "</dcvalue>\n";
     823            }
     824           
     825        }
     826        }
     827    }
     828    }
     829
     830    if ($all_text eq "") {
     831    $all_text .= "   There is no Dublin Core metatdata in this document\n";
     832    }   
     833    $all_text =~ s/[\x00-\x09\x0B\x0C\x0E-\x1F]//g;
     834
     835    return $all_text;
     836}
     837
     838# Build up dublin_core metadata.  Priority given to dc.* over ex.*
     839# This method was apparently added by Jeffrey and committed by Shaoqun.
     840# But we don't know why it was added, so not using it anymore.
     841sub new_get_dc_metadata {
     842   
     843    my $self = shift(@_);
     844    my ($doc_obj, $section, $version) = @_;
     845
     846    # build up string of dublin core metadata
     847    $section="" unless defined $section;
     848   
     849    my $section_ptr=$doc_obj->_lookup_section($section);
     850    return "" unless defined $section_ptr;
     851
     852    my $all_text = "";
     853    foreach my $data (@{$section_ptr->{'metadata'}}){
     854    my $escaped_value = &docprint::escape_text($data->[1]);
     855    my $dc_element =  $data->[0];
     856   
     857    my @array = split('\.',$dc_element);
     858    my ($type,$name);
     859
     860    if(defined $array[1])
     861    {
     862        $type = $array[0];
     863        $name = $array[1];
     864    }
     865    else
     866    {
     867        $type = "ex";
     868        $name = $array[0];
     869    }
     870   
     871    $all_text .= '   <Metadata Type="'. $type.'" Name="'.$name.'">'. $escaped_value. "</Metadata>\n";
     872    }
     873    return $all_text;
     874}
     875
     876
    7298771;
Note: See TracChangeset for help on using the changeset viewer.