Index: /greenstone3/trunk/bin/script/convert_coll_from_gs2.pl
===================================================================
--- /greenstone3/trunk/bin/script/convert_coll_from_gs2.pl	(revision 14753)
+++ /greenstone3/trunk/bin/script/convert_coll_from_gs2.pl	(revision 14754)
@@ -128,5 +128,5 @@
     my $collwriter = new XML::Writer(OUTPUT => $colloutput, NEWLINES => 1);
     
-    $collwriter->startTag('collectionConfig', 'xmlns:gsf'=>"http://www.greenstone.org/greenstone3/schema/ConfigFormat", 'xmlns:xsl'=>'http://www.w3.org/1999/XSL/Transform');
+    $collwriter->startTag('CollectionConfig', 'xmlns:gsf'=>"http://www.greenstone.org/greenstone3/schema/ConfigFormat", 'xmlns:xsl'=>'http://www.w3.org/1999/XSL/Transform');
     
     #output the collection metadata to the collectionConfig file
@@ -134,7 +134,8 @@
     
     my $creator = $collectcfg->{'creator'};
-    &output_metadata($collwriter, 'creator', $creator);
+    &output_metadata($collwriter,'default', 'creator', $creator);
     my $public =$collectcfg->{'public'};
-    &output_metadata($collwriter, 'public', $public);
+    &output_metadata($collwriter,'default', 'public', $public);
+    
     $collwriter->endTag('metadataList');
 
@@ -169,6 +170,6 @@
     my $numdocs = $buildcfg->{'numdocs'};
     $buildwriter->startTag('metadataList');
-    &output_metadata($buildwriter, 'numDocs', $numdocs);
-    &output_metadata($buildwriter, 'buildType', $buildtype);
+    &output_metadata($buildwriter,'', 'numDocs', $numdocs);
+    &output_metadata($buildwriter,'', 'buildType', $buildtype);
     $buildwriter->endTag('metadataList');
     
@@ -191,6 +192,6 @@
 	    $indexmap->{$k} = $v;
 	    push @indexlist, $k;
-	    if ($first) {
-		$defaultindex = $v;
+	    if ($first == 1) {
+		$defaultindex = $k;
 		$first = 0;
 	    }	
@@ -202,5 +203,5 @@
     if (defined $collectcfg->{'defaultindex'}) {
 	$defaultindex = $collectcfg->{'defaultindex'};
-	$defaultindex = $indexmap->{$defaultindex};
+	#$defaultindex = $indexmap->{$defaultindex};
     }
     
@@ -209,4 +210,5 @@
     my @levellist = ();
     my $default_search_level = "";
+    my $default_search_level_shortname = "";
     my $default_retrieve_level = "Sec";
     $first = 1;
@@ -219,5 +221,6 @@
 		push @levellist, $k;
 		if ($first) {
-		    $default_search_level = $v;
+		    $default_search_level = $k;
+		    $default_search_level_shortname = $v;
 		    $first = 0;
 		}
@@ -227,5 +230,6 @@
 	if (defined $collectcfg->{'defaultlevel'}) {
 	    $default_search_level = $collectcfg->{'defaultlevel'};
-	    $default_search_level = $levelmap->{$default_search_level};
+	    #$default_search_level = $levelmap->{$default_search_level};
+	    $default_search_level_shortname = $levelmap->{$default_search_level};
 	}
 	if (defined $buildcfg->{'textlevel'}) {
@@ -237,5 +241,5 @@
 
     #output the search stuff to coll cfg
-    $collwriter->startTag('search');
+    $collwriter->startTag('search','type'=>$buildtype);
     foreach my $i (keys %$indexmap) {
 	$collwriter->startTag('index', 'name'=>$i);
@@ -244,7 +248,42 @@
 	foreach my $lang (keys %{$collectionmeta->{$indexdisplay}}) {
 	    my $value = $collectionmeta->{$indexdisplay}->{$lang};
-	    output_display($collwriter, 'name', $lang, $value);
+	    output_display($collwriter, 'name', $lang, $i);
 	}
 	$collwriter->endTag('index');
+    }
+
+    #output the defaultIndex to coll cfg
+    $collwriter->emptyTag('defaultIndex','name'=>$defaultindex);
+
+    #indexSubcollection
+    my $indexsubcollections = $collectcfg->{'indexsubcollections'};
+   
+    if (defined $indexsubcollections) {
+	my $indexsubcollections_t= $collectcfg->{'indexsubcollections'};
+	foreach my $i ( @$indexsubcollections_t) {
+	    $collwriter->startTag('indexSubcollection', 'name'=>$i);
+	    &output_display($collwriter, 'name', $defaultlang, $i);
+	    $collwriter->endTag('indexSubcollection');
+	}
+    } 
+
+    #subcollection
+    my $subcollection = $collectcfg->{'subcollection'};
+    if (defined $subcollection){
+	foreach my $entry (keys %$subcollection){
+	    my $value = $subcollection->{$entry};
+	    $collwriter->emptyTag('subcollection','filter'=>$value,'name'=>$entry);
+	}
+    }
+
+    #indexlanguage
+    my $languages = $collectcfg->{'languages'};
+    if (defined $languages){
+	my $languages_t = $collectcfg->{'languages'};
+	foreach my $i (@$languages_t){
+	    $collwriter->startTag('indexLanguage','name'=>$i);
+	     &output_display($collwriter, 'name', $defaultlang, $i);
+	    $collwriter->endTag('indexLanguage');
+	}
     }
 
@@ -261,5 +300,14 @@
 	    $collwriter->endTag('level');
 	}
-    }
+	$collwriter->emptyTag('defaultLevel', 'name'=>$default_search_level);
+    }
+    
+    # add in the search type 
+    if (defined $format->{'SearchTypes'}){
+	$collwriter->startTag('format', 'name'=>"searchType");
+	$collwriter->charactersXML($format->{'SearchTypes'});
+	$collwriter->endTag('format');
+    }
+
     # add in the format stuff
     if (defined $format->{'SearchVList'}) {
@@ -276,5 +324,38 @@
     
     $collwriter->endTag('search');
-    
+
+    # import plugins
+  
+    my $plugins = $collectcfg->{'plugin'};
+    
+    if (defined $plugins){
+	$collwriter->startTag('import');
+	$collwriter->startTag('pluginList');
+	foreach my $pl (@$plugins) {
+	    my ($pluginname) = @$pl[0];
+	    $collwriter->startTag('plugin','name'=>$pluginname);
+
+	    for (my $i=1; $i<scalar(@$pl); $i++) {
+		my $arg =@$pl[$i];
+		if ($arg =~ /^-/){
+		    my $option_name=@$pl[$i];
+		    my $option_value=@$pl[$i+1];
+		    if (defined $option_value){
+			if ($option_value =~ /^-/){
+			    $collwriter->startTag('option','name'=>$option_name); 
+			    $collwriter->endTag('option');
+			}else{
+			    $collwriter->startTag('option','name'=>$option_name,'value'=>$option_value); 
+			    $collwriter->endTag('option');
+			}
+		    }
+		}
+	    }
+	    $collwriter->endTag('plugin');
+	}
+	$collwriter->endTag('pluginList');
+	$collwriter->endTag('import');
+    }
+
     $buildwriter->startTag('serviceRackList');
     
@@ -288,4 +369,28 @@
     }
 
+ #indexSubcollectionList
+
+    my $subcollectionmap = $buildcfg->{'subcollectionmap'};
+    my $firstsubcollection = 1;
+    my $defaultsubcollection = "";
+    my @subcollist;
+    my $subcolmap = {};
+
+    if (defined $buildcfg->{'subcollectionmap'}) {
+	my $subcolmap_t = $buildcfg->{'subcollectionmap'};
+
+	foreach my $l (@$subcolmap_t) {
+	    my @pair = split(/->/, $l);
+	    $subcolmap->{$pair[0]} = $pair[1];
+	    push @subcollist, $pair[0];
+	    if ($firstsubcollection==1) {
+		$defaultsubcollection = $pair[1];
+		$firstsubcollection = 0;
+	    }	
+	}
+
+    }
+
+
     #do the retrieve service
     $buildwriter->startTag('serviceRack', 'name'=>"GS2".$service_type."Retrieve");
@@ -294,6 +399,10 @@
     } elsif ($buildtype eq "mg") {
 	$buildwriter->emptyTag('defaultIndex', 'shortname'=>$defaultindex);
-	
-    }
+    }
+    
+    if ((defined $defaultsubcollection) && ($defaultsubcollection ne "")) {
+	$buildwriter->emptyTag('defaultIndexSubcollection', 'shortname'=>$defaultsubcollection);
+    }
+
     if (defined $indexstem) {
 	$buildwriter->emptyTag('indexStem', 'name'=>$indexstem);
@@ -362,4 +471,5 @@
 	    if ($horizontalAtTop) {
 		$buildwriter->emptyTag('classifier', 'name'=>$name, 'content'=>$content, 'horizontalAtTop'=>'true');
+
 	    } else {
 		$buildwriter->emptyTag('classifier', 'name'=>$name, 'content'=>$content);
@@ -367,5 +477,23 @@
 	    
 	    
-	    $collwriter->startTag('classifier', 'name'=>$name);
+	   # $collwriter->startTag('classifier', 'name'=>$name);
+	    $collwriter->startTag('classifier', 'name'=>$classname);
+	    for (my $i=1; $i<scalar(@$cl); $i++) {
+		my $arg =@$cl[$i];
+		if ($arg =~ /^-/){
+		    my $option_name=@$cl[$i];
+		    my $option_value=@$cl[$i+1];
+		    if (defined $option_value){
+			if ($option_value=~ /^-/){
+			    $collwriter->startTag('option','name'=>$option_name); 
+			    $collwriter->endTag('option');
+			}else{
+			    $collwriter->startTag('option','name'=>$option_name,'value'=>$option_value); 
+			    $collwriter->endTag('option');
+			}
+		    }
+		}
+	    }
+
 	    my $vlist = $name."VList";
 	    my $hlist = $name."HList";
@@ -411,5 +539,5 @@
     # do the search service
     $buildwriter->startTag('serviceRack', 'name'=>'GS2'.$service_type.'Search');
-    $buildwriter->emptyTag('defaultIndex', 'shortname'=>$defaultindex);
+    #$buildwriter->emptyTag('defaultIndex', 'shortname'=>$defaultindex);
     $buildwriter->startTag('indexList');
     #for each index
@@ -444,5 +572,5 @@
 		
 	# level info
-	$buildwriter->emptyTag('defaultLevel', 'shortname'=>$default_search_level);
+	$buildwriter->emptyTag('defaultLevel', 'shortname'=>$default_search_level_shortname);
 	$buildwriter->emptyTag('defaultGDBMLevel', 'shortname'=>$default_retrieve_level);
 	$buildwriter->startTag('levelList');
@@ -474,6 +602,41 @@
     } 
     
-
-    
+    #indexLanguageList
+    my $indexlanguages = $collectcfg->{'languages'};
+    my $firstindexlanguage = 1;
+    my $defaultindexlanguage_shortname;
+    if (defined $indexlanguages){
+	$buildwriter->startTag('indexLanguageList');
+	my $languages_t = $collectcfg->{'languages'};
+	foreach my $i (@$languages_t){
+	    $buildwriter->startTag('indexLanguage','name'=>$i);
+	     &output_display($buildwriter, 'name', $i, $i);
+	    $buildwriter->endTag('indexLanguage');
+	    if ($firstindexlanguage==1){
+		$defaultindexlanguage_shortname = $i;
+		$firstindexlanguage=0;
+	    }
+	}
+    $buildwriter->endTag('indexLanguageList');
+    $buildwriter->startTag('defaultIndexLanguage', 'name'=>$defaultindexlanguage_shortname,'shortname'=>$defaultindexlanguage_shortname);
+    $buildwriter->endTag('defaultIndexLanguage');
+    }
+
+  #  my $defaultsubcollection = "";
+   # my @subcollist;
+
+    if (scalar(@subcollist)>0){
+
+	$buildwriter->startTag('indexSubcollectionList');
+	foreach my $i (keys %$subcolmap){
+	    my $short_name = $subcolmap->{$i};
+	    $buildwriter->emptyTag('indexSubcollection', 'name'=>$i, 'shortname'=>$short_name);
+	}
+
+	$buildwriter->endTag('indexSubcollectionList');
+	$buildwriter->emptyTag('defaultIndexSubcollection', 'shortname'=>$defaultsubcollection);
+    }
+
+   
     $buildwriter->endTag('serviceRack');
     
@@ -484,5 +647,5 @@
     # collection
     $collwriter->emptyTag('replaceListRef', 'id'=>'gs2-standard');
-    $collwriter->endTag('collectionConfig');
+    $collwriter->endTag('CollectionConfig');
     $collwriter->end();
     $buildwriter->end();
@@ -494,6 +657,11 @@
 
 sub output_metadata {
-    my ($writer, $metaname,  $metavalue) = @_;
-    $writer->startTag('metadata',  'name'=>$metaname);
+    my ($writer, $lang, $metaname,  $metavalue) = @_;
+    $lang = 'en' if $lang eq 'default';
+    if ($lang ne ""){
+	$writer->startTag('metadata', 'lang'=>$lang, 'name'=>$metaname);
+    }else{
+	$writer->startTag('metadata', 'name'=>$metaname);
+    }
     $writer->characters($metavalue);
     $writer->endTag('metadata');
@@ -506,4 +674,5 @@
 	($lang) = $lang =~ /\[l=(.*)\]/;
     }
+
     $writer->startTag('displayItem', 'name'=>$name, 'lang'=>$lang);
     $writer->characters($value);
