Changeset 13496


Ignore:
Timestamp:
2006-12-12T12:12:39+13:00 (16 years ago)
Author:
shaoqun
Message:

make the marc xml record disply nicely

File:
1 edited

Legend:

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

    r13486 r13496  
    7171    $self->{'metadata_mapping'} = undef;
    7272    $self->{'num_processed'} = 0;
    73    
     73    $self->{'indent'} = 0;
     74
    7475    return bless $self, $class;
    7576}
     
    168169    my $file = $self->{'file'};
    169170    my $filename = $self->{'filename'};
    170    
     171       
    171172    my ($language, $encoding) = $self->textcat_get_language_encoding ($filename);
    172173
     
    174175    $self->{'encoding'} = $encoding;
    175176    $self->{'element_count'} = 1;
    176    
     177    $self->{'indent'} = 0;
    177178    my $outhandle = $self->{'outhandle'};
    178179    print $outhandle "MARCXMLPlug: processing $self->{'file'}\n" if $self->{'verbosity'} > 1;
     
    189190    my $expat = shift;
    190191    my $element = shift; 
     192
     193    my $text =  $self->escape_text($_);
    191194 
    192195    $self->{'current_element'} = $element;
    193 
    194     if ($element ne "collection"){
    195     $self->{'content'} .= $_;
    196     }
    197196
    198197    ##get all atributes of this element and store it in a map name=>value   
     
    201200    while ($attrstring =~ /(\w+)=\"(\w+)\"/){
    202201    $attr_map{$1}=$2;
    203     $attrstring = $';
     202    $attrstring = $'; #'
    204203    }
    205204
     
    209208    ##create a new document for each record
    210209    if ($element eq "record") {
    211     my $filename = $self->{'filename'};
     210        my $filename = $self->{'filename'};
    212211    my $language = $self->{'language'};
    213212        my $encoding = $self->{'encoding'};
     
    240239    ## get the marc code, for example 520
    241240     if ($element eq "datafield") {
    242      if (defined $attr_map{'tag'} and $attr_map{'tag'} ne ""){
     241         if (defined $attr_map{'tag'} and $attr_map{'tag'} ne ""){
    243242         $self->{'current_tag'} = $attr_map{tag}; 
    244243     }
     
    248247    ## append the subcode to the marc code for example 520a or 520b
    249248    if ($element eq "subfield"){
    250     if (defined $attr_map{'code'} and $attr_map{'code'} ne "" and $self->{'current_tag'} ne ""){
     249    if (defined $attr_map{'code'} and $attr_map{'code'} ne "" and $self->{'current_tag'} ne ""){
    251250        $self->{'current_code'} = $attr_map{'code'};
    252251    }
    253252    }
     253
     254   if ($element eq "record"){
     255        $self->{'indent'} = 0;
     256    }
     257    else {
     258         if ($element ne "subfield"){
     259              $self->{'indent'} = 1;
     260         }
     261         else{
     262           $self->{'indent'} = 2;
     263         }
     264    }
     265   
     266   
     267   if ($element ne "collection"){
     268        $self->{'content'} .= "<br/>".$self->calculate_indent($self->{'indent'}).$text;
     269   }
    254270}
    255271
     
    259275    my $self = shift(@_);
    260276    my ($expat, $element) = @_;
    261 
    262     $self->{'content'} .= $_;
    263 
     277    my $text =  $self->escape_text($_);
     278 
    264279    if ($element eq "record" and defined $self->{'doc_obj'}) {
    265280    # process the document
    266281    my $processor = $self->{'processor'};
    267282    my $doc_obj = $self->{'doc_obj'};
    268     $doc_obj->add_utf8_text($doc_obj->get_top_section(), $self->{'content'});
     283        $self->{'content'} .= "<br/>".$text;
     284     
     285    $doc_obj->add_utf8_text($doc_obj->get_top_section(),$self->{'content'});
    269286        $processor->process($doc_obj);
    270287
     
    272289    $self->{'content'} = ""; 
    273290    $self->{'doc_obj'} = undef;
     291        return;
    274292    }
    275293
     
    322340    $self->{'current_tag'} = "";
    323341    }
     342 
     343   if ($element eq "datafield"){
     344       $self->{'indent'} = 1;
     345       $self->{'content'} .= "<br/>".$self->calculate_indent($self->{'indent'}).$text;
     346   }
     347    else{
     348    $self->{'content'} .= $text;   
     349    }
     350     
    324351}
    325352
     
    345372    }
    346373   
    347     $self->{'content'} .= $_;
     374    $self->{'content'} .=$self->escape_text($_);
    348375   
    349376}
    350377
     378sub calculate_indent{
     379   my ($self,$num) = @_;
     380
     381   my $indent ="";
     382 
     383   for (my $i=0; $i<$num;$i++){
     384       $indent .= "&nbsp;&nbsp;&nbsp;&nbsp;";
     385    }
     386 
     387   return $indent;
     388
     389}
     390
     391sub escape_text {
     392    my ($self,$text) = @_;
     393    # special characters in the xml encoding
     394    $text =~ s/&/&amp;/g; # this has to be first...
     395    $text =~ s/</&lt;/g;
     396    $text =~ s/>/&gt;/g;
     397    $text =~ s/\"/&quot;/g;
     398
     399    return $text;
     400}
     401
    351402
    3524031;
Note: See TracChangeset for help on using the changeset viewer.