Changeset 15619

Show
Ignore:
Timestamp:
21.05.2008 20:09:44 (12 years ago)
Author:
ak19
Message:

Reads collectionConfig.xml file's collection name and description as collectionmeta for GS3, just as these elements were part of the collectionmeta for Greenstone 2

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/cfgread4gs3.pm

    r15600 r15619  
    8989 
    9090# use those unique attribute values to locate the text within the elements 
    91 # creator, public, maintainer. 
     91# creator, public, maintainer and within a displayItem. 
    9292my $currentLocation = ""; 
    9393my $stringexp = q/^(creator|maintainer|public)$/; 
     94my $displayItemNames = q/^(name|description)$/; 
     95   
     96# For storing the attributes during the StartTag subroutine, so that  
     97# we can use it later in Text (or EndTag) subroutines 
     98my $currentAttrRef = undef;  
    9499 
    95100my $currentLevel = ""; 
     
    100105my $arrayexp = q/^(index|level|indexSubcollection|indexLanguage)$/; 
    101106my $arrayarrayexp= q/^(plugin|classifier)$/; 
     107my $hashexp = q/^(subcollection)$/; # add other element names that should be represented by hash expressions here 
     108my $hashhashexp = q/^(displayItem)$/; # add other (collectionmeta) element names that should be represented by hashes of hashes here. 
    102109 
    103110my $defaults = q/^(defaultIndex|defaultLevel|defaultIndexLanguage|languageMetadata)$/; 
     
    107114# so that if/elsif is used to avoid unnecessary tests 
    108115    my ($expat, $element) = @_; 
     116     
     117    # See http://search.cpan.org/~msergeant/XML-Parser-2.36/Parser.pm#Stream 
     118    # %_ is a hash of all the attributes of this element, we want to store them  so we can use the attributes 
     119    # when the textnode contents of the element are parsed in the subroutine Text (that's the handler for Text).  
     120    $currentAttrRef = \%_;  
    109121 
    110122    my $name = $_{'name'}; 
     
    136148    } 
    137149 
     150    #@ handling the displayItems name and description (known as collectionname and collectionextra in GS2) 
     151    elsif($element eq "displayItemList") { 
     152    $currentLevel = "displayItemList"; # storing the parent if it is displayItemList 
     153    }  
     154    elsif($element =~ /$hashhashexp/) { # can expand on this to check for other collectionmeta elements 
     155    if((!defined $assigned) || (defined $assigned and $assigned =~ /\w/ and $assigned eq "true")) { 
     156        # either when there is no "assigned" attribute, or when assigned=true (for displayItems): 
     157        $currentLocation = $name; 
     158    } 
     159    } 
     160     
    138161    #@ Handling indexer: mgpp/mg/lucene; stringexp 
    139162    elsif ($element eq "search") { 
     
    193216 
    194217    #@ use hash of hash of strings: hashexp 
    195     elsif ($element eq "subcollection") { 
    196       if (!defined $data->{'subcollection'}) { 
    197     $data->{'subcollection'} = {}; 
     218    elsif ($element =~ /$hashexp/) { 
     219      if (!defined $data->{$element}) { 
     220    $data->{$element} = {}; 
    198221      } 
    199222      if (defined $name and $name =~ /\w/) { 
    200223    if (defined $filter and $filter =~ /\w/) { 
    201       $data->{'subcollection'}->{$name} = $filter; 
     224      $data->{$element}->{$name} = $filter; 
    202225 
    203226    } 
     
    259282sub EndTag { 
    260283    my ($expat, $element) = @_; 
    261     my $endTags = q/^(browse|pluginList)$/;    
     284    my $endTags = q/^(browse|pluginList|displayItemList)$/;    
    262285    if ($element =~ /$endTags/) { 
    263286        $currentIndex = 0; 
     
    268291        $currentIndex = $currentIndex + 1; 
    269292    } 
    270   
    271293} 
    272294 
    273295sub Text { 
    274   #@ Handling block metadataList(creator, maintainer, public) 
    275   if (defined $currentLocation and $currentLocation =~ /$stringexp/){ 
    276      #print $currentLocation; 
    277      my $key = $nameMap->{$currentLocation};     
    278      $data->{$key} = $_; 
    279      undef $currentLocation; 
    280   } 
    281   #@ Handling searchtype: plain,form; arrayexp 
    282   if (defined $currentLocation and $currentLocation =~ /searchType/) { 
    283     # map 'searchType' into 'searchtype' 
    284     my $key = $nameMap->{$currentLocation}; 
    285     # split it by ',' 
    286     my ($plain, $form) = split (",", $_); 
     296    if (defined $currentLocation) {  
     297    #@ Handling block metadataList(creator, maintainer, public) 
     298    if($currentLocation =~ /$stringexp/){ 
     299        #print $currentLocation; 
     300        my $key = $nameMap->{$currentLocation};  
     301        $data->{$key} = $_; 
     302        undef $currentLocation; 
     303    } 
    287304     
    288     if (!defined $data->{$key}) { 
    289         $data->{$key} = []; 
    290     } 
    291     if (defined $plain and $plain =~ /\w/) { 
    292         push @{ $data->{$key} }, $plain; 
    293     } 
    294     if (defined $form and $form =~ /\w/) { 
    295         push @{ $data->{$key} }, $form; 
    296     } 
    297   }  
    298 } 
     305    #@ Handling displayItem metadata that are children of displayItemList 
     306    # that means we will be getting the collection's name and possibly description ('collectionextra' in GS2). 
     307    elsif($currentLevel eq "displayItemList" && $currentLocation =~ /$displayItemNames/) { 
     308        my $lang = $currentAttrRef->{'lang'}; 
     309        my $name = $currentAttrRef->{'name'}; 
     310         
     311        # this is how data->collectionmeta's language is set in Greenstone 2.  
     312        # Need to be consistent, since export.pl accesses these values all in the same way 
     313        if(!defined $lang) { 
     314        $lang = 'default'; 
     315        } else { 
     316        $lang = "[l=$lang]";  
     317        } 
     318         
     319        if(defined $name and $name =~ /$displayItemNames/) { # attribute name = 'name' || 'description' 
     320        # using $nameMap->$name resolves to 'collectionname' if $name='name' and 'collectionextra' if $name='description' 
     321        $data->{'collectionmeta'}->{$nameMap->{$name}}->{$lang} = $_; # the value is the Text parsed 
     322        #print STDERR "***Found: $nameMap->{$name} collectionmeta, lang is $lang. Value: $data->{'collectionmeta'}->{$nameMap->{$name}}->{$lang}\n"; 
     323        } 
     324        undef $currentLocation; 
     325    } 
     326   
     327    #@ Handling searchtype: plain,form; arrayexp 
     328    elsif (defined $currentLocation and $currentLocation =~ /searchType/) { 
     329        # map 'searchType' into 'searchtype' 
     330        my $key = $nameMap->{$currentLocation}; 
     331        # split it by ',' 
     332        my ($plain, $form) = split (",", $_); 
     333         
     334        if (!defined $data->{$key}) { 
     335        $data->{$key} = []; 
     336        } 
     337        if (defined $plain and $plain =~ /\w/) { 
     338        push @{ $data->{$key} }, $plain; 
     339        } 
     340        if (defined $form and $form =~ /\w/) { 
     341        push @{ $data->{$key} }, $form; 
     342        } 
     343    } 
     344    }    
     345} 
     346 
    299347# This sub is for debugging purposes 
    300348sub Display { 
    301349    # metadataList 
    302      
     350    foreach my $k (keys %{$data}) { 
     351    print STDERR "*** metadatalist key $k\n";  
     352    } 
     353   
    303354    print $data->{'creator'}."\n" if (defined $data->{'creator'}); 
    304355    print $data->{"maintainer"}."\n" if (defined $data->{"maintainer"}); 
     
    351402    return undef; 
    352403} 
     404 
    353405# Reads in the model collection configuration file, collectionConfig.xml, 
    354406# into a structure which complies with the one used by gs2 (i.e. one read 
     
    387439    } 
    388440 
    389     #print "*** collectionConfig.xml internal ***\n"; 
    390441    #&Display;  
    391442    return $data;