Changeset 15619
- Timestamp:
- 2008-05-21T20:09:44+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/cfgread4gs3.pm
r15600 r15619 89 89 90 90 # use those unique attribute values to locate the text within the elements 91 # creator, public, maintainer .91 # creator, public, maintainer and within a displayItem. 92 92 my $currentLocation = ""; 93 93 my $stringexp = q/^(creator|maintainer|public)$/; 94 my $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 98 my $currentAttrRef = undef; 94 99 95 100 my $currentLevel = ""; … … 100 105 my $arrayexp = q/^(index|level|indexSubcollection|indexLanguage)$/; 101 106 my $arrayarrayexp= q/^(plugin|classifier)$/; 107 my $hashexp = q/^(subcollection)$/; # add other element names that should be represented by hash expressions here 108 my $hashhashexp = q/^(displayItem)$/; # add other (collectionmeta) element names that should be represented by hashes of hashes here. 102 109 103 110 my $defaults = q/^(defaultIndex|defaultLevel|defaultIndexLanguage|languageMetadata)$/; … … 107 114 # so that if/elsif is used to avoid unnecessary tests 108 115 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 = \%_; 109 121 110 122 my $name = $_{'name'}; … … 136 148 } 137 149 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 138 161 #@ Handling indexer: mgpp/mg/lucene; stringexp 139 162 elsif ($element eq "search") { … … 193 216 194 217 #@ 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} = {}; 198 221 } 199 222 if (defined $name and $name =~ /\w/) { 200 223 if (defined $filter and $filter =~ /\w/) { 201 $data->{ 'subcollection'}->{$name} = $filter;224 $data->{$element}->{$name} = $filter; 202 225 203 226 } … … 259 282 sub EndTag { 260 283 my ($expat, $element) = @_; 261 my $endTags = q/^(browse|pluginList )$/;284 my $endTags = q/^(browse|pluginList|displayItemList)$/; 262 285 if ($element =~ /$endTags/) { 263 286 $currentIndex = 0; … … 268 291 $currentIndex = $currentIndex + 1; 269 292 } 270 271 293 } 272 294 273 295 sub 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 } 287 304 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 299 347 # This sub is for debugging purposes 300 348 sub Display { 301 349 # metadataList 302 350 foreach my $k (keys %{$data}) { 351 print STDERR "*** metadatalist key $k\n"; 352 } 353 303 354 print $data->{'creator'}."\n" if (defined $data->{'creator'}); 304 355 print $data->{"maintainer"}."\n" if (defined $data->{"maintainer"}); … … 351 402 return undef; 352 403 } 404 353 405 # Reads in the model collection configuration file, collectionConfig.xml, 354 406 # into a structure which complies with the one used by gs2 (i.e. one read … … 387 439 } 388 440 389 #print "*** collectionConfig.xml internal ***\n";390 441 #&Display; 391 442 return $data;
Note:
See TracChangeset
for help on using the changeset viewer.