Index: /gsdl/trunk/perllib/cfgread4gs3.pm
===================================================================
--- /gsdl/trunk/perllib/cfgread4gs3.pm	(revision 15618)
+++ /gsdl/trunk/perllib/cfgread4gs3.pm	(revision 15619)
@@ -89,7 +89,12 @@
 
 # use those unique attribute values to locate the text within the elements
-# creator, public, maintainer.
+# creator, public, maintainer and within a displayItem.
 my $currentLocation = "";
 my $stringexp = q/^(creator|maintainer|public)$/;
+my $displayItemNames = q/^(name|description)$/;
+  
+# For storing the attributes during the StartTag subroutine, so that 
+# we can use it later in Text (or EndTag) subroutines
+my $currentAttrRef = undef; 
 
 my $currentLevel = "";
@@ -100,4 +105,6 @@
 my $arrayexp = q/^(index|level|indexSubcollection|indexLanguage)$/;
 my $arrayarrayexp= q/^(plugin|classifier)$/;
+my $hashexp = q/^(subcollection)$/; # add other element names that should be represented by hash expressions here
+my $hashhashexp = q/^(displayItem)$/; # add other (collectionmeta) element names that should be represented by hashes of hashes here.
 
 my $defaults = q/^(defaultIndex|defaultLevel|defaultIndexLanguage|languageMetadata)$/;
@@ -107,4 +114,9 @@
 # so that if/elsif is used to avoid unnecessary tests
     my ($expat, $element) = @_;
+    
+    # See http://search.cpan.org/~msergeant/XML-Parser-2.36/Parser.pm#Stream
+    # %_ is a hash of all the attributes of this element, we want to store them  so we can use the attributes
+    # when the textnode contents of the element are parsed in the subroutine Text (that's the handler for Text). 
+    $currentAttrRef = \%_; 
 
     my $name = $_{'name'};
@@ -136,4 +148,15 @@
     }
 
+    #@ handling the displayItems name and description (known as collectionname and collectionextra in GS2)
+    elsif($element eq "displayItemList") {
+	$currentLevel = "displayItemList"; # storing the parent if it is displayItemList
+    } 
+    elsif($element =~ /$hashhashexp/) { # can expand on this to check for other collectionmeta elements
+	if((!defined $assigned) || (defined $assigned and $assigned =~ /\w/ and $assigned eq "true")) {
+	    # either when there is no "assigned" attribute, or when assigned=true (for displayItems):
+	    $currentLocation = $name;
+	}
+    }
+    
     #@ Handling indexer: mgpp/mg/lucene; stringexp
     elsif ($element eq "search") {
@@ -193,11 +216,11 @@
 
     #@ use hash of hash of strings: hashexp
-    elsif ($element eq "subcollection") {
-      if (!defined $data->{'subcollection'}) {
-	$data->{'subcollection'} = {};
+    elsif ($element =~ /$hashexp/) {
+      if (!defined $data->{$element}) {
+	$data->{$element} = {};
       }
       if (defined $name and $name =~ /\w/) {
 	if (defined $filter and $filter =~ /\w/) {
-	  $data->{'subcollection'}->{$name} = $filter;
+	  $data->{$element}->{$name} = $filter;
 
 	}
@@ -259,5 +282,5 @@
 sub EndTag {
     my ($expat, $element) = @_;
-    my $endTags = q/^(browse|pluginList)$/;   
+    my $endTags = q/^(browse|pluginList|displayItemList)$/;   
     if ($element =~ /$endTags/) {
 		$currentIndex = 0;
@@ -268,37 +291,65 @@
      	$currentIndex = $currentIndex + 1;
     }
- 
 }
 
 sub Text {
-  #@ Handling block metadataList(creator, maintainer, public)
-  if (defined $currentLocation and $currentLocation =~ /$stringexp/){
-     #print $currentLocation;
-     my $key = $nameMap->{$currentLocation};	
-     $data->{$key} = $_;
-     undef $currentLocation;
-  }
-  #@ Handling searchtype: plain,form; arrayexp
-  if (defined $currentLocation and $currentLocation =~ /searchType/) {
-	# map 'searchType' into 'searchtype'
-	my $key = $nameMap->{$currentLocation};
-	# split it by ','
-	my ($plain, $form) = split (",", $_);
+    if (defined $currentLocation) { 
+	#@ Handling block metadataList(creator, maintainer, public)
+	if($currentLocation =~ /$stringexp/){
+	    #print $currentLocation;
+	    my $key = $nameMap->{$currentLocation};	
+	    $data->{$key} = $_;
+	    undef $currentLocation;
+	}
 	
-	if (!defined $data->{$key}) {
-	    $data->{$key} = [];
-	}
-	if (defined $plain and $plain =~ /\w/) {
-	    push @{ $data->{$key} }, $plain;
-	}
-	if (defined $form and $form =~ /\w/) {
-	    push @{ $data->{$key} }, $form;
-	}
-  }	
-}
+	#@ Handling displayItem metadata that are children of displayItemList
+	# that means we will be getting the collection's name and possibly description ('collectionextra' in GS2).
+	elsif($currentLevel eq "displayItemList" && $currentLocation =~ /$displayItemNames/) {
+	    my $lang = $currentAttrRef->{'lang'};
+	    my $name = $currentAttrRef->{'name'};
+	    
+	    # this is how data->collectionmeta's language is set in Greenstone 2. 
+	    # Need to be consistent, since export.pl accesses these values all in the same way
+	    if(!defined $lang) {
+		$lang = 'default';
+	    } else {
+		$lang = "[l=$lang]"; 
+	    }
+	    
+	    if(defined $name and $name =~ /$displayItemNames/) { # attribute name = 'name' || 'description'
+		# using $nameMap->$name resolves to 'collectionname' if $name='name' and 'collectionextra' if $name='description'
+		$data->{'collectionmeta'}->{$nameMap->{$name}}->{$lang} = $_; # the value is the Text parsed
+		#print STDERR "***Found: $nameMap->{$name} collectionmeta, lang is $lang. Value: $data->{'collectionmeta'}->{$nameMap->{$name}}->{$lang}\n";
+	    }
+	    undef $currentLocation;
+	}
+  
+	#@ Handling searchtype: plain,form; arrayexp
+	elsif (defined $currentLocation and $currentLocation =~ /searchType/) {
+	    # map 'searchType' into 'searchtype'
+	    my $key = $nameMap->{$currentLocation};
+	    # split it by ','
+	    my ($plain, $form) = split (",", $_);
+	    
+	    if (!defined $data->{$key}) {
+		$data->{$key} = [];
+	    }
+	    if (defined $plain and $plain =~ /\w/) {
+		push @{ $data->{$key} }, $plain;
+	    }
+	    if (defined $form and $form =~ /\w/) {
+		push @{ $data->{$key} }, $form;
+	    }
+	}
+    }	
+}
+
 # This sub is for debugging purposes
 sub Display {
     # metadataList
-    
+    foreach my $k (keys %{$data}) {
+	print STDERR "*** metadatalist key $k\n"; 
+    }
+  
     print $data->{'creator'}."\n" if (defined $data->{'creator'});
     print $data->{"maintainer"}."\n" if (defined $data->{"maintainer"});
@@ -351,4 +402,5 @@
     return undef;
 }
+
 # Reads in the model collection configuration file, collectionConfig.xml,
 # into a structure which complies with the one used by gs2 (i.e. one read
@@ -387,5 +439,4 @@
     }
 
-    #print "*** collectionConfig.xml internal ***\n";
     #&Display; 
     return $data;
