Index: gsdl/trunk/perllib/plugins/ReadXMLFile.pm
===================================================================
--- gsdl/trunk/perllib/plugins/ReadXMLFile.pm	(revision 15865)
+++ gsdl/trunk/perllib/plugins/ReadXMLFile.pm	(revision 15871)
@@ -1,5 +1,5 @@
 ###########################################################################
 #
-# XMLPlug.pm -- base class for XML plugins
+# ReadXMLFile.pm -- base class for XML plugins
 # A component of the Greenstone digital library software
 # from the New Zealand Digital Library Project at the 
@@ -24,7 +24,7 @@
 ###########################################################################
 
-package XMLPlug;
-
-use BasPlug;
+package ReadXMLFile;
+
+use BasePlugin;
 use doc;
 use strict;
@@ -32,5 +32,5 @@
 
 sub BEGIN {
-    @XMLPlug::ISA = ('BasPlug');
+    @ReadXMLFile::ISA = ('BasePlugin');
     unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
 }
@@ -40,16 +40,16 @@
 my $arguments =
     [ { 'name' => "process_exp",
-	'desc' => "{BasPlug.process_exp}",
+	'desc' => "{BasePlugin.process_exp}",
 	'type' => "regexp",
 	'deft' => &get_default_process_exp(),
 	'reqd' => "no" },
       { 'name' => "xslt",
-	'desc' => "{XMLPlug.xslt}",
+	'desc' => "{ReadXMLFile.xslt}",
 	'type' => "string",
 	'deft' => "",
 	'reqd' => "no" } ];
 
-my $options = { 'name'     => "XMLPlug",
-		'desc'     => "{XMLPlug.desc}",
+my $options = { 'name'     => "ReadXMLFile",
+		'desc'     => "{ReadXMLFile.desc}",
 		'abstract' => "yes",
 		'inherits' => "yes",
@@ -61,17 +61,17 @@
     push(@$pluginlist, $class);
 
-    if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
-    if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
-    
-    # $self is global for use within subroutines called by XML::Parser
-    my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);
+    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
+    push(@{$hashArgOptLists->{"OptList"}},$options);
+    
+    my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
 
     if ($self->{'info_only'}) {
-	# don't worry about any options etc
+	# don't worry about creating the XML parser as all we want is the 
+	# list of plugin options
 	return bless $self, $class;
     }
 
     my $parser = new XML::Parser('Style' => 'Stream',
-                                 'Pkg' => 'XMLPlug',
+                                 'Pkg' => 'ReadXMLFile',
                                  'PluginObj' => $self,
 				 'Handlers' => {'Char' => \&Char,
@@ -198,5 +198,5 @@
     if (defined $result) {
 	# we think we are processing this, but check that we actually are
-	my $filename = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/;
+	my $filename = $self->get_full_filename($base_dir, $file);
 
 	if ($self->check_doctype($filename)) {
@@ -207,4 +207,6 @@
 }
 
+# we need to implement read cos we are not just using process_exp to determine
+# whether to process this or not.
 sub read {
     my $self = shift (@_);  
@@ -213,9 +215,9 @@
 
     # Make sure we're processing the correct file, do blocking etc
-    my ($block_status,$filename) = $self->read_block(@_);    
+    my ($block_status,$filename_full_path) = $self->read_block(@_);    
     return $block_status if ((!defined $block_status) || ($block_status==0));
 
     ## check the doctype to see whether we really want to process the file
-    if (!$self->check_doctype($filename)) {
+    if (!$self->check_doctype($filename_full_path)) {
 	# this file is not for us
 	return undef;
@@ -225,5 +227,5 @@
     $self->{'base_dir'} = $base_dir;
     $self->{'file'} = $file;
-    $self->{'filename'} = $filename;
+    $self->{'filename'} = $filename_full_path;
     $self->{'processor'} = $processor;
     $self->{'metadata'} = $metadata;
@@ -233,5 +235,5 @@
 	if (defined $xslt && ($xslt ne "")) {
 	    # perform xslt
-	    my $transformed_xml = $self->apply_xslt($xslt,$filename);
+	    my $transformed_xml = $self->apply_xslt($xslt,$filename_full_path);
 
 	    # feed transformed file (now in memory as string) into XML parser
@@ -239,5 +241,5 @@
 	}
 	else {
-	    $self->{'parser'}->parsefile($filename);
+	    $self->{'parser'}->parsefile($filename_full_path);
 	}
     };
@@ -246,5 +248,5 @@
 
 	# parsefile may either croak somewhere in XML::Parser (e.g. because
-	# the document is not well formed) or die somewhere in XMLPlug or a
+	# the document is not well formed) or die somewhere in ReadXMLFile or a
 	# derived plugin (e.g. because we're attempting to process a
 	# document whose DOCTYPE is not meant for this plugin). For the
@@ -271,24 +273,4 @@
 }
 
-# the following two methods are for if you want to do the parsing from a
-# plugin that inherits from this. it seems that you can't call the parse 
-# methods directly. WHY???
-#
-# [Stefan 27/5/07] These two methods may not be necessary any more as I've
-# fixed XMLPlug so $self is no longer required to be a global variable
-# (that was why inheritance wasn't working quite right with XMLPlug I
-# think). I don't really know what other plugins rely on these methods
-# though so have left them here for now.
-sub parse_file {
-    my $self = shift (@_); 
-    my ($filename) = @_;
-    $self->{'parser'}->parsefile($filename);
-}
-
-sub parse_string {
-    my $self = shift (@_); 
-    my ($xml_string) = @_;
-    $self->{'parser'}->parse($xml_string);
-}
 
 sub get_default_process_exp {
@@ -344,5 +326,5 @@
 
     my ($expat, $name, $sysid, $pubid, $internal) = @_;
-    die "XMLPlug Cannot process XML document with DOCTYPE of $name";
+    die "ReadXMLFile Cannot process XML document with DOCTYPE of $name";
 }
 
@@ -395,4 +377,7 @@
     $self->{'doc_obj'} = new doc ($self->{'filename'}, "indexed_doc");
     $self->{'doc_obj'}->set_OIDtype ($self->{'processor'}->{'OIDtype'}, $self->{'processor'}->{'OIDmetadata'});
+    $self->{'doc_obj'}->add_utf8_metadata($self->{'doc_obj'}->get_top_section(), "Plugin", "$self->{'plugin_type'}");
+
+    # do we want other auto metadata here (see BasePlugin.read_into_doc_obj)
 }
 
@@ -400,4 +385,7 @@
     my $self = shift(@_);
     my $doc_obj = $self->{'doc_obj'};
+
+    # do we want other auto stuff here, see BasePlugin.read_into_doc_obj
+
     # include any metadata passed in from previous plugins 
     # note that this metadata is associated with the top level section
@@ -410,5 +398,5 @@
    
     # add an OID
-    $doc_obj->set_OID();
+    $self->add_OID();
     
     $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
@@ -419,4 +407,6 @@
     
     $self->{'num_processed'} ++;
+    undef $self->{'doc_obj'};
+    undef $doc_obj; # is this the same as above??
 }
 
