Index: main/trunk/package-kits/scripts/perllib/Greenstone/Directory.pm
===================================================================
--- main/trunk/package-kits/scripts/perllib/Greenstone/Directory.pm	(revision 29677)
+++ main/trunk/package-kits/scripts/perllib/Greenstone/Directory.pm	(revision 29677)
@@ -0,0 +1,68 @@
+package Greenstone::Directory;
+
+use strict;
+use warnings;
+use utf8;
+use base 'Exporter';
+
+use Greenstone::Config;
+
+our $VERSION = 1.00;
+our @EXPORT = ( );
+
+sub new {
+    my ($parent, $class, $name, %args) = @_;
+    ref $class and die "Constructor used as object method\n";
+    defined $name or die "A site must have a name\n";
+    my $self = bless (
+        {
+            name   => $name,
+            parent => $parent,
+        },
+        $class
+    );
+    for my $param (keys %args) {
+        $self->{$param} = $args{$param};
+    }
+    return $self;
+}
+
+sub list {
+    my $parent = shift;
+    ref $parent and die "Static method called on object\n";
+    my $sites = {};
+    my $dir = "$Greenstone::Config::GSDL3HOME/$parent";
+    opendir DH, $dir or die "Could not open sites directory '$dir'\n";
+    while (my $site = readdir DH) {
+        # skip hidden files and current/parent directory
+        $site =~ /^\./ and next;
+        # skip non-directories
+        -d "$dir/$site" or next;
+        # We don't really need to store anything more than the fact that the site exists
+        # So we just store nothing, which is enough to put the key in the hash
+        # (i.e. it acts as a hashset)
+        $sites->{$site} = ();
+    }
+    closedir DH;
+    return $sites;
+}
+
+sub exists {
+    my $self = shift;
+    my $sites = list $self->{parent};
+    return exists $sites->{$self->{name}};
+}
+
+sub dir {
+    my $self = shift;
+    return "$Greenstone::Config::GSDL3HOME/$self->{parent}/$self->{name}";
+}
+
+sub create {
+    my $self = shift;
+    $self->exists and return 0;
+    mkdir $self->dir or die "Failed to create directory: $!\n";
+    return 1;
+}
+
+1;
Index: main/trunk/package-kits/scripts/perllib/Greenstone/Site.pm
===================================================================
--- main/trunk/package-kits/scripts/perllib/Greenstone/Site.pm	(revision 29676)
+++ main/trunk/package-kits/scripts/perllib/Greenstone/Site.pm	(revision 29677)
@@ -4,59 +4,24 @@
 use warnings;
 use utf8;
-use base 'Exporter';
-
-use Greenstone::Config;
-use XML::Tidy;
-
-our $VERSION = 1.00;
-our @EXPORT = ( );
+use Greenstone::Directory;
+use Greenstone::XML::Tidy;
+use parent 'Greenstone::Directory';
+
+my $dir = "sites";
+
+sub new {
+    return Greenstone::Directory::new ($dir, @_);
+}
+
+sub list {
+    return Greenstone::Directory::list $dir;
+}
+
 my $configTemplate;
-
-sub new {
-    my ($class, $name, %args) = @_;
-    ref $class and die "Constructor used as object method\n";
-    defined $name or die "A site must have a name\n";
-    my $self = bless (
-        {
-            name => $name,
-        },
-        $class
-    );
-    for my $param (keys %args) {
-        $self->{$param} = $args{$param};
-    }
-    return $self;
-}
-
-sub list {
-    ref shift and die "Static method called on object\n";
-    my $sites = {};
-    my $dir = "$Greenstone::Config::GSDL3HOME/sites";
-    opendir DH, $dir or die "Could not open sites directory '$dir'\n";
-    while (my $site = readdir DH) {
-        # skip hidden files and current/parent directory
-        $site =~ /^\./ and next;
-        # skip non-directories
-        -d "$dir/$site" or next;
-        # We don't really need to store anything more than the fact that the site exists
-        # So we just store nothing, which is enough to put the key in the hash
-        # (i.e. it acts as a hashset)
-        $sites->{$site} = ();
-    }
-    closedir DH;
-    return $sites;
-}
-
-sub exists {
-    my $self = shift;
-    my $sites = list;
-    return exists $sites->{$self->{name}};
-}
 
 sub create {
     my $self = shift;
-    $self->exists and return 0;
-    my $dir = "$Greenstone::Config::GSDL3HOME/sites/$self->{name}";
-    mkdir $dir or die "Failed to create site directory: $!\n";
+    $self->SUPER::create or return 0;
+    my $dir = $self->dir;
     mkdir "$dir/collect" or die "Failed to create collections directory: $!\n";
     open FH, '>', "$dir/siteConfig.xml" or die "Failed to create site config: $!\n";
@@ -497,2 +462,3 @@
 };
 
+1;
Index: main/trunk/package-kits/scripts/perllib/Greenstone/XML/Tidy.pm
===================================================================
--- main/trunk/package-kits/scripts/perllib/Greenstone/XML/Tidy.pm	(revision 29677)
+++ main/trunk/package-kits/scripts/perllib/Greenstone/XML/Tidy.pm	(revision 29677)
@@ -0,0 +1,158 @@
+package Greenstone::XML::Tidy;
+
+use strict;
+use warnings;
+use utf8;
+use XML::Parser;
+use base 'Exporter';
+
+our $VERSION = 1.00;
+our @EXPORT = ( 'read_xml', 'write_xml' );
+ 
+# Reads the servlets partial XML file using XML::Parser,
+# Then converts the obtained data structure to a more readable one
+# Example conversion:
+=xml
+<servlet>
+  <servlet-name>library</servlet-name>
+  <description attribute="example">The standard gsdl3 library program</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>
+</servlet>
+=cut
+=data_structure
+{
+    'servlet' => {
+        'servlet-class' => 'org.greenstone.gsdl3.LibraryServlet',
+        'servlet-name' => 'library',
+        'description' => {
+            '.value' => 'The standard gsdl3 library program',
+            '.attr' => {
+                'attribute' => 'example'
+            }
+        },
+        'init-param' => [
+            {
+                'param-value' => 'library',
+                'param-name' => 'library_name'
+            },
+            {
+                'param-name' => 'site_name',
+                'param-value' => 'localsite'
+            }
+        ]
+    }
+}
+=cut
+sub read_xml {
+    my $FH = shift;
+    local $/ = undef;
+    my $xml = <$FH>;
+    # The xml needs a root element, so we wrap it in one
+    $xml='<__root__>' . $xml . '</__root__>';
+    # Parse the data using XML::Parser
+    my $data = new XML::Parser (Style => 'Tree')->parse ($xml);
+
+    sub tidy {
+        my %hash;
+        # If the element has attributes, add them to the hash
+        my $attr = shift;
+        if (scalar keys %$attr > 0) {
+            $hash{'.attr'} = $attr;
+        }
+        # Read any child elements or text value
+        while (@_) {
+            my $element = shift;
+            my $value   = shift;
+            if ($element eq 0) {
+                $value =~ /^\s*$/ || ($hash{'.value'} .= $value);
+            } else {
+                # If there is more than one of a single tupe of child element,
+                # That child element must become an array
+                if (defined $hash{$element}) {
+                    unless (ref $hash{$element} eq 'ARRAY') {
+                        $hash{$element} = [ $hash{$element} ];
+                    }
+                    push @{$hash{$element}}, tidy (@{$value});
+                } else {
+                    $hash{$element} = tidy (@{$value});
+                }
+            }
+        }
+        # If the element only has a value, it can become a scalar
+        if (scalar keys %hash == 1 and defined $hash{'.value'}) {
+            return $hash{'.value'};
+        }
+        return \%hash;
+    }
+    return tidy (@{@$data[1]});
+}
+
+# Writes a data structure to an XML file
+sub write_xml {
+    my ($hash, $FH) = @_;
+    select $FH;
+    sub open_tag {
+        my ($indent, $tag, $attr) = @_;
+        print $indent, "<", $tag;
+        if (defined $attr) {
+            for my $key (sort keys %$attr) {
+                print " ", $key, '="', $attr->{$key}, '"';
+            }
+        }
+        print ">";
+    }
+    sub write_element {
+        my ($indent, $hash) = @_;
+        for my $key (sort keys %$hash) {
+            $key eq '.attr' && next;
+            my $val = $hash->{$key};
+            $key eq '.value' && do {
+                print $val, "\n";
+                next;
+            };
+            for (ref $val) {
+                /^ARRAY$/ && do {
+                    for my $element (@$val) {
+                        open_tag ($indent, $key, $element->{'.attr'});
+                        for (ref $element) {
+                            /^HASH$/ && do {
+                                print "\n";
+                                write_element ("  $indent", $element);
+                                print $indent, "</", $key, ">\n";
+                                last;
+                            };
+                            print $element, "</", $key, ">\n";
+                        }
+                    }
+                    last;
+                };
+                /^HASH$/ && do {
+                    open_tag ($indent, $key, $val->{'.attr'});
+                    # If the element only has a value with attributes,
+                    # it can be formatted on one line
+                    if (scalar keys %$val == 2 and defined $val->{'.value'}) {
+                        print $val->{'.value'}, "</", $key, ">\n";
+                    } else {
+                        print "\n";
+                        write_element ("  $indent", $val);
+                        print $indent, "</", $key, ">\n";
+                    }
+                    last;
+                };
+                open_tag ($indent, $key);
+                print $val;
+                print "</", $key, ">\n";
+            }
+        }
+    }
+    write_element ("", $hash);
+    select STDOUT;
+}
Index: main/trunk/package-kits/scripts/perllib/XML/Tidy.pm
===================================================================
--- main/trunk/package-kits/scripts/perllib/XML/Tidy.pm	(revision 29676)
+++ 	(revision )
@@ -1,158 +1,0 @@
-package XML::Tidy;
-
-use strict;
-use warnings;
-use utf8;
-use XML::Parser;
-use base 'Exporter';
-
-our $VERSION = 1.00;
-our @EXPORT = ( 'read_xml', 'write_xml' );
- 
-# Reads the servlets partial XML file using XML::Parser,
-# Then converts the obtained data structure to a more readable one
-# Example conversion:
-=xml
-<servlet>
-  <servlet-name>library</servlet-name>
-  <description attribute="example">The standard gsdl3 library program</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>
-</servlet>
-=cut
-=data_structure
-{
-    'servlet' => {
-        'servlet-class' => 'org.greenstone.gsdl3.LibraryServlet',
-        'servlet-name' => 'library',
-        'description' => {
-            '.value' => 'The standard gsdl3 library program',
-            '.attr' => {
-                'attribute' => 'example'
-            }
-        },
-        'init-param' => [
-            {
-                'param-value' => 'library',
-                'param-name' => 'library_name'
-            },
-            {
-                'param-name' => 'site_name',
-                'param-value' => 'localsite'
-            }
-        ]
-    }
-}
-=cut
-sub read_xml {
-    my $FH = shift;
-    local $/ = undef;
-    my $xml = <$FH>;
-    # The xml needs a root element, so we wrap it in one
-    $xml='<__root__>' . $xml . '</__root__>';
-    # Parse the data using XML::Parser
-    my $data = new XML::Parser (Style => 'Tree')->parse ($xml);
-
-    sub tidy {
-        my %hash;
-        # If the element has attributes, add them to the hash
-        my $attr = shift;
-        if (scalar keys %$attr > 0) {
-            $hash{'.attr'} = $attr;
-        }
-        # Read any child elements or text value
-        while (@_) {
-            my $element = shift;
-            my $value   = shift;
-            if ($element eq 0) {
-                $value =~ /^\s*$/ || ($hash{'.value'} .= $value);
-            } else {
-                # If there is more than one of a single tupe of child element,
-                # That child element must become an array
-                if (defined $hash{$element}) {
-                    unless (ref $hash{$element} eq 'ARRAY') {
-                        $hash{$element} = [ $hash{$element} ];
-                    }
-                    push @{$hash{$element}}, tidy (@{$value});
-                } else {
-                    $hash{$element} = tidy (@{$value});
-                }
-            }
-        }
-        # If the element only has a value, it can become a scalar
-        if (scalar keys %hash == 1 and defined $hash{'.value'}) {
-            return $hash{'.value'};
-        }
-        return \%hash;
-    }
-    return tidy (@{@$data[1]});
-}
-
-# Writes a data structure to an XML file
-sub write_xml {
-    my ($hash, $FH) = @_;
-    select $FH;
-    sub open_tag {
-        my ($indent, $tag, $attr) = @_;
-        print $indent, "<", $tag;
-        if (defined $attr) {
-            for my $key (sort keys %$attr) {
-                print " ", $key, '="', $attr->{$key}, '"';
-            }
-        }
-        print ">";
-    }
-    sub write_element {
-        my ($indent, $hash) = @_;
-        for my $key (sort keys %$hash) {
-            $key eq '.attr' && next;
-            my $val = $hash->{$key};
-            $key eq '.value' && do {
-                print $val, "\n";
-                next;
-            };
-            for (ref $val) {
-                /^ARRAY$/ && do {
-                    for my $element (@$val) {
-                        open_tag ($indent, $key, $element->{'.attr'});
-                        for (ref $element) {
-                            /^HASH$/ && do {
-                                print "\n";
-                                write_element ("  $indent", $element);
-                                print $indent, "</", $key, ">\n";
-                                last;
-                            };
-                            print $element, "</", $key, ">\n";
-                        }
-                    }
-                    last;
-                };
-                /^HASH$/ && do {
-                    open_tag ($indent, $key, $val->{'.attr'});
-                    # If the element only has a value with attributes,
-                    # it can be formatted on one line
-                    if (scalar keys %$val == 2 and defined $val->{'.value'}) {
-                        print $val->{'.value'}, "</", $key, ">\n";
-                    } else {
-                        print "\n";
-                        write_element ("  $indent", $val);
-                        print $indent, "</", $key, ">\n";
-                    }
-                    last;
-                };
-                open_tag ($indent, $key);
-                print $val;
-                print "</", $key, ">\n";
-            }
-        }
-    }
-    write_element ("", $hash);
-    select STDOUT;
-}
