Index: /trunk/gsdl3/bin/script/ConstructCollection
===================================================================
--- /trunk/gsdl3/bin/script/ConstructCollection	(revision 3688)
+++ /trunk/gsdl3/bin/script/ConstructCollection	(revision 3688)
@@ -0,0 +1,30 @@
+#!/bin/sh
+echo "Constructing collections ..."
+ 
+if [ "x$GSDLHOME" = "x" ] ; then
+  echo "You must have GSDLHOME set for building to work"
+  exit
+fi
+ 
+if [ "x$GSDL3HOME" = "x" ] ; then
+  echo "You must have GSDL3HOME set for building to work"
+  exit
+fi
+ 
+if [ "x$GSDLOS" = "x" ] ; then
+  echo "You must have GSDLOS set for building to work"
+  exit
+fi
+ 
+
+# -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
+ 
+echo "running java -DGSDLHOME=$GSDLHOME -DGSDLOS=$GSDLOS -DGSDL3HOME=$GSDL3HOME -DPATH=$PATH org.greenstone.gsdl3.build.ConstructCollection  $*"
+java -DGSDLHOME=$GSDLHOME -DGSDLOS=$GSDLOS -DGSDL3HOME=$GSDL3HOME -DPATH=$PATH org.greenstone.gsdl3.build.ConstructCollection  $*
+ 
+echo "Done!"
Index: /trunk/gsdl3/bin/script/convert_coll_from_gs2.pl
===================================================================
--- /trunk/gsdl3/bin/script/convert_coll_from_gs2.pl	(revision 3688)
+++ /trunk/gsdl3/bin/script/convert_coll_from_gs2.pl	(revision 3688)
@@ -0,0 +1,240 @@
+#!/usr/bin/perl -w
+
+BEGIN {
+    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
+    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
+    #unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
+   # unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
+}
+
+#use arcinfo;
+use colcfg;
+#use plugin;
+use docprint;
+use util;
+use parsargv;
+use FileHandle;
+use XML::Writer;
+
+&main();
+sub print_usage() {
+    print STDOUT "Usage: convert_coll_from_gs2.pl [options] coll-name\n";
+    print STDOUT "options:\n";
+    
+}
+
+sub main {
+
+    my ($collectdir);
+    # note that no defaults are passed for most options as they're set
+    # later (after we check the collect.cfg file)
+    if (!parsargv::parse(\@ARGV,
+			 'verbosity/\d+/', \$verbosity,
+			 'collectdir/.*/', \$collectdir,
+			 'faillog/.*/', \$faillog)) {
+	&print_usage();
+	die "\n";
+    }
+
+    # get and check the collection name
+    if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
+	&print_usage();
+	die "\n";
+    }
+
+    $collconfigfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
+    my $collectcfg;
+    if (-e $collconfigfilename) {
+	$collectcfg = &colcfg::read_collect_cfg ($collconfigfilename);
+
+    }
+    $buildconfigfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "building", "build.cfg");
+    my $buildcfg;
+    if (-e $buildconfigfilename) {
+	$buildcfg = &colcfg::read_build_cfg ($buildconfigfilename);
+
+    }
+
+    my $outfile = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "building", "buildConfig.xml");
+    if (-e $outfile) {
+	print STDOUT "buildConfig file already exists! overwriting it!\n";
+	
+    }
+
+    my $buildtype;
+    if (defined $collectcfg->{'buildtype'}) {
+	$buildtype = $collectcfg->{'buildtype'};
+    } else {
+	$buildtype = 'mg';
+    }
+
+    my $output = new IO::File(">$outfile");
+    my $writer = new XML::Writer(OUTPUT => $output);
+
+    $writer->startTag('buildConfig');
+ 
+    if (defined $collectcfg->{'collectionmeta'}) {
+	my $collmeta = $collectcfg->{'collectionmeta'};
+	$writer->startTag('metadataList');
+	#just do collname for now
+	my $collnames = $collmeta->{'collectionname'};
+	foreach $lang (keys %$collnames) {
+	    my $short_lang;
+	    if ($lang eq 'default') {
+		$short_lang = 'en';
+	    } else {
+	        ($short_lang) = $lang =~ /^\[l=(..)\]/;
+	    }
+	    $writer->startTag('metadata', 'lang'=>$short_lang, 'name'=>'collName');
+	    $writer->characters($collnames->{$lang});
+	    $writer->endTag('metadata');
+	}
+	my $collabouts = $collmeta->{'collectionextra'};
+	foreach $lang (keys %$collabouts) {
+	    my $short_lang;
+	    if ($lang eq 'default') {
+		$short_lang = 'en';
+	    } else {
+	        ($short_lang) = $lang =~ /^\[l=(..)\]/;
+	    }
+	    $writer->startTag('metadata', 'lang'=>$short_lang, 'name'=>'collDescript');
+	    $writer->characters($collabouts->{$lang});
+	    $writer->endTag('metadata');
+	}
+	$writer->endTag('metadataList');
+    }
+    $writer->startTag('serviceRackList');
+    
+    if ($buildtype =~ /^mg/) {
+	if ($buildtype eq 'mgpp') {
+	    #for each level
+	    my @levels = ('Document');
+	    my $defaultlevel = 'Document';
+	    if (defined $collectcfg->{'levels'}) {
+		push @levels, @{$collectcfg->{'levels'}};
+
+		foreach $l(@levels){
+		    $defaultlevel = 'Section' if $l eq 'Section';
+		}
+	    }
+	   
+	    $writer->startTag('serviceRack', 'name'=>'GS2MGPPRetrieve');
+	    $writer->emptyTag('defaultLevel', 'name'=>$defaultlevel);
+	    $writer->endTag('serviceRack');
+	    
+	    $writer->startTag('serviceRack', 'name'=>'GS2MGPPSearch');
+	    $writer->emptyTag('defaultLevel', 'name'=>$defaultlevel);
+	    $writer->startTag('levelList');
+	    foreach $level (@levels) {
+		$writer->emptyTag('level', 'name'=>$level);
+	    }
+	    $writer->endTag('levelList');
+	    
+            #fieldlist
+	    
+	} elsif ($buildtype eq 'mg') {
+	    $writer->emptyTag('serviceRack', 'name'=>'GS2MGRetrieve');
+	    $writer->startTag('serviceRack', 'name'=>'GS2MGSearch');
+	}
+	
+	#indexes
+	my $indexmap = {};
+	if (defined $buildcfg->{'indexmap'}) {
+	    $indexmap_t = $buildcfg->{'indexmap'};
+	    foreach $i (@$indexmap_t) {
+		my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
+		$indexmap->{$k} = $v;
+	    }
+	} else {
+	    print STDERR "indexmap not defined";
+	}
+	my $defaultindex;
+	if (defined $collectcfg->{'defaultindex'}) {
+	    $defaultindex = $collectcfg->{'defaultindex'};
+	} else {
+	    print STDERR "defaultindex not defined";
+	}
+	$defaultindex = $indexmap->{$defaultindex};
+	$writer->emptyTag('defaultIndex', 'name'=>$defaultindex);
+	$writer->startTag('indexList');
+	#for each index
+	foreach $i (keys %$indexmap) {
+	    $index = $indexmap->{$i};
+	    $writer->emptyTag('index', 'name'=>$index);
+	}	
+	$writer->endTag('indexList');
+	
+	$writer->endTag('serviceRack');
+    }
+
+    #my $classifiers = {};
+    my $count = 1;
+    my $phind = 0;
+    my $started_classifiers = 0;
+    if (defined $collectcfg->{'classify'}) { 
+	my $classifiers = $collectcfg->{'classify'};
+	foreach $cl (@$classifiers) {
+	    print STDERR "cl=$cl\n";
+	    $name = "CL$count";
+	    $count++;
+	    my ($classname) = @$cl[0];
+	    if ($classname eq "Phind") {
+		$phind=1;
+		next;
+	    }
+	    
+	    if (not $started_classifiers) {
+		$writer->startTag('serviceRack', 'name'=>'GS2Browse');
+		$writer->startTag('classifierList');
+		$started_classifiers = 1;
+	    }
+	    my $title = ''; #use buttonname if defined, otherwise use metadata
+	    
+	    for ($i=0; $i<scalar(@$cl); $i++) {
+		$arg = @$cl[$i];
+		if ($arg eq "-buttonname") {
+		    $title = @$cl[$i+1];
+		    last;
+		}
+		if ($arg eq "-metadata") {
+		    $title = @$cl[$i+1];
+		}
+	    }
+
+	    $writer->startTag('classifier', 'name'=>$name);
+	    $writer->startTag('metadataList');
+	    #title meta
+	    $writer->startTag('metadata', 'name'=>'Title');
+	    $writer->characters($title);
+	    $writer->endTag('metadata');
+	    $writer->endTag('metadataList');
+	    $writer->endTag('classifier');
+	    
+	    
+	} #foreach classifier
+	if ($started_classifiers) {
+	    # end the classifiers
+	    $writer->endTag('classifierList');
+	    $writer->endTag('serviceRack');
+	}
+	if ($phind) {
+	    # if phind classifier
+	    $writer->emptyTag('serviceRack', 'name'=>'PhindPhraseBrowse');
+	}
+	
+    }
+    $writer->endTag('serviceRackList');
+    $writer->endTag('buildConfig');
+    $writer->end();
+    $output->close();
+
+}
+
+#$writer->startTag('');
+#$writer->endTag('');
+#$writer->characters();
+#$writer->emptyTag('');
+
+1;
Index: /trunk/gsdl3/bin/script/gs2_mkcol.pl
===================================================================
--- /trunk/gsdl3/bin/script/gs2_mkcol.pl	(revision 3688)
+++ /trunk/gsdl3/bin/script/gs2_mkcol.pl	(revision 3688)
@@ -0,0 +1,268 @@
+#!/usr/bin/perl -w
+
+###########################################################################
+#
+# gs2_mkcol.pl -- create the framework for a gs2 compatible collection in 
+# gs3
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# 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.
+#
+###########################################################################
+
+
+# This program will setup a new collection from a model one. It does this by
+# copying the model, moving files to have the correct names, and replacing
+# text within the files to match the parameters.
+
+package gs2_mkcol;
+
+BEGIN {
+    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
+    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
+}
+
+use parsargv;
+use util;
+use cfgread;
+
+sub print_usage {
+    print STDOUT "\n";
+    print STDOUT "gs2_mkcol.pl: Creates the directory structure for a new\n";
+    print STDOUT "          Greenstone2 compatible collection in Greenstone3.\n\n";
+    print STDOUT "  usage: $0 -site site-home -creator email [options] collection-name\n\n";
+    print STDOUT "  options:\n";
+    print STDOUT "   -optionfile file    Get options from file, useful on systems where\n";
+    print STDOUT "                       long command lines may cause problems\n";
+    print STDOUT "   -collectdir         Directory where new collection will be created.\n";
+    print STDOUT "                       Default is " . 
+	&util::filename_cat("site-home", "collect") . "\n";
+    print STDOUT "   -maintainer email   The collection maintainer's email address (if\n";
+    print STDOUT "                       different from the creator)\n";
+    print STDOUT "   -public true|false  If this collection has anonymous access\n";
+    print STDOUT "   -title text         The title for the collection\n";
+    print STDOUT "   -about text         The about text for the collection\n";
+    print STDOUT "   -plugin text        perl plugin module to use (there may be multiple\n";
+    print STDOUT "                       plugin entries)\n";
+    print STDOUT "   -quiet              Operate quietly\n";
+    print STDOUT "  Note that -creator and -site must be specified. You can make changes to all\n";
+    print STDOUT "  options later by editing the collect.cfg configuration file for your\n";
+    print STDOUT "  new collection (it'll be in the \"etc\" directory).\n\n";
+    print STDOUT "  [Type \"perl -S mkcol.pl | more\" if this help text scrolled off your screen]";
+    print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
+}
+
+sub traverse_dir
+{
+    my ($modeldir, $coldir) = @_;
+    my ($newfile, @filetext);
+
+    if (!(-e $coldir)) {
+
+	my $store_umask = umask(0002);
+	my $mkdir_ok = mkdir ($coldir, 0777);
+	umask($store_umask);
+
+	if (!$mkdir_ok) 
+	{
+	    die "$!";
+	}
+    }
+
+    opendir(DIR, $modeldir) || die "Can't read $modeldir";
+    my @files = grep(!/^(\.\.?|CVS)$/, readdir(DIR));
+    closedir(DIR);
+
+    foreach $file (@files)
+    {
+	my $thisfile = &util::filename_cat ($modeldir, $file);
+	if (-d $thisfile) {
+	    my $colfiledir = &util::filename_cat ($coldir, $file);
+	    traverse_dir ($thisfile, $colfiledir);
+
+	} else {
+	    my $destfile = $file;
+	    $destfile =~ s/^modelcol/$collection/;
+	    $destfile =~ s/^MODELCOL/$capcollection/;
+	    print STDOUT "  doing replacements for $destfile\n" unless $quiet;
+	    $destfile = &util::filename_cat ($coldir, $destfile);
+	    
+	    open (INFILE, $thisfile) || 
+		die "ERROR: Can't read file $thisfile";
+	    open (OUTFILE, ">$destfile") ||
+		die "ERROR: Can't create file $destfile";
+
+	    while (defined ($line = <INFILE>)) {
+		$line =~ s/\*\*collection\*\*/$collection/g;
+		$line =~ s/\*\*COLLECTION\*\*/$capcollection/g;
+		$line =~ s/\*\*creator\*\*/$creator/g;
+		$line =~ s/\*\*maintainer\*\*/$maintainer/g;
+		$line =~ s/\*\*public\*\*/$public/g;
+		$line =~ s/\*\*title\*\*/$title/g;
+		$line =~ s/\*\*about\*\*/$about/g;
+		$line =~ s/\*\*plugins\*\*/$pluginstring/g;
+
+		print OUTFILE $line;
+	    }
+	    
+	    close (OUTFILE);
+	    close (INFILE);
+	}
+    }
+}
+
+# get and check options
+sub parse_args {
+    my ($argref) = @_;
+    if (!&parsargv::parse($argref,
+			  'optionfile/.*/', \$optionfile,
+			  'collectdir/.*/', \$collectdir,
+			  'site/.*/', \$sitehome,
+			  'creator/\w+\@[\w\.]+/', \$creator,
+			  'maintainer/\w+\@[\w\.]+/', \$maintainer,
+			  'public/true|false/true', \$public,
+			  'title/.+/', \$title,
+			  'about/.+/', \$about,
+			  'plugin/.+', \@plugin,
+			  'quiet', \$quiet,
+			  )) {
+	&print_usage();
+	die "\n";
+    }
+}
+
+sub main {
+
+    &parse_args (\@ARGV);
+    if ($optionfile =~ /\w/) {
+	open (OPTIONS, $optionfile) || die "Couldn't open $optionfile\n";
+	my $line = [];
+	my $options = [];
+	while (defined ($line = &cfgread::read_cfg_line ('mkcol::OPTIONS'))) {
+	    push (@$options, @$line);
+	}
+	close OPTIONS;
+	&parse_args ($options);
+
+    }
+
+    # load default plugins if none were on command line    
+    if (!scalar(@plugin)) {
+	@plugin = (ZIPPlug,GAPlug,TEXTPlug,HTMLPlug,EMAILPlug,
+		   PDFPlug,RTFPlug,WordPlug,PSPlug,ArcPlug,RecPlug);
+    }
+
+    # get and check the collection name
+    ($collection) = @ARGV;
+    if (!defined($collection)) {
+	print STDOUT "ERROR: no collection name was specified\n";
+	&print_usage();
+	die "\n";
+    }
+
+    if (length($collection) > 8) {
+	print STDOUT "ERROR: The collection name must be less than 8 characters\n";
+	print STDOUT "       so compatibility with earlier filesystems can be\n";
+	print STDOUT "       maintained.\n";
+	die "\n";
+    }
+
+    if ($collection eq "gs2model" || $collection eq "gs3model") {
+	print STDOUT "ERROR: No collection can be named gs2model or gs3model as these are  the\n";
+	print STDOUT "       names of the model collections.\n";
+	die "\n";
+    }
+
+    if ($collection eq "CVS") {
+	print STDOUT "ERROR: No collection can be named CVS as this may interfere\n";
+	print STDOUT "       with directories created by the CVS versioning system\n";
+	die "\n";
+    }
+
+    #check that -site has been specified
+    if (!defined($sitehome) || $sitehome eq "") {
+	print STDOUT "ERROR: The site was not defined. This variable is\n";
+	print STDOUT "       needed to locate the collect directory.\n";
+	die "\n";
+    }
+    #check that its a valid directory
+    if (!-d $sitehome) {
+	print STDOUT "ERROR: $sitehome doesn't exist\n";
+	die "\n";
+    }
+    if (!defined($creator) || $creator eq "") {
+	print STDOUT "ERROR: The creator was not defined. This variable is\n";
+	print STDOUT "       needed to recognise duplicate collection names.\n";
+	die "\n";
+    }
+
+    if (!defined($maintainer) || $maintainer eq "") {
+	$maintainer = $creator;
+    }
+
+    $public = "true" unless defined $public;
+
+    if (!defined($title) || $title eq "") {
+	$title = $collection;
+    }
+
+    # get capitalised version of the collection
+    $capcollection = $collection;
+    $capcollection =~ tr/a-z/A-Z/;
+
+    # get the strings to include.
+    $pluginstring = "";
+    foreach $plugin (@plugin) {
+	if ($plugin eq RecPlug) {
+	    $pluginstring .= "plugin         $plugin -use_metadata_files\n";
+	} else {
+	    $pluginstring .= "plugin         $plugin\n";
+	}
+    }
+
+    $mdir = &util::filename_cat ($sitehome, "collect", "gs2model");
+    
+    if (defined $collectdir && $collectdir =~ /\w/) {
+	if (!-d $collectdir) {
+	    print STDOUT "ERROR: $collectdir doesn't exist\n";
+	    die "\n";
+	}
+	$cdir = &util::filename_cat ($collectdir, $collection);
+    } else {
+	$cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
+    }
+
+    # make sure the model collection exists
+    die "ERROR: Cannot find the model collection $mdir" unless (-d $mdir);
+
+    # make sure this collection does not already exist
+    if (-e $cdir) {
+	print STDOUT "ERROR: This collection already exists\n";
+	die "\n";
+    }
+
+    # start creating the collection
+    print STDOUT "\nCreating the collection $collection...\n" unless $quiet;
+    &traverse_dir ($mdir, $cdir);
+    print STDOUT "\nThe new collection was created successfully at\n" unless $quiet;
+    print STDOUT "$cdir\n" unless $quiet;
+}
+
+&main ();
