diff --git a/lib/libraries.txt b/lib/libraries.txt
index 1fb9adf6c56..5c7b1075b64 100644
--- a/lib/libraries.txt
+++ b/lib/libraries.txt
@@ -19,3 +19,8 @@ PHPUTF8 UTF-8 Character Handling Library
* URL:
* Version: 0.5 (Aug 12, 2007)
* License: LGPL
+
+SWORD PHP API Library
+ * URL:
+ * Version: 0.9 (Oct 5, 2009)
+ * License: Modified BSD
diff --git a/lib/swordapp/LICENCE b/lib/swordapp/LICENCE
new file mode 100644
index 00000000000..4f807677b55
--- /dev/null
+++ b/lib/swordapp/LICENCE
@@ -0,0 +1,33 @@
+Copyright (c) 2008-2009, Stuart Lewis (stuart@stuartlewis.com)
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ - Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of the Author nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
diff --git a/lib/swordapp/README b/lib/swordapp/README
new file mode 100644
index 00000000000..61e298b593e
--- /dev/null
+++ b/lib/swordapp/README
@@ -0,0 +1,149 @@
+Welcome to the SWORDAPP PHP client library!
+-------------------------------------------
+Version: 0.9
+
+The SWORDAPP PHP client library is a PHP library designed to assist with the
+creation of SWORD deposit tools. The client library allows PHP code to easily
+make use of the two SWORD functions:
+
+ - GETting a Service Document
+ - POSTing a file into a repository
+
+The library was originally written by Stuart Lewis (stuart@stuartlewis.com) as
+part of the JISC funded SWORD2 project. Limited support for the library is
+availble via the sword-app-tech email list:
+
+ - https://lists.sourceforge.net/lists/listinfo/sword-app-tech
+
+
+Licence
+-------
+The library is licenced with a BSD licence. See the file LICENCE in the
+distribution directory.
+
+
+SWORD Compatibility
+-------------------
+This version of the library is compatable with SWORD version 1.3
+
+
+Prerequisites
+-------------
+This library requires:
+
+ - PHP version 5
+ + CURL extension
+ + SimpleXML extension
+ + ZIP extension (for the packager only)
+
+To test the library run the following from the command line to request a
+service document and deposit a package:
+
+ - php test-swordappclient.php
+
+ In order to use this test script you will need a username and password for a
+ SWORD repository. If you don't have one, you can sign up for one at
+ http://dspace.swordapp.org/jspui/register Once you have done so, enter your
+ email address and password in to the test-swordappclient.php script.
+
+ The library also comes with a packager to convert a file and metadata into
+ a package (zip file) containing the metadata encoded in METS and SWAP along
+ with the file.
+
+You can create a test deposit package by running:
+
+ - php test-packager-mets_swap.php
+
+
+How to use the library
+----------------------
+The easiest way to understand the library is to look at the
+test-swordappclient.php file which exercises all the functions and variables of
+the library.
+
+The two main methods of use are from swordappclient.php:
+
+ - function servicedocument(url, username, password, on-behalf-of-user)
+ - function deposit(url, username, password, on-behalf-of-user, filename,
+ [format_namespace, package_type, noop, verbose])
+
+The functions return a SWORDAPPServiceDocument, a SWORDAPPEntry or a
+SWORDAPPErrorDocument object as appropriate. These classes can then be
+interogated (e.g. $servicedocument->sac_workspaces).
+
+
+Examples
+--------
+Example SWORD applications are included in the examples directory:
+
+ - examples/imap-email/ An example client that reads emails from an IMAP
+ mail folder, and deposits them using SWORD.
+
+
+Changes
+-------
+0.9 (5th October 2009)
+ - Fixed typos in test-packager-mets_swap.php that meant it didn't create a
+ proper package
+ - Added some validation to the SWAP/METS packager to allow it to cope with
+ filenames containing ampersands
+ - Changed swordappservicedocument to build the servcedocument from the xml
+ response rather than having the swordappclient do the work. This allows
+ the service document to be parsed at a later time.
+ - Changed the swordappclient deposit method to stream the file being
+ deposited straight from disk rather than via memory to avoid using
+ excessive memory and potentially exceeding the PHP memory limit.
+
+0.8 (28th July 2009)
+ - Added example IMAP email application (/examples/imap-email/imap-email.php)
+
+0.7 (23rd June 2009)
+ - Added X-No-Op and X-Verbose facility to deposits in deposit method
+ - Added 'Content-Disposition: filename=' in the deposit method
+
+0.6 (29th April 2009)
+ - Corrected typo in deposit entry document http status response text
+ - Entry documents now do not require src and type attributes in the content
+ - Extended the METS/SWAP packager to contain more than one file
+ - Fixed swordappentry bug with undefined constants
+ - Fixed variable name typo in SWAP/METS packager in the the exception
+ thrown by the create method
+ - Client now accepts responses in the 2xx range, rather than just 201
+
+0.5 (12th December 2008)
+ - Upgraded support to SWORD version 1.3. Support for version 1.2 deprecated
+ - Changed sword:level to sword:version
+ - Added user-agent header to all transactions
+ - Added support for nested service documents into collection.php
+ - Added support for maxUplaodSize in service documents
+ - Added support for acceptPackaging in service documents
+ - Deposit process now sets X-Packaging header
+ - atom:generator now ready from entry, not from entry/source
+ - Error documents created when deposits fail
+ - Renamed swordappdeposit.php to swordappentry.php
+ - Added new class swordapperrordocument.php to handle error documents
+
+0.4 (30th November 2008)
+ - Fixes bug where atom documents using atom as a default namespace are not
+ parsed correctly
+ - Corrected typo in format namespace variable name
+ - Changed README and test-swordappclient.php to make user sign up for their
+ own SWORD user on a repository
+
+0.3 (3rd November 2008)
+ - Classes SWORDAPPServiceDocument and SWORDAPPDeposit now store the
+ raw XML returned for debudding ($sac_xml)
+ - The deposit function now accepts optional parameters for format-namespace
+ and content-disposition
+ - MD5 checksums are now created for deposited files and the Content-MD5 header
+ set
+ - Added copyrightHolder and bibliographicCitation elements to mets/swap
+ packager
+
+0.2 (28th October 2008)
+ - Added exception handling to swordappclient.php
+ - Created packager-mets_swap.php
+ - Renamed test files
+
+0.1 (20th September 2008)
+ - First release
diff --git a/lib/swordapp/collection.php b/lib/swordapp/collection.php
new file mode 100644
index 00000000000..6134939ef46
--- /dev/null
+++ b/lib/swordapp/collection.php
@@ -0,0 +1,52 @@
+sac_colltitle = sac_clean($sac_newcolltitle);
+
+ // Create the accepts arrays
+ $sac_accept = array();
+ $sac_acceptpackaging = array();
+ }
+
+ // Add a new supported packaging type
+ function addAcceptPackaging($ap) {
+ $format = (string)$ap[0];
+ $q = (string)$ap[0]['q'];
+ if (empty($q)) {
+ $q = "1.0";
+ }
+ $this->sac_acceptpackaging[$format] = $q;
+ }
+}
+
+?>
diff --git a/lib/swordapp/packager_mets_swap.php b/lib/swordapp/packager_mets_swap.php
new file mode 100644
index 00000000000..4ef6b2e2395
--- /dev/null
+++ b/lib/swordapp/packager_mets_swap.php
@@ -0,0 +1,315 @@
+sac_root_in = $sac_rootin;
+ $this->sac_dir_in = $sac_dirin;
+ $this->sac_root_out = $sac_rootout;
+ $this->sac_file_out = $sac_fileout;
+ $this->sac_creators = array();
+ $this->sac_files = array();
+ $this->sac_mimetypes = array();
+ $this->sac_filecount = 0;
+ }
+
+ function setType($sac_thetype) {
+ $this->sac_type = $sac_thetype;
+ }
+
+ function setTitle($sac_thetitle) {
+ $this->sac_title = $this->clean($sac_thetitle);
+ }
+
+ function setAbstract($sac_thetitle) {
+ $this->sac_abstract = $this->clean($sac_thetitle);
+ }
+
+ function addCreator($sac_creator) {
+ array_push($this->sac_creators, $this->clean($sac_creator));
+ }
+
+ function setIdentifier($sac_theidentifier) {
+ $this->sac_identifier = $sac_theidentifier;
+ }
+
+ function setStatusStatement($sac_thestatus) {
+ $this->sac_statusstatement = $sac_thestatus;
+ }
+
+ function setCopyrightHolder($sac_thecopyrightholder) {
+ $this->sac_copyrightholder = $sac_thecopyrightholder;
+ }
+
+ function setCustodian($sac_thecustodian) {
+ $this->sac_custodian = $this->clean($sac_thecustodian);
+ }
+
+ function setCitation($sac_thecitation) {
+ $this->sac_citation = $this->clean($sac_thecitation);
+ }
+
+ function setDateAvailable($sac_thedta) {
+ $this->sac_dateavailable = $sac_thedta;
+ }
+
+ function addFile($sac_thefile, $sac_themimetype) {
+ array_push($this->sac_files, $sac_thefile);
+ array_push($this->sac_mimetypes, $sac_themimetype);
+ $this->sac_filecount++;
+ }
+
+ function create() {
+ // Write the metadata (mets) file
+ $fh = @fopen($this->sac_root_in . '/' . $this->sac_dir_in . '/' . $this->sac_metadata_filename, 'w');
+ if (!$fh) {
+ throw new Exception("Error writing metadata file (" .
+ $this->sac_root_in . '/' . $this->sac_dir_in . $this->sac_metadata_filename . ")");
+ }
+ $this->writeHeader($fh);
+ $this->writeDmdSec($fh);
+ $this->writeFileGrp($fh);
+ $this->writeStructMap($fh);
+ $this->writeFooter($fh);
+ fclose($fh);
+
+ // Create the zipped package
+ $zip = new ZipArchive();
+ $zip->open($this->sac_root_out . '/' . $this->sac_file_out, ZIPARCHIVE::CREATE);
+ $zip->addFile($this->sac_root_in . '/' . $this->sac_dir_in . '/mets.xml',
+ 'mets.xml');
+ for ($i = 0; $i < $this->sac_filecount; $i++) {
+ $zip->addFile($this->sac_root_in . '/' . $this->sac_dir_in . '/' . $this->sac_files[$i],
+ $this->sac_files[$i]);
+ }
+ $zip->close();
+ }
+
+ function writeheader($fh) {
+ fwrite($fh, "\n");
+ fwrite($fh, "\n");
+ fwrite($fh, "\t\n");
+ fwrite($fh, "\t\t\n");
+ if (isset($this->sac_custodian)) { fwrite($fh, "\t\t\t$this->sac_custodian\n"); }
+ else { fwrite($fh, "\t\t\tUnknown\n"); }
+ fwrite($fh, "\t\t\n");
+ fwrite($fh, "\t\n");
+ }
+
+ function writeDmdSec($fh) {
+ fwrite($fh, "\n");
+ fwrite($fh, "\n");
+ fwrite($fh, "\n");
+ fwrite($fh, "\n");
+ fwrite($fh, "\n");
+
+ if (isset($this->sac_type)) {
+ $this->statementValueURI($fh,
+ "http://purl.org/dc/elements/1.1/type",
+ $this->sac_type);
+ }
+
+ if (isset($this->sac_title)) {
+ $this->statement($fh,
+ "http://purl.org/dc/elements/1.1/title",
+ $this->valueString($this->sac_title));
+ }
+
+ if (isset($this->sac_abstract)) {
+ $this->statement($fh,
+ "http://purl.org/dc/terms/abstract",
+ $this->valueString($this->sac_abstract));
+ }
+
+ foreach ($this->sac_creators as $sac_creator) {
+ $this->statement($fh,
+ "http://purl.org/dc/elements/1.1/creator",
+ $this->valueString($sac_creator));
+ }
+
+ if (isset($this->sac_identifier)) {
+ $this->statement($fh,
+ "http://purl.org/dc/elements/1.1/identifier",
+ $this->valueString($this->sac_identifier));
+ }
+
+ fwrite($fh, "\n");
+
+ fwrite($fh, "\n");
+
+ fwrite($fh, "\n");
+
+ $this->statementValueURI($fh,
+ "http://purl.org/dc/elements/1.1/type",
+ "http://purl.org/eprint/entityType/Expression");
+
+ $this->statementVesURI($fh,
+ "http://purl.org/dc/elements/1.1/language",
+ "http://purl.org/dc/terms/RFC3066",
+ $this->valueString("en"));
+
+ $this->statementVesURIValueURI($fh,
+ "http://purl.org/dc/elements/1.1/type",
+ "http://purl.org/eprint/terms/Type",
+ "http://purl.org/eprint/entityType/Expression");
+
+ if (isset($this->sac_dateavailable)) {
+ $this->statement($fh,
+ "http://purl.org/dc/terms/available",
+ $this->valueStringSesURI("http://purl.org/dc/terms/W3CDTF",
+ $this->sac_dateavailable));
+ }
+
+ if (isset($this->sac_statusstatement)) {
+ $this->statementVesURIValueURI($fh,
+ "http://purl.org/eprint/terms/Status",
+ "http://purl.org/eprint/terms/Status",
+ $this->sac_statusstatement);
+ }
+
+ if (isset($this->sac_copyrightholder)) {
+ $this->statement($fh,
+ "http://purl.org/eprint/terms/copyrightHolder",
+ $this->valueString($this->sac_copyrightholder));
+ }
+
+ if (isset($this->sac_citation)) {
+ $this->statement($fh,
+ "http://purl.org/eprint/terms/bibliographicCitation",
+ $this->valueString($this->sac_citation));
+ }
+
+ fwrite($fh, "\n");
+
+ fwrite($fh, "\n");
+ fwrite($fh, "\n");
+ fwrite($fh, "\n");
+ fwrite($fh, "\n");
+ }
+
+ function writeFileGrp($fh) {
+ fwrite($fh, "\t\n");
+ fwrite($fh, "\t\t\n");
+ for ($i = 0; $i < $this->sac_filecount; $i++) {
+ fwrite($fh, "\t\t\tsac_mimetypes[$i] . "\">\n");
+ fwrite($fh, "\t\t\t\tclean($this->sac_files[$i]) . "\" />\n");
+ fwrite($fh, "\t\t\t\n");
+ }
+ fwrite($fh, "\t\t\n");
+ fwrite($fh, "\t\n");
+ }
+
+ function writeStructMap($fh) {
+ fwrite($fh, "\t\n");
+ fwrite($fh, "\t\t