Changeset 18402 for gsdl

Show
Ignore:
Timestamp:
16.01.2009 13:39:45 (11 years ago)
Author:
mdewsnip
Message:

Fixed inconsistent and incorrect escaping of square brackets in metadata values, and also tidied up some ghastly code while I was there.

Files:
1 modified

Legend:

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

    r16970 r18402  
    334334    { 
    335335    my $gsdl_field = $metadata_mapping->{$marc_field}; 
    336     my $meta_value = undef; 
    337336     
    338337    # have we got a subfield? 
     
    343342    } 
    344343    if (defined $subfield) { 
    345         $meta_value = $marc->subfield($marc_field, $subfield); 
     344        my $meta_value = $marc->subfield($marc_field, $subfield); 
    346345        if (defined $meta_value) { 
    347         ## escape [ and ] 
    348         $meta_value =~ s/\[/\\\[/g; 
    349         $meta_value =~ s/\]/\\\]/g; 
     346        # Square brackets in metadata values need to be escaped so they don't confuse Greenstone/GLI 
     347        $meta_value =~ s/\[/&\#091;/g; 
     348        $meta_value =~ s/\]/&\#093;/g; 
    350349        my $metavalue_str = $self->to_utf8($encoding, $meta_value); 
    351350        $doc_obj->add_utf8_metadata ($section, $gsdl_field, $metavalue_str); 
    352351        } 
    353     } else { 
    354          
    355         my @metavalues = $marc->field($marc_field); 
    356          
    357         if (scalar(@metavalues)>0) 
     352    } 
     353    else 
     354    { 
     355        foreach my $meta_value_obj ($marc->field($marc_field)) 
    358356        { 
    359         my $metavalue = undef; 
    360         foreach $metavalue ( @metavalues ) 
    361         { 
    362             my $metavalue_str = $self->to_utf8($encoding,$metavalue->as_string()); 
    363             $doc_obj->add_utf8_metadata ($section, $gsdl_field, $metavalue_str); 
    364         } 
     357        my $meta_value = $meta_value_obj->as_string(); 
     358 
     359        # Square brackets in metadata values need to be escaped so they don't confuse Greenstone/GLI 
     360        $meta_value =~ s/\[/&\#091;/g; 
     361        $meta_value =~ s/\]/&\#093;/g; 
     362        my $metavalue_str = $self->to_utf8($encoding, $meta_value); 
     363        $doc_obj->add_utf8_metadata ($section, $gsdl_field, $metavalue_str); 
    365364        } 
    366365    }