Index: eenstone3/branches/customizingGreenstone3/README-CVS.txt
===================================================================
--- /greenstone3/branches/customizingGreenstone3/README-CVS.txt	(revision 15190)
+++ 	(revision )
@@ -1,94 +1,0 @@
-Greenstone 3 (GSDL3)
-Copyright (C) 2003 New Zealand Digital Libraries, University Of Waikato
-Greenstone3 comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt
-This is free software, and you are welcome to redistribute it
-
-These are some extra notes for installing Greenstone from CVS. Please also read the README.txt file for general information as almost all of that applies here too.
-
-Installing Greenstone from a CVS checkout:
----------------------------------------------------------------------
-
-Make sure the CVS executable is on your PATH.
-
-Checkout the code:
-
-cvs -d :pserver:cvs_anon@cvs.scms.waikato.ac.nz:2402/usr/local/global-cvs/gsdl-src co greenstone3
-
-Build and install:
-
-In the greenstone3 directory, edit the build.properties file (see 'Configuring your installation' in README.txt), and run 'ant prepare install'. The two targets can be run separately if you like.
-
-The 'prepare' target will download additional code (using CVS and http), so you need to be online to run it. The 'install' target can be run offline.
-
-The prepare/install targets will ask you if you accept the properties before starting.
-To suppress this prompt, use the -Dproperties.accepted=yes flag. E.g.
-ant -Dproperties.accepted=yes prepare install (from CVS), or
-To log the output, run
-ant -Dproperties.accepted=yes -logfile build.log prepare install (from CVS), or
-
-Extra Configuration notes:
---------------------------------------------------------------
-
-Greenstone 3 uses some parts of Greenstone 2 for collection building, 
-including external packages and the Librarian Interface. These will be 
-installed during the Greenstone 3 installation process. If you do not want 
-collection building capability, please set the disable.collection.building property to true in build.properties. 
-
-
-Common install/update targets:
----------------------------------------------------------------------
-1. Install for the first time from CVS:
-cvs co greenstone3
-cd greenstone3
-ant prepare install
-
-2. Install for the first time from CVS, mostly offline:
-[online]
-cvs co greenstone3
-cd greenstone3
-ant prepare
-[offline]
-ant install
-
-3. Install for the first time, with CVS done outside of Ant (if you have problems running CVS commands from Ant):
-cvs co -P greenstone3
-cd greenstone3
-[if you want collection building:
-cvs co -P gli
-cvs co -P gs2build
-]
-[if you didn't want collection building
-cd src/packages
-cvs co indexers
-cd ../../
-]
-[if you are on windows
-cvs co winbin
-]
-ant -Dnocvs.mode=yes prepare install (prepare needs to be online, install can be done offline)
-
-4. Updating your Greenstone installation from CVS (and reconfigure/recompile):
-cd greenstone3
-ant update
-
-5. Updating your Greenstone installation from CVS, offline:
-cd greenstone3
-[online]
-ant cvsupdate
-[offline]
-ant -Dnocvs.mode=yes update
-
-6. Updating your Greenstone installation, with CVS done outside of Ant:
-cd greenstone3
-cvs update -l
-cvs update -dP bin docs lib resources src winutil packages 
-cd web (or the path-to-tomcat/webapps/greenstone3 if have installed greenstone as a webapp in Tomcat, see Using External Tomcat section)
-cvs update -dP 
-cd ../
-[ if you have greenstone 2 building:
-cvs update -dP gli
-cvs checkout -P gs2build
-Note that the gs2build one uses checkout not update.
-]
-ant -Dnocvs.mode=yes update
-
Index: /greenstone3/branches/customizingGreenstone3/README-SVN.txt
===================================================================
--- /greenstone3/branches/customizingGreenstone3/README-SVN.txt	(revision 15191)
+++ /greenstone3/branches/customizingGreenstone3/README-SVN.txt	(revision 15191)
@@ -0,0 +1,63 @@
+Greenstone 3 (GSDL3)
+Copyright (C) 2003 New Zealand Digital Libraries, University Of Waikato
+Greenstone3 comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt
+This is free software, and you are welcome to redistribute it
+
+These are some extra notes for installing Greenstone from SVN. Please also read the README.txt file for general information as almost all of that applies here too.
+
+Installing Greenstone from an SVN checkout:
+---------------------------------------------------------------------
+
+Make sure an SVN executable is on your PATH.
+
+Checkout the code:
+
+svn co http://svn.greenstone.org/greenstone3/trunk greenstone3
+
+Build and install:
+
+In the greenstone3 directory, edit the build.properties file (see 'Configuring your installation' in README.txt), and run 'ant prepare install'. The two targets can be run separately if you like.
+
+The 'prepare' target will download additional code (using SVN and http), so you need to be online to run it. The 'install' target can be run offline.
+
+The prepare/install targets will ask you if you accept the properties before starting.
+To suppress this prompt, use the -Dproperties.accepted=yes flag. E.g.
+ant -Dproperties.accepted=yes prepare install (from CVS), or
+To log the output, run
+ant -Dproperties.accepted=yes -logfile build.log prepare install (from CVS), or
+
+Extra Configuration notes:
+--------------------------------------------------------------
+
+Greenstone 3 uses some parts of Greenstone 2 for collection building, 
+including external packages and the Librarian Interface. These will be 
+installed during the Greenstone 3 installation process. If you do not want 
+collection building capability, please set the disable.collection.building property to true in build.properties. 
+
+
+Common install/update targets:
+---------------------------------------------------------------------
+1. Install for the first time from SVN:
+svn co http://svn.greenstone.org/greenstone3/trunk greenstone3
+cd greenstone3
+ant prepare install
+
+2. Install for the first time from SVN, mostly offline:
+[online]
+svn co http://svn.greenstone.org/greenstone3/trunk greenstone3
+cd greenstone3
+ant prepare
+[offline]
+ant install
+
+3. Updating your Greenstone installation from SVN (and reconfigure/recompile):
+cd greenstone3
+ant update
+
+4. Updating your Greenstone installation from SVN, mostly offline:
+cd greenstone3
+[online]
+ant svnupdate
+[offline]
+ant -Dnosvn.mode=yes update
+
Index: /greenstone3/branches/customizingGreenstone3/README.txt
===================================================================
--- /greenstone3/branches/customizingGreenstone3/README.txt	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/README.txt	(revision 15191)
@@ -21,10 +21,10 @@
 See 'Installing from a Source Distribution' section below for extra notes about installing from Source.
 
-See the README-CVS.txt file for extra notes about installing from CVS.
+See the README-SVN.txt file for extra notes about installing directly from SVN.
 
 Running Greenstone:
 ---------------------------------------------------------
 
-To start up Greenstone, select Greenstone 2 Digital Library from the Start menu (Windows), or run gs3-server.sh/bat. This launches a small server program, which starts up Tomcat and launches a browser. A small window pops up which allows you to chnage some settings for your library and restart the Tomcat server. Closing this program will stop Tomcat running.
+To start up Greenstone, select Greenstone3 Digital Library from the Start menu (Windows), or run gs3-server.sh/bat. This launches a small server program, which starts up Tomcat and launches a browser. A small window pops up which allows you to chnage some settings for your library and restart the Tomcat server. Closing this program will stop Tomcat running.
 
 Alternatively, you can start Tomcat directly through using Ant. 'ant start', 'ant restart' and 'ant stop' starts, restarts and shuts down Tomcat, respectively. This will only start/stop a local server (one installed by Greenstone). You will need to manually start/stop an external Tomcat (see below for notes about using a version of Tomcat external to Greenstone).
@@ -39,7 +39,6 @@
 You need to have Perl installed and on your PATH. Perl is included as part of 
 the Windows binary distribution.
-run  'ant gli", or cd to greenstone3/gli and run gli4gs3.sh/bat. This is a 
-graphical tool for building collections. Once you have created and built a 
-collection, you can see it by clicking 'Preview collection' on the Build panel.
+You can build collections using the Greenstone Librarian Interface (GLI). To start GLI, run  'ant gli", or cd to greenstone3/gli and run gli4gs3.sh/bat. 
+Once you have created and built a collection, you can see it by clicking 'Preview collection' on the Build panel.
 
 Note that GLI doesn't start up the Greenstone Tomcat server so you should 
@@ -141,5 +140,5 @@
 Download the greenstone-3.xx-src.tar.gz package from sourceforge.net/projects/greenstone3, and unpack it.
 In the greenstone3 directory, edit the build.properties file and run 
-ant prepare install
+ant install
 
 Tomcat will be installed as part of the prepare process. To stop this set the tomcat.installed.path to be the root of an existing Tomcat installation. 
@@ -181,7 +180,7 @@
 To recompile your Greenstone3 installation, in the top level greenstone3 directory, run:
 
+ant clean (use distclean instead if you want to regenerate the C++ Makefiles)
 ant configure
 ant configure-c++
-ant clean
 ant compile
 
Index: /greenstone3/branches/customizingGreenstone3/bin/script/convert_coll_from_gs2.pl
===================================================================
--- /greenstone3/branches/customizingGreenstone3/bin/script/convert_coll_from_gs2.pl	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/bin/script/convert_coll_from_gs2.pl	(revision 15191)
@@ -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);
Index: /greenstone3/branches/customizingGreenstone3/build.properties
===================================================================
--- /greenstone3/branches/customizingGreenstone3/build.properties	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/build.properties	(revision 15191)
@@ -50,3 +50,8 @@
 ## Mac OS X specific stuff
 # set the path to your GDBM here
-gdbm.installed.path=
+#install.gdbm=true
+#gdbm.installed.path=${gdbm.home}
+
+##Flax stuff##
+##uncomment if you want to install flax
+#install.flax=true
Index: /greenstone3/branches/customizingGreenstone3/build.xml
===================================================================
--- /greenstone3/branches/customizingGreenstone3/build.xml	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/build.xml	(revision 15191)
@@ -1,31 +1,30 @@
 <?xml version="1.0"?>
-
 <!-- ====================================================================== 
      March 2005                                                    
 
      Greenstone3 build and install script
-                   
+                  
      kjdon                                                                
      ====================================================================== -->
 <project name="greenstone3" default="usage" basedir=".">
 
-	<!-- ============ classpath =================== -->
-	<path id="project.classpath">
-	   <fileset dir="lib/java">
-	      <include name="**/*.jar"/>
-	   </fileset>
-	</path>
-
-	<!-- ============ self defined tasks =================== -->
-
-	<taskdef name="mysetproxy" classname="org.greenstone.anttasks.MySetProxy" classpath="${basedir}/lib/java/anttasks.jar"/>
-	<taskdef name="getuserandpassword" classname="org.greenstone.anttasks.MyGetUserAndPassword" classpath="${basedir}/lib/java/anttasks.jar"/>
-	<taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="project.classpath"/>
-	<taskdef name="rsr" classname="org.greenstone.anttasks.RegexSearchReplace" classpath="${basedir}/lib/java/anttasks.jar"/>
-
-
-<!-- ===================== Property Definitions =========================== -->
-
-<!--
+  <!-- ============ classpath =================== -->
+  <path id="project.classpath">
+    <fileset dir="lib/java">
+      <include name="**/*.jar"/>
+    </fileset>
+  </path>
+  
+  <!-- ============ self defined tasks =================== -->
+  <taskdef name="mysetproxy" classname="org.greenstone.anttasks.MySetProxy" classpathref="project.classpath"/>
+  <taskdef name="getuserandpassword" classname="org.greenstone.anttasks.MyGetUserAndPassword" classpathref="project.classpath"/>
+  <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask" classpathref="project.classpath"/>
+  <taskdef name="rsr" classname="org.greenstone.anttasks.RegexSearchReplace" classpathref="project.classpath"/>
+  <taskdef name="if" classname="ise.antelope.tasks.IfTask" classpathref="project.classpath"/>
+  <taskdef name="try" classname="ise.antelope.tasks.TryTask" classpathref="project.classpath"/>
+  
+  <!-- ===================== Property Definitions =========================== -->
+  
+  <!--
 
   Each of the following properties are used in the build script.
@@ -36,8 +35,8 @@
 
   * Definitions from a "build.properties" file in the top level
-    source directory of this application.
+  source directory of this application.
 
   * Definitions from a "build.properties" file in the user's
-    home directory.
+  home directory.
 
   * Default definitions in this build.xml file.
@@ -49,6 +48,10 @@
   "build.properties" files as well as in the "build.xml" script.
 
--->
-
+  -->
+
+  
+  <!--the first two properties have to be put on the top to be used by build.properties-->
+  <property name="src.packages.home" value="${basedir}/src/packages"/>
+  <property name="gdbm.home" value="${src.packages.home}/gdbm-1.8.3"/>
   <property file="build.properties"/>
   <property file="${user.home}/build.properties"/>
@@ -56,7 +59,14 @@
   <!-- get properties from the environment -->
   <property environment="env"/>
+
+    
+  <!-- version properties for external packages -->
+  <property name="tomcat.version" value="apache-tomcat-5.5.25"/>
+  <property name="axis.zip.version" value="axis-bin-1_2_1.zip"/>
+  <property name="axis.dir.version" value="axis-1_2_1"/>
+  <property name="gdbm.version" value="gdbm-1.8.3"/>
+
   <property name="build.home" value="${basedir}/build"/>
   <property name="src.home" value="${basedir}/src/java"/>
-  <property name="src.packages.home" value="${basedir}/src/packages"/>
   <property name="packages.home" value="${basedir}/packages"/>
   <!-- this may be set in build.properties, eg if you move the web dir to 
@@ -69,7 +79,10 @@
   <!-- other files needed by the servlet go here -->
   <property name="web.classes" value="${web.home}/WEB-INF/classes"/>
+  <!--- flax: the WordNet home -->
+  <property name="wn.home" value="${web.home}/WEB-INF/classes/flax/WordNet"/>
+
   <!-- jni libraries and java wrappers go here -->
   <property name="lib.jni" value="${basedir}/lib/jni"/>
-    
+  
   <property name="javadocs" value="${basedir}/docs/javadoc"/>
 
@@ -78,24 +91,14 @@
 
 
-  <!-- version number stuff -->
-
-  <!-- app.version defaults to trunk -->
-  <condition property="app.version" value="trunk">
-    <not><isset property="app.version"/></not>
-  </condition>
-
-	<!-- determine the 'branch path' -->
-  <condition property="branch.path" value="trunk">
-    <equals arg1="${app.version}" arg2="trunk" />
-  </condition>
-  <condition property="branch.path" value="branches/${app.version}">
-    <not><equals arg1="${app.version}" arg2="trunk" /></not>
-  </condition>
-
-
+  <!-- defaults - set these on the command line or in build.properties or they will take these default values-->
+  <property name="app.version" value="trunk"/>
+  <property name="branch.path" value="trunk"/>
+  <property name="branch.revision" value="HEAD"/>
+
+  <!--constants -->
   <property name="flax.svn.root" value="http://svn.greenstone.org/flax"/>
-
   <property name="svn.root" value="http://svn.greenstone.org"/>
-<!--  <property name="cvs.root" value=":pserver:cvs_anon@cvs.scms.waikato.ac.nz:2402/usr/local/global-cvs/gsdl-src"/> -->
+
+  <!--  <property name="cvs.root" value=":pserver:cvs_anon@cvs.scms.waikato.ac.nz:2402/usr/local/global-cvs/gsdl-src"/> -->
   <!-- catalina home is set to tomcat basedir is already installed, otherwise
   use greenstone's tomcat -->
@@ -160,5 +163,12 @@
     <isset property="disable.collection.building"/>
   </condition>
-    
+
+  <!-- where is search4j tool -->
+  <condition property="search4j.exec" value="bin/search4j.exe"> 
+    <isset property="current.os.iswindows"/>
+  </condition>
+  <property name="search4j.exec" value="bin/search4j"/>
+
+  
   <!-- ============= Base dirs for each package and component ============ -->
   <property name="src.applet.home" value="${src.home}/org/greenstone/applet"/>
@@ -168,5 +178,5 @@
   <property name="gli.home" value="${basedir}/gli"/>
   <property name="javagdbm.home" value="${src.packages.home}/javagdbm"/>
-
+  
   <!--<property name="indexers.home" value="${basedir}/src/packages/indexers">-->
   <condition property="indexers.home" value="${basedir}/src/packages/indexers">
@@ -184,7 +194,7 @@
 
 
-<!--  ==================== Compilation Control Options ==================== -->
-
-<!--
+  <!--  ==================== Compilation Control Options ==================== -->
+
+  <!--
 
   These properties control option settings on the Javac compiler when it
@@ -197,5 +207,5 @@
   compile.optimize     Should compilation include the optimize option?
 
--->
+  -->
 
   <property name="compile.debug"       value="true"/>
@@ -203,5 +213,5 @@
   <property name="compile.optimize"    value="true"/>
 
-<!--
+  <!--
 
   Rather than relying on the CLASSPATH environment variable, Ant includes
@@ -212,5 +222,5 @@
   that you explicitly added.
 
--->
+  -->
 
   <path id="compile.classpath">
@@ -228,6 +238,6 @@
     <!-- Include the axis jar files -->
     <!--<fileset dir="${basedir}/comms/soap/axis/lib">
-      <include name="*.jar"/>
-    </fileset>-->
+    <include name="*.jar"/>
+  </fileset>-->
     
     <!-- include the jar files from the source packages -->
@@ -265,4 +275,5 @@
     <pathelement path="${env.PATH}"/>
     <pathelement path="${env.Path}"/>
+    <pathelement path="${wn.home}/bin"/>
   </path>
 
@@ -275,11 +286,11 @@
     <echo>os.unix: ${os.unix}</echo>
   </target>
-<!-- ==================== Primary and Global Targets ============================= -->
+  <!-- ==================== Primary and Global Targets ============================= -->
 
   <!-- add comments about using xxx-core, xxx-packages if only want certain parts?? -->
 
-  <target name="prepare" depends="accept-properties,init,prepare-core,prepare-packages,prepare-gs2building,prepare-tomcat,prepare-axis,prepare-web,prepare-collections"
+  <target name="prepare" depends="accept-properties,init,prepare-core,prepare-packages,prepare-gs2building,prepare-tomcat,prepare-axis,prepare-web,prepare-collections,prepare-gdbm, prepare-flax"
     description="Use this when you first checkout the code: 'ant prepare install'. This will do some additional subversion checkouts and downloads, so you need to be online to run this.">
-<!--  <target name="prepare" depends="accept-properties,init,prepare-core,prepare-packages,prepare-gs2building,prepare-tomcat,prepare-axis,prepare-web,prepare-collections"
+    <!--  <target name="prepare" depends="accept-properties,init,prepare-core,prepare-packages,prepare-gs2building,prepare-tomcat,prepare-axis,prepare-web,prepare-collections"
     description="Use this when you first checkout the code: 'ant prepare install'. This will do some additional cvs checkouts and downloads, so you need to be online to run this.">-->
 
@@ -293,6 +304,6 @@
     description="Install Greenstone 3. Use this when you first checkout the code: 'ant prepare install'."/>
   
-<!--  <target name="cvsupdate" depends="init,cvsupdate-packages,cvsupdate-core,cvsupdate-gs2building,cvsupdate-web"
-    description="Do a cvs update for all sources. Doesn't recompile the code. You need to be online to run this."/>-->
+  <!--  <target name="cvsupdate" depends="init,cvsupdate-packages,cvsupdate-core,cvsupdate-gs2building,cvsupdate-web"
+  description="Do a cvs update for all sources. Doesn't recompile the code. You need to be online to run this."/>-->
   <target name="svnupdate" depends="init,svnupdate-packages,svnupdate-core,svnupdate-gs2building,svnupdate-web"
     description="Do a `svn update` for all sources. Doesn't recompile the code. You need to be online to run this."/>
@@ -305,15 +316,24 @@
     description="Configure the installation. Includes setting up config files. Should be re-run if you change the build.properties file."/>
 
-  <target name="clean" depends="init,clean-packages,clean-core,clean-gs2building"
+  <target name="clean" depends="init,clean-packages,clean-core,clean-gs2building,clean-gdbm"
     description="Remove all old compiled code. Includes core, packages and gs2building if necessary"/>
+  
+  <target name="distclean" depends="init,distclean-packages,clean-core,distclean-gs2building,distclean-gdbm"
+    description="Remove all compiled code and also any Makefiles etc generated during configure-c++. Includes core, packages, gs2building as necessary"/>
   
   <target name="compile" depends="init,compile-web,compile-packages,compile-core,compile-gs2building"
     description="Compile all the source code, includes core, packages and gs2building if necessary. Copy jar files and executables to their correct places."/>
-    
+  
   <target name="update" depends="init,svnupdate,clean,configure,configure-c++,compile" 
-    description="Update (thru Subversion) all the source (including core, packages and gs2building), then clean, configure and recompile."/>
+    description="Update (thru Subversion) all the source (including core, packages and gs2building), then clean, configure and recompile. To do this without any SVN updates, run it like 'ant -Dnosvn.mode=yes update'"/>
 
   <target name="start" depends="init,start-tomcat"
-    description="Startup the Tomcat server." />
+    description="Startup the Tomcat server." >
+    <echo>${app.name} (${app.version}) server running using Apache Tomcat and Java</echo> 
+    <echo>Tomcat:	${catalina.home}</echo> 
+    <echo>Java:	${java.home}</echo>
+    <echo>URL:	http://${tomcat.server}:${tomcat.port}${app.path}/</echo>
+    <!-- assuming that index.html is not needed here -->   
+  </target>
 
   <target name="stop" depends="init,stop-tomcat" 
@@ -323,5 +343,5 @@
 
 
-<!-- =========== Help targets ===================================  -->
+  <!-- =========== Help targets ===================================  -->
   
   <property name="install-command" value="ant [options] prepare install"/>
@@ -331,7 +351,7 @@
     <echo message="  Execute 'ant -help' for Ant help."/>
     <echo>To install Greenstone3, run '${install-command}'. 
-There are properties defined in build.properties. The install process will ask you if these properties are set correctly. To avoid this prompt, use the '-Dproperties.accepted=yes' option.
-To log the output, use the '-logfile build.log' option.
-The README.txt file has more information about the ant targets and install process.
+      There are properties defined in build.properties. The install process will ask you if these properties are set correctly. To avoid this prompt, use the '-Dproperties.accepted=yes' option.
+      To log the output, use the '-logfile build.log' option.
+      The README.txt file has more information about the ant targets and install process.
     </echo>
   </target>
@@ -343,14 +363,14 @@
   </target>
 
-<!-- ====== initialization and setup targets ================== -->
+  <!-- ====== initialization and setup targets ================== -->
 
   <target name="accept-properties" unless="properties.accepted">
     <input addproperty="properties.ok" validargs="y,n">The following properties (among others) are being used from a build.properties file found in this directory:
-tomcat.server=${tomcat.server}
-tomcat.port=${tomcat.port} 
-tomcat.installed.path=${tomcat.installed.path} (this is the location of Tomcat's base dir if it is already installed)
-proxy.host=${proxy.host}
-proxy.port=${proxy.port}
-If these are not acceptable, please change them and rerun this target. Continue [y/n]? />
+      tomcat.server=${tomcat.server}
+      tomcat.port=${tomcat.port} 
+      tomcat.installed.path=${tomcat.installed.path} (this is the location of Tomcat's base dir if it is already installed)
+      proxy.host=${proxy.host}
+      proxy.port=${proxy.port}
+      If these are not acceptable, please change them and rerun this target. Continue [y/n]? />
     </input>
     <condition property="do.abort"> 
@@ -360,15 +380,4 @@
   </target>
 
-<!--  <target name="check-cvsroot">
-    <condition property="svnroot.notset">
-      <or>
-			<not>
-			  <isset property="env.CVSROOT"/>
-			</not>
-			<equals arg1="" arg2="${env.CVSROOT}"/>
-      </or>
-    </condition>
-    <fail if="cvsroot.notset" message="You need to set the CVSROOT variable"/>
-  </target> -->
 
   <!-- this sets up some initial properties -->
@@ -397,5 +406,10 @@
     </condition>
     
-      <echo>tomcat.port:${tomcat.port}, gli.present:${gli.present} gs2build.present=${gs2build.present} gsdl2.installed.path = ${gsdl2.installed.path}</echo>
+    <echo>tomcat.port = ${tomcat.port}</echo>
+    <echo>gli.present = ${gli.present}</echo> 
+    <echo>gs2build.present = ${gs2build.present}</echo>
+    <echo>gsdl2.installed.path = ${gsdl2.installed.path}</echo>
+    <!-- gsdl2.installed.path appears not to be set? -->
+
     <condition property="proxy.present">
       <and>
@@ -427,6 +441,6 @@
     <mysetproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" proxyuser="${proxy.username}" proxypassword="${proxy.password}"/>
   </target>
-     
- <!-- ========== Web app Targets ================================ -->
+  
+  <!-- ========== Web app Targets ================================ -->
   
   <target name="prepare-web" depends="init,configure-java-version">
@@ -435,25 +449,168 @@
   </target>
   
-  <!-- if we are using java 1.5, we need the xalan.jar file in web/WEB-INF/lib,  but if we are using java 1.4, we can't have it there -->
+  <!-- if we are using java 1.5+, we need the xalan.jar file in web/WEB-INF/lib,  but if we are using java 1.4, we can't have it there -->
   <target name="configure-java-version" depends="init"
-    description="Run this target if you have changed the default version of java since installing greenstone3">
+    description="Activates or deactivates some jar libraries as needed depending on your java version">
+
+    <available property="have.xalan.jar" file="${web.lib}/xalan.jar"/>
     <condition property="need.xalan.jar">
-      <equals arg1="1.5" arg2="${ant.java.version}"/>
+      <or>
+	<equals arg1="1.5" arg2="${ant.java.version}"/>
+	<equals arg1="1.6" arg2="${ant.java.version}"/>
+      </or>
     </condition>
-    <antcall target="activate-xalan-jar"/>
-    <antcall target="deactivate-xalan-jar"/>
-  </target>
-  
-  <target name="activate-xalan-jar" if="need.xalan.jar">
+
+    <!-- if they have xalan.jar but dont need it -->
+    <if>
+      <bool>
+	<and>
+	  <isset property="have.xalan.jar"/>
+	  <not><isset property="need.xalan.jar"/></not>
+	</and>
+      </bool>
+      <antcall target="deactivate-xalan-jar"/>
+    </if>
+
+    <!-- if they need xalan.jar but dont have it -->
+    <if>
+      <bool>
+	<and>
+	  <not><isset property="have.xalan.jar"/></not>
+	  <isset property="need.xalan.jar"/>
+	</and>
+      </bool>
+      <antcall target="activate-xalan-jar"/>
+    </if>
+
+  </target>
+  
+  <target name="activate-xalan-jar">
+    <echo>activating xalan.jar</echo>
     <copy file="${web.lib}/xalan.jar.tmp" tofile="${web.lib}/xalan.jar"/>
-  </target>
-  
-  <target name="deactivate-xalan-jar" unless="need.xalan.jar">
+    <if><bool><isset property="current.os.ismac"/></bool>
+      <copy file="${web.lib}/xalan.jar.tmp" tofile="${catalina.home}/common/endorsed/xalan.jar"/> 
+    </if>
+  </target>
+
+  <!-- to delete -->
+  <target name="copy-xalan-for-mac"></target>
+
+  <target name="deactivate-xalan-jar">
+    <echo>deactivating xalan.jar</echo>
     <delete file="${web.lib}/xalan.jar"/>
   </target>
 
+<target name="prepare-collections" depends="init">
+    <property name="collect.dir" value="${web.home}/sites/localsite/collect"/>
+<echo message="installing collections..."/>
+<antcall target="gs2mgdemo-install"/>
+<antcall target="gs2mgppdemo-install"/>
+<antcall target="gberg-install"/>
+
+</target>
+
+<target name="gs2mgdemo-prepare" if="collect.dir">
+ <property name="gs2mgdemo.dir" value="${collect.dir}/gs2mgdemo"/>
+ <property name="gs2mgdemo.import.zip" value="${gs2mgdemo.dir}/import.zip"/>
+  <property name="gs2mgdemo.metadata.zip" value="${gs2mgdemo.dir}/metadata.zip"/>
+  <property name="gs2mgdemo.index.zip" value="${gs2mgdemo.dir}/index.zip"/>
+
+<fileset id="gs2mgdemofiles" dir="${gs2mgdemo.dir}">
+	<include name="${gs2mgdemo.import.zip}"/>
+	<include name="${gs2mgdemo.metadata.zip}"/>
+	<include name="${gs2mgdemo.index.zip}"/>
+</fileset>
+
+<condition property="gs2mgdemo.present">
+    <and>
+	<available file="${gs2mgdemo.import.zip}"/>
+	<available file="${gs2mgdemo.metadata.zip}"/>
+        <available file="${gs2mgdemo.index.zip}"/>
+    </and>
+  </condition>
+</target>
+
+<target name="gs2mgdemo-install" if="gs2mgdemo.present"  depends="gs2mgdemo-prepare">
+<echo> installing gs2mgdemo</echo>
+<unzip dest="${gs2mgdemo.dir}">
+	<fileset refid="gs2mgdemofiles"/>
+</unzip>
+<delete>
+	<fileset refid="gs2mgdemofiles"/>
+</delete>
+<echo>collection gs2mgdemo installed</echo>
+</target>
+
+<target name="gs2mgppdemo-prepare" if="collect.dir">
+ <property name="gs2mgppdemo.dir" value="${collect.dir}/gs2mgppdemo"/>
+ <property name="gs2mgppdemo.import.zip" value="${gs2mgppdemo.dir}/import.zip"/>
+  <property name="gs2mgppdemo.metadata.zip" value="${gs2mgppdemo.dir}/metadata.zip"/>
+  <property name="gs2mgppdemo.index.zip" value="${gs2mgppdemo.dir}/index.zip"/>
+
+<fileset id="gs2mgppdemofiles" dir="${gs2mgppdemo.dir}">
+        <include name="${gs2mgppdemo.import.zip}"/>
+        <include name="${gs2mgppdemo.metadata.zip}"/>
+        <include name="${gs2mgppdemo.index.zip}"/>
+</fileset>
+
+<condition property="gs2mgppdemo.present">
+    <and>
+        <available file="${gs2mgppdemo.import.zip}"/>
+        <available file="${gs2mgppdemo.metadata.zip}"/>
+        <available file="${gs2mgppdemo.index.zip}"/>
+    </and>
+  </condition>
+</target>
+
+<target name="gs2mgppdemo-install" if="gs2mgppdemo.present" depends="gs2mgppdemo-prepare">
+<unzip dest="${gs2mgppdemo.dir}">
+        <fileset refid="gs2mgppdemofiles"/>
+</unzip>
+<delete>
+        <fileset refid="gs2mgppdemofiles"/>
+</delete>
+<echo>collection gs2mgppdemo installed</echo>
+</target>    
+
+<target name="gberg-prepare" if="collect.dir">
+ <property name="gberg.dir" value="${collect.dir}/gberg"/>
+ <property name="gberg.index.zip" value="${gberg.dir}/index.zip"/>
+
+<fileset id="gbergfiles" dir="${gberg.dir}">
+        <include name="${gberg.index.zip}"/>
+</fileset>
+<available file="${gberg.index.zip}" property="gberg.present"/>
+</target>
+
+<target name="gberg-install" if="gberg.present" depends="gberg-prepare">
+<unzip dest="${gberg.dir}">
+        <fileset refid="gbergfiles"/>
+</unzip>
+<delete>
+        <fileset refid="gbergfiles"/>
+</delete>
+<echo>collection gberg installed</echo>
+</target>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<!--
   <target name="prepare-collections" depends="init">
     <property name="collect.dir" value="${web.home}/sites/localsite/collect"/>
-    <!-- gs2mgdemo -->
+   
     <unzip src="${collect.dir}/gs2mgdemo/import.zip" 
       dest="${collect.dir}/gs2mgdemo"/>
@@ -465,5 +622,5 @@
     <delete file="${collect.dir}/gs2mgdemo/metadata.zip"/>
     <delete file="${collect.dir}/gs2mgdemo/index/index.zip"/>
-    <!-- gs2mgppdemo -->
+   
     <unzip src="${collect.dir}/gs2mgppdemo/import.zip" 
       dest="${collect.dir}/gs2mgppdemo"/>
@@ -475,10 +632,10 @@
     <delete file="${collect.dir}/gs2mgppdemo/metadata.zip"/>
     <delete file="${collect.dir}/gs2mgppdemo/index/index.zip"/>
-    <!-- gberg -->
+  
     <unzip src="${collect.dir}/gberg/index/index.zip" 
       dest="${collect.dir}/gberg/index"/>
     <delete file="${collect.dir}/gberg/index/index.zip"/>
   </target>
-
+-->
   
   <target name="configure-web" depends="init"
@@ -510,9 +667,9 @@
   </target>
 
-	<target name="svnupdate-web" unless="nosvn.mode">
-		<svn>
-			<update dir="${web.home}"/>
-		</svn>
-	</target>
+  <target name="svnupdate-web" unless="nosvn.mode">
+    <svn>
+      <update dir="${web.home}"/>
+    </svn>
+  </target>
 
   <target name="update-web" depends="init,svnupdate-web,configure-web"
@@ -520,5 +677,5 @@
 
 
-<!-- ======================= Tomcat Targets ========================== -->
+  <!-- ======================= Tomcat Targets ========================== -->
   
   <!-- this target downloads and installs Tomcat -->
@@ -528,18 +685,18 @@
     <!-- check that packages dir is there -->
     <mkdir dir="${packages.home}"/>
-    <get src="http://www.greenstone.org/gs3files/apache-tomcat-5.5.12.zip"
-      dest="${packages.home}/apache-tomcat-5.5.12.zip"
+    <get src="http://www.greenstone.org/gs3files/${tomcat.version}.zip"
+      dest="${packages.home}/${tomcat.version}.zip"
       usetimestamp="true"/>
-    <unzip src="${packages.home}/apache-tomcat-5.5.12.zip" 
+    <unzip src="${packages.home}/${tomcat.version}.zip" 
       dest="${packages.home}"/>
-    <get src="http://www.greenstone.org/gs3files/apache-tomcat-5.5.12-compat.zip"
-      dest="${packages.home}/apache-tomcat-5.5.12-compat.zip"
+    <get src="http://www.greenstone.org/gs3files/${tomcat.version}-compat.zip"
+      dest="${packages.home}/${tomcat.version}-compat.zip"
       usetimestamp="true"/>
-    <unzip src="${packages.home}/apache-tomcat-5.5.12-compat.zip" 
+    <unzip src="${packages.home}/${tomcat.version}-compat.zip" 
       dest="${packages.home}"/>
     <!-- delete any existing tomcat -->
     <delete dir="${packages.home}/tomcat"/>
     <move todir="${packages.home}/tomcat">
-      <fileset dir="${packages.home}/apache-tomcat-5.5.12"/>
+      <fileset dir="${packages.home}/${tomcat.version}"/>
     </move>
     <copy file="${basedir}/resources/tomcat/setclasspath.bat"
@@ -576,7 +733,7 @@
     <!-- need to edit the config file, or do we get the user to do this???-->
   </target>
-    
-  <target name="start-tomcat" description="Startup only Tomcat" depends="init" if="tomcat.islocal">
-   <property name="tomcat.classpath" refid="local.tomcat.classpath"/>
+  
+  <target name="start-tomcat" description="Startup only Tomcat" depends="init,configure-java-version" if="tomcat.islocal">
+    <property name="tomcat.classpath" refid="local.tomcat.classpath"/>
     <property name="tomcat.path" refid="local.tomcat.path"/>
     <property name="catalina.opts" value="-Djava.util.prefs.syncInterval=2000000 -DGSDL3HOME=$GSDL3HOME -DGSDLOS=$GSDLOS -DPATH=$PATH -Xmx400M"/>
@@ -590,4 +747,5 @@
       <env key="LD_LIBRARY_PATH" path="${env.LD_LIBRARY_PATH}:${lib.jni}"/>
       <env key="DYLD_LIBRARY_PATH" path="${env.DYLD_LIBRARY_PATH}:${lib.jni}:${gdbm.installed.path}/lib"/> <!-- for mac os -->
+      <env key="WNHOME" path="${wn.home}"/>
     </exec>
     <exec executable="${catalina.home}/bin/startup.bat" os="${os.windows}" dir="${catalina.home}/bin" spawn="true">
@@ -607,5 +765,7 @@
     </waitfor>
   </target>
+
   <!-- windows: do we want to launch a webrowser?? -->
+  <!-- shouldn't this test whether anything is running first? -->
   <target name="stop-tomcat" description="Shutdown only Tomcat" depends="init" if="tomcat.islocal">
     <exec executable="${catalina.home}/bin/shutdown.sh" os="${os.unix}" dir="${catalina.home}/bin" spawn="false">
@@ -642,5 +802,5 @@
 
 
-<!-- ======================= ant Targets ============================ --> 
+  <!-- ======================= ant Targets ============================ --> 
   <target name="prepare-ant" depends="init">
     <get src="http://www.greenstone.org/gs3files/apache-ant-1.7.0-bin.zip"
@@ -654,14 +814,14 @@
   </target>
 
-<!-- ======================= Axis Targets ============================ --> 
+  <!-- ======================= Axis Targets ============================ --> 
 
   <target name="prepare-axis" depends="init">
-    <get src="http://www.greenstone.org/gs3files/axis-bin-1_2_1.zip"
-      dest="${packages.home}/axis-bin-1_2_1.zip"
+    <get src="http://www.greenstone.org/gs3files/${axis.zip.version}"
+      dest="${packages.home}/${axis.zip.version}"
       usetimestamp="true"/>
-    <unzip src="${packages.home}/axis-bin-1_2_1.zip"
+    <unzip src="${packages.home}/${axis.zip.version}"
       dest="${packages.home}"/>
     <move todir="${packages.home}/axis">
-      <fileset dir="${packages.home}/axis-1_2_1"/>
+      <fileset dir="${packages.home}/${axis.dir.version}"/>
     </move>
     <!-- install axis into greenstone web app -->
@@ -734,5 +894,5 @@
       </and>
     </condition>
-   </target> 
+  </target> 
 
   <target name="create-deployment-files" depends="get-sitename,get-siteuri,check-deployment-files" 
@@ -743,5 +903,5 @@
       tofile="${basedir}/resources/soap/${axis.sitename}.wsdd"
       filtering="true"/>
-     <copy file="${basedir}/resources/soap/undeploy-site.wsdd.template"
+    <copy file="${basedir}/resources/soap/undeploy-site.wsdd.template"
       tofile="${basedir}/resources/soap/undeploy-${axis.sitename}.wsdd"
       filtering="true"/>
@@ -762,14 +922,14 @@
     <copy file="${build.home}/org/greenstone/gsdl3/SOAPServer${axis.sitename}.class" tofile="${web.classes}/org/greenstone/gsdl3/SOAPServer${axis.sitename}.class" />
   </target>
-    
-
-<!-- ====================== Core targets ============================== -->
-<!-- core targets refer to the core gsdl3 java src -->
-  
-  <target name="prepare-core" unless="nocvs.mode">
+  
+
+  <!-- ====================== Core targets ============================== -->
+  <!-- core targets refer to the core gsdl3 java src -->
+  
+  <target name="prepare-core" unless="nosvn.mode">
     <!-- just get rid of empty directories-->
     <svn>
-		<update dir="."/>
-	</svn>
+      <update dir="."/>
+    </svn>
   </target>
   
@@ -779,20 +939,20 @@
     description="Update only the Greenstone core" />
   
-  <target name="svnupdate-core" unless="nocvs.mode">
-
-	<svn>
-		<update dir="." recurse="false"/>
-	</svn>
-
-   <svn>
-		<update dir="bin"/>
-		<update dir="comms"/>
-		<update dir="dist-resources"/>
-		<update dir="docs"/>
-		<update dir="lib"/>
-		<update dir="resources"/>
-		<update dir="src"/>
-		<update dir="winutil"/>
-	</svn>
+  <target name="svnupdate-core" unless="nosvn.mode">
+
+    <svn>
+      <update dir="." recurse="false"/>
+    </svn>
+
+    <svn>
+      <update dir="bin"/>
+      <update dir="comms"/>
+      <update dir="dist-resources"/>
+      <update dir="docs"/>
+      <update dir="lib"/>
+      <update dir="resources"/>
+      <update dir="src"/>
+      <update dir="winutil"/>
+    </svn>
 
   </target>
@@ -803,5 +963,5 @@
   </target>
 
-   <target name="compile-core" depends="init" 
+  <target name="compile-core" depends="init" 
     description="Compile only the Greenstone core">
     <mkdir dir="${build.home}"/>
@@ -837,5 +997,5 @@
       </manifest>
     </jar>
-      
+    
     <jar destfile="${build.home}/phind.jar">
       <fileset dir="${build.home}">
@@ -880,15 +1040,14 @@
     <copy file="${build.home}/server.jar" todir="${basedir}"/>
   </target>
- 
-<!-- ================== Packages targets ================================ -->
+  
+  <!-- ================== Packages targets ================================ -->
   <!-- these targets refer to the greenstone source packages - these need 
   updating less often, so are in  separate targets to the core -->
   <target name="prepare-packages" depends="init,prepare-indexers"/>
   
-  <target name="checkout-indexers" depends="init" if="independent-indexers" unless="nocvs.mode">
-<!--  <target name="checkout-indexers" depends="check-svnroot,init" if="independent-indexers" unless="nocvs.mode"> -->
+  <target name="checkout-indexers" depends="init" if="independent-indexers" unless="nosvn.mode">
     <svn>
-		<checkout url="${svn.root}/indexers/${branch.path}" dest="${src.packages.home}/indexers"/>
-	</svn>
+      <checkout url="${svn.root}/indexers/${branch.path}" dest="${src.packages.home}/indexers" revision="${branch.revision}"/>
+    </svn>
   </target>
   
@@ -900,8 +1059,8 @@
     description="Update only the source packages"/>
 
-  <target name="svnupdate-packages" unless="nocvs.mode"> 
-   <svn>
-		<update dir="${src.packages.home}"/>
-	</svn>
+  <target name="svnupdate-packages" unless="nosvn.mode"> 
+    <svn>
+      <update dir="${src.packages.home}"/>
+    </svn>
   </target>
   
@@ -922,20 +1081,20 @@
       <arg value="--prefix=${basedir}"/>
       <arg value="--libdir=${lib.jni}"/>
-     <arg value="--with-gdbm=${gdbm.installed.path}"/>
+      <arg value="--with-gdbm=${gdbm.installed.path}"/>
     </exec>    
   </target>
 
-<!-- Message from oran. I removed the condition from this line becuase it meant
-	the indexers would only be configured if collection building was DISabled.
-	Shouldn't they be configured when collection building is ENabled? -->
-
-<!--	<target name="configure-indexers" depends="init" if="independent-indexers"> -->
-<target name="configure-indexers" depends="init">
-		<echo>Configuring Indexers</echo>
-		<exec executable="${indexers.home}/configure" os="${os.unix}" dir="${indexers.home}">
-			<arg value="--prefix=${basedir}"/>
-			<arg value="--libdir=${lib.jni}"/>
-		</exec>          
-	</target>
+  <!-- Message from oran. I removed the condition from this line becuase it meant
+  the indexers would only be configured if collection building was DISabled.
+  Shouldn't they be configured when collection building is ENabled? -->
+
+  <!--	<target name="configure-indexers" depends="init" if="independent-indexers"> -->
+  <target name="configure-indexers" depends="init">
+    <echo>Configuring Indexers</echo>
+    <exec executable="${indexers.home}/configure" os="${os.unix}" dir="${indexers.home}">
+      <arg value="--prefix=${basedir}"/>
+      <arg value="--libdir=${lib.jni}"/>
+    </exec>          
+  </target>
 
   <target name="clean-packages" depends="init,clean-javagdbm,clean-indexers" description="Clean only the packages"/>
@@ -954,84 +1113,104 @@
     </exec>
     <exec executable="${indexers.home}/winMake.bat" os="${os.windows}"
-       dir="${indexers.home}">
-       <arg value="clean"/>
-    </exec>
-
-  </target>
-   
-	<target name="compile-packages" description="Compile only the source packages">
-
-		<!-- javagdbm -->
-		<echo>compile javagdbm</echo>
-		<exec executable="make" os="${os.unix}" dir="${javagdbm.home}"/>
-		<exec executable="make" os="${os.unix}" dir="${javagdbm.home}">
-			<arg value="install"/>
-		</exec>
-
-		<!-- windows: just the java stuff. -->
-		<echo>Windows: compile javagdbm (java only)</echo>
-		<exec executable="${javagdbm.home}/winMake.bat" os="${os.windows}" dir="${javagdbm.home}">
-			<arg value="compile"/>
-			<arg value="javaonly"/>
-		</exec>
-
-		<!-- install the jar file -->
-		<echo>Install the javagdbm jar file</echo>
-		<copy file="${javagdbm.home}/javagdbm.jar" todir="${lib.jni}"/>
-
-		<!-- Indexers -->
-
-		<!-- this may be in gs2build - we will be recompiling, but never mind -->
-		<echo>Indexers: make (from ${indexers.home})</echo>
-		<exec executable="make" os="${os.unix}" dir="${indexers.home}"/>
-		<echo>Indexers: make install</echo>
-		<exec executable="make" os="${os.unix}" dir="${indexers.home}">
-			<arg value="install"/>
-		</exec>
-
-		<echo>Indexers: make</echo>
-		<exec executable="${indexers.home}/winMake.bat" os="${os.windows}" dir="${indexers.home}">
-			<arg value="all"/>
-		</exec>
-		<echo>Indexers: make install</echo>
-		<exec executable="${indexers.home}/winMake.bat" os="${os.windows}" dir="${indexers.home}">
-			<arg value="install"/>
-		</exec>
-
-		<!-- install the jar and jni files -->
-		<echo>Install the indexers' jar and jni files</echo>
-		<copy file="${mg.home}/mg.jar" todir="${lib.jni}"/>
-		<copy file="${mgpp.home}/mgpp.jar" todir="${lib.jni}"/>
-		<copy file="${lucene.home}/LuceneWrapper.jar" todir="${web.lib}"/>
-		<antcall target="install-jni-files"/>
-	</target>
+      dir="${indexers.home}">
+      <arg value="clean"/>
+    </exec>
+
+  </target>
+  <target name="distclean-packages" depends="init,distclean-javagdbm,distclean-indexers" description="Distclean only the packages"/>
+
+  <target name="distclean-javagdbm" depends="init">
+    <exec executable="make" os="${os.unix}"
+      dir="${javagdbm.home}">
+      <arg value="distclean"/>
+    </exec>
+  </target>
+  
+  <target name="distclean-indexers" depends="init" if="independent-indexers">
+    <exec executable="make" os="${os.unix}"
+      dir="${indexers.home}">
+      <arg value="distclean"/>
+    </exec>
+    <exec executable="${indexers.home}/winMake.bat" os="${os.windows}"
+      dir="${indexers.home}">
+      <arg value="clean"/>
+    </exec>
+
+  </target>
+  
+  <target name="compile-packages" description="Compile only the source packages">
+    
+    <!-- javagdbm -->
+    <echo>compile javagdbm</echo>
+    <exec executable="make" os="${os.unix}" dir="${javagdbm.home}"/>
+    <exec executable="make" os="${os.unix}" dir="${javagdbm.home}">
+      <arg value="install"/>
+    </exec>
+
+    <!-- windows: just the java stuff. -->
+    <echo>Windows: compile javagdbm (java only)</echo>
+    <exec executable="${javagdbm.home}/winMake.bat" os="${os.windows}" dir="${javagdbm.home}">
+      <arg value="compile"/>
+      <arg value="javaonly"/>
+    </exec>
+
+    <!-- install the jar file -->
+    <echo>Install the javagdbm jar file</echo>
+    <copy file="${javagdbm.home}/javagdbm.jar" todir="${lib.jni}"/>
+
+    <!-- Indexers -->
+
+    <!-- this may be in gs2build - we will be recompiling, but never mind -->
+    <echo>Indexers: make (from ${indexers.home})</echo>
+    <exec executable="make" os="${os.unix}" dir="${indexers.home}"/>
+    <echo>Indexers: make install</echo>
+    <exec executable="make" os="${os.unix}" dir="${indexers.home}">
+      <arg value="install"/>
+    </exec>
+
+    <echo>Indexers: make</echo>
+    <exec executable="${indexers.home}/winMake.bat" os="${os.windows}" dir="${indexers.home}">
+      <arg value="all"/>
+    </exec>
+    <echo>Indexers: make install</echo>
+    <exec executable="${indexers.home}/winMake.bat" os="${os.windows}" dir="${indexers.home}">
+      <arg value="install"/>
+    </exec>
+
+    <!-- install the jar and jni files -->
+    <echo>Install the indexers' jar and jni files</echo>
+    <copy file="${mg.home}/mg.jar" todir="${lib.jni}"/>
+    <copy file="${mgpp.home}/mgpp.jar" todir="${lib.jni}"/>
+    <copy file="${lucene.home}/LuceneWrapper.jar" todir="${web.lib}"/>
+    <antcall target="install-jni-files"/>
+  </target>
 
   <target name="install-jni-files" depends="init,install-jni-files-linux,install-jni-files-windows,install-jni-files-macos"/>
 
-    <target name="install-jni-files-linux" depends="init" if="current.os.isunixnotmac">
+  <target name="install-jni-files-linux" depends="init" if="current.os.isunixnotmac">
     <copy file="${mg.home}/jni/libmgretrievejni.so" todir="${lib.jni}"/>
     <copy file="${mg.home}/jni/libmgsearchjni.so" todir="${lib.jni}"/>
-     <copy file="${mg.home}/jni/libmgpassjni.so" todir="${lib.jni}"/>
+    <copy file="${mg.home}/jni/libmgpassjni.so" todir="${lib.jni}"/>
     <copy file="${mgpp.home}/jni/libmgppretrievejni.so" todir="${lib.jni}"/>
     <copy file="${mgpp.home}/jni/libmgppsearchjni.so" todir="${lib.jni}"/>
-     <copy file="${mgpp.home}/jni/libmgpppassjni.so" todir="${lib.jni}"/>
-   </target>
-   <target name="install-jni-files-windows" depends="init" if="current.os.iswindows">
+    <copy file="${mgpp.home}/jni/libmgpppassjni.so" todir="${lib.jni}"/>
+  </target>
+  <target name="install-jni-files-windows" depends="init" if="current.os.iswindows">
     <copy file="${mg.home}/jni/mgretrievejni.dll" todir="${lib.jni}"/>
     <copy file="${mg.home}/jni/mgsearchjni.dll" todir="${lib.jni}"/>
-     <copy file="${mg.home}/jni/mgpassjni.dll" todir="${lib.jni}"/>
+    <copy file="${mg.home}/jni/mgpassjni.dll" todir="${lib.jni}"/>
     <copy file="${mgpp.home}/jni/mgppretrievejni.dll" todir="${lib.jni}"/>
     <copy file="${mgpp.home}/jni/mgppsearchjni.dll" todir="${lib.jni}"/>
-     <copy file="${mgpp.home}/jni/mgpppassjni.dll" todir="${lib.jni}"/>
-   </target>
-   <target name="install-jni-files-macos" depends="init" if="current.os.ismac">
+    <copy file="${mgpp.home}/jni/mgpppassjni.dll" todir="${lib.jni}"/>
+  </target>
+  <target name="install-jni-files-macos" depends="init" if="current.os.ismac">
     <copy file="${mg.home}/jni/libmgretrievejni.jnilib" todir="${lib.jni}"/>
     <copy file="${mg.home}/jni/libmgsearchjni.jnilib" todir="${lib.jni}"/>
-     <copy file="${mg.home}/jni/libmgpassjni.jnilib" todir="${lib.jni}"/>
+    <copy file="${mg.home}/jni/libmgpassjni.jnilib" todir="${lib.jni}"/>
     <copy file="${mgpp.home}/jni/libmgppretrievejni.jnilib" todir="${lib.jni}"/>
     <copy file="${mgpp.home}/jni/libmgppsearchjni.jnilib" todir="${lib.jni}"/>
-     <copy file="${mgpp.home}/jni/libmgpppassjni.jnilib" todir="${lib.jni}"/>
-   </target>
- 
+    <copy file="${mgpp.home}/jni/libmgpppassjni.jnilib" todir="${lib.jni}"/>
+  </target>
+  
   <!-- ================== gs2building targets ===============-->
 
@@ -1041,95 +1220,165 @@
     description="Update only the Greenstone 2 building components"/>
 
-  <target name="svnupdate-gs2building" if="collection.building.enabled" depends="init,svnupdate-gs2build,svnupdate-gli" unless="nocvs.mode">
-  </target>
-  <target name="svnupdate-gs2build" if="collection.building.enabled" depends="init" unless="nocvs.mode">
-    <!-- Note: can't do a -d update here cos it will get all of gsdl 
-     also, an update doesn't get new files, so we do a checkout instead. -->
-		<antcall target="checkout-gs2build"/>
-  </target>
-  
-  <target name="svnupdate-gli" if="collection.building.enabled" depends="init" unless="nocvs.mode">
+  <target name="svnupdate-gs2building" if="collection.building.enabled" depends="init,svnupdate-gs2build,svnupdate-gli" unless="nosvn.mode">
+  </target>
+
+  <target name="svnupdate-gs2build" if="collection.building.enabled" depends="init" unless="nosvn.mode">
+    <!-- please keep this function in sync with checkout-gs2build -->
+
+    <echo>updating gs2build</echo>
+    <!-- svn updates -->
     <svn>
-		<update dir="${gli.home}"/>
-	</svn>
+      <!-- perllib -->
+      <update dir="gs2build/perllib" revision="${branch.revision}"/>
+
+      <!-- selected packages -->
+      <update dir="gs2build/packages/cpan" revision="${branch.revision}" />
+      <update dir="gs2build/packages/expat" revision="${branch.revision}" />
+      <update dir="gs2build/packages/html-tidy" revision="${branch.revision}" />
+      <update dir="gs2build/packages/isis-gdl" revision="${branch.revision}" />
+      <update dir="gs2build/packages/kea" revision="${branch.revision}" />
+      <update dir="gs2build/packages/pdftohtml" revision="${branch.revision}" />
+      <update dir="gs2build/packages/rtftohtml" revision="${branch.revision}" />
+      <update dir="gs2build/packages/w3mir" revision="${branch.revision}" />
+      <update dir="gs2build/packages/wget" revision="${branch.revision}" />
+      <update dir="gs2build/packages/windows" revision="${branch.revision}" />
+      <update dir="gs2build/packages/wv" revision="${branch.revision}" />
+      <update dir="gs2build/packages/xlhtml" revision="${branch.revision}" />
+      <update dir="gs2build/packages/yaz" revision="${branch.revision}" />
+      
+      <!-- some of src (db2txt hashfile phind txt2db) -->
+      <update dir="gs2build/src/db2txt" revision="${branch.revision}" />
+      <update dir="gs2build/src/hashfile" revision="${branch.revision}" />
+      <update dir="gs2build/src/phind" revision="${branch.revision}" />
+      <update dir="gs2build/src/txt2db" revision="${branch.revision}" />
+
+      <!-- bin -->
+      <update dir="gs2build/bin/script" revision="${branch.revision}" />
+
+      <!-- mappings -->
+      <update dir="gs2build/mappings" revision="${branch.revision}"/>
+
+      <!-- etc/packages -->
+      <update dir="gs2build/etc/packages" revision="${branch.revision}"/>
+      
+      <!-- collect -->
+      <update dir="gs2build/collect/modelcol" revision="${branch.revision}"/>
+
+      <!-- gs2build-extra -->
+      <update dir="gs2build/gs2build-extra" revision="${branch.revision}"/>
+
+      <!-- indexers -->
+      <update dir="gs2build/indexers" revision="${branch.revision}"/>
+
+      <!-- single files -->
+      
+      <!-- some files from lib -->
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/lib/text_t.h" destPath="gs2build/lib/text_t.h"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/lib/text_t.cpp" destPath="gs2build/lib/text_t.cpp"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/lib/gsdlconf.h" destPath="gs2build/lib/gsdlconf.h"/>
+
+      <!-- some files from etc -->
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/etc/marctodc.txt" destPath="gs2build/etc/marctodc.txt"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/etc/dc2marc-mapping.xml" destPath="gs2build/etc/dc2marc-mapping.xml"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/etc/dc2marc.xsl" destPath="gs2build/etc/dc2marc.xsl"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/etc/qdc2marc-mapping.xml" destPath="gs2build/etc/qdc2marc-mapping.xml"/>
+
+      <!-- some files from the gsdl root directory -->
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/setup.bash" destPath="gs2build/setup.bash"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/config.sub" destPath="gs2build/config.sub"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/config.guess" destPath="gs2build/config.guess"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/config.h.in" destPath="gs2build/config.h.in"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/configtest.pl" destPath="gs2build/configtest.pl"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/install-sh" destPath="gs2build/install-sh"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/acconfig.h" destPath="gs2build/acconfig.h"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/aclocal.m4" destPath="gs2build/aclocal.m4"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/WIN32cfg.h" destPath="gs2build/WIN32cfg.h"/>
+    </svn>
+  </target>
+  
+  <target name="svnupdate-gli" if="collection.building.enabled" depends="init" unless="nosvn.mode">
+    <svn>
+      <update dir="${gli.home}" revision="${branch.revision}"/>
+    </svn>
   </target>
 
   <target name="prepare-gs2building" depends="init,prepare-gs2build,prepare-gli" if="collection.building.enabled">
   </target>
-
-  <target name="checkout-gs2build" depends="init" if="collection.building.enabled" unless="nocvs.mode">
+  <target name="checkout-gs2build" depends="init" if="collection.building.enabled" unless="nosvn.mode">
+    <!-- please keep this function in sync with update-gs2build -->
     <echo>checking out gs2build</echo>
-		<!-- svn checkouts -->
-		<svn>
-			<!-- perllib -->
-			<checkout url="${svn.root}/gsdl/${branch.path}/perllib" destPath="gs2build/perllib"/>
-
-			<!-- selected packages -->
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/cpan" destPath="gs2build/packages/cpan"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/expat" destPath="gs2build/packages/expat"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/html-tidy" destPath="gs2build/packages/html-tidy"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/isis-gdl" destPath="gs2build/packages/isis-gdl"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/kea" destPath="gs2build/packages/kea"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/pdftohtml" destPath="gs2build/packages/pdftohtml"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/rtftohtml" destPath="gs2build/packages/rtftohtml"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/w3mir" destPath="gs2build/packages/w3mir"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/wget" destPath="gs2build/packages/wget"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/windows" destPath="gs2build/packages/windows"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/wv" destPath="gs2build/packages/wv"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/xlhtml" destPath="gs2build/packages/xlhtml"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/packages/yaz" destPath="gs2build/packages/yaz"/>
-			
-			<!-- some of src (db2txt hashfile phind txt2db) -->
-			<checkout url="${svn.root}/gsdl/${branch.path}/src/db2txt" destPath="gs2build/src/db2txt"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/src/hashfile" destPath="gs2build/src/hashfile"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/src/phind" destPath="gs2build/src/phind"/>
-			<checkout url="${svn.root}/gsdl/${branch.path}/src/txt2db" destPath="gs2build/src/txt2db"/>
-
-			<!-- bin -->
-			<checkout url="${svn.root}/gsdl/${branch.path}/bin/script" destPath="gs2build/bin/script"/>
-
-			<!-- mappings -->
-			<checkout url="${svn.root}/gsdl/${branch.path}/mappings" destPath="gs2build/mappings"/>
-
-			<!-- etc/packages -->
-			<checkout url="${svn.root}/gsdl/${branch.path}/etc/packages" destPath="gs2build/etc/packages"/>
-	
-			<!-- collect -->
-			<checkout url="${svn.root}/gsdl/${branch.path}/collect/modelcol" destPath="gs2build/collect/modelcol"/>
-
-			<!-- gs2build-extra -->
-			<checkout url="${svn.root}/other-projects/trunk/gs2build-extra" destPath="gs2build/gs2build-extra"/>
-
-			<!-- indexers -->
-			<checkout url="${svn.root}/indexers/${branch.path}" destPath="gs2build/indexers"/>
-
-
-		</svn>
-		<!-- regular downloads -->
-
-		<!-- some files from lib -->
-		<mkdir dir="gs2build/lib"/>
-		<get src="${svn.root}/gsdl/${branch.path}/lib/text_t.h" dest="gs2build/lib/text_t.h"/>
-		<get src="${svn.root}/gsdl/${branch.path}/lib/text_t.cpp" dest="gs2build/lib/text_t.cpp"/>
-		<get src="${svn.root}/gsdl/${branch.path}/lib/gsdlconf.h" dest="gs2build/lib/gsdlconf.h"/>
-
-		<!-- some files from etc -->
-		<get src="${svn.root}/gsdl/${branch.path}/etc/marctodc.txt" dest="gs2build/etc/marctodc.txt"/>
-		<get src="${svn.root}/gsdl/${branch.path}/etc/dc2marc-mapping.xml" dest="gs2build/etc/dc2marc-mapping.xml"/>
-		<get src="${svn.root}/gsdl/${branch.path}/etc/dc2marc.xsl" dest="gs2build/etc/dc2marc.xsl"/>
-		<get src="${svn.root}/gsdl/${branch.path}/etc/qdc2marc-mapping.xml" dest="gs2build/etc/qdc2marc-mapping.xml"/>
-
-		<!-- some files from the gsdl root directory -->
-		<get src="${svn.root}/gsdl/${branch.path}/setup.bash" dest="gs2build/setup.bash"/>
-		<get src="${svn.root}/gsdl/${branch.path}/config.sub" dest="gs2build/config.sub"/>
-		<get src="${svn.root}/gsdl/${branch.path}/config.guess" dest="gs2build/config.guess"/>
-		<get src="${svn.root}/gsdl/${branch.path}/config.h.in" dest="gs2build/config.h.in"/>
-		<get src="${svn.root}/gsdl/${branch.path}/configtest.pl" dest="gs2build/configtest.pl"/>
-		<get src="${svn.root}/gsdl/${branch.path}/install-sh" dest="gs2build/install-sh"/>
-		<get src="${svn.root}/gsdl/${branch.path}/acconfig.h" dest="gs2build/acconfig.h"/>
-		<get src="${svn.root}/gsdl/${branch.path}/aclocal.m4" dest="gs2build/aclocal.m4"/>
-		<get src="${svn.root}/gsdl/${branch.path}/WIN32cfg.h" dest="gs2build/WIN32cfg.h"/>
-
-	</target>
+
+    <!-- this has to be created first to avoid errors when trying to export to it later -->
+    <mkdir dir="${basedir}/gs2build/lib"/>
+
+    <!-- svn checkouts -->
+    <svn>
+      <!-- perllib -->
+      <checkout url="${svn.root}/gsdl/${branch.path}/perllib" destPath="gs2build/perllib" revision="${branch.revision}"/>
+
+      <!-- selected packages -->
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/cpan" destPath="gs2build/packages/cpan" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/expat" destPath="gs2build/packages/expat" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/html-tidy" destPath="gs2build/packages/html-tidy" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/isis-gdl" destPath="gs2build/packages/isis-gdl" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/kea" destPath="gs2build/packages/kea" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/pdftohtml" destPath="gs2build/packages/pdftohtml" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/rtftohtml" destPath="gs2build/packages/rtftohtml" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/w3mir" destPath="gs2build/packages/w3mir" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/wget" destPath="gs2build/packages/wget" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/windows" destPath="gs2build/packages/windows" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/wv" destPath="gs2build/packages/wv" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/xlhtml" destPath="gs2build/packages/xlhtml" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/packages/yaz" destPath="gs2build/packages/yaz" revision="${branch.revision}" />
+      
+      <!-- some of src (db2txt hashfile phind txt2db) -->
+      <checkout url="${svn.root}/gsdl/${branch.path}/src/db2txt" destPath="gs2build/src/db2txt" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/src/hashfile" destPath="gs2build/src/hashfile" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/src/phind" destPath="gs2build/src/phind" revision="${branch.revision}" />
+      <checkout url="${svn.root}/gsdl/${branch.path}/src/txt2db" destPath="gs2build/src/txt2db" revision="${branch.revision}" />
+
+      <!-- bin -->
+      <checkout url="${svn.root}/gsdl/${branch.path}/bin/script" destPath="gs2build/bin/script" revision="${branch.revision}" />
+
+      <!-- mappings -->
+      <checkout url="${svn.root}/gsdl/${branch.path}/mappings" destPath="gs2build/mappings" revision="${branch.revision}"/>
+
+      <!-- etc/packages -->
+      <checkout url="${svn.root}/gsdl/${branch.path}/etc/packages" destPath="gs2build/etc/packages" revision="${branch.revision}"/>
+      
+      <!-- collect -->
+      <checkout url="${svn.root}/gsdl/${branch.path}/collect/modelcol" destPath="gs2build/collect/modelcol" revision="${branch.revision}"/>
+
+      <!-- gs2build-extra -->
+      <checkout url="${svn.root}/other-projects/trunk/gs2build-extra" destPath="gs2build/gs2build-extra" revision="${branch.revision}"/>
+
+      <!-- indexers -->
+      <checkout url="${svn.root}/indexers/${branch.path}" destPath="gs2build/indexers" revision="${branch.revision}"/>
+
+      <!-- single files -->
+      
+      <!-- some files from lib -->
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/lib/text_t.h" destPath="gs2build/lib/text_t.h"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/lib/text_t.cpp" destPath="gs2build/lib/text_t.cpp"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/lib/gsdlconf.h" destPath="gs2build/lib/gsdlconf.h"/>
+
+      <!-- some files from etc -->
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/etc/marctodc.txt" destPath="gs2build/etc/marctodc.txt"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/etc/dc2marc-mapping.xml" destPath="gs2build/etc/dc2marc-mapping.xml"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/etc/dc2marc.xsl" destPath="gs2build/etc/dc2marc.xsl"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/etc/qdc2marc-mapping.xml" destPath="gs2build/etc/qdc2marc-mapping.xml"/>
+
+      <!-- some files from the gsdl root directory -->
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/setup.bash" destPath="gs2build/setup.bash"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/config.sub" destPath="gs2build/config.sub"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/config.guess" destPath="gs2build/config.guess"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/config.h.in" destPath="gs2build/config.h.in"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/configtest.pl" destPath="gs2build/configtest.pl"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/install-sh" destPath="gs2build/install-sh"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/acconfig.h" destPath="gs2build/acconfig.h"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/aclocal.m4" destPath="gs2build/aclocal.m4"/>
+      <export srcUrl="${svn.root}/gsdl/${branch.path}/WIN32cfg.h" destPath="gs2build/WIN32cfg.h"/>
+    </svn>
+  </target>
 
   <target name="prepare-gs2build" depends="init" if="collection.building.enabled" unless="gs2build.present">
@@ -1144,15 +1393,15 @@
 
   <target name="checkout-winbin" depends="init" if="current.os.iswindows" 
-    unless="nocvs.mode">
+    unless="nosvn.mode">
     <svn>
-		<checkout url="${svn.root}/other-projects/trunk/winbin" destPath="${basedir}/winbin"/>
-	</svn>	
-  </target>
-
-  <target name="update-winbin" depends="init" if="current.os.iswindows" unless="nocvs.mode">
-		<svn>
-			<update dir="${svn.root}/other-projects/trunk/winbin"/>
-		</svn>	
-	</target>
+      <checkout url="${svn.root}/other-projects/trunk/winbin" destPath="${basedir}/winbin" revision="${branch.revision}"/>
+    </svn>	
+  </target>
+
+  <target name="update-winbin" depends="init" if="current.os.iswindows" unless="nosvn.mode">
+    <svn>
+      <update dir="winbin"/>
+    </svn>	
+  </target>
   
   <target name="get-windows-binaries" depends="init" if="collection.building.enabled.windows">
@@ -1167,14 +1416,14 @@
   <target name="unzip-windows-packages" depends="init" if="collection.building.enabled.windows">  
     <unzip src="${gs2build.home}/packages/windows/gdbm/gdbm.zip"
-    dest="${gs2build.home}/packages/windows/gdbm"/>
-   <unzip src="${gs2build.home}/packages/windows/crypt/crypt.zip"
-    dest="${gs2build.home}/packages/windows/crypt"/>
-       <unzip src="${gs2build.home}/packages/windows/expat/expat.zip"
-    dest="${gs2build.home}/packages/windows/expat"/>
-   </target>
+      dest="${gs2build.home}/packages/windows/gdbm"/>
+    <unzip src="${gs2build.home}/packages/windows/crypt/crypt.zip"
+      dest="${gs2build.home}/packages/windows/crypt"/>
+    <unzip src="${gs2build.home}/packages/windows/expat/expat.zip"
+      dest="${gs2build.home}/packages/windows/expat"/>
+  </target>
   
   <!-- downloads a good XML-Parser -->
   <target name="get-macos-extra" depends="init" if="need.macos.extra">	
-      <get src="http://www.greenstone.org/gs3files/XML-Parser.tar.gz"
+    <get src="http://www.greenstone.org/gs3files/XML-Parser.tar.gz"
       dest="${gs2build.home}/perllib/cpan/XML-Parser.tar.gz"
       usetimestamp="true"/>
@@ -1211,5 +1460,5 @@
       <filterset>
 	<filter token="gsdlhome" value="${gs2build.home.windows}"/>
-     </filterset>
+      </filterset>
     </move>  
     <move file="${gs2build.home}/setup-tmp.bat" tofile="${gs2build.home}/setup.bat" />
@@ -1239,12 +1488,11 @@
   </target>
   
-<!--  <target name="checkout-gli" depends="check-cvsroot,init" if="collection.building.enabled" unless="nocvs.mode"> -->
-  <target name="checkout-gli" depends="init" if="collection.building.enabled" unless="nocvs.mode">
+  <target name="checkout-gli" depends="init" if="collection.building.enabled" unless="nosvn.mode">
     <echo>checking out gli</echo>
     <svn>
-		<checkout url="${svn.root}/gli/${branch.path}" destPath="gli"/>
-	</svn>
-  </target>
-    
+      <checkout url="${svn.root}/gli/${branch.path}" destPath="gli" revision="${branch.revision}"/>
+    </svn>
+  </target>
+  
   <target name="configure-gs2building" depends="init" if="collection.building.enabled"
     description="Configure only the Greenstone 2 building components">
@@ -1283,19 +1531,20 @@
     <!-- windows: -->    
     <!-- run the setup script -->
-    <exec executable="${compile.windows.c++.setup}"/>
-    <exec executable="nmake" dir="${gs2build.home}">
-     <arg value="/f"/>
-     <arg value="win32.mak"/>
-     <arg value="clean"/>
-    </exec>
-  </target>
-  
+    <exec executable="${compile.windows.c++.setup}" os="${os.windows}" />
+    <exec executable="nmake" dir="${gs2build.home}" os="${os.windows}" >
+      <arg value="/f"/>
+      <arg value="win32.mak"/>
+      <arg value="clean"/>
+    </exec>
+  </target>
+  
+  <target name="distclean-gs2building" depends="init,clean-gli,clean-gs2build,distclean-gs2build" 
+    description="Distclean only the Greenstone 2 building components" 
+    if="collection.building.enabled"/>
+
   <target name="distclean-gs2build" depends="init" if="collection.building.enabled">
-    <!-- gs2build -->
-    <!--linux:  -->
     <exec executable="make" os="${os.unix}" dir="${gs2build.home}">
       <arg value="distclean"/>
     </exec>
-    <!-- windows: -->    
   </target>
   
@@ -1308,17 +1557,17 @@
     <property name="gli.home" value="${basedir}/gli"/>
 
-		<!-- change the version number -->
-		<rsr file="${gli.home}/src/org/greenstone/gatherer/Gatherer.java" pattern="^(.*)String\s*PROGRAM_VERSION\s*=\s*&quot;(.*)&quot;" replacement="$1String PROGRAM_VERSION = &quot;${app.version}&quot;"/>
+    <!-- change the version number -->
+    <rsr file="${gli.home}/src/org/greenstone/gatherer/Gatherer.java" pattern="^(.*)String\s*PROGRAM_VERSION\s*=\s*&quot;(.*)&quot;" replacement="$1String PROGRAM_VERSION = &quot;${app.version}&quot;"/>
     <!-- linux -->
     <exec executable="makegli.sh" os="${os.unix}" dir="${gli.home}" resolveExecutable="true"/>
-     <!--remote gli-->
-     <exec executable="makejar.sh" os="${os.unix}" dir="${gli.home}"
+    <!--remote gli-->
+    <exec executable="makejar.sh" os="${os.unix}" dir="${gli.home}"
       resolveExecutable="true"/>
     <!-- windows -->
     <exec executable="makegli.bat" os="${os.windows}" dir="${gli.home}" resolveExecutable="true"/>
     <!--remote gli-->
-     <exec executable="makejar.bat" os="${os.windows}" dir="${gli.home}"
+    <exec executable="makejar.bat" os="${os.windows}" dir="${gli.home}"
       resolveExecutable="true"/> 
-     <copy file="${gli.home}/GLIServer.jar" todir="${gs2build.home}/bin/java" />
+    <copy file="${gli.home}/GLIServer.jar" todir="${gs2build.home}/bin/java" />
   </target>
   
@@ -1334,11 +1583,11 @@
     <exec executable="${compile.windows.c++.setup}" os="${os.windows}"/>
     <exec executable="nmake" dir="${gs2build.home}" os="${os.windows}">
-     <arg value="/f"/>
-     <arg value="win32.mak"/>
+      <arg value="/f"/>
+      <arg value="win32.mak"/>
     </exec>
     <exec executable="nmake" dir="${gs2build.home}" os="${os.windows}">
-     <arg value="/f"/>
-     <arg value="win32.mak"/>
-     <arg value="install"/>
+      <arg value="/f"/>
+      <arg value="win32.mak"/>
+      <arg value="install"/>
     </exec>
     <!-- LuceneWrapper jar file not installed by default -->
@@ -1374,7 +1623,7 @@
     </echo>
   </target>
- 
-
-<!-- ======================== TESTING Targets ========================= -->
+  
+
+  <!-- ======================== TESTING Targets ========================= -->
   
   <target name="test" description="Run the (incomplete) JUnit test suite "
@@ -1399,45 +1648,131 @@
     <echo>
       *********************************************
-       Test output can be found in directory 'test'
+      Test output can be found in directory 'test'
       *********************************************
     </echo>
   </target>
-  <target name="checkout-flax" description="check out flax source code from another repository">
+
+  <!-- ======================== FLAX Targets ========================= -->
+  <target name="prepare-flax" description="check out flax source code from another repository" if="install.flax">
     <echo>checking out flax ...</echo>
     <mkdir dir="${basedir}/src/java/org/flax"/>
     <mkdir dir="${basedir}/src/java/org/greenstone/gsdl3/flax"/>
-    <mkdir dir="${basedir}/web/WEB-INF/classes/flax"/>
-    <mkdir dir="${basedir}/web/interfaces/flax"/>
-    <mkdir dir="${basedir}/web/sites/flax"/>
+    <mkdir dir="${web.home}/WEB-INF/classes/flax"/>
+    <mkdir dir="${web.home}/interfaces/flax"/>
+    <mkdir dir="${web.home}/sites/flax"/>
+    <mkdir dir="${basedir}/flax-resources"/>
+    <mkdir dir="${basedir}/flax-lib"/>
     <svn>
       <checkout url="${flax.svn.root}/flax1.0/trunk/src/java/org/flax/"  
-                destPath="${basedir}/src/java/org/flax"/>
+	destPath="${basedir}/src/java/org/flax"/>
       <checkout url="${flax.svn.root}/flax1.0/trunk/src/java/org/greenstone/gsdl3/flax/" 
-                destPath="${basedir}/src/java/org/greenstone/gsdl3/flax"/>
+	destPath="${basedir}/src/java/org/greenstone/gsdl3/flax"/>
       <checkout url="${flax.svn.root}/flax1.0/trunk/web/WEB-INF/classes/flax/" 
-                destPath="${basedir}/web/WEB-INF/classes/flax"/>
+	destPath="${web.home}/WEB-INF/classes/flax"/>
       <checkout url="${flax.svn.root}/flax1.0/trunk/web/interfaces/flax/" 
-                destPath="${basedir}/web/interfaces/flax"/>
+	destPath="${web.home}/interfaces/flax"/>
       <checkout url="${flax.svn.root}/flax1.0/trunk/web/sites/flax/" 
-                destPath="${basedir}/web/sites/flax"/>
+	destPath="${web.home}/sites/flax"/>
+      <checkout url="${flax.svn.root}/flax1.0/trunk/flax-resources"
+	destPath="${basedir}/flax-resources"/>
+      <checkout url="${flax.svn.root}/flax1.0/trunk/lib"
+	destPath="${basedir}/flax-lib"/>
     </svn>
-    <move file="${basedir}/web/WEB-INF/web.xml" tofile="${basedir}/web/WEB-INF/web.xml.greenstone3backup"/>
-    <copy file="${basedir}/web/WEB-INF/classes/flax/web.xml" todir="${basedir}/web/WEB-INF" />
-
-    <property name="coll.dir" value="${basedir}/web/sites/flax/collect"/>
-    <!-- betterfa -->
-    <unzip src="${coll.dir}/betterfa/archives/archives.zip" dest="${coll.dir}/betterfa/archives"/>
-    <unzip src="${coll.dir}/betterfa/import/import.zip" dest="${coll.dir}/betterfa/import"/>
-    <unzip src="${coll.dir}/betterfa/index/index.zip" dest="${coll.dir}/betterfa/index"/>
-    <!-- imagegue -->
-    <unzip src="${coll.dir}/imagegue/archives/archives.zip" dest="${coll.dir}/imagegue/archives"/>
-    <unzip src="${coll.dir}/imagegue/import/import.zip" dest="${coll.dir}/imagegue/import"/>
-    <unzip src="${coll.dir}/imagegue/index/index.zip" dest="${coll.dir}/imagegue/index"/>
-    <!-- wikill -->
-    <unzip src="${coll.dir}/wikill/archives/archives.zip" dest="${coll.dir}/wikill/archives"/>
-    <unzip src="${coll.dir}/wikill/import/import.zip" dest="${coll.dir}/wikill/import"/>
-    <unzip src="${coll.dir}/wikill/index/index.zip" dest="${coll.dir}/wikill/index"/>
-
-  </target>
+    <echo>prepare flax files...</echo>
+    <move file="${web.home}/WEB-INF/web.xml" tofile="${web.home}/WEB-INF/web.xml.greenstone3backup"/>
+    <antcall target="flax-copy-files" />
+    <antcall target="unzip-flax-collections" />
+    <antcall target="unzip-flax-resources" />
+  </target>
+
+  <target name="update-flax" description="update flax from repository">
+    <echo>updating flax ...</echo>
+    <svn>
+      <update dir="${basedir}/src/java/org/flax"/>
+      <update dir="${basedir}/src/java/org/greenstone/gsdl3/flax"/>
+      <update dir="${web.home}/WEB-INF/classes/flax"/>
+      <update dir="${web.home}/interfaces/flax"/>
+      <update dir="${web.home}/sites/flax"/>
+    </svn>
+    <antcall target="flax-copy-files" />
+    <antcall target="unzip-flax-collections" />       
+  </target>
+
+  <target name="unzip-flax-collections" >
+    <property name="coll.dir" value="${web.home}/sites/flax/collect"/>
+    <unzip dest="${coll.dir}">  
+      <fileset dir="${coll.dir}">
+	<include name="*.zip"/>
+      </fileset>    
+    </unzip>    
+    <delete>
+      <fileset dir="${coll.dir}" includes="*.zip"/>
+    </delete>
+  </target>
+
+  <target name="unzip-flax-resources" >
+    <property name="classes.dir" value="${web.home}/WEB-INF/classes/flax"/>
+    <unzip dest="${classes.dir}">  
+      <fileset dir="${classes.dir}">
+	<include name="*.zip"/>
+      </fileset>    
+    </unzip>    
+    <delete>
+      <fileset dir="${classes.dir}" includes="*.zip"/>
+    </delete>
+  </target>
+  
+  <target name="flax-copy-files" description="copy some flax files into the appropriate greenstone3 directories">
+    <echo>copying flax files ...</echo>
+    <copy file="${web.home}/WEB-INF/classes/flax/web.xml" todir="${web.home}/WEB-INF" overwrite="true" />
+    <!-- A configuration file containing web service binding information for the axis engine -->
+    <copy file="${web.home}/WEB-INF/classes/flax/server-config.wsdd" todir="${web.home}/WEB-INF" overwrite="true" />
+    <copy file="${basedir}/flax-resources/flax-build.xml" todir="${basedir}" overwrite="true" />
+    <copy file="${basedir}/flax-lib/opennlp-tools-1.3.0.jar" todir="${web.home}/WEB-INF/lib" overwrite="true" />    
+  </target>
+
+
+  <!-- ======================== GDBM Targets ========================= -->
+
+  <target name="prepare-gdbm" depends="init" if="install.gdbm">
+    <get src="http://www.greenstone.org/gs3files/${gdbm.version}.tar.gz"
+      dest="${src.packages.home}/${gdbm.version}.tar.gz"  usetimestamp="true"/>
+    <untar compression= "gzip" src="${src.packages.home}/${gdbm.version}.tar.gz" dest="${src.packages.home}" />  
+    <chmod dir="${src.packages.home}/${gdbm.version}" perm="ugo+wrx" includes="**" />
+    <antcall target="configure-gdbm" />
+    <antcall target="compile-gdbm" /> 
+  </target>  
+
+  <target name="configure-gdbm" if="install.gdbm">
+    <echo>
+      Configuring GDBM
+    </echo>
+    <exec executable="${gdbm.home}/configure" os="${os.mac},${os.unix}"
+      dir="${gdbm.home}">
+      <arg value="--prefix=${gdbm.home}"/>
+    </exec>    
+  </target>
+
+  <target name="clean-gdbm" depends="init"  if="install.gdbm">   
+    <echo>clean GDBM</echo>
+    <exec executable="make" os="${os.unix}" dir="${gdbm.home}" >
+      <arg value="clean"/>
+    </exec>
+  </target> 
+
+  <target name="distclean-gdbm" depends="init"  if="install.gdbm">   
+    <echo>distclean GDBM</echo>
+    <exec executable="make" os="${os.unix}" dir="${gdbm.home}" >
+      <arg value="distclean"/>
+    </exec>
+  </target> 
+
+  <target name="compile-gdbm" depends="init"  if="install.gdbm">   
+    <echo>compile GDBM</echo>
+    <exec executable="make" os="${os.unix}" dir="${gdbm.home}"/>
+    <exec executable="make" os="${os.unix}" dir="${gdbm.home}">
+      <arg value="install"/>
+    </exec>
+  </target> 
 
 </project>
Index: /greenstone3/branches/customizingGreenstone3/dist-resources/convert-build-xml-source.xsl
===================================================================
--- /greenstone3/branches/customizingGreenstone3/dist-resources/convert-build-xml-source.xsl	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/dist-resources/convert-build-xml-source.xsl	(revision 15191)
@@ -21,5 +21,5 @@
   <xsl:template match="target[starts-with(@name, 'rename-gs2build')]"></xsl:template>
   <xsl:template match="target[@name='test']"></xsl:template>
-  <xsl:template match="target[@name='get-macos-extra']"></xsl:template>
+  <xsl:template match="target[@name='get-macos-extra']"><target name="get-macos-extra"></target></xsl:template>
   <xsl:template match="target[@name='get-windows-binaries']"></xsl:template>
   
Index: /greenstone3/branches/customizingGreenstone3/dist-resources/convert-build-xml.xsl
===================================================================
--- /greenstone3/branches/customizingGreenstone3/dist-resources/convert-build-xml.xsl	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/dist-resources/convert-build-xml.xsl	(revision 15191)
@@ -24,5 +24,5 @@
   <xsl:template match="target[starts-with(@name, 'rename-gs2build')]"></xsl:template>
   <xsl:template match="target[@name='test']"></xsl:template>
-  <!--<xsl:template match="target[@name='get-macos-extra']"></xsl:template>-->
+  <xsl:template match="target[@name='get-macos-extra']"><target name="get-macos-extra"></target></xsl:template>
   <xsl:template match="target[@name='get-windows-binaries']"></xsl:template>
 
Index: /greenstone3/branches/customizingGreenstone3/docs/manual/manual.tex
===================================================================
--- /greenstone3/branches/customizingGreenstone3/docs/manual/manual.tex	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/docs/manual/manual.tex	(revision 15191)
@@ -2297,5 +2297,5 @@
 This will prompt you for the sitename (the site's directory name), and a unique URI for the site. It creates a new SOAPServer class for the site \\(\gst{\$GSDL3SRCHOME/src/java/org/greenstone/gsdl3/SOAPServer<sitename>.java}), creates a resource file for deployment (\gst{\$GSDL3SRCHOME/resources/soap/<sitename>.wsdd}), and then tries to deploy the service.
 
-Information about deployed services is maintained between Tomcat sessions---you only need to deploy something once. To undeploy a site, use \gst{ant undeploy-soap-site}.
+Information about deployed services is maintained between Tomcat sessions---you only need to deploy something once. To undeploy a site, use \gst{ant soap-undeploy-site}.
 
 The axis services can be accessed at \gst{localhost:8080/greenstone3/index.jsp}.
Index: /greenstone3/branches/customizingGreenstone3/gs3-server.bat
===================================================================
--- /greenstone3/branches/customizingGreenstone3/gs3-server.bat	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/gs3-server.bat	(revision 15191)
@@ -1,131 +1,25 @@
 @echo off
 
-set SERVERLANG=en
+echo Greenstone 3 Server
+echo Copyright (C) 2006, New Zealand Digital Library Project, University Of Waikato
+echo This software comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt
+echo This is free software, and you are welcome to redistribute it
 
-:: -------- Run the Greenstone 3 Server --------
-
-:: This script must be run from within the directory in which it lives
-if exist gs3-server.bat goto start
-    if "%SERVERLANG%" == "en" echo This script must be run from the directory in which it resides.
-    if "%SERVERLANG%" == "es" echo Este guiÂ¢n deberÂ  ejecutarse desde el directorio en el que reside.
-    if "%SERVERLANG%" == "fr" echo Ce script doit Ëtre exâcutâ âŠ partir du râpertoire dans lequel il se trouve.
-    if "%SERVERLANG%" == "ru" echo ÂÃ¢Â®Ã¢ Ã¡ÂªÃ ÂšÂ¯Ã¢ Â€Â®Â«ÂŠÂ¥Â­ Â¡Ã«Ã¢Ã¬ Â¢Â§Ã¯Ã¢ ÂšÂ§ Â€ÂšÃ Â¥ÂªÃ¢Â®Ã ÂšÂš, Â¢ ÂªÂ®Ã¢Â®Ã Â®Â© Â®Â­ Ã Â Ã¡Â¯Â®Â«Â®ÂŠÂ¥Â­
-    goto exit
-
-:start
-if "%OS%" == "Windows_NT" goto findGSDL
-    :: Invoke a new command processor to ensure there's enough environment space
-    if "%1" == "Second" goto findGSDL
-        command /E:2048 /C %0 Second %1 %2 %3 %4 %5 %6 %7 %8 %9
-        goto done
-
-:findGSDL
-echo.
-if "%SERVERLANG%" == "en" echo Greenstone3 Server
-if "%SERVERLANG%" == "en" echo Copyright (C) 2006, New Zealand Digital Library Project, University Of Waikato
-if "%SERVERLANG%" == "en" echo This program comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt
-if "%SERVERLANG%" == "en" echo This is free software, and you are welcome to redistribute it
-
-echo.
 ::  ---- Determine GSDL3HOME ----
+:: Some users may set the above line manually
 set GSDL3PATH=
 
-:: Some users may set the above line manually
- if not "%GSDL3PATH%" == "" goto prepGSDL
+:: The default location is the current directory
+ if "%GSDL3PATH%" == "" set GSDL3PATH=.
 
- :: The default location is the current directory
- set GSDL3PATH=.
+:: Setup Greenstone, unless it has already been done
+if "%GSDL3SRCHOME%" == "" call "%GSDL3PATH%\gs3-setup.bat" SetEnv > nul
 
- :: If it is set, use the GSDLHOME environment variable
-  if "%GSDL3SRCHOME%" == "" goto prepGSDL
-  set GSDL3PATH=%GSDL3SRCHOME%
-
-:prepGSDL
-:: Setup Greenstone, unless it has already been done
-if not "%GSDL3SRCHOME%" == "" goto doneGSDL
-   call "%GSDL3PATH%\gs3-setup.bat" SetEnv > nul
-
-:doneGSDL
-:: GSDL3PATH is no longer needed, since GSDL3SRCHOME should now be set
 set GSDL3PATH=
 
-:findJava
-:: ---- Check Java exists ----
-set JAVAPATH=
+"%RUNJAVA%" -cp "%CLASSPATH%" org.greenstone.server.Server "%GSDL3SRCHOME%"
 
-:: Some users may set the above line manually
-if not "%JAVAPATH%" == "" goto testJava
 
-:: If it is set, use the JAVA_HOME environment variable
- if not "%JAVA_HOME%" == "" goto javahome
 
-:: Check if Java is on the search path
- echo %PATH%| winutil\which.exe java.exe | winutil\setvar.exe JAVAPATH > setjava.bat
- call setjava.bat
- del setjava.bat
- if not "%JAVAPATH%" == "" goto testJava
-
-    :: Still haven't found anything, so try looking in the registry (gulp!)
-    type nul > jdk.reg
-    regedit /E jdk.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit"
-    type jdk.reg > jdk.txt
-    del jdk.reg
-    type nul > jre.reg
-    regedit /E jre.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment"
-    type jre.reg > jre.txt
-    del jre.reg
-
-    winutil\findjava.exe jdk.txt jre.txt | winutil\setvar.exe JAVAPATH > setjava.bat
-    del jdk.txt
-    del jre.txt
-    call setjava.bat
-    del setjava.bat
-
-   :: If nothing was found in the registry, we're stuck
-   if "%JAVAPATH%" == "" goto noJava
-
-   set JAVAPATH=%JAVAPATH%\bin
-   goto testJava
-
-:javahome
-    set JAVAPATH=%JAVA_HOME%\bin
-
-:testJava
-:: Check that a Java executable has been found
-  if "%SERVERLANG%" == "en" echo Checking Java: %JAVAPATH%
-  if "%SERVERLANG%" == "es" echo Revisando Java: %JAVAPATH%
-  if "%SERVERLANG%" == "fr" echo Vârification de Java: %JAVAPATH%
-  if "%SERVERLANG%" == "ru" echo ÂÃ Â®Â¢Â¥Ã ÂªÂ  Java: %JAVAPATH%
-  if exist "%JAVAPATH%\java.exe" goto checkServer
-
-:noJava
- echo.
-    if "%SERVERLANG%" == "en" echo Failed to locate an appropriate version of Java. You must install a
-    if "%SERVERLANG%" == "en" echo Java Runtime Environment (version 1.4 or greater) before running the
-    if "%SERVERLANG%" == "en" echo Greenstone3 Server.
-    goto exit
-
-:checkServer
-::---- Check that the server program has been compiled ----
-if exist "server.jar" goto runServer
-if "%SERVERLANG%" == "en" echo "You need to compile the code before running the server"
-goto exit
-
-:runServer
-echo Running the Greenstone Server
-:: -Xms32M          To set minimum memory
-:: -Xmx32M          To set maximum memory
-:: -verbose:gc      To set garbage collection messages
-:: -Xincgc          For incremental garbage collection
-:: -Xprof           Function call profiling
-:: -Xloggc:<file>   Write garbage collection log
-
-"%JAVAPATH%\java" -cp "%CLASSPATH%" org.greenstone.server.Server "%GSDL3SRCHOME%"
-
-:exit
-
-:done
-:: ---- Clean up ----
-set JAVAPATH=
 
  
Index: /greenstone3/branches/customizingGreenstone3/gs3-server.sh
===================================================================
--- /greenstone3/branches/customizingGreenstone3/gs3-server.sh	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/gs3-server.sh	(revision 15191)
@@ -2,10 +2,10 @@
 serverlang=en
 
-echo
+java_min_version=1.4.0_00
+
 echo "Greenstone 3 Server"
 echo "Copyright (C) 2006, New Zealand Digital Library Project, University Of Waikato"
 echo "This software comes with ABSOLUTELY NO WARRANTY; for details see LICENSE.txt"
 echo "This is free software, and you are welcome to redistribute it"
-echo
 
 ##  -------- Run the Greenstone 3 Server --------
@@ -14,16 +14,7 @@
 thisdir=`pwd`
 if [ ! -f "${thisdir}/gs3-server.sh" ]; then
-    if [ "$serverlang" == "es" ]; then
-        echo "Este guión deberá ejecutarse desde el directorio en el que reside."
-    elif [ "$serverlang" == "fr" ]; then
-	echo "Ce script doit être exécuté à partir du répertoire dans lequel il se trouve."
-    elif [ "$serverlang" == "ru" ]; then
-	echo "üÔÏÔ ÓËÒÉÐÔ ÄÏÌÖÅÎ ÂÙÔØ ×ÚÑÔ ÉÚ ÄÉÒÅËÔÏÒÉÉ, × ËÏÔÏÒÏÊ ÏÎ ÒÁÓÐÏÌÏÖÅÎ"
-    else
-	echo "This script must be run from the directory in which it resides."
-    fi
+    echo "This script must be run from the directory in which it resides."
     exit 1
 fi
-
 
 ##  ---- Determine GSDL3SRCHOME ----
@@ -31,77 +22,20 @@
 
 # Some users may set the above line manually
-if [ "x$gsdl3path" == "x" ]; then
-    # Check the environment variable first
-    if [ "x$GSDL3SRCHOME" != "x" ]; then
-	gsdl3path=$GSDL3SRCHOME
-    else
-	gsdl3path=`pwd`
-    fi
+if [ -z "$gsdl3path" ]; then
+   gsdl3path=`pwd`  
 fi
 
 # Setup Greenstone3, unless it has already been done
-if [ "x$GSDL3SRCHOME" == "x" ]; then
-    pushd $gsdl3path > /dev/null
-    source gs3-setup.sh
-    popd > /dev/null
-fi
-
-## ---- Check Java exists ----
-javapath=
-
-# Some users may set the above line manually
-if [ "x$javapath" = "x" ]; then
-
-    # If it is set, use the JAVA_HOME environment variable
-    if [ "x$JAVA_HOME" != "x" ]; then
-        javapath="$JAVA_HOME/bin/java"
-
-    # Check if Java is on the search path
-    else
-        javapath=`which java 2> /dev/null`
-    fi
-fi
-
-# Check that a Java executable has been found
-if [ "$glilang" = "es" ]; then
-    echo "Revisando Java: $javapath"
-elif [ "$glilang" = "fr" ]; then
-    echo "V<E9>rification de Java: $javapath"
-elif [ "$glilang" = "ru" ]; then
-    echo "<F0><D2><CF><D7><C5><D2><CB><C1> Java: $javapath"
-else
-    echo "Checking Java: $javapath"
-fi
-if [ ! -x "$javapath" ]; then
-    echo
-    echo "Failed to locate an appropriate version of Java. You must installa"
-    echo "Java Runtime Environment (version 1.4 or greater) before running the"
-    echo "Greenstone Server."
-exit 1
-fi
-
-## -- Check the version of Java is new enough (1.4.0 or higher) to run the Server -- do we need this?
-#`$javapath -classpath . CheckJavaVersion > /dev/null`
-#if [ $? -ne 2 ] ; then
-#   echo "The version of the Java Runtime Environment you have installed is too"
-#   echo "old to run the Greenstone Librarian Interface. Please install a new"
-#   echo "version of the JRE (version 1.4 or newer) and rerun this script."
-#exit 1
-#fi
-
-## ---- Check that the server has been compiled ----
-if [ ! -f server.jar ]; then
-  echo "You need to compile the server before running this script"
-  exit 1
+if [ -z "$GSDL3SRCHOME" ]; then 
+  pushd $gsdl3path > /dev/null
+  source gs3-setup.sh
+  popd > /dev/null
 fi
 
 
-# Other arguments you can provide to java 
-# -Xms<number>M    To set minimum memory (by default 32MB)
-# -Xmx<number>M    To set maximum memory (by default the nearest 2^n to the total remaining physical memory)
-# -verbose:gc      To set garbage collection messages
-# -Xincgc          For incremental garbage collection (significantly slows performance)
-# -Xprof           Function call profiling
-# -Xloggc:<file>   Write garbage collection log
+# JRE_HOME or JAVA_HOME must be set correctly to run this program
+search4j -m $java_min_version &> /dev/null
+if [ "$?" == "0" ]; then
+	`search4j -m $java_min_version -e` org.greenstone.server.Server $GSDL3SRCHOME 
+fi
 
-java -cp $CLASSPATH org.greenstone.server.Server $GSDL3SRCHOME 
Index: /greenstone3/branches/customizingGreenstone3/gs3-setup.bat
===================================================================
--- /greenstone3/branches/customizingGreenstone3/gs3-setup.bat	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/gs3-setup.bat	(revision 15191)
@@ -1,3 +1,5 @@
 @echo off
+
+set java_min_version=1.4.0_00
 
 if exist gs3-setup.bat goto start
@@ -7,10 +9,8 @@
 :start
 :: ---- Set the GSDL3HOME variable to the current directory ----
-cd | winutil\setvar.exe GSDL3SRCHOME > setgsdl3.bat
-call setgsdl3.bat
-del setgsdl3.bat
-echo GSDL3SRCHOME: %GSDL3SRCHOME%
+cd | winutil\setvar.exe GSDL3SRCHOME > %SystemRoot%\Temp\setgsdl3.bat
+call %SystemRoot%\Temp\setgsdl3.bat
+del %SystemRoot%\Temp\setgsdl3.bat
 set GSDL3HOME=%GSDL3SRCHOME%\web
-echo GSDL3HOME: %GSDL3HOME%
 
 :: change if using external tomcat
@@ -19,78 +19,32 @@
 :: ---- Set other important environment variables ----
 set GSDLOS=windows
-set PATH=%PATH%;%GSDL3SRCHOME%\bin;%GSDL3SRCHOME%\bin\script;%GSDL3SRCHOME%\lib\jni;
+set ANT_HOME=%GSDL3SRCHOME%\packages\ant
+set PATH=%PATH%;%GSDL3SRCHOME%\bin;%GSDL3SRCHOME%\bin\script;%GSDL3SRCHOME%\lib\jni;%ANT_HOME%\bin
 
 :: ---- Set the CLASSPATH environment variable ----
+if "%GS_CP_SET%" == "yes" goto skipSetCp
 set CLASSPATH=.;%GSDL3HOME%\WEB-INF\classes;%GSDL3SRCHOME%\resources\java;%CLASSPATH%
-if exist setcp.bat del setcp.bat
-for %%j in ("%GSDL3SRCHOME%"\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
-for %%j in ("%GSDL3HOME%"\WEB-INF\lib\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
-for %%j in ("%GSDL3SRCHOME%"\lib\jni\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
-for %%j in ("%TOMCAT_HOME%"\common\endorsed\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
-for %%j in ("%GSDL3SRCHOME%"\build\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> setcp.bat
+if exist %SystemRoot%\Temp\setcp.bat del %SystemRoot%\Temp\setcp.bat
+for %%j in ("%GSDL3SRCHOME%"\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+for %%j in ("%GSDL3HOME%"\WEB-INF\lib\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+for %%j in ("%GSDL3SRCHOME%"\lib\jni\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+for %%j in ("%TOMCAT_HOME%"\common\endorsed\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+for %%j in ("%GSDL3SRCHOME%"\build\*.jar) do echo set CLASSPATH=%%CLASSPATH%%;%%j>> %SystemRoot%\Temp\setcp.bat
+echo set GS_CP_SET=yes >> %SystemRoot%\Temp\setcp.bat
+call %SystemRoot%\Temp\setcp.bat
+del %SystemRoot%\Temp\setcp.bat
+:skipSetCp
 
-call setcp.bat
-del setcp.bat
+winutil\search4j.exe -m %java_min_version% | winutil\setvar.exe _JRE_HOME > %SystemRoot%\Temp\set_jre_home.bat
+call %SystemRoot%\Temp\set_jre_home.bat
+del %SystemRoot%\Temp\set_jre_home.bat
 
-echo CLASSPATH: %CLASSPATH%
+echo %_JRE_HOME%\bin\java.exe | winutil\setvar.exe RUNJAVA > %SystemRoot%\Temp\setrunjava.bat
+call %SystemRoot%\Temp\setrunjava.bat
+del %SystemRoot%\Temp\setrunjava.bat
 
-::cd %GSDL3HOME%
+if "%JRE_HOME%" == "" set JRE_HOME=%_JRE_HOME%
 
-:findJava
-:: ---- Check Java SDK exists ----
-set JAVAPATH=
-
-:: Some users may set the above line manually
-if not "%JAVAPATH%" == "" goto testJava
-   
-:: If it is set, use the JAVA_HOME environment variable
-    if not "%JAVA_HOME%" == "" goto javahome
-
-    :: Check if Java is on the search path
-    echo %PATH%| winutil\which.exe java.exe | winutil\setvar.exe JAVAPATH > setjava.bat
-    call setjava.bat
-    del setjava.bat
-    echo %JAVAPATH%
-    if not "%JAVAPATH%" == "" goto testJava
-
-    :: Still haven't found anything, so try looking in the registry (gulp!)
-    type nul > jdk.reg
-    regedit /E jdk.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit"
-    type jdk.reg > jdk.txt
-    del jdk.reg
-    type nul > jre.reg
-    regedit /E jre.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment"
-    type jre.reg > jre.txt
-    del jre.reg
-
-    winutil\findjava.exe jdk.txt jre.txt | winutil\setvar.exe JAVAPATH > setjava.bat
-    del jdk.txt
-    del jre.txt
-    call setjava.bat
-    del setjava.bat
-
-    :: If nothing was found in the registry, we're stuck
-    if "%JAVAPATH%" == "" goto noJava
-
-    set JAVAPATH=%JAVAPATH%\bin
-    goto testJava
-
-:javahome
-    set JAVAPATH=%JAVA_HOME%\bin
-
-:testJava
-if exist "%JAVAPATH%\java.exe" goto  exit
-
-
-:noJava
-    echo.
-    echo Failed to locate an appropriate version of Java. You must install a
-    echo Java Development Kit (version 1.4 or greater) before running the
-    echo Greenstone 3 Digital Library Software.
-    pause
-    goto exit
-
-:exit
-
-
-
+echo GSDL3SRCHOME : %GSDL3SRCHOME%
+echo GSDL3HOME    : %GSDL3HOME%
+echo JAVA         : %RUNJAVA%
Index: /greenstone3/branches/customizingGreenstone3/gs3-setup.sh
===================================================================
--- /greenstone3/branches/customizingGreenstone3/gs3-setup.sh	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/gs3-setup.sh	(revision 15191)
@@ -2,131 +2,169 @@
 # this should work under ash, bash, zsh, ksh, sh style shells.
 
-# make sure we are sourced, and not run
+#the purpose of this file is to check/set up the environment for greenstone3
+#sorts out
+#	- gsdl3home
+#	- java
 
-if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then
-# if $0 contains "gs3-setup.sh" we've been run... $0 is shellname if sourced.
-# One exception is zsh has an option to set it temporarily to the script name
-  if test -z "$ZSH_NAME" ; then
-  # we aren't using zsh
-  gsdl_not_sourced=true
-  fi
-fi
-
-if test -n "$gsdl_not_sourced" ; then
-  echo "	Error: Make sure you source this script, not execute it. Eg:"
-  echo "		$ source gs3-setup.sh"
-  echo "	or"
-  echo "		$ . ./gs3-setup.sh"
-  echo "	not"
-  echo "		$ ./gs3-setup.sh"
-  unset gsdl_not_sourced
-  exit 1
-fi
-
-if test ! -f gs3-setup.sh ; then
-  echo "You must source the script from within the Greenstone home directory"
-  exit 1
-fi
-
-GSDL3SRCHOME=`pwd`
-GSDL3HOME=$GSDL3SRCHOME/web
-export GSDL3HOME
-export GSDL3SRCHOME
-GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-# check for running bash under cygwin
-if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
-    GSDLOS=windows
-fi
-export GSDLOS
-
-#change this if external tomcat
-TOMCAT_HOME=$GSDL3SRCHOME/packages/tomcat
-
-PATH=$GSDL3SRCHOME/bin/script:$GSDL3SRCHOME/bin:$PATH
-export PATH
-MANPATH=$MANPATH:$GSDL3SRCHOME/doc/man
-export MANPATH
-
-CLASSPATH=$GSDL3HOME/WEB-INF/classes:$GSDL3SRCHOME/resources/java:$CLASSPATH
-for JARFILE in $GSDL3SRCHOME/*.jar; do
-    CLASSPATH=$CLASSPATH:$JARFILE
-done
-for JARFILE in $GSDL3SRCHOME/lib/jni/*.jar; do
-    CLASSPATH=$CLASSPATH:$JARFILE
-done
-for JARFILE in $GSDL3HOME/WEB-INF/lib/*.jar; do
-    CLASSPATH=$CLASSPATH:$JARFILE
-done
-for JARFILE in $TOMCAT_HOME/common/endorsed/*.jar; do
-    CLASSPATH=$CLASSPATH:$JARFILE
-done    
-for JARFILE in $GSDL3SRCHOME/build/*.jar; do
-    CLASSPATH=$CLASSPATH:$JARFILE
-done
-
-export CLASSPATH
-
-LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
-export LD_LIBRARY_PATH
-## for mac
-DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
-export DYLD_LIBRARY_PATH
+java_min_version=1.5.0_00
 
 
-# see if we can find java
-java="java"
-jfound=1
-jok=1
-# if JAVAHOME or JAVA_HOME is set we'll use it to determine where java lives, otherwise
-#  we just hope it's on the search path
-if [ "$JAVA_HOME" != "" ] ; then
-    java="$JAVA_HOME/bin/java"
-elif [ "$JAVAHOME" != "" ] ; then
-    java="$JAVAHOME/bin/java"
-    export JAVA_HOME=$JAVAHOME
-else
-    java=`which java 2> /dev/null`
-    if [ ! -x "$java" ]; then
-	echo "Failed to locate Java. You must install a java runtime environment"
-	echo "(version 1.4 or greater) before installing Greenstone 3."
-	jfound=0
-	jok=0
-    else
-	export JAVA_HOME=`echo $java | sed -n 's/[\\\/]bin[\\\/]java$//p'`
-    fi
-fi
-if [ $jfound -eq 1 ]; then
-    javaversion=`$java -version 2>&1 | sed -n 's/^java version \"\(.*\)\"/\1/p'`
-    jvmajor=`echo $javaversion | sed -n 's/^\([0-9]*\).*$/\1/p'`
-    jvminor=`echo $javaversion | sed -n 's/^[0-9]*\.\([0-9]*\).*$/\1/p'`
-    
-    if [ $jvmajor -lt 1 ] ; then
-	jok=0
-    fi
-    if [ $jvmajor -eq 1 ] && [ $jvminor -lt 4 ] ; then
-	jok=0
-    fi
-fi
+function testSource(){
 
-if [ $jfound -eq 1 ] && [ $jok -eq 0 ] ; then
-    echo "The version of the java runtime environment you have installed is too"
-    echo "old to run Greenstone 3. Please install a new version of the JRE (version"
-    echo "1.4 or newer) and rerun this installation."
-else
-    echo "Your environment has successfully been set up to run Greenstone3"
-fi
+  if test "$0" != "`echo $0 | sed s/gs3-setup\.sh//`" ; then
+  # if $0 contains "gs3-setup.sh" we've been run... $0 is shellname if sourced.
+  # One exception is zsh has an option to set it temporarily to the script name
+    if test -z "$ZSH_NAME" ; then
+    # we aren't using zsh
+     gsdl_not_sourced=true
+   fi 
+  fi
 
-#do we need to check for perl???
-# make sure perl is ok
-#perl=`which perl 2> /dev/null`
-# echo "perl: $perl"
-#if [ ! -x "$perl" ] ; then
-#    echo "Greenstone 3 requires perl in order to operate but this installation"
-#    echo "could not detect perl on your system. Please ensure that perl is installed"
-#    echo "and is on your search path then rerun this installation script."
-#    exit 1
-#fi
+  if test -n "$gsdl_not_sourced" ; then
+     echo "	Error: Make sure you source this script, not execute it. Eg:"
+     echo "		$ source gs3-setup.sh"
+     echo "	or"
+     echo "		$ . gs3-setup.sh"
+     echo "	not"
+     echo "		$ ./gs3-setup.sh"
+     unset gsdl_not_sourced
+     exit 1
+  fi
+
+  if test ! -f gs3-setup.sh ; then
+    echo "You must source the script from within the Greenstone home directory"
+    exit 1
+  fi
+
+}
+
+function setGS3ENV() {
+
+	echo "Setting up your environment for Greenstone3"
+	## main greenstone environment variables ##
+	GSDL3SRCHOME=`pwd`
+	GSDL3HOME=$GSDL3SRCHOME/web
+	export GSDL3HOME
+	export GSDL3SRCHOME
+
+	GSDLOS=`uname -s | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	# check for running bash under cygwin
+	if test "`echo $GSDLOS | sed 's/cygwin//'`" != "$GSDLOS" ; then
+		GSDLOS=windows
+	fi 
+	export GSDLOS
+	echo "  - Exported GSDL3HOME, GSDL3SRCHOME and GSDLOS"
+
+	#change this if external tomcat
+	TOMCAT_HOME=$GSDL3SRCHOME/packages/tomcat
 
 
+	## adjustments to users (existing) environment ##
 
+	#PATH
+	if [ `isinpath "$PATH" "$GSDL3SRCHOME/bin"` == "false" ]; then
+		PATH=$GSDL3SRCHOME/bin/script:$GSDL3SRCHOME/bin:$PATH
+		export PATH
+		MANPATH=$MANPATH:$GSDL3SRCHOME/doc/man
+		export MANPATH
+		echo "  - Adjusted PATH"
+	else
+		echo "  - PATH already correct"
+	fi
 
+	#CLASSPATH
+	if [ `isinpath "$CLASSPATH" "$GSDL3HOME/WEB-INF/classes"` == "false" ]; then
+		CLASSPATH=$GSDL3HOME/WEB-INF/classes:$GSDL3SRCHOME/resources/java:$CLASSPATH
+		for JARFILE in $GSDL3SRCHOME/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done
+		for JARFILE in $GSDL3SRCHOME/lib/jni/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done
+		for JARFILE in $GSDL3HOME/WEB-INF/lib/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done
+		for JARFILE in $TOMCAT_HOME/common/endorsed/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done    
+		for JARFILE in $GSDL3SRCHOME/build/*.jar; do
+			CLASSPATH=$CLASSPATH:$JARFILE
+		done
+		export CLASSPATH
+		echo "  - Adjusted CLASSPATH"
+	else
+		echo "  - CLASSPATH already correct"
+	fi
+
+	#LD_LIBRARY_PATH
+	if [ `isinpath "$LD_LIBRARY_PATH" "$GSDL3SRCHOME/lib/jni"` == "false" ]; then
+		LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
+		export LD_LIBRARY_PATH
+		DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GSDL3SRCHOME/lib/jni
+		export DYLD_LIBRARY_PATH
+		echo "  - Adjusted LD_LIBRARY_PATH"
+	else
+		echo "  - LD_LIBRARY_PATH already correct"
+	fi
+
+	#ant
+	which ant &> /dev/null
+	if [ "$?" != "0" ]; then
+			ANT_HOME=$GSDL3SRCHOME/packages/ant
+			PATH=$ANT_HOME/bin:$PATH
+		echo "  - Setup ant"
+	else
+		echo "  - Ant already setup"
+	fi
+
+	echo
+}
+
+function checkJava() {
+	echo "Checking Java"
+
+  bin/search4j -m $java_min_version &> /dev/null
+  if [ "$?" != "0" ]; then
+
+		#java is not set up already
+	  bin/search4j -m $java_min_version -h packages/jre &> /dev/null
+	  if [ "$?" == "0" ]; then
+			#bundled java exists, set up
+			export JAVA_HOME=`pwd`/packages/jre
+  		echo "  - Exported JAVA_HOME to point to bundled java"
+		else
+			#no java exists
+	  	echo "  - Failed to locate java ($java_min_version or greater)"
+			bin/search4j &> /dev/null; if [ "$?" == "0" ]; then echo "  (It looks like you hava java but it's too old)"; fi
+			echo "  - Please set JAVA_HOME or JRE_HOME to point to an appropriate java"
+  		echo "    And add JAVA_HOME/bin or JRE_HOME/bin to your PATH"
+		fi
+
+	else
+
+		#java is already set up
+		echo "  - Found java at: `bin/search4j -m $java_min_version`"
+
+  fi
+	echo
+}
+
+function pauseAndExit(){
+ echo -n "Please press any key to continue... "
+ read 
+}
+
+function isinpath() {
+	for file in `echo $1 | sed 's/:/ /g'`; do
+		if [ "$file" == "$2" ]; then
+			echo true
+			return
+		fi
+	done
+	echo false
+}
+
+echo
+testSource
+setGS3ENV
+checkJava
Index: /greenstone3/branches/customizingGreenstone3/resources/java/global.properties.in
===================================================================
--- /greenstone3/branches/customizingGreenstone3/resources/java/global.properties.in	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/resources/java/global.properties.in	(revision 15191)
@@ -1,5 +1,5 @@
 ## greenstone home
 gsdl3.home=@gsdl3home@
-gsdl3.version=@gsdl3version@
+gsdl3.version=S20080214
 
 # tomcat info
Index: /greenstone3/branches/customizingGreenstone3/resources/tomcat/setclasspath.bat
===================================================================
--- /greenstone3/branches/customizingGreenstone3/resources/tomcat/setclasspath.bat	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/resources/tomcat/setclasspath.bat	(revision 15191)
@@ -6,14 +6,26 @@
 
 rem Make sure prerequisite environment variables are set
-if not "%JAVA_HOME%" == "" goto gotJavaHome
-echo The JAVA_HOME environment variable is not defined
-echo This environment variable is needed to run this program
+if not "%JAVA_HOME%" == "" goto gotJdkHome
+if not "%JRE_HOME%" == "" goto gotJreHome
+echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
+echo At least one of these environment variable is needed to run this program
 goto exit
-:gotJavaHome
+
+:gotJreHome
+if not exist "%JRE_HOME%\bin\java.exe" goto noJavaHome
+if not exist "%JRE_HOME%\bin\javaw.exe" goto noJavaHome
+if not ""%1"" == ""debug"" goto okJavaHome
+echo JAVA_HOME should point to a JDK in order to run in debug mode.
+goto exit
+
+:gotJdkHome
 if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
 if not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHome
 if not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHome
 if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
+if not "%JRE_HOME%" == "" goto okJavaHome
+set JRE_HOME=%JAVA_HOME%
 goto okJavaHome
+
 :noJavaHome
 echo The JAVA_HOME environment variable is not defined correctly
@@ -45,6 +57,6 @@
 rem Note that NT requires a window name argument when using start.
 rem Also note the quoting as JAVA_HOME may contain spaces.
-set _RUNJAVA="%JAVA_HOME%\bin\java"
-set _RUNJAVAW="%JAVA_HOME%\bin\javaw"
+set _RUNJAVA="%JRE_HOME%\bin\java"
+set _RUNJAVAW="%JRE_HOME%\bin\javaw"
 set _RUNJDB="%JAVA_HOME%\bin\jdb"
 set _RUNJAVAC="%JAVA_HOME%\bin\javac"
Index: /greenstone3/branches/customizingGreenstone3/resources/tomcat/setclasspath.sh
===================================================================
--- /greenstone3/branches/customizingGreenstone3/resources/tomcat/setclasspath.sh	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/resources/tomcat/setclasspath.sh	(revision 15191)
@@ -7,12 +7,16 @@
 
 # First clear out the user classpath
-# gs3 - we need to set classpath
 CLASSPATH=$CLASSPATH
 
 # Make sure prerequisite environment variables are set
 if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
-  echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
-  echo "At least one of these environment variable is needed to run this program"
-  exit 1
+  # Bugzilla 37284
+  if $darwin && [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home" ]; then
+    export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home"
+  else
+    echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
+    echo "At least one of these environment variable is needed to run this program"
+    exit 1
+  fi
 fi
 if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/action/QueryAction.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/action/QueryAction.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/action/QueryAction.java	(revision 15191)
@@ -107,4 +107,6 @@
 	mr_query_message.appendChild(format_request);
 
+	logger.info(GSXML.xmlNodeToString(mr_query_message));
+
 	// do the query
        	Element mr_query_response = (Element)this.mr.process(mr_query_message);
@@ -207,10 +209,11 @@
 	// check the hits_per_page param - is it a service param??
 	String hits_pp = (String) service_params.get("hitsPerPage");
-	if (hits_pp != null) {
-	    // the service is doing the paging, so we want to display all of the returned docs
-	    return (Element)this.doc.importNode(orig_doc_list, true);
-	}
-	
-	hits_pp = (String)params.get("hitsPerPage");
+	if (hits_pp == null) {
+	    // the service is doing the paging, so we want to display all of the returned docs(???)
+	//    return (Element)this.doc.importNode(orig_doc_list, true);
+	// try hitsPerPage in the globle param
+	     hits_pp = (String)params.get("hitsPerPage");
+        }
+	
 	int hits = 20;
 	if (hits_pp != null && !hits_pp.equals("")) {
@@ -235,5 +238,10 @@
 	// now we need our own doc list
 	Element result_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
-	String start_p = (String)params.get("startPage");
+	
+	String start_p = (String) service_params.get("startPage");
+	if(start_p == null){
+	    start_p = (String)params.get("startPage");
+	}
+
 	int start = 1;
 	if (start_p != null && !start_p.equals("")) {
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java	(revision 15191)
@@ -61,7 +61,7 @@
  * @see Communicator
  *
-  * Since some service classes are moved into a separate directory in order for them to be checked out from a different repository,
+ * Since some service classes are moved into a separate directory in order for them to be checked out from a different repository,
  * we modify the configureServices method to search some of the classes in other place if they are not found in the service directory.
-*/
+ */
 public class MessageRouter implements  ModuleInterface {
   
@@ -75,4 +75,5 @@
   protected String site_http_address=null;
   
+  
   protected String library_name = null;
 
@@ -91,5 +92,8 @@
   /** list of collections that can be reached */
   protected Element collection_list = null;
-  
+  /** list of collections that are loaded but are private */
+  protected Element private_collection_list = null;
+    
+       
   /** list of collections that are public and OAI-supportive */
   protected Element oai_collection_list = null;
@@ -117,10 +121,5 @@
   
   public void cleanUp() {
-    if (this.module_map != null) {
-      Iterator i = this.module_map.values().iterator();
-      while (i.hasNext()) {
-        ((ModuleInterface)i.next()).cleanUp();
-      }
-    }
+    cleanUpModuleMapEntire();
   }
   
@@ -133,5 +132,5 @@
   }
   
- /** site_name must be set before configure is called */
+  /** library_name must be set before configure is called */
   public void setLibraryName(String library_name) {
     this.library_name = library_name;
@@ -150,5 +149,5 @@
   public boolean configure() {
     
-    logger.info("configuring site");
+    logger.info("configuring the Message Router");
     
     if (this.site_name==null) {
@@ -175,8 +174,8 @@
           // set up the authenticator
           Authenticator.setDefault(new Authenticator(){
-            protected PasswordAuthentication getPasswordAuthentication(){
-              return new PasswordAuthentication(user, new String(passwd).toCharArray());
-            }
-          });
+	      protected PasswordAuthentication getPasswordAuthentication(){
+		return new PasswordAuthentication(user, new String(passwd).toCharArray());
+	      }
+	    });
           
         } catch (Exception e) {
@@ -187,40 +186,9 @@
     }
     
-    // read thru own config file - create services and connect to sites
-    File configFile = new File(GSFile.siteConfigFile(this.site_home));
-    
-    if (!configFile.exists() ) {
-      logger.error(" site config file: "+configFile.getPath()+" not found!");
-      return false;
-    }
-    
-    Document config_doc = this.converter.getDOM(configFile);
-    if (config_doc == null) {
-      logger.error(" couldn't parse site config file: "+configFile.getPath());
-      return false;
-    }
-    
-    config_info = config_doc.getDocumentElement();
-    
     this.module_map = new HashMap();
     
-    // load up the services: serviceRackList
-    Element service_rack_list = (Element)GSXML.getChildByTagName(config_info, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
-    configureServices(service_rack_list);
-    
-    // load up the service clusters
-    Element cluster_list = (Element)GSXML.getChildByTagName(config_info, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
-    configureClusters(cluster_list);
-    
-    // load up the collections
-    configureCollections();
-    
-    // load up the external sites - this also adds their services/clusters/collections to the other lists - so must be done last
-    Element site_list = (Element)GSXML.getChildByTagName(config_info, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
-    configureSites(site_list);
-    
-    
-    return true;
-    
+    // This stuff may be done at a reconfigure also
+    return configureLocalSite();
+  
   }
   
@@ -250,6 +218,4 @@
   public Element process(Element message) {
     
-    logger.debug("MR received request");
-    //logger.info(this.converter.getString(message));
     // check that its a correct message tag
     if (!message.getTagName().equals(GSXML.MESSAGE_ELEM)) {
@@ -288,9 +254,4 @@
           // its a messaging request - modifies the requests/responses
           result = modifyMessages(req, message, mainResult);
-        } else if (type_att.equals(OAIXML.OAI_SET_LIST)) {
-            logger.info("oaiSetList request received");
-            //this is the oai receptionist asking for a list of oai-support collections
-            result = this.doc.createElement(GSXML.RESPONSE_ELEM);
-            result.appendChild(oai_collection_list);//getCollectionList();
         } else {
           // standard request
@@ -300,4 +261,7 @@
         mainResult.appendChild(this.doc.importNode(result, true));
       } else {
+	// The message needs to go to another module. The same message can 
+	// be passed to multiple modules  - they will be in a comma 
+	// separated list in the 'to' attribute
         String [] modules = path.split(",");
         
@@ -315,5 +279,4 @@
           if (this.module_map.containsKey(obj)) {
             copied_request.setAttribute(GSXML.TO_ATT, this_mod);
-//            logger.info("::::::::::::::: \n"+this.converter.getString(req));
             result = ((ModuleInterface)this.module_map.get(obj)).process(mess);
             if (result !=null ) {
@@ -345,13 +308,114 @@
     return mainResult;    
   }
-  
+  public Element getCollectionList() {
+	    return collection_list;
+  }
   // ********************************************************************
-  // auxiliary configure methods
+  // auxiliary configure and cleanup methods
   // *******************************************************************
   
-  
+  /** Calls clean up on all modules referenced in the module_map and 
+      removes them . */
+  protected void cleanUpModuleMapEntire() {
+    if (this.module_map != null) {
+      Iterator i = this.module_map.values().iterator();
+      while (i.hasNext()) {
+        ((ModuleInterface)i.next()).cleanUp();
+	i.remove();
+      }
+    }
+  }
+
+  /**
+     Goes through the children of list, and for each local/site-specific
+     name attribute, calls cleanUp on the module and removes it from the 
+     module_map and removes it from the list
+  */
+  protected void cleanUpModuleMapSubset(Element list, String remote_site) {
+    logger.error(this.converter.getString(list));
+    NodeList elements = list.getChildNodes(); // we are assuming no extraneous nodes
+    for(int i=elements.getLength()-1; i>=0; i--) {
+      Element item = (Element)elements.item(i);
+      String name = item.getAttribute(GSXML.NAME_ATT);
+      String potential_site_name = GSPath.getFirstLink(name);
+      if (remote_site != null) {
+	if (remote_site.equals(potential_site_name)) {
+	  list.removeChild(item);
+	}
+      } else {
+	if (name.equals(potential_site_name)) {// there was no site
+	  list.removeChild(item);
+	  ModuleInterface m = (ModuleInterface)this.module_map.remove(name);
+	  m.cleanUp(); // clean up any open files/connections etc 
+	  m=null;
+	}
+      }
+    }
+		    
+    logger.error(this.converter.getString(list));	    
+	    
+  }
+
+  /** removes all site modules from module_map, and any stored info about this sites collections and services */
+  protected void cleanUpAllExternalSiteInfo() {
+
+    NodeList site_nodes = this.site_list.getChildNodes();
+    for(int i=site_nodes.getLength()-1; i>=0; i--) {
+      Element item = (Element)site_nodes.item(i);
+      String name = item.getAttribute(GSXML.NAME_ATT);
+      // will remove the node from site_list
+      deactivateModule(GSXML.SITE_ELEM, name);	    
+    }
+	
+  }
+  /** read thru own site config file - create services and connect to sites
+   */
+  protected boolean configureLocalSite() {
+	
+    // this may be a reconfigure, so clean up the old moduleMap
+    cleanUpModuleMapEntire();
+
+    File configFile = new File(GSFile.siteConfigFile(this.site_home));
+    
+    if (!configFile.exists() ) {
+      logger.error(" site config file: "+configFile.getPath()+" not found!");
+      return false;
+    }
+    
+    Document config_doc = this.converter.getDOM(configFile);
+    if (config_doc == null) {
+      logger.error(" couldn't parse site config file: "+configFile.getPath());
+      return false;
+    }
+    
+    this.config_info = config_doc.getDocumentElement();
+    
+    // load up the services: serviceRackList
+    this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
+    Element service_rack_list_elem = (Element)GSXML.getChildByTagName(config_info, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
+    configureServices(service_rack_list_elem);
+    
+    // load up the service clusters
+    this.cluster_list = this.doc.createElement(GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
+    Element cluster_list_elem = (Element)GSXML.getChildByTagName(config_info, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
+    configureClusters(cluster_list_elem);
+    
+    // load up the collections
+    this.collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER);
+    this.private_collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER);
+    this.oai_collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER);
+    configureCollections();
+    
+    // load up the external sites - this also adds their services/clusters/collections to the other lists - so must be done last
+    this.site_list = this.doc.createElement(GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
+    Element site_list_elem = (Element)GSXML.getChildByTagName(config_info, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
+    configureExternalSites(site_list_elem);
+        
+    return true;
+    
+  }
+
   protected boolean configureServices(Element service_rack_list) {
     
-    this.service_list = this.doc.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
     
     // load up the individual services
@@ -380,18 +444,17 @@
       Class service_class = null;
       try {
-    	  service_class = Class.forName("org.greenstone.gsdl3.service."+service_name);
+	service_class = Class.forName("org.greenstone.gsdl3.service."+service_name);
       } catch(ClassNotFoundException e) {
     	  
-    	  try {
-    		  //try the service_name alone in case the package name is already specified
-    		  service_class = Class.forName(service_name);
+	try {
+	  //try the service_name alone in case the package name is already specified
+	  service_class = Class.forName(service_name);
     		  
-    	  }catch(ClassNotFoundException ae) {
-    		  logger.info(ae.getMessage());
-    	  }
+	}catch(ClassNotFoundException ae) {
+	  logger.info(ae.getMessage());
+	}
       }
       try {
     	  
-        //ServiceRack s = (ServiceRack)Class.forName("org.greenstone.gsdl3.service."+service_name).newInstance();
     	ServiceRack s = (ServiceRack)service_class.newInstance();
 	s.setSiteHome(this.site_home);
@@ -400,5 +463,8 @@
         s.setMessageRouter(this);
         // pass the XML node to the service for service configuration
-        s.configure(n, null);
+        if (!s.configure(n, null)) {
+	  logger.error ("couldn't configure ServiceRack "+service_name);
+	  continue;
+	}
         
         // find out the supported services for this service module
@@ -426,5 +492,4 @@
   protected boolean configureClusters(Element config_cluster_list) {
     
-    this.cluster_list = this.doc.createElement(GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
     // load up the service clusters
     logger.info("loading service clusters ...");
@@ -448,5 +513,9 @@
       sc.setClusterName(name);
       sc.setMessageRouter(this);
-      sc.configure(cluster);
+      if (!sc.configure(cluster)) {
+	logger.error ("couldn't configure ServiceCluster "+name);
+	continue;
+      }
+
       this.module_map.put(name, sc); // this replaces the old one if there was one already present
       //add short info to cluster list
@@ -459,8 +528,6 @@
   }
   
+  /** looks through the collect directory and activates any collections it finds. If this is a reconfigure, clean up must be done first before calling this */
   protected boolean configureCollections() {
-    
-    this.collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER);
-    this.oai_collection_list = this.doc.createElement(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER);
     
     // read thru the collect directory and activate all the valid collections
@@ -482,7 +549,79 @@
   }
   
-  protected boolean configureSites(Element config_site_list) {
-    
-    this.site_list = this.doc.createElement(GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
+  /** creates and configures a new collection
+      if this is done for a reconfigure, the collection should be deactivated first.
+      *
+      *@param col_name the name of the collection
+      *@return true if collection created ok
+      */
+  protected boolean activateCollectionByName(String col_name) {
+    
+    logger.info("Activating collection: "+col_name+".");
+    
+    // Look for the etc/collectionInit.xml file, and see what sort of Collection to load
+    Collection c = null;
+    File init_file = new File(GSFile.collectionInitFile(this.site_home, col_name));
+    
+    if (init_file.exists()) {
+      Document init_doc = this.converter.getDOM(init_file);
+      if (init_doc != null) {
+        Element init_elem = init_doc.getDocumentElement();
+        if (init_elem != null) {
+          String coll_class_name = init_elem.getAttribute("class");
+          if (!coll_class_name.equals("")) {
+            try {
+              c = (Collection)Class.forName("org.greenstone.gsdl3.collection."+coll_class_name).newInstance();
+            } catch (Exception e) {
+              logger.info(" couldn't create a new collection, type "+coll_class_name+", defaulting to class Collection");
+            }
+          }
+        }
+      }
+    }
+    if (c==null) { // we haven't found another classname to use
+      c = new Collection();
+    }
+    
+    c.setCollectionName(col_name);
+    c.setSiteHome(this.site_home);
+    c.setSiteAddress(this.site_http_address);
+    c.setMessageRouter(this);
+    if (c.configure()) {
+      logger.info("have just configured collection " + col_name);
+      // add to list of collections
+      this.module_map.put(col_name, c);
+      Element e = this.doc.createElement(GSXML.COLLECTION_ELEM);
+      e.setAttribute(GSXML.NAME_ATT, col_name);
+      
+      if(c.isPublic()) {
+        // only public collections will appear on the home page
+        // add short description_ to collection_list_
+	this.collection_list.appendChild(e);
+	
+        if (c.hasOAI()) {
+          Element ane = this.doc.createElement(GSXML.COLLECTION_ELEM);
+          //The collection name is returned as site_name:coll_name, which is in fact the set specification
+          ane.setAttribute(GSXML.NAME_ATT, site_name + ":" + col_name);
+          ane.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
+          
+          this.oai_collection_list.appendChild(ane);
+          //logger.info(GSXML.xmlNodeToString(oai_collection_list));
+        }      
+        
+      } else {
+	this.private_collection_list.appendChild(e);
+      }
+      return true;
+    } else {
+      logger.error("Couldn't configure collection: "+
+		   col_name+".");
+      return false;
+    }
+  }
+  
+
+  /** Goes through the siteList and activates each site found. If this is done for a reconfigure, a clean up must be done first ****HOW??? */
+  protected boolean configureExternalSites(Element config_site_list) {
+    
     // load up the sites
     logger.info("loading external sites...");
@@ -511,9 +650,47 @@
   }
   
+  protected boolean activateSiteByName(String site_name) {
+    logger.info("Activating site: "+site_name+".");
+    
+    File configFile = new File(GSFile.siteConfigFile(this.site_home));
+    
+    if (!configFile.exists() ) {
+      logger.error(" site config file: "+configFile.getPath()+" not found!");
+      return false;
+    }
+    Document config_doc = this.converter.getDOM(configFile);
+    if (config_doc == null) {
+      logger.error(" couldn't parse site config file: "+configFile.getPath());
+      return false;
+    }
+    Element config_elem = config_doc.getDocumentElement();
+    
+    Element config_site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
+    if (config_site_list ==null ) {
+      logger.error("activateSite, no sites found");
+      return false;
+    }
+    // this is a name to identify the current site in the Communicator
+    String local_site_name = config_site_list.getAttribute("localSiteName");
+    if (local_site_name.equals("")) {
+      local_site_name = site_name;
+    }
+    
+    Element this_site_elem = GSXML.getNamedElement(config_site_list, GSXML.SITE_ELEM, GSXML.NAME_ATT, site_name);
+    if (this_site_elem == null) {
+      logger.error("activateSite, site "+site_name+" not found");
+      return false;
+    }
+    
+    return activateSite(this_site_elem, local_site_name);
+  }
+
   protected boolean activateSite(Element site_elem, String local_site_name) {
+    
     Communicator comm=null;
     String type = site_elem.getAttribute(GSXML.TYPE_ATT);
     String name = site_elem.getAttribute(GSXML.NAME_ATT);
     if (type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) {
+      logger.info("activating SOAP site "+name);
       comm = new SOAPCommunicator();
       if (comm.configure(site_elem)) {
@@ -527,8 +704,8 @@
         // have to be added later
         if (!getRemoteSiteInfo(comm, name)) {
-          logger.error(" couldn't get info from site "+name);
+          logger.error(" couldn't get info from site");
         }
       } else {
-        logger.error(" couldn't configure soap site:"+name);
+        logger.error(" couldn't configure site");
         return false;
       }
@@ -599,4 +776,77 @@
   
   
+  
+  protected boolean activateServiceClusterByName(String cluster_name) {
+    return false;
+    
+  }
+  
+  protected boolean activateServiceRackByName(String module_name) {
+    return false;
+  }
+  
+  protected boolean deactivateModule(String type, String name) {
+    
+    logger.info("deactivating "+ type+"  module: "+name);
+    if (this.module_map.containsKey(name)) {
+      
+      logger.info("found the module");
+      ModuleInterface m = (ModuleInterface)this.module_map.remove(name);
+      // also remove the xml bit from description list
+      if (type.equals(GSXML.COLLECTION_ELEM)) {
+	if (((Collection)m).isPublic()) { 
+	  Element this_col = GSXML.getNamedElement(this.collection_list, GSXML.COLLECTION_ELEM, GSXML.NAME_ATT, name);
+	  if (this_col != null) {
+	    this.collection_list.removeChild(this_col);
+	  }
+	  if (((Collection)m).hasOAI()) {
+	    this_col = GSXML.getNamedElement(this.oai_collection_list, GSXML.COLLECTION_ELEM, GSXML.NAME_ATT, name);
+	    if (this_col != null) {
+	      this.oai_collection_list.removeChild(this_col);
+	    }
+	  }
+	} else {
+	  // a private collection
+	  Element this_col = GSXML.getNamedElement(this.private_collection_list, GSXML.COLLECTION_ELEM, GSXML.NAME_ATT, name);
+	  if (this_col != null) {
+	    this.private_collection_list.removeChild(this_col);
+	  } 
+	}
+      } else if (type.equals(GSXML.SERVICE_ELEM)) {
+        Element this_service = GSXML.getNamedElement(this.service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, name);
+        if (this_service != null) {
+          this.service_list.removeChild(this_service);
+        }
+      } else if (type.equals(GSXML.CLUSTER_ELEM)) {
+        Element this_cluster = GSXML.getNamedElement(this.cluster_list, GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, name);
+        if (this_cluster != null) {
+          this.cluster_list.removeChild(this_cluster);
+        }
+      } else if (type.equals(GSXML.SITE_ELEM)) {
+        Element this_site = GSXML.getNamedElement(this.site_list, GSXML.SITE_ELEM, GSXML.NAME_ATT, name);
+        if (this_site != null) {
+          this.site_list.removeChild(this_site);
+         
+          // also remove this sites colls, services, clusters etc
+          cleanUpModuleMapSubset(this.collection_list, name);
+          cleanUpModuleMapSubset(this.cluster_list, name);
+          cleanUpModuleMapSubset(this.service_list, name);
+	  
+	  // can remote collections be in the oai_coll list, or private coll list ??
+        }
+      } else {
+        logger.error("invalid module type: "+type+", can't remove info about this module");
+      }	
+      
+      m.cleanUp(); // clean up any open files/connections etc - can cause trouble on windows
+      m=null;
+      return true;
+    }
+    // else not deactivated
+    logger.error(name+" module not found");
+    return false;
+    
+  }
+   
   //*****************************************************************
   // auxiliary process methods
@@ -650,5 +900,14 @@
       
     }
-    
+        
+    if (type.equals(OAIXML.OAI_SET_LIST)) {
+      logger.info("oaiSetList request received");
+      //this is the oai receptionist asking for a list of oai-support collections
+      response.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SET_LIST );
+      response.appendChild(this.oai_collection_list);
+      return response;
+    } 
+
+
     if (type.equals(GSXML.REQUEST_TYPE_SYSTEM)) {
       
@@ -667,5 +926,5 @@
           if (subset.equals("")) {
             // need to reconfigure the MR
-            this.configure();
+            this.configureLocalSite();
             Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM,  "MessageRouter reconfigured successfully");
             response.appendChild(s);
@@ -674,4 +933,7 @@
             // else it a specific request
             if (subset.equals(GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER)) {
+	      // get rid of all the old collection stuff (not counting remote ones) before activating all the new ones
+	      cleanUpModuleMapSubset(this.collection_list, null);
+	      cleanUpModuleMapSubset(this.private_collection_list, null);
               success = configureCollections();
             } else {
@@ -694,13 +956,14 @@
               if (subset.equals(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER)) {
                 Element service_rack_list = (Element)GSXML.getChildByTagName(site_config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER);
-                
+                cleanUpModuleMapSubset(this.service_list, null);
                 success = configureServices(service_rack_list);
               } else if (subset.equals(GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER)) {
                 Element cluster_list = (Element)GSXML.getChildByTagName(site_config_elem, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
-                
+                cleanUpModuleMapSubset(this.cluster_list, null);
                 success = configureClusters(cluster_list);
               } else if (subset.equals(GSXML.SITE_ELEM+GSXML.LIST_MODIFIER)) {
                 Element site_list = (Element)GSXML.getChildByTagName(site_config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
-                success = configureSites(site_list);
+		cleanUpAllExternalSiteInfo();
+                success = configureExternalSites(site_list);
               }
             }
@@ -721,8 +984,17 @@
           
           if (action.equals(GSXML.SYSTEM_TYPE_DEACTIVATE)) {
-            deactivateModule(module_type, module_name);
-            Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" deactivated");
-            response.appendChild(s);
+            success = deactivateModule(module_type, module_name);
+	    if (success) {
+	      Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" deactivated");
+	      response.appendChild(s);
+	    } else {
+	      Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, module_type+": "+module_name+" could not be deactivated");
+	      response.appendChild(s);
+	    }
+            
           } else if (action.equals(GSXML.SYSTEM_TYPE_ACTIVATE)) {
+	    // we need to deactivate the module first, in case this is a 
+	    // reconfigure
+	    deactivateModule(module_type, module_name);
             if (module_type.equals(GSXML.COLLECTION_ELEM)) {
               success = activateCollectionByName(module_name);
@@ -753,4 +1025,7 @@
     
   }
+
+  //* Used to copy nodes from one message to another. E.g. copy a response node to the next request. Not sure if this is actually used anywhere yet... */
+
   protected Element modifyMessages(Element request, Element message, Element result) {
     Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
@@ -814,192 +1089,5 @@
   // ****************************************************
   
-  /** creates and configures a new collection
-   *
-   *@param col_name the name of the collection
-   *@return true if collection created ok
-   */
-  protected boolean activateCollectionByName(String col_name) {
-    
-    logger.info("Activating collection: "+col_name+".");
-    
-    // Look for the etc/collectionInit.xml file, and see what sort of Collection to load
-    Collection c = null;
-    File init_file = new File(GSFile.collectionInitFile(this.site_home, col_name));
-    
-    if (init_file.exists()) {
-      Document init_doc = this.converter.getDOM(init_file);
-      if (init_doc != null) {
-        Element init_elem = init_doc.getDocumentElement();
-        if (init_elem != null) {
-          String coll_class_name = init_elem.getAttribute("class");
-          if (!coll_class_name.equals("")) {
-            try {
-              c = (Collection)Class.forName("org.greenstone.gsdl3.collection."+coll_class_name).newInstance();
-            } catch (Exception e) {
-              logger.info(" couldn't create a new collection, type "+coll_class_name+", defaulting to class Collection");
-            }
-          }
-        }
-      }
-    }
-    if (c==null) { // we haven't found another classname to use
-      c = new Collection();
-    }
-    
-    c.setCollectionName(col_name);
-    c.setSiteHome(this.site_home);
-    c.setSiteAddress(this.site_http_address);
-    c.setMessageRouter(this);
-    if (c.configure()) {
-      // this could be a reactivation, so delete the old version
-      deactivateModule(GSXML.COLLECTION_ELEM, col_name);
-      // add to list of collections
-      this.module_map.put(col_name, c);
-      
-      if(c.isPublic()) {
-        // only public collections will appear on the home page
-        // add short description_ to collection_list_
-        Element e = this.doc.createElement(GSXML.COLLECTION_ELEM);
-        e.setAttribute(GSXML.NAME_ATT, col_name);
-//        if (c.hasOAI()) {
-//          e.setAttribute(OAIXML.HAS_OAI, "true");
-//        } else {
-//          e.setAttribute(OAIXML.HAS_OAI, "false");
-//        } 
-        if (c.hasOAI() == true) {
-          Element ane = this.doc.createElement(GSXML.COLLECTION_ELEM);
-          //The collection name is returned as site_name:coll_name, which is in fact the set specification
-          ane.setAttribute(GSXML.NAME_ATT, site_name + ":" + col_name);
-          ane.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
-          
-          this.oai_collection_list.appendChild(ane);
-          //logger.info(GSXML.xmlNodeToString(oai_collection_list));
-        }      
-        this.collection_list.appendChild(e);
-      }
-      return true;
-    } else {
-      logger.error("Couldn't configure collection: "+
-        col_name+".");
-      return false;
-    }
-  }
-  protected Element getCollectionList() {
-    return collection_list;
-  }
-  
-  
-  protected boolean activateSiteByName(String site_name) {
-    logger.info("Activating site: "+site_name+".");
-    
-    // just in case this is a reactivation, deactivate this site first
-    deactivateModule(GSXML.SITE_ELEM, site_name);
-    File configFile = new File(GSFile.siteConfigFile(this.site_home));
-    
-    if (!configFile.exists() ) {
-      logger.error(" site config file: "+configFile.getPath()+" not found!");
-      return false;
-    }
-    Document config_doc = this.converter.getDOM(configFile);
-    if (config_doc == null) {
-      logger.error(" couldn't parse site config file: "+configFile.getPath());
-      return false;
-    }
-    Element config_elem = config_doc.getDocumentElement();
-    
-    Element config_site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);
-    if (config_site_list ==null ) {
-      logger.error("activateSite, no sites found");
-      return false;
-    }
-    // this is a name to identify the current site in the Communicator
-    String local_site_name = config_site_list.getAttribute("localSiteName");
-    if (local_site_name.equals("")) {
-      local_site_name = site_name;
-    }
-    
-    Element this_site_elem = GSXML.getNamedElement(config_site_list, GSXML.SITE_ELEM, GSXML.NAME_ATT, site_name);
-    if (this_site_elem == null) {
-      logger.error("activateSite, site "+site_name+" not found");
-      return false;
-    }
-    
-    return activateSite(this_site_elem, local_site_name);
-  }
-  
-  protected boolean activateServiceClusterByName(String cluster_name) {
-    return false;
-    
-  }
-  
-  protected boolean activateServiceRackByName(String module_name) {
-    return false;
-  }
-  
-  protected boolean deactivateModule(String type, String name) {
-    
-    if (this.module_map.containsKey(name)) {
-      
-      logger.info(" deactivating "+name);
-      ModuleInterface m = (ModuleInterface)this.module_map.remove(name);
-      m.cleanUp(); // clean up any open files/connections etc - can cause trouble on windows
-      // also remove the xml bit from description list
-      if (type.equals(GSXML.COLLECTION_ELEM)) {
-        Element this_col = GSXML.getNamedElement(this.collection_list, GSXML.COLLECTION_ELEM, GSXML.NAME_ATT, name);
-        if (this_col != null) {
-          this.collection_list.removeChild(this_col);
-        }
-        return true;
-      } else if (type.equals(GSXML.SERVICE_ELEM)) {
-        Element this_service = GSXML.getNamedElement(this.service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, name);
-        if (this_service != null) {
-          this.service_list.removeChild(this_service);
-        }
-        return true;
-      } else if (type.equals(GSXML.CLUSTER_ELEM)) {
-        Element this_cluster = GSXML.getNamedElement(this.cluster_list, GSXML.CLUSTER_ELEM, GSXML.NAME_ATT, name);
-        if (this_cluster != null) {
-          this.cluster_list.removeChild(this_cluster);
-        }
-        return true;
-      } else if (type.equals(GSXML.SITE_ELEM)) {
-        Element this_site = GSXML.getNamedElement(this.site_list, GSXML.SITE_ELEM, GSXML.NAME_ATT, name);
-        if (this_site != null) {
-          this.site_list.removeChild(this_site);
-          
-          // also remove this sites colls, services, clusters etc
-          removeRemoteSiteInfo(this.collection_list, GSXML.COLLECTION_ELEM, name);
-          removeRemoteSiteInfo(this.cluster_list, GSXML.CLUSTER_ELEM, name);
-          removeRemoteSiteInfo(this.service_list, GSXML.SERVICE_ELEM, name);
-        }
-      } else {
-        logger.error(" couldn't deactivate coll");
-        // couldn't do it
-        return false;
-      }
-    }
-    // else not deactivated
-    return false;
-    
-  }
-  
-  /**
-   * this looks through a list (module_list) of elements named module_name,
-   * and removes any whose names start with site_name
-   */
-  protected void removeRemoteSiteInfo(Element module_list,
-    String module_name,
-    String site_name) {
-    
-    NodeList modules = module_list.getElementsByTagName(module_name);
-    // will this work??
-    for (int i=modules.getLength()-1; i>=0; i--) {
-      
-      String name = ((Element)modules.item(i)).getAttribute(GSXML.NAME_ATT);
-      if (GSPath.getFirstLink(name).equals(site_name)) {
-        module_list.removeChild(modules.item(i));
-      }
-    }
-  }
+ 
   
 }
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/core/Receptionist.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/core/Receptionist.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/core/Receptionist.java	(revision 15191)
@@ -264,5 +264,5 @@
 	Element option_list = (Element)GSXML.getChildByTagName(config_elem, "optionList");
 	if (option_list != null) {
-	    logger.error("found an option list");
+	    logger.info("found an interface optionList");
 	    // we set any options in the config params
 	    NodeList options = option_list.getElementsByTagName("option");
@@ -271,5 +271,5 @@
 		String name = option.getAttribute(GSXML.NAME_ATT);
 		String value = option.getAttribute(GSXML.VALUE_ATT);
-		logger.error("option: "+name+", "+value);
+		logger.info("option: "+name+", "+value);
 		if (!name.equals("") && !value.equals("")) {
 		    this.config_params.put(name, value);
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2FieldSearch.java	(revision 15191)
@@ -333,8 +333,10 @@
 	    if (level_ids.size()>1) {
 		// the first one is the default
-		param = GSXML.createParameterDescription2(this.doc, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)level_ids.get(0), level_ids, level_names);
+		//param = GSXML.createParameterDescription2(this.doc, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)level_ids.get(0), level_ids, level_names);
+		param = GSXML.createParameterDescription2(this.doc, LEVEL_PARAM, getTextString("param."+LEVEL_PARAM, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, this.default_level, level_ids, level_names);
 	    } else {
 		// we need to set the level, but hidden, in case there is an invalid level saved
-		param = GSXML.createParameterDescription(this.doc, LEVEL_PARAM, "", GSXML.PARAM_TYPE_INVISIBLE, (String)level_ids.get(0), null, null);
+		//param = GSXML.createParameterDescription(this.doc, LEVEL_PARAM, "", GSXML.PARAM_TYPE_INVISIBLE, (String)level_ids.get(0), null, null);
+	    param = GSXML.createParameterDescription(this.doc, LEVEL_PARAM, "", GSXML.PARAM_TYPE_INVISIBLE, this.default_level, null, null);
 	    }
 	} else if (name.equals(RANK_PARAM)) {
@@ -358,5 +360,13 @@
 	    getIndexData(fields, field_names, lang);
 	    // the field list -  read from config file
-	    param = GSXML.createParameterDescription2(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)fields.get(0), fields, field_names );
+	    
+	    // Fix for http://trac.greenstone.org/ticket/245 "java crash, index out of bounds"
+	    // org.greenstone.gsdl3.service.AbstractGS2FieldSearch.createParameter(AbstractGS2FieldSearch.java:362)
+	    // Changed from:
+	    // param = GSXML.createParameterDescription2(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, (String)fields.get(0), fields, field_names );
+	    String default_value = (fields.size() > 0) ? (String)fields.get(0) : null;
+	          // don't want to access element 0 if fields.size()==0, and
+	          // GSXML.createParameterDescription2 checks for default_value==null condition
+	    param = GSXML.createParameterDescription2(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_ENUM_SINGLE, default_value, fields, field_names );
 	    
 	} else if (name.equals(FIELD_COMBINE_PARAM)) {
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/AbstractSearch.java	(revision 15191)
@@ -93,5 +93,9 @@
 
     protected String default_index_language = "";
-
+   
+    protected String default_max_docs = "100";
+    
+    protected String default_hits_per_page = "10";
+ 
     public AbstractSearch()
     {
@@ -285,12 +289,13 @@
 	    param_list.appendChild(param);
 	}
-        else if (name.equals(MAXDOCS_PARAM) || name.equals(HITS_PER_PAGE_PARAM)) {
-	    String default_val = "100";
-	    if (name.equals(HITS_PER_PAGE_PARAM)) {
-		default_val = "10";
-	    }
-	    param = GSXML.createParameterDescription(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_INTEGER, default_val, null, null);
-	    param_list.appendChild(param);
-	} else if (name.equals(CASE_PARAM) || name.equals(STEM_PARAM) || name.equals(ACCENT_PARAM)) {
+        else if (name.equals(MAXDOCS_PARAM)) {
+	    param = GSXML.createParameterDescription(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_INTEGER, this.default_max_docs, null, null);
+	    param_list.appendChild(param);
+	}
+	else if(name.equals(HITS_PER_PAGE_PARAM)){
+	     param = GSXML.createParameterDescription(this.doc, name, getTextString("param."+name, lang), GSXML.PARAM_TYPE_INTEGER, this.default_hits_per_page, null, null);
+	    param_list.appendChild(param);
+	}
+	else if (name.equals(CASE_PARAM) || name.equals(STEM_PARAM) || name.equals(ACCENT_PARAM)) {
 	    String[] bool_ops = {"0", "1"};
 	    String[] bool_texts = {getTextString("param.boolean.off", lang),getTextString("param.boolean.on", lang)}; 
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java	(revision 15191)
@@ -99,6 +99,6 @@
     Set entries = params.entrySet();
     Iterator i = entries.iterator();
-    String physical_sub_index_name=null;
-    String physical_index_language_name=null;
+    String physical_sub_index_name= this.default_index_subcollection;
+    String physical_index_language_name= this.default_index_language;
     while (i.hasNext()) {
       Map.Entry m = (Map.Entry)i.next();
@@ -151,5 +151,4 @@
     mgpp_src.loadIndexData(indexdir);
     
-    physical_index_name="idx";
     return true;
   }
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java	(revision 15191)
@@ -126,4 +126,5 @@
 	    synchronized(this.mg_src){
                 String indexpath = GSFile.collectionIndexPath(this.index_stem, this.default_index);        
+		this.mg_src.setIndex(indexpath);
 		doc_content =  this.mg_src.getDocument (this.mg_basedir,
 							this.mg_textdir, doc_num);
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java	(revision 15191)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java	(revision 15191)
@@ -0,0 +1,196 @@
+/*
+ *    GS2MGPPSearch.java
+ *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *   the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.greenstone.gsdl3.service;
+
+
+// Greenstone classes
+import org.greenstone.mgpp.*;
+import org.greenstone.gsdl3.util.*;
+import org.w3c.dom.Element; 
+
+import java.util.Vector;
+import java.util.ArrayList;
+import java.util.Collections;
+import org.apache.log4j.*;
+
+/**
+ *
+ * @author <a href="mailto:shaoqun@cs.waikato.ac.nz">Shaoqun Wu</a>
+ */
+
+public class GoogleNgramMGPPSearch
+  extends GS2MGPPSearch {
+   static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GoogleNgramMGPPSearch.class.getName());
+   protected GDBMWrapper gdbm_src = null;
+  
+    /** constructor */
+    public GoogleNgramMGPPSearch(){
+	super();
+	gdbm_src = new GDBMWrapper();
+	
+    }
+    
+  /** configure this service */
+    public boolean configure(Element info, Element extra_info) {
+	if (!super.configure(info, extra_info)){
+	    return false;
+	}
+
+	// Open GDBM database for querying
+	String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);
+       	if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
+	    logger.error("Could not open GDBM database!");
+	    return false;
+	}
+	this.default_max_docs = "-1";
+	this.default_hits_per_page = "30";
+        this.does_stem = false;
+	this.does_paging = true;
+	return true;
+    }
+  
+    // sort the doc_nums by their frequency
+    protected String [] getDocIDs(Object query_result) {
+	try{
+	  Vector docs = ((MGPPQueryResult)query_result).getDocs();
+	  //ArrayList docList_past = new ArrayList(); 
+          //ArrayList docList_future = new ArrayList();	 
+	  //ArrayList docList_present = new ArrayList();
+	  
+	 ArrayList docList = new ArrayList();
+
+	  for (int d = 0; d < docs.size(); d++) {
+	      String num = Long.toString((((MGPPDocInfo) docs.elementAt(d)).num_));
+	      String doc_id = internalNum2OID(num);
+	      DBInfo gdbmInfo = this.gdbm_src.getInfo(doc_id);
+	      String fre = (String)gdbmInfo.getInfo("Frequency");
+	      String tense = (String)gdbmInfo.getInfo("Tense");
+	     
+	      if(!fre.equals("")){
+		  //  if (tense.equals("past")){
+		  //    docList_past.add(new DocWrapper(num,Integer.parseInt(fre),tense));
+		  // }
+		  // else{
+		  //    if (tense.equals("future")){
+		  //	  docList_future.add(new DocWrapper(num,Integer.parseInt(fre),tense));
+		  //     }
+		  //    else{
+		  //	  if(tense.equals("present")){
+		  //	      docList_present.add(new DocWrapper(num,Integer.parseInt(fre),tense));   
+		  //	  }
+		  //    }
+		  //}
+		  docList.add(new DocWrapper(num,Integer.parseInt(fre),tense));
+	      }
+	      
+	  }
+	  
+	  
+	  //Collections.sort(docList_past);
+	  //Collections.sort(docList_future);
+	  //Collections.sort(docList_present);
+	  
+	  Collections.sort(docList);
+	  int i_pa =  0;
+	  int i_f =  0;
+	  int i_pre = 0;
+	  
+	  //String [] doc_nums = new String [docList_past.size()+docList_future.size()+docList_present.size()];
+	  String [] doc_nums = new String [docList.size()];
+	  int interval = 10;
+
+	  for(int d = 0; d < doc_nums.length; d++){
+
+	      // for(;i_pre < docList_present.size() && interval > 0;i_pre++){
+// 		  doc_nums[d] = ((DocWrapper)docList_present.get(i_pre)).num;
+// 		  d++;
+// 		  interval--;
+// 	      }
+	      
+// 	      interval = 10+interval;
+	 
+// 	      for(;i_pa < docList_past.size() && interval > 0;i_pa++){
+// 		  doc_nums[d] = ((DocWrapper)docList_past.get(i_pa)).num;
+// 		  d++;
+// 		  interval--;
+// 	      }
+
+	     
+// 	      interval = 10+interval;
+
+// 	      for(;i_f < docList_future.size() && interval > 0;i_f++){
+// 		  doc_nums[d] = ((DocWrapper)docList_future.get(i_f)).num;
+// 		  d++;
+// 		  interval--;
+// 	      }
+
+// 	    interval = 10;
+
+	      doc_nums[d] = ((DocWrapper)docList.get(d)).num;
+	    
+	  }
+
+	  return doc_nums;
+    }
+    catch(Exception e){
+	e.printStackTrace();
+    }
+
+    return null;
+  }
+
+  static class DocWrapper implements Comparable{
+	public int fre = 0;
+	public String num = "";
+        public String tense = "";
+
+
+      public DocWrapper(String num, int fre, String tense){
+	    this.fre = fre;
+	    this.num = num;
+	    this.tense = tense;
+	}
+
+	public int compareTo(Object o){
+	    
+	    if (!(o instanceof DocWrapper)) return -1;
+	    DocWrapper docIn = (DocWrapper)o;
+	    if (num.equals(docIn.num)){
+		return 0;
+	    }
+
+	    if (fre > docIn.fre) return -1; 
+	    return 1;	
+	}
+
+	public boolean equals(Object o){
+	    if (!(o instanceof DocWrapper)) return false;
+	    DocWrapper docIn = (DocWrapper)o;
+	    if (num.equals(docIn.num)){
+		return true;
+	    }
+	    return false;
+	}
+
+
+    }
+    
+      
+}
+
+
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/DatabaseFactory.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/DatabaseFactory.java	(revision 15191)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/DatabaseFactory.java	(revision 15191)
@@ -0,0 +1,93 @@
+package org.greenstone.gsdl3.sql;
+
+/**
+ * Returns a sql server according to the user's selection
+ *
+ */
+
+import org.apache.log4j.*;
+
+import java.util.HashMap;
+
+public class DatabaseFactory{
+    private static HashMap serverMap = new HashMap();
+    private static HashMap wrapperMap = new HashMap();
+    private static Logger logger = Logger.getLogger(org.greenstone.gsdl3.sql.DatabaseFactory.class.getName());
+
+
+    //upcase the first letter
+    public static String properDBName(String name_in){
+	String name_out = "";
+	name_in = name_in.toLowerCase();
+	if (name_in.length() >= 1){
+	    String firstLetter = name_in.substring(0,1).toUpperCase();
+	    name_out = firstLetter +  name_in.substring(1);
+	}
+	return name_out;
+    }
+
+
+    public static final SQLServer getDatabaseServer(String dbname){
+	dbname = properDBName(dbname);
+	if (serverMap.containsKey(dbname)) return (SQLServer) serverMap.get(dbname);
+	String fullName = "org.greenstone.gsdl3.sql." + dbname.toLowerCase()+ "." + dbname +"SQLServer";
+	try {
+	    SQLServer server = (SQLServer)Class.forName(fullName).newInstance();
+	    serverMap.put(dbname, server);
+	    return server;
+	} catch (Exception e) {
+	    logger.info("Couldn't load the database server "+ fullName);
+	}
+	
+	return null; 
+    }
+
+    public static final MetadataDBWrapper getMetadataDBWrapper(String dbname, String sqlstate){
+	dbname = properDBName(dbname);
+	if (wrapperMap.containsKey(dbname + ":" + sqlstate)) return (MetadataDBWrapper)wrapperMap.get(dbname + ":" + sqlstate);	
+
+	String fullName = "org.greenstone.gsdl3.sql." + dbname.toLowerCase()+ "." + dbname +"DBWrapper";
+	try {
+	    MetadataDBWrapper wrapper = (MetadataDBWrapper)Class.forName(fullName).newInstance();
+	    if (wrapper != null){
+		//load SQLServer class
+		SQLServer server = getDatabaseServer(dbname);
+		if (server != null){
+		    wrapper.setSQLServer(server);
+		}
+
+		String fullsqlstate = "org.greenstone.gsdl3.sql." + sqlstate;
+		//load SQLStatements class
+		try{
+		   SQLStatements state = (SQLStatements)Class.forName(fullsqlstate).newInstance(); 
+		   if (state != null){
+		       wrapper.setSQLStatements(state); 
+		       wrapperMap.put(dbname + ":" + sqlstate, wrapper);
+		       return wrapper;
+		   }
+		}
+		catch (Exception e) {
+		    // if falied use sqlstate as a full path
+		    try{
+			SQLStatements state = (SQLStatements)Class.forName(sqlstate).newInstance(); 
+			if (state != null){
+			    wrapper.setSQLStatements(state);
+			    wrapperMap.put(dbname + ":" + sqlstate,wrapper);
+			    return wrapper;
+			}
+		    }
+		    catch (Exception e2) {
+			// failed again, give up
+			logger.info("Couldn't load the sql statement  "+ sqlstate);
+		    }
+		}
+	    }
+	} catch (Exception e) {
+	    logger.info("Couldn't load the database wrapper "+ fullName);
+	}
+	
+	return null; 
+
+    }
+
+}
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/MetadataDBWrapper.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/MetadataDBWrapper.java	(revision 15191)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/MetadataDBWrapper.java	(revision 15191)
@@ -0,0 +1,22 @@
+package org.greenstone.gsdl3.sql;
+
+import java.util.ArrayList;
+import org.greenstone.gsdl3.util.DBInfo;
+import org.greenstone.gsdl3.sql.SQLServer;
+
+public interface MetadataDBWrapper{
+
+    public DBInfo getInfo(String id);
+
+    public void setSQLServer(SQLServer server);
+
+    public void setSQLStatements(SQLStatements sqlstate);
+
+    public boolean openConnection(String databasepath);
+
+     //return a list of rows
+    public ArrayList executeQuery(String query_statement);
+
+    public void closeConnection(String databasepath);
+   
+}
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/SQLServer.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/SQLServer.java	(revision 15191)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/SQLServer.java	(revision 15191)
@@ -0,0 +1,21 @@
+package org.greenstone.gsdl3.sql;
+
+import java.sql.Connection;
+
+/*
+ * this class provide an interface for connecting and querying a database system. In order to not tie Greenstone to a particalur database system 
+ * every database action should go through this interface 
+ * 
+ */
+public interface SQLServer{
+ 
+    /** connect to a database without creating the database if it doesn't exist */
+    public Connection connect(String databasePath);
+
+    /** connect to a database and create the database if it doesn't exist */
+    public Connection connectAndCreate(String databasePath); 
+
+    public boolean disconnect(String databasePath);
+
+   	
+ }
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/SQLStatements.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/SQLStatements.java	(revision 15191)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/SQLStatements.java	(revision 15191)
@@ -0,0 +1,7 @@
+package org.greenstone.gsdl3.sql;
+
+public interface SQLStatements{
+
+    public String getDBInfoStatement(String node_id);
+    public String undoDBSafe(Object text);
+}
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/derby/DerbyDBWrapper.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/derby/DerbyDBWrapper.java	(revision 15191)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/derby/DerbyDBWrapper.java	(revision 15191)
@@ -0,0 +1,123 @@
+package org.greenstone.gsdl3.sql.derby;
+
+import  org.greenstone.gsdl3.sql.*;
+
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.greenstone.gsdl3.util.DBInfo;
+
+import org.apache.log4j.*;
+
+public class DerbyDBWrapper implements MetadataDBWrapper{
+    protected SQLServer sqlServer = null;
+    protected SQLStatements sqlState = null;
+    protected Connection connection = null; 
+    protected Statement statement = null;
+    protected static Logger logger = Logger.getLogger(org.greenstone.gsdl3.sql.derby.DerbyDBWrapper.class.getName());
+
+
+    public DBInfo getInfo(String id){
+	if(sqlState == null) return null;
+        String dbInfoState = sqlState.getDBInfoStatement(id);
+        ArrayList result = executeQuery(dbInfoState);
+	if (result.size() == 0) return null;
+	DBInfo info = new DBInfo();
+	for(int i=0;  i<result.size();i++){
+	    HashMap arow = (HashMap)result.get(i);
+	    Iterator ite = arow.keySet().iterator();
+	    while(ite.hasNext()){
+		String key = (String)ite.next();
+		Object value = arow.get(key);
+		logger.info(key + "=>" +value);
+		if (value == null || value.equals("")) continue;
+		info.addInfo(key.toLowerCase(),sqlState.undoDBSafe(value));
+	    }
+	}
+
+	return info;
+    }
+
+    public void setSQLServer(SQLServer server){
+	sqlServer = server;
+    }
+
+    public void setSQLStatements(SQLStatements state){
+	sqlState = state;
+    }
+
+    public boolean openConnection(String databasepath){
+	connection = sqlServer.connect(databasepath);
+	if (connection == null) return false;
+
+	try{
+	    statement = connection.createStatement();
+	}
+	catch(SQLException sqle){
+	    logger.error("Database Error occured when creating a statement object",sqle);
+	    return false;
+	}
+	return true;
+    }
+
+    //return a list of rows array->hashmap
+    public ArrayList executeQuery(String query_statement){
+	//the database hasn't been correct yet
+	if (statement == null){
+	    logger.info("the database hasn't been correct yet");
+	    return new ArrayList();
+	}
+	
+	ArrayList results = new ArrayList();
+
+	try{
+	   ResultSet rs = statement.executeQuery(query_statement);
+	   ResultSetMetaData rsmd = rs.getMetaData();
+	   int numOfColumns = rsmd.getColumnCount();
+	   while(rs.next()){
+	       HashMap arow = new HashMap();
+	       for(int i = 1; i < numOfColumns ; i++){
+		   arow.put(rsmd.getColumnName(i), rs.getObject(i));
+	       }
+	       results.add(arow);  
+	   }
+	}
+	catch(SQLException sqle){
+	    logger.error("Database Error occured when executeQuery " + query_statement,sqle);
+	    return results;
+	}
+	return results;
+    }
+    
+     /** check for the existence of a table**/
+    public boolean check4Table (String check_table) {
+         try {
+	  statement.execute(check_table);
+      }  catch (SQLException sqle) {
+	  String theError = (sqle).getSQLState();
+	  if (theError.equals("42X05"))   // Table does not exist
+	      { 
+		  return false;
+	      }   
+	  else{
+	      return true;
+	  }
+      }
+      //  System.out.println("Just got the warning - table exists OK ");
+      return true;
+    }   
+
+    public void closeConnection(String databasepath){
+	sqlServer.disconnect(databasepath);
+    }
+  
+ }
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/derby/DerbySQLServer.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/derby/DerbySQLServer.java	(revision 15191)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/sql/derby/DerbySQLServer.java	(revision 15191)
@@ -0,0 +1,70 @@
+package org.greenstone.gsdl3.sql.derby;
+
+
+import org.apache.log4j.*;
+import org.greenstone.gsdl3.sql.*;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public class DerbySQLServer implements SQLServer{
+    static final String PROTOCOL = "jdbc:derby:";
+    static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
+    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.sql.derby.DerbySQLServer.class.getName());     
+
+    public DerbySQLServer(){
+	try{
+	    Class.forName(DRIVER).newInstance();
+	}
+        catch(Exception e){
+	    logger.error("Couldn't find derby driver: "+DRIVER,e);
+	}
+    }
+
+    public Connection connect(String databasePath){
+	try{
+	    String  protocol_str = PROTOCOL + databasePath; 
+	    Connection connection = DriverManager.getConnection(protocol_str);
+	    return connection;
+	}
+        catch(Exception e){
+	    logger.info("Connect to database "+databasePath + " failed!");
+	}
+
+	return null;
+	
+    }
+
+    public Connection connectAndCreate(String databasePath){
+	try{
+	    String  protocol_str = PROTOCOL + databasePath + ";create=true"; 
+	    Connection connection = DriverManager.getConnection(protocol_str);
+	    return connection;
+	}
+	catch(Exception e){
+	    logger.error("Connect to database "+databasePath + " failed!",e);
+	
+	}
+	return null;
+    } 
+
+    public boolean disconnect(String databasePath){
+	try{
+	    String protocol_str = PROTOCOL + databasePath + ";shutdown=true"; 
+	    DriverManager.getConnection(protocol_str);
+	}catch (SQLException se){
+	    String theError = (se).getSQLState();
+	    if (!theError.equals("08006")){
+		logger.error("Database "+databasePath + " couldn't be shut down properly!",se);
+	    }
+	    else{
+		return true;
+	    }
+	}
+	
+	return false;
+    }
+
+
+   
+}
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/util/GDBMWrapper.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/util/GDBMWrapper.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/util/GDBMWrapper.java	(revision 15191)
@@ -52,5 +52,5 @@
     }
 
-    /** cloase the database associated with this wrapper */
+    /** close the database associated with this wrapper */
     public void closeDatabase() {
 	try {
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/util/GSFile.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/util/GSFile.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/util/GSFile.java	(revision 15191)
@@ -291,4 +291,8 @@
     /** the gdbm database file - 
      * note, need to change extension depending on OS */
+    // The perl code can't detect big vs little endian on a Mac, so the Perl
+    // code will always name the gdbm db file .bdb on a Mac whether its little
+    // endian or not. A Mac little endian file is NOT the same as a Linux 
+    // little endian file
     static public String GDBMDatabaseFile(String site_home, 
 					  String collection_name,
@@ -296,5 +300,5 @@
 
 	String db_ext = ".ldb";
-	if (Misc.isBigEndian()) {
+	if (Misc.isMac() || Misc.isBigEndian()) {
 	    db_ext = ".bdb";
 	}
Index: /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java
===================================================================
--- /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java	(revision 15191)
@@ -694,4 +694,22 @@
     return null;
   }
+  /** returns a NodeList of elements: ancestor/node_name[@attribute_name='attribute_value']
+   */
+  public static NodeList getNamedElements(Element ancestor, String node_name, String attribute_name, String attribute_value) {
+	    MyNodeList node_list = new MyNodeList();
+	    NodeList children = ancestor.getElementsByTagName(node_name);
+	    
+		if(children != null && children.getLength() > 0) {
+			
+			for (int i=0; i<children.getLength(); i++) {
+				Node child = children.item(i);
+				if (child.getNodeName().equals(node_name)) {
+					if (((Element)child).getAttribute(attribute_name).equals(attribute_value))
+						node_list.addNode(child);
+				}			
+			}			
+	    }
+	    return node_list;
+  }
   
   public static int SORT_TYPE_STRING = 0;
Index: /greenstone3/branches/customizingGreenstone3/web/WEB-INF/classes/AbstractGS2FieldSearch.properties
===================================================================
--- /greenstone3/branches/customizingGreenstone3/web/WEB-INF/classes/AbstractGS2FieldSearch.properties	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/web/WEB-INF/classes/AbstractGS2FieldSearch.properties	(revision 15191)
@@ -14,5 +14,4 @@
 param.fqk.2=NOT
 param.fqa=accent
-param.indexSubcollection=Index sub collection
 param.indexLanguage=Index language
 
Index: /greenstone3/branches/customizingGreenstone3/web/WEB-INF/classes/AbstractSearch.properties
===================================================================
--- /greenstone3/branches/customizingGreenstone3/web/WEB-INF/classes/AbstractSearch.properties	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/web/WEB-INF/classes/AbstractSearch.properties	(revision 15191)
@@ -10,4 +10,5 @@
 param.hitsPerPage=Hits per page
 param.startPage=Start from page
+param.indexSubcollection=Index sub collection
 
 #optional params
Index: /greenstone3/branches/customizingGreenstone3/web/WEB-INF/web.xml
===================================================================
--- /greenstone3/branches/customizingGreenstone3/web/WEB-INF/web.xml	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/web/WEB-INF/web.xml	(revision 15191)
@@ -76,31 +76,17 @@
     <servlet-class>TestServlet</servlet-class>
   </servlet>
-  
- <servlet>
-    <servlet-name>dev</servlet-name>
-    <description>blah</description>
-    <servlet-class>org.greenstone.gsdl3.LibraryServlet</servlet-class>
-    <init-param>
-      <param-name>library_name</param-name>
-      <param-value>library</param-value>
-    </init-param>
-    <init-param>
-      <param-name>site_name</param-name>
-      <param-value>localsite</param-value>
-    </init-param>
-    <init-param>
-      <param-name>interface_name</param-name>
-      <param-value>default</param-value>
-    </init-param>
-    <init-param>
-      <param-name>receptionist_class</param-name>
-      <param-value>SkinnedReceptionist</param-value>
-    </init-param>
-    <init-param>
-      <param-name>default_lang</param-name>
-      <param-value>en</param-value>
-    </init-param>
-  </servlet>
-
+
+<!-- add new servlet definition here -->
+
+ <servlet>       
+    <servlet-name>mat</servlet-name>
+    <description>a metadata analysis servlet</description>
+    <servlet-class>MatServlet</servlet-class>          
+  </servlet>
+
+
+
+
+  
   <servlet>
     <servlet-name>library</servlet-name>
@@ -117,5 +103,5 @@
     <init-param>
       <param-name>interface_name</param-name>
-      <param-value>default</param-value>
+      <param-value>classic</param-value>
     </init-param>
     <init-param>
@@ -123,6 +109,9 @@
       <param-value>en</param-value>
     </init-param>
-  </servlet>
-  
+    <init-param>
+      <param-name>session_expiration</param-name>
+      <param-value>1800</param-value>
+    </init-param>
+  </servlet>
   <servlet>
     <servlet-name>gateway</servlet-name>
@@ -251,5 +240,5 @@
     -->
     
-<!--There is no need for this mapping, I think -->
+
 <servlet-mapping>
       <servlet-name>oaiserver</servlet-name>
@@ -262,8 +251,10 @@
   </servlet-mapping>
 
-  <servlet-mapping>
-    <servlet-name>dev</servlet-name>
-    <url-pattern>/dev</url-pattern>
-  </servlet-mapping>
+ <servlet-mapping>
+    <servlet-name>mat</servlet-name>
+    <url-pattern>/mat</url-pattern>
+  </servlet-mapping>
+
+
   
   <servlet-mapping>
Index: /greenstone3/branches/customizingGreenstone3/web/index.html
===================================================================
--- /greenstone3/branches/customizingGreenstone3/web/index.html	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/web/index.html	(revision 15191)
@@ -1,47 +1,42 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
-
   <head>
     <meta http-equiv="Content-Type"
       content="text/html; charset=iso-8859-1">
-      <title>Greenstone Version 3</title>
-  </head>
-  
-  <body bgcolor="#ffffff" text="#000000" link="#006666" 
-    alink="#cc9900" vlink="#666633" background="interfaces/default/images/chalk.gif">
+     <title>Greenstone Version 3</title>
+     <style type="text/css">
+        li {padding: 0.8em 0;}
+     </style> 
+  </head>  
+<body bgcolor="#ffffff" text="#000000" background="interfaces/default/images/chalk.gif">
     
-    <!-- page banner (_style:pagebanner_) -->
-    <center>
-      <table width=537 cellspacing=0 cellpadding=0>
-	<tr valign=top>
-	  <td rowspan=2 align=left><center><img src="interfaces/default/images/gsdlhead.gif" width=300 height=100 alt="Greenstone Digital Library Software"></center></td>
-	  <td align=right></td>
-	</tr>
+<p style="text-align:center;">
+<img src="interfaces/default/images/gsdlhead.gif" 
+width="225" height="66" alt="Greenstone Digital Library Software">
+</p>
+
+<div style="margin-left: 90px;">
+
+<h2 style="font-size:110%;font-family:sans-serif;">Welcome to your Greenstone3 installation</h2>
+<p>What do you want to do today?</p>
 	
-	<tr>
-	  <td align=right></td>
-	</tr>
-	
-	<tr>
-	  <td colspan=2></td>
-	</tr>
-      </table>
-    </center>
-    <!-- end of page banner -->
-    
-    <center>
-      
-      <table width=537>
-	<tr><td><h3>Hello! Welcome to your Greenstone3 installation</h3></td></tr>
-	<tr><td>&nbsp;</td></tr>
-	<tr><td>What do you want to do today?</td></tr>
-	<tr><td>&nbsp;</td></tr>
-	
-	
-	<tr><td><a href="testing">Run</a> the test servlet</td></tr>
-	<tr><td><a href="library">Run</a> the standard library servlet. View the demo collections that come with Greenstone, using the default look and feel.</td></tr>
-	<tr><td><a href="classic">Run</a> the 'classic' servlet. View the same collections using the 'classic' (or Greenstone 2) look and feel.</td></tr>
-	<tr><td><a href="gateway">Run</a> the gateway servlet. This uses the standard look and feel, and talks via SOAP to the site with demo collections (localsite). Note that SOAP needs to be installed, and a SOAP server needs to be running for localsite.</td></tr>
-      </table>
-    </center>
-  </body>
+<ul>	
+<li><a href="testing">Run the test servlet.</a>
+<li><a href="library">Run the standard library servlet.</a> View the demo collections that come with Greenstone, using 
+the default look and feel.
+<li><a href="classic">Run the 'classic' servlet.</a> View the same collections using the 'classic' (or Greenstone 2) 
+look and feel.
+<li><a href="gateway">Run the gateway servlet.</a> This uses the standard look and feel, and talks via SOAP to the site 
+with demo collections (localsite).
+<ul>
+<li>Note that SOAP needs to be installed, and a SOAP server needs to be running for localsite.
+</ul>
+</ul>
+
+</div>
+
+<p style="text-align:right; font-size: 75%;">powered by <a 
+href="http://www.greenstone.org/greenstone3-home">greenstone3</a></p>
+
+</body>
 </html>
Index: /greenstone3/branches/customizingGreenstone3/web/interfaces/classic/transform/pref.xsl
===================================================================
--- /greenstone3/branches/customizingGreenstone3/web/interfaces/classic/transform/pref.xsl	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/web/interfaces/classic/transform/pref.xsl	(revision 15191)
@@ -204,5 +204,5 @@
     <xsl:param name="prefix"/>
     
-    <xsl:if test="not(@name='matchMode') and not(@name='level') and not(@name='index') and not(@name='sortBy') and (@type='boolean' or @type='enum_single')"><xsl:apply-templates select="." mode="radio"><xsl:with-param name="display" select="$display"/><xsl:with-param name="prefix" select="$prefix"/><xsl:with-param name="paramIdx" select="position()"/></xsl:apply-templates></xsl:if>    
+    <xsl:if test="not(@name='matchMode') and not(@name='level') and not(@name='index') and not(@name='sortBy') and not(@name='indexSubcollection') and not(@name='indexLanguage') and (@type='boolean' or @type='enum_single')"><xsl:apply-templates select="." mode="radio"><xsl:with-param name="display" select="$display"/><xsl:with-param name="prefix" select="$prefix"/><xsl:with-param name="paramIdx" select="position()"/></xsl:apply-templates></xsl:if>    
   </xsl:template>
   
@@ -224,5 +224,5 @@
       <tr><xsl:attribute name="id"><xsl:value-of select="concat($prefix, '-', $paramIdx, '-', position())"/></xsl:attribute><xsl:if test="$display='n'"><xsl:attribute name="style">display:none</xsl:attribute></xsl:if>
       <xsl:if test="position()=1"><td rowspan='{$numOptions}' valign='baseline'><xsl:value-of select="../displayItem"/></td></xsl:if>
-      <td><input type='radio' name='{$cachedName}' value="{$value}"><xsl:if test="$cachedValue=$value"><xsl:attribute name="checked"></xsl:attribute></xsl:if></input></td>
+      <td><input type='radio' name='{$cachedName}' value="{$value}"><xsl:if test="$cachedValue=$value"><xsl:attribute name="checked">true</xsl:attribute></xsl:if></input></td>
       <td><xsl:value-of select="displayItem"/></td>
       </tr>
Index: /greenstone3/branches/customizingGreenstone3/web/interfaces/classic/transform/query-common.xsl
===================================================================
--- /greenstone3/branches/customizingGreenstone3/web/interfaces/classic/transform/query-common.xsl	(revision 15190)
+++ /greenstone3/branches/customizingGreenstone3/web/interfaces/classic/transform/query-common.xsl	(revision 15191)
@@ -29,5 +29,5 @@
   <xsl:template match="paramList" priority='2'>    	
 	<span class="textselect">
-		Search for <xsl:apply-templates select="param[@name='index']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='index']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates><xsl:if test="param[@name='level' and not(@type='invisible')]">at <xsl:apply-templates select="param[@name='level']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='level']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates> level</xsl:if><xsl:call-template name='query_mode'/>
+		Search for <xsl:apply-templates select="param[@name='index']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='index']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates><xsl:if test="param[@name='indexSubcollection']"> of <xsl:apply-templates select="param[@name='indexSubcollection']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='indexSubcollection']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates></xsl:if><xsl:if test="param[@name='indexLanguage']"> in <xsl:apply-templates select="param[@name='indexLanguage']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='indexLanguage']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates></xsl:if><xsl:if test="param[@name='level' and not(@type='invisible')]"> at <xsl:apply-templates select="param[@name='level']"><xsl:with-param name="default"><xsl:apply-templates select="param[@name='level']" mode="calculate-default"/></xsl:with-param></xsl:apply-templates> level</xsl:if><xsl:call-template name='query_mode'/>
     </span>	
     <span class="querybox"> 
