diff -Naur ../eprints-3.3.6_original/perl_lib/EPrints/Apache/Rewrite.pm ./perl_lib/EPrints/Apache/Rewrite.pm
--- ../eprints-3.3.6_original/perl_lib/EPrints/Apache/Rewrite.pm	2011-09-21 12:18:16.000000000 +0200
+++ ./perl_lib/EPrints/Apache/Rewrite.pm	2012-02-22 11:09:52.323522905 +0100
@@ -278,6 +278,17 @@
 		return OK;
 	}
 
+	# PURE deposit api
+	if ( $uri =~ m! ^$urlpath/pda !x )
+	{
+		$r->handler( 'perl-script' );
+
+		$r->set_handlers( PerlResponseHandler => [ 'PDA::PDAHandler' ] ); 
+		
+		return OK;	
+
+	}
+
 	# URI redirection
 	if( $uri =~ m! ^$urlpath/id/(repository|dump)$ !x )
 	{
diff -Naur ../eprints-3.3.6_original/perl_lib/EPrints/Apache/Rewrite.pm.orig ./perl_lib/EPrints/Apache/Rewrite.pm.orig
--- ../eprints-3.3.6_original/perl_lib/EPrints/Apache/Rewrite.pm.orig	1970-01-01 01:00:00.000000000 +0100
+++ ./perl_lib/EPrints/Apache/Rewrite.pm.orig	2012-02-22 11:08:57.627522835 +0100
@@ -0,0 +1,701 @@
+######################################################################
+#
+# EPrints::Apache::Rewrite
+#
+######################################################################
+#
+#
+######################################################################
+
+
+=pod
+
+=head1 NAME
+
+B<EPrints::Apache::Rewrite> - rewrite cosmetic URL's to internally useful ones.
+
+=head1 DESCRIPTION
+
+This rewrites the URL apache receives based on certain things, such
+as the current language.
+
+Expands 
+/archive/00000123/*
+to 
+/archive/00/00/01/23/*
+
+and so forth.
+
+This should only ever be called from within the mod_perl system.
+
+This also causes some pages to be regenerated on demand, if they are stale.
+
+=over 4
+
+=cut
+
+package EPrints::Apache::Rewrite;
+
+use EPrints::Apache::AnApache; # exports apache constants
+
+use Data::Dumper;
+
+use strict;
+  
+sub handler 
+{
+	my( $r ) = @_;
+
+	my $repoid = $r->dir_config( "EPrints_ArchiveID" );
+	return DECLINED if !$repoid;
+
+	if( defined $EPrints::HANDLE )
+	{
+		$EPrints::HANDLE->init_from_request( $r );
+	}
+	else
+	{
+		EPrints->abort( __PACKAGE__."::handler was called before EPrints was initialised (you may need to re-run generate_apacheconf)" );
+	}
+
+	my $repository = $EPrints::HANDLE->current_repository();
+	if( !defined $repository )
+	{
+		EPrints->abort( "'$repoid' is not a valid repository identifier:\nPerlSetVar EPrints_ArchiveID $repoid" );
+	}
+
+	my $esec = $r->dir_config( "EPrints_Secure" );
+	my $secure = (defined $esec && $esec eq "yes" );
+	my $urlpath;
+	my $cgipath;
+	if( $secure ) 
+	{ 
+		$urlpath = $repository->get_conf( "https_root" );
+		$cgipath = $repository->get_conf( "https_cgiroot" );
+	}
+	else
+	{ 
+		$urlpath = $repository->get_conf( "http_root" );
+		$cgipath = $repository->get_conf( "http_cgiroot" );
+	}
+
+	my $uri = $r->uri;
+	{
+		$uri = eval { Encode::decode_utf8( $uri ) };
+		$uri = Encode::decode( "iso-8859-1", $uri ) if $@; # utf-8 failed
+	}
+
+	# Not an EPrints path (only applies if we're in a non-standard path)
+	if( $uri !~ /^(?:$urlpath)|(?:$cgipath)/ )
+	{
+		return DECLINED;
+	}
+
+	# Non-EPrints paths within our tree
+	my $exceptions = $repository->config( 'rewrite_exceptions' );
+	$exceptions = [] if !defined $exceptions;
+	foreach my $exppath ( @$exceptions )
+	{
+		next if $exppath eq '/cgi/'; # legacy
+		next if $exppath eq '/archive/'; # legacy
+		return DECLINED if( $uri =~ m/^$exppath/ );
+	}
+
+	# database needs updating
+	if( $r->is_initial_req && !$repository->get_database->is_latest_version )
+	{
+		my $msg = "Database schema is out of date: ./bin/epadmin upgrade ".$repository->get_id;
+		$repository->log( $msg );
+		EPrints::Apache::AnApache::send_status_line( $r, 500, "EPrints Database schema is out of date" );
+		return 500;
+	}
+
+	# 404 handler
+	$r->custom_response( Apache2::Const::NOT_FOUND, $repository->current_url( path => "cgi", "handle_404" ) );
+
+	my $args = $r->args;
+	$args = "" if !defined $args;
+	$args = "?$args" if length($args);
+
+	my $lang = EPrints::Session::get_session_language( $repository, $r );
+
+	my $rc = undef;
+	$repository->run_trigger( EPrints::Const::EP_TRIGGER_URL_REWRITE,
+		request => $r,
+		   lang => $lang,    # en
+		   args => $args,    # "" or "?foo=bar"
+		urlpath => $urlpath, # "" or "/subdir"
+		cgipath => $cgipath, # /cgi or /subdir/cgi
+		    uri => $uri,     # /foo/bar
+		 secure => $secure,  # boolean
+            return_code => \$rc,     # set to trigger a return
+	);
+	# if the trigger has set an return code
+	return $rc if defined $rc;
+
+	# /archive/ redirect
+	if( $uri =~ m! ^$urlpath/archive/(.*) !x )
+	{
+		return redir( $r, "$urlpath/$1$args" );
+	}
+
+	# don't respond to anything containing '/.'
+	if( $uri =~ /\/\./ )
+	{
+		return DECLINED;
+	}
+
+	# /perl/ redirect
+	my $perlpath = $cgipath;
+	$perlpath =~ s! /cgi\b ! /perl !x;
+	if( $uri =~ s! ^$perlpath !!x )
+	{
+		return redir( $r, "$cgipath$uri$args" );
+	}
+
+	# CGI
+	if( $uri =~ s! ^$cgipath !!x )
+	{
+		# redirect secure stuff
+		if( $repository->config( "securehost" ) && !$secure && $uri =~ s! ^/(
+			(?:users/)|
+			(?:change_user)|
+			(?:confirm)|
+			(?:register)|
+			(?:reset_password)|
+			(?:set_password)
+			) !!x )
+		{
+			my $https_redirect = $repository->current_url(
+				scheme => "https", 
+				host => 1,
+				path => "cgi",
+				"$1$uri" ) . $args;
+			return redir( $r, $https_redirect );
+		}
+
+		if( $repository->config( "use_mimetex" ) && $uri eq "mimetex.cgi" )
+		{
+			$r->handler('cgi-script');
+			$r->filename( $repository->config( "executables", "mimetex" ) );
+			return OK;
+		}
+
+		$r->filename( EPrints::Config::get( "cgi_path" ).$uri );
+
+		# !!!Warning!!!
+		# If path_info is defined before the Response stage Apache will
+		# attempt to find the file identified by path_info using an internal
+		# request (presumably to get the content-type). We don't want that to
+		# happen so we delay setting path_info until just before the response
+		# is generated.
+		my $path_info;
+		# strip the leading '/'
+		my( undef, @parts ) = split m! /+ !x, $uri;
+		PATH: foreach my $path (
+				$repository->config( "cgi_path" ),
+				EPrints::Config::get( "cgi_path" ),
+			)
+		{
+			for(my $i = $#parts; $i >= 0; --$i)
+			{
+				my $filename = join('/', $path, @parts[0..$i]);
+				if( -f $filename )
+				{
+					$r->filename( $filename );
+					$path_info = join('/', @parts[$i+1..$#parts]);
+					$path_info = '/' . $path_info if length($path_info);
+					last PATH;
+				}
+			}
+		}
+
+		if( $uri =~ m! ^/users\b !x )
+		{
+			$r->push_handlers(PerlAccessHandler => [
+				\&EPrints::Apache::Auth::authen,
+				\&EPrints::Apache::Auth::authz
+				] );
+		}
+
+		$r->handler('perl-script');
+
+		$r->set_handlers(PerlResponseHandler => [
+			# set path_info for the CGI script
+			sub { $_[0]->path_info( $path_info ); DECLINED },
+			'ModPerl::Registry'
+			]);
+
+		return OK;
+	}
+
+	# SWORD-APP
+	if( $uri =~ s! ^$urlpath/sword-app/servicedocument$ !!x )
+	{
+		$r->handler( 'perl-script' );
+
+		$r->set_handlers( PerlMapToStorageHandler => sub { OK } );
+
+		$r->push_handlers(PerlAccessHandler => [
+			\&EPrints::Apache::Auth::authen,
+			\&EPrints::Apache::Auth::authz
+			] );
+
+		$r->set_handlers( PerlResponseHandler => [ \&EPrints::Apache::CRUD::servicedocument ] );
+
+		return OK;
+	}
+
+	# robots.txt (nb. only works if site is in root / of domain.)
+	if( $uri =~ m! ^$urlpath/robots\.txt$ !x )
+	{
+		$r->handler( 'perl-script' );
+
+	 	$r->set_handlers(PerlResponseHandler => \&EPrints::Apache::RobotsTxt::handler );
+
+		return OK;
+	}
+
+	# sitemap.xml (nb. only works if site is in root / of domain.)
+	if( $uri =~ m! ^$urlpath/sitemap\.xml$ !x )
+	{
+		$r->handler( 'perl-script' );
+
+	 	$r->set_handlers(PerlResponseHandler => \&EPrints::Apache::SiteMap::handler );
+
+		return OK;
+	}
+
+
+	# REST
+	if( $uri =~ m! ^$urlpath/rest !x )
+	{
+		$r->handler( 'perl-script' );
+
+		$r->set_handlers( PerlMapToStorageHandler => sub { OK } );
+
+	 	$r->set_handlers(PerlResponseHandler => \&EPrints::Apache::REST::handler );
+		return OK;
+	}
+
+	# URI redirection
+	if( $uri =~ m! ^$urlpath/id/(repository|dump)$ !x )
+	{
+		my $file = $1;
+		my $accept = EPrints::Apache::AnApache::header_in( $r, "Accept" );
+		$accept = "application/rdf+xml" unless defined $accept;
+		my $can_accept = "list/triple";
+
+		my $plugin = content_negotiate_best_plugin( 
+			$repository, 
+			accept_header => $accept,
+			consider_summary_page => 0,
+			plugins => [$repository->get_plugins(
+				type => "Export",
+				is_visible => "all",
+				can_accept => $can_accept )]
+		);
+	
+		if( !defined $plugin )  { return NOT_FOUND; }
+
+		my $url = $repository->config( "http_cgiurl" )."/export/$file/".
+			$plugin->get_subtype."/".$repository->get_id.$plugin->param("suffix");
+
+		return redir_see_other( $r, $url );
+	}
+
+	if( $uri =~ m! ^$urlpath/id/([^\/]+)/(ext-.*)$ !x )
+	{
+		my $exttype = $1;
+		my $id = $2;
+		my $accept = EPrints::Apache::AnApache::header_in( $r, "Accept" );
+		$accept = "application/rdf+xml" unless defined $accept;
+
+		my $plugin = content_negotiate_best_plugin( 
+			$repository, 
+			accept_header => $accept,
+			consider_summary_page => 0,
+			plugins => [$repository->get_plugins(
+				type => "Export",
+				is_visible => "all",
+				can_accept => "list/triple" )]
+		);
+
+		if( !defined $plugin )  { return NOT_FOUND; }
+
+		my $fn = $id;
+		$fn=~s/\//_/g;
+		my $url = $repository->config( "http_cgiurl" )."/export/$exttype/".
+			$id."/".$plugin->get_subtype."/$fn".$plugin->param("suffix");
+
+		return redir_see_other( $r, $url );
+	}
+
+	if( $uri =~ s! ^$urlpath/id/contents$ !!x )
+	{
+		$r->pnotes( dataset => $repository->dataset( "eprint" ) );
+		$r->pnotes( uri => $uri );
+
+		my( $rc, $plugin ) =
+			EPrints::Apache::CRUD::content_negotiate_best_plugin( $r );
+
+		return $rc if $rc != OK;
+
+		$r->pnotes( plugin => $plugin );
+
+		$r->handler( 'perl-script' );
+
+		$r->set_handlers( PerlMapToStorageHandler => sub { OK } );
+
+		$r->push_handlers(PerlAccessHandler => [
+			\&EPrints::Apache::CRUD::authen,
+			\&EPrints::Apache::CRUD::authz
+			] );
+
+		$r->set_handlers( PerlResponseHandler => [ "EPrints::Apache::CRUD" ] );
+
+		return OK;
+	}
+
+	if( $uri =~ s! ^$urlpath/id/([^/]+)/([^/]+)/? !!x )
+	{
+		my( $datasetid, $id ) = ( $1, $2 );
+
+		my $dataset = $repository->get_dataset( $datasetid );
+		return NOT_FOUND if !defined $dataset;
+
+		($id, my @relations) = split /\./, $id;
+
+		my $dataobj = $dataset->dataobj( $id );
+		return NOT_FOUND if !defined $dataobj;
+
+		# get the real eprint dataset
+		if( $dataset->base_id eq "eprint" )
+		{
+			$dataset = $dataobj->get_dataset;
+		}
+
+		$r->pnotes( dataset => $dataset );
+		$r->pnotes( dataobj => $dataobj );
+		$r->pnotes( relations => \@relations );
+		$r->pnotes( uri => $uri );
+
+		my( $rc, $plugin ) =
+			EPrints::Apache::CRUD::content_negotiate_best_plugin( $r );
+
+		return $rc if $rc != OK;
+
+		$r->pnotes( plugin => $plugin );
+
+		$r->handler( 'perl-script' );
+
+		$r->set_handlers( PerlMapToStorageHandler => sub { OK } );
+
+		$r->push_handlers(PerlAccessHandler => [
+			\&EPrints::Apache::CRUD::authen,
+			\&EPrints::Apache::CRUD::authz
+			] );
+
+		$r->set_handlers( PerlResponseHandler => [ "EPrints::Apache::CRUD" ] );
+
+		return OK;
+	}
+
+	# /XX/ eprints
+	if( $uri =~ s! ^$urlpath/(0*)([1-9][0-9]*)\b !!x )  # ignore leading 0s
+	{
+		# It's an eprint...
+	
+		my $eprintid = $2;
+		my $eprint = $repository->dataset( "eprint" )->dataobj( $eprintid );
+		if( !defined $eprint )
+		{
+			return NOT_FOUND;
+		}
+
+		# redirect to canonical path - /XX/
+		if( !length($uri) )
+		{
+			return redir( $r, "$urlpath/$eprintid/$args" );
+		}
+		elsif( length($1) )
+		{
+			return redir( $r, "$urlpath/$eprintid$uri$args" );
+		}
+
+		if( $uri =~ s! ^/(0*)([1-9][0-9]*)\b !!x )
+		{
+			# It's a document....			
+
+			my $pos = $2;
+			my $doc = EPrints::DataObj::Document::doc_with_eprintid_and_pos( $repository, $eprintid, $pos );
+			if( !defined $doc )
+			{
+				return NOT_FOUND;
+			}
+
+			if( !length($uri) )
+			{
+				return redir( $r, "$urlpath/$eprintid/$pos/$args" );
+			}
+			elsif( length($1) )
+			{
+				return redir( $r, "$urlpath/$eprintid/$pos$uri$args" );
+			}
+
+			$uri =~ s! ^([^/]*)/ !!x;
+			my @relations = grep { length($_) } split /\./, $1;
+
+			my $filename = $uri;
+
+			$r->pnotes( eprint => $eprint );
+			$r->pnotes( document => $doc );
+			$r->pnotes( dataobj => $doc );
+			$r->pnotes( filename => $filename );
+
+			$r->handler('perl-script');
+
+			# no real file to map to
+			$r->set_handlers(PerlMapToStorageHandler => sub { OK } );
+
+			$r->push_handlers(PerlAccessHandler => [
+				\&EPrints::Apache::Auth::authen_doc,
+				\&EPrints::Apache::Auth::authz_doc
+				] );
+
+		 	$r->set_handlers(PerlResponseHandler => \&EPrints::Apache::Storage::handler );
+
+			$r->pool->cleanup_register(\&EPrints::Apache::LogHandler::document, $r);
+
+			my $rc = undef;
+			$repository->run_trigger( EPrints::Const::EP_TRIGGER_DOC_URL_REWRITE,
+				# same as for URL_REWRITE
+				request => $r,
+				   lang => $lang,    # en
+				   args => $args,    # "" or "?foo=bar"
+				urlpath => $urlpath, # "" or "/subdir"
+				cgipath => $cgipath, # /cgi or /subdir/cgi
+				    uri => $uri,     # /foo/bar
+				 secure => $secure,  # boolean
+			    return_code => \$rc,     # set to trigger a return
+				# extra bits
+				 eprint => $eprint,
+			       document => $doc,
+			       filename => $filename,
+			      relations => \@relations,
+			);
+
+			# if the trigger has set an return code
+			return $rc if defined $rc;
+	
+			# This way of getting a status from a trigger turns out to cause 
+			# problems and is included as a legacy feature only. Don't use it, 
+			# set ${$opts->{return_code}} = 404; or whatever, instead.
+			return $r->status if $r->status != 200;
+		}
+		# OK, It's the EPrints abstract page (or something whacky like /23/fish)
+		else
+		{
+			my $path = "/archive/" . $eprint->store_path();
+			EPrints::Update::Abstract::update( $repository, $lang, $eprint->id, $path );
+
+			if( $uri =~ m! /$ !x )
+			{
+				$uri .= "index.html";
+			}
+			$r->filename( $eprint->_htmlpath( $lang ) . $uri );
+
+			if( $uri =~ /\.html$/ )
+			{
+				$r->pnotes( eprint => $eprint );
+
+				$r->handler('perl-script');
+				$r->set_handlers(PerlResponseHandler => [ 'EPrints::Apache::Template' ] );
+
+				# log abstract hits
+				$r->pool->cleanup_register(\&EPrints::Apache::LogHandler::eprint, $r);
+			}
+		}
+
+		return OK;
+	}
+
+	# apache 2 does not automatically look for index.html so we have to do it ourselves
+	my $localpath = $uri;
+	$localpath =~ s! ^$urlpath !!x;
+	if( $uri =~ m! /$ !x )
+	{
+		$localpath.="index.html";
+	}
+	$r->filename( $repository->get_conf( "htdocs_path" )."/".$lang.$localpath );
+
+	if( $uri =~ m! ^$urlpath/view(/|\$.*) !x )
+	{
+		$uri =~ s! ^$urlpath !!x;
+		# redirect /foo to /foo/ 
+		if( $uri eq "/view" || $uri =~ m! ^/view/[^/]+$ !x )
+		{
+			return redir( $r, "$urlpath$uri/" );
+		}
+
+		local $repository->{preparing_static_page} = 1; 
+		my $filename = EPrints::Update::Views::update_view_file( $repository, $lang, $localpath, $uri );
+		return NOT_FOUND if( !defined $filename );
+
+		$r->filename( $filename );
+	}
+	else
+	{
+		local $repository->{preparing_static_page} = 1; 
+		EPrints::Update::Static::update_static_file( $repository, $lang, $localpath );
+	}
+
+	# set all static files to +1 month expiry
+	$r->headers_out->{Expires} = Apache2::Util::ht_time(
+		$r->pool,
+		time + 30 * 86400
+	);
+	# let Firefox cache secure, static files
+	if( $repository->get_secure )
+	{
+		$r->headers_out->{'Cache-Control'} = 'public';
+	}
+
+	if( $r->filename =~ /\.html$/ )
+	{
+		my $ua = $r->headers_in->{'User-Agent'};
+		if( $ua && $ua =~ /MSIE ([0-9]{1,}[\.0-9]{0,})/ && $1 >= 8.0 )
+		{
+			$r->headers_out->{'X-UA-Compatible'} = "IE=9";
+		}
+		$r->handler('perl-script');
+		$r->set_handlers(PerlResponseHandler => [ 'EPrints::Apache::Template' ] );
+	}
+
+	return OK;
+}
+
+sub redir
+{
+	my( $r, $url ) = @_;
+
+	EPrints::Apache::AnApache::send_status_line( $r, 302, "Found" );
+	EPrints::Apache::AnApache::header_out( $r, "Location", $url );
+	EPrints::Apache::AnApache::send_http_header( $r );
+	return DONE;
+} 
+
+sub redir_see_other
+{
+	my( $r, $url ) = @_;
+
+	EPrints::Apache::AnApache::send_status_line( $r, 303, "See Other" );
+	EPrints::Apache::AnApache::header_out( $r, "Location", $url );
+	EPrints::Apache::AnApache::send_http_header( $r );
+	return DONE;
+} 
+
+sub content_negotiate_best_plugin
+{
+	my( $repository, %o ) = @_;
+
+	EPrints::Utils::process_parameters( \%o, {
+		accept_header => "*REQUIRED*",
+		consider_summary_page => 1, 
+		plugins => "*REQUIRED*",
+	 } );
+
+	my $pset = {};
+	if( $o{consider_summary_page} )
+	{
+		$pset->{"text/html"} = { qs=>0.99, DEFAULT_SUMMARY_PAGE=>1 };
+	}
+
+	foreach my $plugin ( @{$o{plugins}} )
+	{
+		my( $type, %params ) = split( /\s*[;=]\s*/, $plugin->{mimetype} );
+	
+		next if( defined $pset->{$type} && $pset->{$type}->{qs} >= $plugin->{qs} );
+		$pset->{$type} = $plugin;
+	}
+	my @pset_order = sort { $pset->{$b}->{qs} <=> $pset->{$a}->{qs} } keys %{$pset};
+
+	my $accepts = { "*/*" => { q=>0.000001 }};
+	CHOICE: foreach my $choice ( split( /\s*,\s*/, $o{accept_header} ) )
+	{
+		my( $mime, %params ) = split( /\s*[;=]\s*/, $choice );
+		$params{q} = 1 unless defined $params{q};
+		my $match = $pset->{$mime};
+		$params{q} *= defined $match ? $match->{qs} : 0;
+		$accepts->{$mime} = \%params;
+	}
+	my @acc_order = sort { $accepts->{$b}->{q} <=> $accepts->{$a}->{q} } keys %{$accepts};
+
+	my $match;
+	CHOICE: foreach my $choice ( @acc_order )
+	{
+		if( $pset->{$choice} ) 
+		{
+			$match = $pset->{$choice};
+			last CHOICE;
+		}
+
+		if( $choice eq "*/*" )
+		{
+			$match = $pset->{$pset_order[0]};
+			last CHOICE;
+		}
+
+		if( $choice =~ s/\*[^\/]+$// )
+		{
+			foreach my $type ( @pset_order )
+			{
+				if( $choice eq substr( $type, 0, length $type ) )
+				{
+					$match = $pset->{$type};
+					last CHOICE;
+				}
+			}
+		}
+	}
+
+	if( $match->{DEFAULT_SUMMARY_PAGE} )
+	{
+		return "DEFAULT_SUMMARY_PAGE";
+	}
+
+	return $match; 
+}
+
+
+1;
+
+
+
+=head1 COPYRIGHT
+
+=for COPYRIGHT BEGIN
+
+Copyright 2000-2011 University of Southampton.
+
+=for COPYRIGHT END
+
+=for LICENSE BEGIN
+
+This file is part of EPrints L<http://www.eprints.org/>.
+
+EPrints is free software: you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as published
+by the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+EPrints 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 Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with EPrints.  If not, see L<http://www.gnu.org/licenses/>.
+
+=for LICENSE END
+
diff -Naur ../eprints-3.3.6_original/perl_lib/EPrints/Repository.pm ./perl_lib/EPrints/Repository.pm
--- ../eprints-3.3.6_original/perl_lib/EPrints/Repository.pm	2011-09-21 12:18:16.000000000 +0200
+++ ./perl_lib/EPrints/Repository.pm	2012-02-22 11:09:52.323522905 +0100
@@ -5351,6 +5351,7 @@
 		"$urlpath/id/",
 		"$urlpath/view/",
 		"$urlpath/sword-app/",
+		"$urlpath/pda/",
 		"$urlpath/thumbnails/";
 
 	foreach my $exppath ( @exceptions )
diff -Naur ../eprints-3.3.6_original/perl_lib/PDA/PDAHandler.pm ./perl_lib/PDA/PDAHandler.pm
--- ../eprints-3.3.6_original/perl_lib/PDA/PDAHandler.pm	1970-01-01 01:00:00.000000000 +0100
+++ ./perl_lib/PDA/PDAHandler.pm	2012-08-09 09:00:03.000000000 +0200
@@ -0,0 +1,729 @@
+package PDA::PDAHandler;
+
+use EPrints;
+use EPrints::XML;
+use EPrints::Apache::AnApache;
+use EPrints::Sword::Utils;
+use EPrints::Plugin::Import;
+use EPrints::Plugin::Import::DefaultXML;
+use EPrints::Plugin::Import::XML;
+EPrints::DataObj::User;
+
+use IO::File;
+
+use PDA::XMLImportManager;
+use PDA::XMLUserIdAugmentingImportManager;
+use PDA::PDAUtil;
+
+use strict;
+
+my @DOC_FIELDS = qw(formatdesc security license date_embargo content);
+my @PRESERVE_FIELDS = qw();
+my @CLEAR_FIELDS = qw();
+
+sub handler {
+	my $request = shift;
+
+	my $session = new EPrints::Session(2);
+	if ( !defined $session ) {
+		print STDERR
+		  "\n[PDA] [INTERNAL-ERROR] Could not create session object.";
+		$request->status(500);
+		return Apache2::Const::DONE;
+	}
+
+	# Authenticating user and behalf user
+	my $response = authenticate( $session, $request );
+
+	# $response->{status_code} defined means there was an authentication error
+	if ( defined $response->{error} ) {
+		if ( defined $response->{error}->{x_error_code} ) {
+			$request->headers_out->{'X-Error-Code'} = $response->{error}->{x_error_code};
+		}
+
+		if ( $response->{error}->{status_code} == 401 ) {
+			$request->headers_out->{'WWW-Authenticate'} = 'Basic realm="PDA"';
+		}
+
+		$request->status( $response->{error}->{status_code} );
+
+		$session->terminate;
+		return Apache2::Const::DONE;
+	}
+
+	my $uri = $request->uri;
+	if($uri =~ /^\/pda\/handler/)
+	{
+		$uri = substr($uri, 12)
+	}
+	
+	my @uri_elements = split('/', $uri);
+	
+	my $user = $response->{owner};
+		
+	my $util = new PDA::PDAUtil($request, $session, $user->get_id(), @uri_elements);
+	my $result = Apache2::Const::DONE;
+	
+	# GET    /                            - Gets repository information (XML document)
+	# POST   /archive                     - Deposits an eprint into the given dataset
+	# GET    /eprint/1                    - Retrieves an eprint
+	# PUT    /eprint/1                    - Update an eprint
+	# DELETE /eprint/1                    - Delete an eprint
+	# POST   /eprint/1/documents/file.pdf - Adds a new document to the eprint
+	# GET    /eprint/1/documents/1        - Reads a file from the eprint
+	# PUT    /eprint/1/documents/1        - Updates file metadata
+	# DELETE /eprint/1/documents/1        - Removes a document from the eprint
+
+	if($uri =~ /^\/$/)                      { serve_identify($util);                  }
+	elsif($uri =~ /^\/\w+$/)                { serve_dataset($util);                   }
+	elsif($uri =~ /^\/\w+\/\d+$/)           { serve_eprint($util);                    }
+	elsif($uri =~ /^\/\w+\/\d+\/documents/) { serve_documents($util);                 }
+	else                    { $util->serve_response(404, "Unknown URI pattern $uri"); }
+	
+	$session->terminate;
+	return $result;
+}
+
+# -------------------------------- Identify --------------------------------
+
+sub serve_identify
+{
+	my($util) = @_;
+	my $session = $util->{session};
+	
+	my $response_element = $session->make_element("identify");
+	my $version_element  = $session->make_element("version");
+	$version_element->appendChild($session->make_text("1.0.0"));
+	$response_element->appendChild($version_element);
+
+	$util->send_xml($response_element);
+}
+
+# -------------------------------- Dataset --------------------------------
+
+sub serve_dataset
+{
+	my($util) = @_;
+	my $session = $util->{session};
+
+	# load dataset
+	my $dataset = $util->get_dataset();
+	return if not $dataset;
+	
+	# check that this is actually a put
+	my $method = $ENV{REQUEST_METHOD};
+	if(not $method eq 'PUT') {
+		$util->serve_response(404, "Method $method not supported on dataset");
+		return;
+	}
+
+	# intialize plugin
+	my $xml_plugin = new PDA::XMLUserIdAugmentingImportManager('session'=>$session, 'owner'=>$util->get_owner());
+	
+	# stream data to tmp file
+	my $tmp_file = "/tmp/pdahandler.$$.data";
+	my $buffer = "";
+	my $tmp_filehandle;
+	open($tmp_filehandle, ">" . $tmp_file);
+	while($util->{request}->read($buffer, 1024))
+	{
+		print $tmp_filehandle $buffer;
+	}
+	close($tmp_filehandle);
+	
+	# and translate XML to a data object
+	open($tmp_filehandle, "<" . $tmp_file);
+	my $publication_list = $xml_plugin->input_fh(
+		dataset=>$dataset
+		, fh=>$tmp_filehandle
+	);
+	close($tmp_filehandle);
+	unlink($tmp_file);
+	my $eprint_id = $publication_list->{ids}[0];
+	my $eprint = $dataset->get_object($session, $eprint_id);
+	$eprint->set_value('userid', $util->get_owner());
+	$eprint->commit();
+
+	# send success XML
+	my $response_element = $session->make_element("response");
+	my $ids_element  = $session->make_element("ids");
+	my $id_element  = $session->make_element("id");
+	$id_element->appendChild( $session->make_text($eprint_id) );
+	$ids_element->appendChild($id_element);
+	$response_element->appendChild($ids_element);
+	
+	$util->send_xml($response_element);
+}
+
+# -------------------------------- EPrint --------------------------------
+
+sub serve_eprint
+{
+	my($util) = @_;
+	my $session = $util->{session};
+
+	# load dataset
+	my $dataset = $util->get_dataset();
+	return if not $dataset;
+	
+	# load eprint
+	my $eprint = $util->get_eprint($dataset);
+	return if not $eprint;
+
+	# switch operation based on method
+	my $method = $ENV{REQUEST_METHOD};
+	if($method eq 'GET')       { serve_eprint_get($util, $eprint);       }
+	elsif($method eq 'PUT')    { serve_eprint_put($util, $eprint);       }
+	elsif($method eq 'DELETE') { serve_eprint_delete($util, $eprint);    }
+	else                       { $util->serve_response(404, "Method $method not available on eprint"); }
+}
+
+sub serve_eprint_get
+{
+	my($util, $eprint) = @_;
+	
+	my $xml = $eprint->to_xml(
+		'no_xmlns'=>0
+		, 'embed'=>0
+	);
+	
+	$util->send_xml($xml);
+}
+
+sub serve_eprint_put
+{
+	my($util, $eprint) = @_;
+	my $eprint_id = $eprint->get_id();
+	my $dataset = $eprint->get_dataset();
+	
+	# intialize plugin
+	my $xml_plugin = new EPrints::Plugin::Import::XML('session'=>$util->{session});
+	
+	# create fake import manager
+	my $xml_import_manager = new PDA::XMLImportManager($util->{session}, $xml_plugin, $eprint);
+	
+	# create XML handler
+	my $handler = {
+		dataset => $dataset,
+		state => 'toplevel',
+		plugin => $xml_import_manager,
+		depth => 0,
+		tmpfiles => [],
+		imported => [], };
+	bless $handler, "EPrints::Plugin::Import::DefaultXML::Handler";
+
+	# stream data to tmp file
+	my $tmp_file = "/tmp/pdahandler.$$.data";
+	my $buffer = "";
+	my $tmp_filehandle;
+	open($tmp_filehandle, ">" . $tmp_file);
+	while($util->{request}->read($buffer, 1024))
+	{
+		print $tmp_filehandle $buffer;
+	}
+	close($tmp_filehandle);
+
+	# parse xml
+	open($tmp_filehandle, "<" . $tmp_file);
+	eval { EPrints::XML::event_parse( $tmp_filehandle, $handler ) };
+	close($tmp_filehandle);
+	unlink($tmp_file);
+	if ($@ and $@ ne "\n") # die if parsing failed
+	{
+		$util->serve_response(500, $@);
+		return;
+	}
+	my $epdata = $xml_import_manager->{epdata};
+	
+	# remove old values
+	foreach my $field ( @{$dataset->{fields}} )
+	{
+		if( ! grep {$_ eq $field->{name}} @CLEAR_FIELDS)
+		{
+			next if grep {$_ eq $field->{name}} @PRESERVE_FIELDS;
+			next if grep {$_ eq $field} @{$dataset->{system_fields}};
+			next if $field->is_virtual;
+		}
+		$field->set_value( $eprint, undef );
+	}
+	
+	# and update eprint with new values
+	foreach my $fieldname (keys %$epdata)
+	{
+		if( $dataset->has_field( $fieldname ) )
+		{
+			# Can't currently set_value on subobjects
+			my $field = $dataset->get_field( $fieldname );
+			next if $field->is_type( "subobject" );
+			$eprint->set_value( $fieldname, $epdata->{$fieldname} );
+		}
+	}
+	my $success = $eprint->commit();
+	if( !$success )
+	{
+		$util->serve_response(500, $success);
+		return;
+	}
+		
+	$util->serve_response(200, "ePrint with id $eprint_id is updated");
+}
+
+sub serve_eprint_delete
+{
+	my($util, $eprint) = @_;
+	
+	my $eprint_id = $eprint->get_id();
+
+    my $status = $eprint->get_value("eprint_status");
+
+    # If status is archive, don't delete, but move to deleted status (UKPURE-912)
+    if ($status eq "archive") {
+        $eprint->move_to_deletion();
+        my $result = $eprint->commit();
+        if ($result) {
+            $util->serve_response(200, "ePrint with id $eprint_id is marked as deleted");
+        } else {
+            $util->serve_response(500, "Unable to mark ePrint with id $eprint_id as deleted");
+        }
+    }
+    else {  # If status != archive, go on and remove the eprint
+	    my $result = $eprint->remove();
+    	if($result) {
+	    	$util->serve_response(200, "ePrint with id $eprint_id is removed");
+    	} else {
+	    	$util->serve_response(500, "Unable to remove ePrint with id $eprint_id");
+    	}
+    }
+}
+
+# -------------------------------- Documents --------------------------------
+sub serve_documents
+{
+	my($util) = @_;
+
+	# load dataset
+	my $dataset = $util->get_dataset();
+	return if not $dataset;
+	
+	# load eprint
+	my $eprint = $util->get_eprint($dataset);
+	return if not $eprint;
+	
+	# switch operation based on method
+	my $method = $ENV{REQUEST_METHOD};
+	if($method eq 'GET')       { serve_documents_get($util, $eprint);    }
+	elsif($method eq 'POST')   { serve_documents_post($util, $eprint);   }
+	elsif($method eq 'PUT')    { serve_documents_put($util, $dataset, $eprint);   }
+	elsif($method eq 'DELETE') { serve_documents_delete($util, $eprint); }
+	else                       { $util->serve_response(404, "Method $method not available on document"); }
+}
+
+sub serve_documents_get
+{
+	my($util, $eprint) = @_;
+	my $document_id = $util->{uri_elements}->[4];
+	
+	# Find document
+	my $document = get_document($util, $eprint, $document_id);
+	return if not $document;
+
+	# Find filename
+	my $filename = $util->{uri_elements}->[5]; # first from URI
+	if($filename eq undef)
+	{
+		$filename = $document->get_main(); # Then from main file
+	}
+	my %files = $document->files(); 
+	if($filename eq undef)
+	{
+		my @file_names = keys %files; # And finally we just take the first file
+		if(scalar @file_names eq 0)
+		{
+			$util->serve_response(404, "No files associated with document");
+			return;
+		}
+		$filename = $file_names[0];
+	}
+
+	# Create document path
+	my $path = $document->local_path."/".$filename;
+	
+	# And send file
+	$util->{request}->content_type($document->get_value("format"));
+	$util->{request}->headers_out->{'Content-Length'} = $files{$filename}; 
+	$util->{request}->sendfile($path);
+}
+
+sub serve_documents_post
+{
+	my($util, $eprint) = @_;
+	my $session = $util->{session};
+	my $repository = $util->{repository};
+	my $request = $util->{request};
+	my $filename = $util->{uri_elements}->[4];
+
+	# Create base document data
+	my $doc_data = { eprintid => $eprint->get_id };
+	$doc_data->{format} = $repository->call( 'guess_doc_type', $session, $filename);
+	
+	# description
+	if($util->get_request_param('description')) 
+	{
+		$doc_data->{formatdesc} = $util->get_request_param('description');
+	}
+
+	# embargo
+	if($util->get_request_param('embargoDate')) 
+	{
+		$doc_data->{date_embargo} = $util->get_request_param('embargoDate');
+	}
+
+	# visibility
+	if($util->get_request_param('visibility') and $util->get_request_param('visibility') ne 'public') 
+	{
+		$doc_data->{security} = $util->get_request_param('visibility');
+	}
+
+	# document version
+	if($util->get_request_param('documentVersion')) 
+	{
+		$doc_data->{content} = $util->get_request_param('documentVersion');
+	}
+	
+	# license
+	if($util->get_request_param('license')) 
+	{
+		$doc_data->{license} = $util->get_request_param('license');
+	}
+
+	# Create document object
+	my $doc_dataset = $repository->get_dataset('document');
+	my $document = $doc_dataset->create_object( $util->{session}, $doc_data );
+	if( !defined $document )
+	{
+		$util->serve_response(500, "Create document failed");
+		return;
+	}
+	
+	# Download file to a tmp file
+	my $tmp_file = "/tmp/pdahandler.$$.data";
+	my $buffer = "";
+	my $tmp_filehandle;
+	open($tmp_filehandle, ">" . $tmp_file);
+	while($request->read($buffer, 1024))
+	{
+		print $tmp_filehandle $buffer;
+	}
+	close($tmp_filehandle);
+
+	my $filesize = -s $tmp_file;
+	my $preserve_path = 'false';
+	
+	# And stream it into the repository
+    
+	open($tmp_filehandle, "<" . $tmp_file);
+	my $success = $document->upload($tmp_filehandle, $filename, $preserve_path, $filesize);
+	if( !$success )
+	{
+		$document->remove();
+		close($tmp_filehandle);
+		unlink($tmp_file);
+		$util->serve_response(500, "Upload failed");
+		return;
+	}
+	close($tmp_filehandle);
+	unlink($tmp_file);
+	
+	# send success XML
+	my $response_element = $session->make_element("response");
+	my $ids_element  = $session->make_element("ids");
+	
+	my $id_element  = $session->make_element("id");
+	$id_element->appendChild( $session->make_text($document->get_value("docid")) );
+	$ids_element->appendChild($id_element);
+	$response_element->appendChild($ids_element);
+	
+	$util->send_xml($response_element);
+}
+
+sub serve_documents_put
+{
+	my($util, $dataset, $eprint) = @_;
+	my $session = $util->{session};
+	my $repository = $util->{repository};
+	my $request = $util->{request};
+
+
+	# Find document
+	my $document_id = $util->{uri_elements}->[4];
+	my $document = get_document($util, $eprint, $document_id);
+	return if not $document;
+	
+	# Find filename
+	my $filename = $util->{uri_elements}->[5]; # first from URI
+	if($filename eq undef)
+	{
+		$filename = $document->get_main(); # Then from main file
+	}
+	my %files = $document->files(); 
+	if($filename eq undef)
+	{
+		my @file_names = keys %files; # And finally we just take the first file
+		if(scalar @file_names eq 0)
+		{
+			$util->serve_response(404, "No files associated with document");
+			return;
+		}
+		$filename = $file_names[0];
+	}
+
+	# Parse posted XML
+	my $doc = parse_posted_xml_to_dom($util, $eprint, $dataset);
+	return if not $doc;
+
+	# Extract fields from xml	
+	my $root = $doc->documentElement;
+	my $epdata = {};
+	foreach my $element ( $root->getChildNodes )
+	{
+		next unless EPrints::XML::is_dom( $element, "Element" ); # we only want elements
+		
+		my $name = $element->nodeName;
+		my $t = '';
+		foreach my $cnode ( $element->getChildNodes )
+		{
+			if( EPrints::XML::is_dom( $cnode,"Text" ) )
+			{
+				$t.=$cnode->nodeValue;
+			}
+		}
+		$epdata->{$name} = $t;
+	}
+	EPrints::XML::dispose($doc);
+		
+	
+	# Update document
+	foreach my $fieldname (@DOC_FIELDS)
+	{
+		$document->set_value($fieldname, $epdata->{$fieldname});
+	}
+
+	my $success = $document->commit();
+	if( !$success )
+	{
+		$util->serve_response(500, $success);
+		return;
+	}
+		
+	$util->serve_response(200, "document with id $document_id is updated");
+}
+
+sub serve_documents_delete
+{
+	my($util, $eprint) = @_;
+	my $document_id = $util->{uri_elements}->[4];
+	
+	# Find document
+	my $document = get_document($util, $eprint, $document_id);
+	return if not $document;
+	
+	# Check for filename (only delete that file)
+	my $filename = $util->{uri_elements}->[5];
+	if($filename)
+	{
+		my %files = $document->files();
+		my $files_size = keys %files;
+		if($files_size > 1) # if we got more than one file, we just remove the file and leave the document
+		{
+			my $success = $document->remove_file($filename);
+			if($success) {
+				$util->serve_response(200, "File with name $filename is removed");
+			} else {
+				$util->serve_response(500, "Unable to remove file with name $filename: " . $success);
+			}
+			return;
+		}
+	}
+	
+	# And remove it
+	my $success = $document->remove();
+	if($success) {
+		$util->serve_response(200, "Document with id $document_id is removed");
+	} else {
+		$util->serve_response(500, "Unable to remove document with id $document_id");
+	}
+}
+
+sub get_document
+{
+	my($util, $eprint, $document_id) = @_;
+	
+	# Loop through documents finding the right one
+	foreach my $doc ( $eprint->get_all_documents )
+	{
+		return $doc if $doc->get_value("docid") eq $document_id;
+	}
+	
+	# Did not find the right one
+	$util->serve_response(404, "Unable to find document with id $document_id");
+	return undef;
+}
+
+sub parse_posted_xml_to_dom 
+{
+	my($util, $eprint, $dataset) = @_;
+	
+	# stream data to tmp file
+	my $tmp_file = "/tmp/pdahandler.$$.data";
+	my $buffer = "";
+	my $tmp_filehandle;
+	open($tmp_filehandle, ">" . $tmp_file);
+	while($util->{request}->read($buffer, 1024))
+	{
+		print $tmp_filehandle $buffer;
+	}
+	close($tmp_filehandle);
+	
+	# parse to dom
+	my $doc;
+	eval { $doc = EPrints::XML::parse_xml("$tmp_file"); };
+
+	unlink($tmp_file);
+
+	if( $@ )
+	{
+		$util->serve_response(500, $@);
+		return;
+	}
+	
+	return $doc;
+}
+
+sub authenticate
+{
+	my ( $session, $request ) = @_;
+
+	my %response;
+
+	my $authen = EPrints::Apache::AnApache::header_in( $request, 'Authorization' );
+
+	$response{verbose_desc} = "";
+
+        if(!defined $authen)
+        {
+		$response{error} = { 	
+					status_code => 401, 
+					x_error_code => "ErrorAuth",
+					error_href => "http://eprints.org/sword/error/ErrorAuth",
+					no_auth => 1, 
+				   };
+
+		$response{verbose_desc} .= "[ERROR] No authentication found in the headers.\n";
+		return \%response;
+        }
+
+	# Check we have Basic authentication sent in the headers, and decode the Base64 string:
+        if($authen =~ /^Basic\ (.*)$/)
+        {
+                $authen = $1;
+        }
+        my $decode_authen = MIME::Base64::decode_base64( $authen );
+        if(!defined $decode_authen)
+        {
+		$response{error} = { 	
+					status_code => 401, 
+					x_error_code => "ErrorAuth",
+					error_href => "http://eprints.org/sword/error/ErrorAuth",
+				   };
+		$response{verbose_desc} .= "[ERROR] Authentication failed (invalid base64 encoding).\n";
+                return \%response;
+        }
+
+        my $username;
+        my $password;
+
+	if($decode_authen =~ /^(\w+)\:(\w+)$/)
+        {
+                $username = $1;
+                $password = $2;
+        }
+        else
+        {
+		$response{error} = { 	
+					status_code => 401, 
+					x_error_code => "ErrorAuth",
+					error_href => "http://eprints.org/sword/error/ErrorAuth",
+				   };
+		$response{verbose_desc} .= "[ERROR] Authentication failed (invalid base64 encoding).\n";
+                return \%response;
+        }
+
+	unless( $session->valid_login( $username, $password ) )
+	{
+		$response{error} = {
+					status_code => 401, 
+					x_error_code => "ErrorAuth",
+					error_href => "http://eprints.org/sword/error/ErrorAuth",
+				   };
+		$response{verbose_desc} .= "[ERROR] Authentication failed.\n";
+                return \%response;
+        }
+
+        my $user = EPrints::DataObj::User::user_with_username( $session, $username );
+
+	# This error could be a 500 Internal Error since the previous check ($db->valid_login) succeeded.
+        if(!defined $user)
+        {
+		$response{error} = {
+					status_code => 401, 
+					x_error_code => "ErrorAuth",
+					error_href => "http://eprints.org/sword/error/ErrorAuth",
+				   };
+		$response{verbose_desc} .= "[ERROR] Authentication failed.\n";
+                return \%response;
+        }
+
+	# Now check we have a behalf user set, and whether the mediated deposit is allowed
+        my $xbehalf = EPrints::Apache::AnApache::header_in( $request, 'X-On-Behalf-Of' );
+        if(defined $xbehalf)
+        {
+		my $behalf_user = EPrints::DataObj::User::user_with_username( $session, $xbehalf );
+
+	        if(!defined $behalf_user)
+		{
+			$response{error} = {
+					status_code => 401, 
+					x_error_code => "TargetOwnerUnknown",
+					error_href => "http://purl.org/net/sword/error/TargetOwnerUnknown",
+				   };
+
+			$response{verbose_desc} .= "[ERROR] Unknown user for mediation: '".$xbehalf."'\n";
+	                return \%response;
+		}
+
+		if(!can_user_behalf( $session, $user->get_value( "username" ), $behalf_user->get_value( "username" ) ))
+		{
+			$response{error} = {
+					status_code => 403, 
+					x_error_code => "TargetOwnerUnknown",
+					error_href => "http://eprints.org/sword/error/MediationForbidden",
+				   };
+			$response{verbose_desc} .= "[ERROR] The user '".$user->get_value( "username" )."' cannot deposit on behalf of user '".$behalf_user->get_value("username")."'\n";
+			return \%response;
+		}
+
+		$response{depositor} = $user;
+		$response{owner} = $behalf_user;
+	}
+	else
+	{
+		$response{owner} = $user;
+	}
+
+	$response{verbose_desc} .= "[OK] Authentication successful.\n";
+
+	return \%response;
+}
+
+1;
+
diff -Naur ../eprints-3.3.6_original/perl_lib/PDA/PDAUtil.pm ./perl_lib/PDA/PDAUtil.pm
--- ../eprints-3.3.6_original/perl_lib/PDA/PDAUtil.pm	1970-01-01 01:00:00.000000000 +0100
+++ ./perl_lib/PDA/PDAUtil.pm	2012-05-08 12:33:24.000000000 +0200
@@ -0,0 +1,126 @@
+package PDA::PDAUtil;
+
+use strict;
+
+use URI::Escape;
+
+sub new
+{
+	my($class, $request, $session, $owner, @uri_elements) = @_;
+
+	my $self = {};
+	bless $self, $class;
+
+	$self->{session} = $session;
+	$self->{request} = $request;
+	$self->{repository} = $session->get_repository;
+	$self->{owner} = $owner;
+	$self->{uri_elements} = \@uri_elements;
+
+	return $self;
+}
+
+# -------------------------------- Utility Methods --------------------------------
+
+sub get_dataset
+{
+	my($self) = @_;
+	
+	my $dataset_name = $self->{uri_elements}->[1];
+
+	# load dataset
+	my $dataset = $self->{repository}->get_dataset($dataset_name);
+	if($dataset eq undef) {
+		serve_response(404, "Unknown dataset " . $dataset_name);
+	}
+	
+	return $dataset;
+}
+
+sub get_eprint
+{
+	my($self, $dataset) = @_;
+
+	my $eprint_id = $self->{uri_elements}->[2];
+	
+	# load eprint
+	my $eprint = $dataset->get_object($self->{session}, $eprint_id);
+	if($eprint eq undef) {
+		$self->serve_response(404, "Unkown eprint $eprint_id in dataset");
+		return;
+	}
+	
+	return $eprint;
+}
+
+sub serve_response
+{
+	my($self, $code, $msg) = @_;
+
+	# response element
+	my $response_element = $self->{session}->make_element("response");
+	
+	my $code_element  = $self->{session}->make_element("code");
+	$code_element->appendChild($self->{session}->make_text($code));
+	$response_element->appendChild($code_element);
+	
+	if($code ne 200) {
+		my $element = $self->{session}->make_element("error");
+		$element->appendChild($self->{session}->make_text($msg));
+		$response_element->appendChild($element);
+	} else {
+		my $element = $self->{session}->make_element("message");
+		$element->appendChild($self->{session}->make_text($msg));
+		$response_element->appendChild($element);
+	}
+	
+
+	$self->send_xml($response_element);
+	
+	$self->{request}->status($code);
+}
+
+sub send_xml
+{
+	my( $self, $xml ) = @_;
+	
+	my $content = '<?xml version="1.0" encoding=\'utf-8\'?>'. "\n" . $xml->toString();
+
+	my $xmlsize = length $content;
+	$self->{request}->content_type('application/xml');
+	# unable to report content length because length does not return the correct number of bytes for UTF-8 data
+	#$request->headers_out->{'Content-Length'} = $xmlsize; 
+
+	# sending data...
+	$self->{request}->puts($content);
+}
+
+sub get_owner
+{
+	my( $self ) = @_;
+	
+	return $self->{owner};
+}
+
+sub get_request_param
+{
+	my( $self, $param ) = @_;
+	
+	my $param_string = $self->{request}->args;
+	return undef if not $param_string;
+
+	# special case for + which is used instead of spaces	
+	$param_string =~ s/\+/ /g;
+	
+	my @key_value_strings = split('&', $param_string);
+	my %params = {};
+	foreach my $key_value (@key_value_strings)
+	{
+		my ($key, $value) = split('=', $key_value);
+		%params->{$key} = uri_unescape($value);
+	}
+	
+	return %params->{$param};	
+}
+
+1;
\ No newline at end of file
diff -Naur ../eprints-3.3.6_original/perl_lib/PDA/XMLImportManager.pm ./perl_lib/PDA/XMLImportManager.pm
--- ../eprints-3.3.6_original/perl_lib/PDA/XMLImportManager.pm	1970-01-01 01:00:00.000000000 +0100
+++ ./perl_lib/PDA/XMLImportManager.pm	2012-08-09 09:38:05.000000000 +0200
@@ -0,0 +1,44 @@
+package PDA::XMLImportManager;
+
+use strict;
+
+sub new
+{
+	my($class, $session, $plugin, $eprint) = @_;
+
+	my $self = {};
+	bless $self, $class;
+
+	$self->{session} = $session;
+	$self->{plugin} = $plugin;
+	$self->{eprint} = $eprint;
+
+	return $self;
+}
+
+sub epdata_to_dataobj
+{
+	my($self, $dataset, $epdata) = @_;
+
+	# store epdata
+	$self->{epdata} = $epdata;
+
+	# fake it and return the original eprint, we wont create the real one until later
+	return $self->{eprint};
+}
+
+sub top_level_tag
+{
+	my($self, $dataset) = @_;
+
+	return $self->{plugin}->top_level_tag($dataset);
+}
+
+sub unknown_start_element
+{
+	my($self, $found, $expected) = @_;
+
+	$self->{plugin}->unknown_start_element($found, $expected);
+}
+
+1;
diff -Naur ../eprints-3.3.6_original/perl_lib/PDA/XMLUserIdAugmentingImportManager.pm ./perl_lib/PDA/XMLUserIdAugmentingImportManager.pm
--- ../eprints-3.3.6_original/perl_lib/PDA/XMLUserIdAugmentingImportManager.pm	1970-01-01 01:00:00.000000000 +0100
+++ ./perl_lib/PDA/XMLUserIdAugmentingImportManager.pm	2012-05-08 12:33:24.000000000 +0200
@@ -0,0 +1,27 @@
+package PDA::XMLUserIdAugmentingImportManager;
+
+use strict;
+
+use EPrints::Plugin::Import::XML;
+
+our @ISA = qw/ EPrints::Plugin::Import::XML /;
+
+sub new
+{
+	my( $class, %params) = @_;
+
+	my $self = $class->SUPER::new(%params);
+	$self->{owner} = %params->{owner};
+
+	return $self;
+}
+
+sub xml_to_epdata
+{
+	my( $self, $dataset, $xml ) = @_;
+	
+	my $epdata = $self->SUPER::xml_to_epdata( @_[1..$#_] );
+	$epdata->{userid} = $self->{owner};
+	
+	return $epdata;
+}
\ No newline at end of file
