Index: /gsdl/trunk/perllib/collConfigxml.pm
===================================================================
--- /gsdl/trunk/perllib/collConfigxml.pm	(revision 20098)
+++ /gsdl/trunk/perllib/collConfigxml.pm	(revision 20099)
@@ -112,4 +112,44 @@
 my $defaults = q/^(defaultIndex|defaultLevel|defaultIndexLanguage|languageMetadata)$/;
 
+# Reads in the model collection configuration file, collectionConfig.xml,
+# into a structure which complies with the one used by gs2 (i.e. one read
+# in by &cfgread::read_cfg_file).
+sub read_cfg_file {
+    my ($filename) = @_;
+    $data = {};
+    if ($filename !~ /collectionConfig\.xml$/ || !-f $filename) {
+        return undef;
+    }
+
+    # create XML::Parser object for parsing metadata.xml files
+    my $parser;
+    if ($]<5.008) {
+	# Perl 5.6
+	$parser = new XML::Parser('Style' => 'Stream',
+				  'Handlers' => {'Char' => \&Char,
+						 'Doctype' => \&Doctype
+						 });
+    }
+    else {
+	# Perl 5.8
+	$parser = new XML::Parser('Style' => 'Stream',
+				  'ProtocolEncoding' => 'ISO-8859-1',
+				  'Handlers' => {'Char' => \&Char,
+						 'Doctype' => \&Doctype
+						 });
+    }
+
+    if (!open (COLCFG, $filename)) {
+	print STDERR "cfgread::read_cfg_file couldn't read the cfg file $filename\n";
+    } else {
+
+      $parser->parsefile ($filename);# (COLCFG);
+      close (COLCFG);
+    }
+
+    #&Display; 
+    return $data;
+}
+
 sub StartTag {
 # Those marked with #@ will not be executed at the same time when this sub is being called
@@ -129,9 +169,9 @@
     my $filter = $_{'filter'};
 
-	# for flax activities
-	my $desid = $_{'desid'};
-	my $assigned = $_{'assigned'};
-	my $lang = $_{'lang'};
-	
+    # for flax activities
+    my $desid = $_{'desid'};
+    my $assigned = $_{'assigned'};
+    my $lang = $_{'lang'};
+    
     #@ Marking repeated block
     if ($element =~ /$repeatedBlock/) {
@@ -410,389 +450,5 @@
 }
 
-# Reads in the model collection configuration file, collectionConfig.xml,
-# into a structure which complies with the one used by gs2 (i.e. one read
-# in by &cfgread::read_cfg_file).
-sub read_cfg_file {
-    my ($filename) = @_;
-    $data = {};
-    if (($filename !~ /collectionConfig\.xml$/ && $filename !~ /buildConfig\.xml$/) || !-f $filename) {
-        return undef;
-    }
-
-    # create XML::Parser object for parsing metadata.xml files
-    my $parser;
-    if ($]<5.008) {
-	# Perl 5.6
-	$parser = new XML::Parser('Style' => 'Stream',
-				  'Handlers' => {'Char' => \&Char,
-						 'Doctype' => \&Doctype
-						 });
-    }
-    else {
-	# Perl 5.8
-	$parser = new XML::Parser('Style' => 'Stream',
-				  'ProtocolEncoding' => 'ISO-8859-1',
-				  'Handlers' => {'Char' => \&Char,
-						 'Doctype' => \&Doctype
-						 });
-    }
-
-    if (!open (COLCFG, $filename)) {
-	print STDERR "cfgread::read_cfg_file couldn't read the cfg file $filename\n";
-    } else {
-
-      $parser->parsefile ($filename);# (COLCFG);
-      close (COLCFG);
-    }
-
-    #&Display; 
-    return $data;
-}
-
-
-sub write_line {
-    my ($filehandle, $line) = @_;
-    print $filehandle join ("", @$line), "\n";
-}
-
-# Create the buildConfig.xml file for a specific collection
-sub write_cfg_file {
-    # this sub is called in make_auxiliary_files() in basebuilder.pm
-    # the received args: $buildoutfile - destination file: buildConfig.xml
-    #                    $buildcfg - all build options, eg, disable_OAI
-    #                    $collectcfg - contents of collectionConfig.xml read in by read_cfg_file sub in collConfigxml.pm.
-    my ($buildoutfile, $buildcfg, $collectcfg, $disable_OAI) = @_;
-    my $line = [];
-
-    if (!open (COLCFG, ">$buildoutfile")) {
-	print STDERR "collConfigxml::write_cfg_file couldn't write the build config file $buildoutfile\n";
-	die;
-    }
-
-    &write_line('COLCFG', ["<buildConfig xmlns:gsf=\"http://www.greenstone.org/greenstone3/schema/ConfigFormat\">"]);  
-
-    # output building metadata to build config file 
-    my $buildtype;
-    if (defined $buildcfg->{"buildtype"}) {
-	$buildtype = $buildcfg->{"buildtype"};
-    } else {
-	$buildtype = "mgpp";
-    }
-    my $numdocs;
-    if (defined $buildcfg->{"numdocs"}) {
-      $numdocs = $buildcfg->{"numdocs"};
-    }
-    &write_line('COLCFG', ["<metadataList>"]);
-    &write_line('COLCFG', ["<metadata name=\"numDocs\">", $numdocs, "</metadata>"]);
-    &write_line('COLCFG', ["<metadata name=\"buildType\">", $buildtype, "</metadata>"]);
-    &write_line('COLCFG', ["</metadataList>"]);
-
-    my $service_type = "MGPP";
-    if ($buildtype eq "mg") {
-	$service_type = "MG";
-    } elsif ($buildtype eq "lucene") {
-	$service_type = "Lucene";
-    }
-
-    # output serviceRackList
-    &write_line('COLCFG', ["<serviceRackList>"]);
-
-    # This serviceRack enables the collection to provide the oai metadata retrieve service, which is served by the OAIPMH.java class
-    # For each collection, we write the following serviceRack in the collection's buildConfig.xml file if the 'disable_OAI' argument is not checked in the GLI (or equivalently, a 'disable_OAI' flag is not specified on the command line). There are also other configurations in the OAIConfig.xml.
-    if ($disable_OAI == 0) {
-      &write_line('COLCFG', ["<serviceRack name=\"OAIPMH\">"]);
-      if (defined $buildcfg->{'indexstem'}) {
-        my $indexstem = $buildcfg->{'indexstem'};
-        &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);     
-      }
-      &write_line('COLCFG', ["</serviceRack>"]);
-    }    
-    # do the search service 
-    &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Search\">"]);
-    if (defined $buildcfg->{'indexstem'}) {
-      my $indexstem = $buildcfg->{'indexstem'};
-      &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);     
-    }
-
-    #indexes
-    # maps index name to shortname
-    my $indexmap = {};
-    # keeps the order for indexes
-    my @indexlist = ();
-    
-    my $defaultindex = "";
-    my $first = 1;
-    my $maptype = "indexfieldmap";
-    if ($buildtype eq "mg") {
-	$maptype = "indexmap";
-    }
-
-    #map {print $_."\n"} keys %$buildcfg;
-
-    if (defined $buildcfg->{$maptype}) {
-	my $indexmap_t = $buildcfg->{$maptype};
-       foreach my $i (@$indexmap_t) {
-    my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
-	    $indexmap->{$k} = $v;
-	    push @indexlist, $k;
-	    if ($first) {
-		$defaultindex = $v;
-		$first = 0;
-	    }	
-	}
-	# now if the user has assigned a default index, we use it 
-	if (defined $collectcfg->{"defaultindex"}) {
-	  $defaultindex = $indexmap->{$collectcfg->{"defaultindex"}};
-	}
-	
-    } else {
-	print STDERR "$maptype not defined";
-    }  
-    #for each index in indexList, write them out
-    &write_line('COLCFG', ["<indexList>"]);
-    foreach my $i (@indexlist) {
-	my $index = $indexmap->{$i};
-	&write_line('COLCFG', ["<index name=\"", $i, "\" ", "shortname=\"", $index, "\" />"]);
-    }	
-    &write_line('COLCFG', ["</indexList>"]);
-
-    
-    &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
-
-
-    # do indexOptionList
-    if ($buildtype eq "mg" || $buildtype eq "mgpp") {
-        &write_line('COLCFG', ["<indexOptionList>"]);
-	my $stemindexes = 3; # default is stem and casefold
-	if (defined $buildcfg->{'stemindexes'} && $buildcfg->{'stemindexes'} =~ /^\d+$/ ) {
-	    $stemindexes = $buildcfg->{'stemindexes'};
-	}
-	&write_line('COLCFG', ["<indexOption name=\"stemIndexes\" value=\"", $stemindexes, "\" />"]);
-	
-	my $maxnumeric = 4; # default
-	if (defined $buildcfg->{'maxnumeric'} && $buildcfg->{'maxnumeric'} =~ /^\d+$/) {
-	    $maxnumeric = $buildcfg->{'maxnumeric'};
-	}
-	&write_line('COLCFG', ["<indexOption name=\"maxnumeric\" value=\"", $maxnumeric, "\" />"]);
-        &write_line('COLCFG', ["</indexOptionList>"]);
-    }
-
-    #  levelList
-    my $levelmap = {};
-    my @levellist = ();
-    my $default_search_level = "Doc";
-    my $default_retrieve_level = "Doc";
-    my $default_db_level = "Doc";
-    $first = 1;
-    if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
-	if (defined $buildcfg->{'levelmap'}) {
-	    my $levelmap_t = $buildcfg->{'levelmap'};
-	    foreach my $l (@$levelmap_t) {
-		my ($key, $val) = $l =~ /^(.*)\-\>(.*)$/;
-		$levelmap->{$key} = $val;
-		push @levellist, $key;
-		if ($first) {
-		    # let default search level follow the first level in the level list
-		    $default_search_level = $val;
-		    # retrieve/database levels may get modified later if text level is defined
-		    $default_retrieve_level = $val;
-		    $default_db_level = $val;
-		    $first = 0;
-		}
-	    }
-	}
-	# the default level assigned by the user is no longer ignored [Shaoqun], but the retrievel level stays the same. 
-       	#if (defined $collectcfg->{"defaultlevel"}) {
-	$default_search_level = $levelmap->{$collectcfg->{"defaultlevel"}};
-        #  $default_retrieve_level = $default_search_level;
-	#}
-	
-	if (defined $buildcfg->{'textlevel'}) {
-	   # let the retrieve/database levels always follow the textlevel
-           $default_retrieve_level = $buildcfg->{'textlevel'};
-	   $default_db_level = $buildcfg->{'textlevel'};
-		 
-	}
-    }
-    #for each level in levelList, write them out
-	if ($buildtype ne "mg") {
-    &write_line('COLCFG', ["<levelList>"]);
-    foreach my $lv (@levellist) {
-	my $level = $levelmap->{$lv};
-        &write_line('COLCFG', ["<level name=\"", $lv, "\" shortname=\"", $level, "\" />"]);
-    }	
-    &write_line('COLCFG', ["</levelList>"]);
-    }
-    # add in defaultLevel as the same level as indexLevelList, making the reading job easier
-    if ($buildtype eq "lucene" || $buildtype eq "mgpp") {
-	&write_line('COLCFG', ["<defaultLevel shortname=\"", $default_search_level, "\" />"]);
-    }
-    if ($buildtype eq "lucene" || $buildtype eq "mgpp") {
-        &write_line('COLCFG', ["<defaultDBLevel shortname=\"", $default_db_level, "\" />"]);
-    }
-    # do searchTypeList
-    if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
-	  &write_line('COLCFG', ["<searchTypeList>"]);
-      
-      if (defined $buildcfg->{"searchtype"}) {
-	  my $searchtype_t = $buildcfg->{"searchtype"};
-	  foreach my $s (@$searchtype_t) {
-	  &write_line('COLCFG', ["<searchType name=\"", $s, "\" />"]);
-	}
-      } else {
-	  &write_line('COLCFG', ["<searchType name=\"plain\" />"]);
-	  &write_line('COLCFG', ["<searchType name=\"form\" />"]);
-      }
-	  &write_line('COLCFG', ["</searchTypeList>"]);
-    }
-
-    # do indexLanguageList [in collect.cfg: languages; in build.cfg: languagemap]
-    $first = 1;
-    my $default_lang = "";
-    my $default_lang_short = "";
-    if (defined $buildcfg->{"languagemap"}) {
-      &write_line('COLCFG', ["<indexLanguageList>"]);
-
-      my $langmap_t = $buildcfg->{"languagemap"};
-      foreach my $l (@$langmap_t) {
-	my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/; 
-
-	&write_line('COLCFG', ["<indexLanguage name=\"", $k, "\" shortname=\"", $v, "\" />"]);
-	if ($first) {
-	  $default_lang = $k; #name
-	  $default_lang_short = $v; #shortname
-	  $first = 0;
-	}
-      }
-
-      &write_line('COLCFG', ["</indexLanguageList>"]);
-      # now if the user has assigned a default language (as "en", "ru" etc.)
-      if (defined $collectcfg->{"defaultlanguage"}) {
-	$default_lang = $collectcfg->{"defaultlanguage"};
-      }
-      &write_line('COLCFG', ["<defaultIndexLanguage name=\"", $default_lang, "\" shortname=\"", $default_lang_short, "\" />"]);
-    }
-
-
-    # do indexSubcollectionList
-    my $default_subcol = "";# make it in sub scope to be used in the concatenation
-    if (defined $buildcfg->{'subcollectionmap'}) {
-      &write_line('COLCFG', ["<indexSubcollectionList>"]);
-      my $subcolmap = {};
-      my @subcollist = ();
-      $first = 1;
-      my $subcolmap_t = $buildcfg->{'subcollectionmap'};
-      foreach my $l (@$subcolmap_t) {
-	my ($k, $v) = $l =~ /^(.*)\-\>(.*)$/;
-	$subcolmap->{$k} = $v;
-	push @subcollist, $k;
-	if ($first) {
-	  $default_subcol = $v;
-	  $first = 0;
-	}
-      }
-      foreach my $sl (@subcollist) {
-	my $subcol = $subcolmap->{$sl};
-	&write_line('COLCFG', ["<indexSubcollection name=\"", $sl, "\" shortname=\"", $subcol, "\" />"]);
-      }	
-
-      &write_line('COLCFG', ["</indexSubcollectionList>"]);
-      &write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
-    }
-      
-    # close off search service 
-    &write_line('COLCFG', ["</serviceRack>"]);
-
-    # do the retrieve service
-    &write_line('COLCFG', ["<serviceRack name=\"GS2", $service_type, "Retrieve\">"]);
-
-    # do default index 
-    if (defined $buildcfg->{"languagemap"}) {
-	&write_line('COLCFG', ["<defaultIndexLanguage shortname=\"", $default_lang, "\" />"]);
-    }
-    if (defined $buildcfg->{'subcollectionmap'}) {
-	&write_line('COLCFG', ["<defaultIndexSubcollection shortname=\"", $default_subcol, "\" />"]);
-    }
-    if ($buildtype eq "mg") {
-      &write_line('COLCFG', ["<defaultIndex shortname=\"", $defaultindex, "\" />"]);
-    }
-
-    if (defined $buildcfg->{'indexstem'}) {
-      my $indexstem = $buildcfg->{'indexstem'};
-      &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);     
-    }
-    if ($buildtype eq "mgpp" || $buildtype eq "lucene") {
-      &write_line('COLCFG', ["<defaultLevel shortname=\"", $default_retrieve_level, "\" />"]);
-    }
-    &write_line('COLCFG', ["</serviceRack>"]);
-
-    # do the browse service
-    my $count = 1;
-    my $phind = 0;
-    my $started_classifiers = 0;
-
-    my $classifiers = $collectcfg->{"classify"};
-    foreach my $cl (@$classifiers) {
-      my $name = "CL$count";
-      $count++;
-      my ($classname) = @$cl[0];
-      if ($classname =~ /^phind$/i) {
-	$phind=1;
-	#should add it into coll config classifiers
-	next;
-      }
-      
-      if (not $started_classifiers) {
-	&write_line('COLCFG', ["<serviceRack name=\"GS2Browse\">"]);
-	if (defined $buildcfg->{'indexstem'}) {
-	  my $indexstem = $buildcfg->{'indexstem'};
-	  &write_line('COLCFG', ["<indexStem name=\"", $indexstem, "\" />"]);     
-	}
-	&write_line('COLCFG', ["<classifierList>"]);		
-	$started_classifiers = 1;
-      }
-      my $content = ''; #use buttonname first, then metadata
-      if ($classname eq "DateList") {
-	$content = "Date";
-      } else {
-	for (my $j=0; $j<scalar(@$cl); $j++) {
-	  my $arg = @$cl[$j];
-	  if ($arg eq "-buttonname"){
-	    $content = @$cl[$j+1];
-	    last;
-	  } elsif ($arg eq "-metadata") {
-	    $content = @$cl[$j+1];
-	  }
-	  
-	}
-      }
-      &write_line('COLCFG', ["<classifier name=\"", $name, "\" content=\"", $content, "\" />"]);
-    }     
-    if ($started_classifiers) {
-      # end the classifiers
-      &write_line('COLCFG', ["</classifierList>"]);
-      # close off the Browse service
-      &write_line('COLCFG', ["</serviceRack>"]);
-    }
-    
-    # the phind classifier is a separate service
-    if ($phind) {
-	# if phind classifier
-	&write_line('COLCFG', ["<serviceRack name=\"PhindPhraseBrowse\" />"]);
-    }
-
-	my $flaxActivities = $collectcfg->{"flaxActivity"};
-    foreach my $fa (@$flaxActivities) {
-    	# Six elements of the array for three attribute name/value pairs: name, desid, and lang.
-    	if(defined $fa and @$fa[0] =~ /\w/ and @$fa[1] =~ /\w/ and @$fa[2] =~ /\w/ and @$fa[3] =~ /\w/  and @$fa[4] =~ /\w/ and @$fa[5] =~ /\w/) {
-	    	&write_line('COLCFG', ["<serviceRack type=\"flaxActivity\" ", @$fa[0], "=\"", @$fa[1], "\" ", @$fa[2], "=\"", @$fa[3], "\" ", @$fa[4], "=\"", @$fa[5], "\" />"]);
-	    }
-    }  
-    
-    &write_line('COLCFG', ["</serviceRackList>"]);
-    &write_line('COLCFG', ["</buildConfig>"]);
-
-    close (COLCFG);
-  }
+
 
 
