From 8ea781a7a364ea81f73ba2fbc9d5228e562c410e Mon Sep 17 00:00:00 2001 From: asmecher Date: Fri, 5 Feb 2010 23:14:20 +0000 Subject: [PATCH] #5036# Added swordapp-php library --- lib/libraries.txt | 5 + lib/swordapp/LICENCE | 33 +++ lib/swordapp/README | 149 +++++++++++ lib/swordapp/collection.php | 52 ++++ lib/swordapp/packager_mets_swap.php | 315 +++++++++++++++++++++++ lib/swordapp/swordappclient.php | 141 ++++++++++ lib/swordapp/swordappentry.php | 154 +++++++++++ lib/swordapp/swordapperrordocument.php | 30 +++ lib/swordapp/swordapplibraryversion.php | 3 + lib/swordapp/swordappservicedocument.php | 82 ++++++ lib/swordapp/utils.php | 13 + lib/swordapp/workspace.php | 67 +++++ 12 files changed, 1044 insertions(+) create mode 100644 lib/swordapp/LICENCE create mode 100644 lib/swordapp/README create mode 100644 lib/swordapp/collection.php create mode 100644 lib/swordapp/packager_mets_swap.php create mode 100644 lib/swordapp/swordappclient.php create mode 100644 lib/swordapp/swordappentry.php create mode 100644 lib/swordapp/swordapperrordocument.php create mode 100644 lib/swordapp/swordapplibraryversion.php create mode 100644 lib/swordapp/swordappservicedocument.php create mode 100644 lib/swordapp/utils.php create mode 100644 lib/swordapp/workspace.php 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
\n"); + fwrite($fh, "\t\t\t
\n"); + for ($i = 0; $i < $this->sac_filecount; $i++) { + fwrite($fh, "\t\t\t\t\n"); + } + fwrite($fh, "\t\t\t
\n"); + fwrite($fh, "\t\t
\n"); + fwrite($fh, "\t
\n"); + } + + function writeFooter($fh) { + fwrite($fh, "
\n"); + } + + function valueString($value) { + return "" . + $value . + "\n"; + } + + function valueStringSesURI($sesURI, $value) { + return "" . + $value . + "\n"; + } + + function statement($fh, $propertyURI, $value) { + fwrite($fh, "\n" . + $value . + "\n"); + } + + function statementValueURI($fh, $propertyURI, $value) { + fwrite($fh, "\n"); + } + + function statementVesURI($fh, $propertyURI, $vesURI, $value) { + fwrite($fh, "\n" . + $value . + "\n"); + } + + function statementVesURIValueURI($fh, $propertyURI, $vesURI, $value) { + fwrite($fh, "\n"); + } + + function clean($data) { + return str_replace(''', ''', htmlspecialchars($data, ENT_QUOTES)); + } +} +?> diff --git a/lib/swordapp/swordappclient.php b/lib/swordapp/swordappclient.php new file mode 100644 index 00000000000..4bc9d6d3e88 --- /dev/null +++ b/lib/swordapp/swordappclient.php @@ -0,0 +1,141 @@ +getMessage() . ")"); + } + } else { + $sac_sdresponse = new SWORDAPPServiceDocument($sac_url, $sac_status); + } + + // Return the servicedocument object + return $sac_sdresponse; + } + + // Perform a deposit to the specified url, with the sepcified credentials, + // on-behlf-of the specified user, and with the given file and formatnamespace and noop setting + function deposit($sac_url, $sac_u, $sac_p, $sac_obo, $sac_fname, + $sac_packaging= '', $sac_contenttype = '', + $sac_noop = false, $sac_verbose = false) { + // Perform the deposit + $sac_curl = curl_init(); + + // To see debugging infomation, un-comment the following line + //curl_setopt($sac_curl, CURLOPT_VERBOSE, 1); + + curl_setopt($sac_curl, CURLOPT_URL, $sac_url); + curl_setopt($sac_curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($sac_curl, CURLOPT_POST, true); + if(!empty($sac_u) && !empty($sac_p)) { + curl_setopt($sac_curl, CURLOPT_USERPWD, $sac_u . ":" . $sac_p); + } + $headers = array(); + global $sal_version; + array_push($headers, "User-Agent: SWORDAPP PHP library (version " . $sal_version . ") " . + "http://php.swordapp.org/"); + $sac_md5 = md5_file($sac_fname); + array_push($headers, "Content-MD5: " . $sac_md5); + if (!empty($sac_obo)) { + array_push($headers, "X-On-Behalf-Of: " . $sac_obo); + } + if (!empty($sac_packaging)) { + array_push($headers, "X-Packaging: " . $sac_packaging); + } + if (!empty($sac_contenttype)) { + array_push($headers, "Content-Type: " . $sac_contenttype); + } + if ($sac_noop == true) { + array_push($headers, "X-No-Op: true"); + } + if ($sac_verbose == true) { + array_push($headers, "X-Verbose: true"); + } + $index = strpos(strrev($sac_fname), '/'); + if ($index) { + $index = strlen($sac_fname) - $index; + $sac_fname_trimmed = substr($sac_fname, $index); + } else { + $sac_filename_trimmed = $sac_fname; + } + array_push($headers, "Content-Disposition: filename=" . $sac_fname_trimmed); + curl_setopt($sac_curl, CURLOPT_READDATA, fopen($sac_fname, 'rb')); + array_push($headers, 'Transfer-Encoding: chunked'); + curl_setopt($sac_curl, CURLOPT_HTTPHEADER, $headers); + + $sac_resp = curl_exec($sac_curl); + $sac_status = curl_getinfo($sac_curl, CURLINFO_HTTP_CODE); + curl_close($sac_curl); + + // Parse the result + $sac_dresponse = new SWORDAPPEntry($sac_status, $sac_resp); + + // Was it a succesful result? + if (($sac_status >= 200) || ($sac_status < 300)) { + try { + // Get the deposit results + $sac_xml = @new SimpleXMLElement($sac_resp); + $sac_ns = $sac_xml->getNamespaces(true); + + // Build the deposit response object + $sac_dresponse->buildhierarchy($sac_xml, $sac_ns); + } catch (Exception $e) { + throw new Exception("Error parsing response entry (" . $e->getMessage() . ")"); + } + } else { + try { + // Parse the result + $sac_dresponse = new SWORDAPPErrorDocument($sac_status, $sac_resp); + + // Get the deposit results + $sac_xml = @new SimpleXMLElement($sac_resp); + $sac_ns = $sac_xml->getNamespaces(true); + + // Build the deposit response object + $sac_dresponse->buildhierarchy($sac_xml, $sac_ns); + } catch (Exception $e) { + throw new Exception("Error parsing error document (" . $e->getMessage() . ")"); + } + } + + // Return the deposit object + return $sac_dresponse; + } +} + +?> diff --git a/lib/swordapp/swordappentry.php b/lib/swordapp/swordappentry.php new file mode 100644 index 00000000000..63f8a27a36e --- /dev/null +++ b/lib/swordapp/swordappentry.php @@ -0,0 +1,154 @@ +sac_status = $sac_newstatus; + + // Store the xml + $this->sac_xml = $sac_thexml; + + // Store the status message + switch($this->sac_status) { + case 201: + $this->sac_statusmessage = "Created"; + break; + case 401: + $this->sac_statusmessage = "Unauthorized"; + break; + case 412: + $this->sac_statusmessage = "Precondition failed"; + break; + case 413: + $this->sac_statusmessage = "Request entity too large"; + break; + case 415: + $this->sac_statusmessage = "Unsupported media type"; + break; + default: + $this->sac_statusmessage = "Unknown erorr (status code " . $this->sac_status . ")"; + break; + } + + // Initalise arrays + $this->sac_authors = array(); + $this->sac_contributors = array(); + $this->sac_links = array(); + + // Assume noOp is false unless we change it later + $this->sac_noOp = false; + } + + // Build the workspace hierarchy + function buildhierarchy($sac_dr, $sac_ns) { + // Set the default namespace + $sac_dr->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom'); + + // Parse the results + $this->sac_id = $sac_dr->children($sac_ns['atom'])->id; + $sac_contentbits = $sac_dr->xpath("atom:content"); + if (!empty($sac_contentbits)) { + $this->sac_content_src = $sac_contentbits[0]['src']; + $this->sac_content_type = $sac_contentbits[0]['type']; + } + + // Store the authors + foreach ($sac_dr->children($sac_ns['atom'])->author as $sac_author) { + $sac_theauthor = $sac_author->children($sac_ns['atom'])->name . ""; + $this->sac_authors[] = $sac_theauthor; + } + + // Store the contributors + foreach ($sac_dr->children($sac_ns['atom'])->contributor as $sac_contributor) { + $sac_thecontributor = $sac_contributor->children($sac_ns['atom'])->name . ""; + $this->sac_contributors[] = $sac_thecontributor; + } + + // Store the links + foreach ($sac_dr->xpath("atom:link") as $sac_link) { + $this->sac_links[] = sac_clean($sac_link[0]['href']); + } + + // Store the title and summary + $this->sac_title = sac_clean($sac_dr->children($sac_ns['atom'])->title); + $this->sac_summary = sac_clean($sac_dr->children($sac_ns['atom'])->summary); + + // Store the updated date + $this->sac_updated = $sac_dr->children($sac_ns['atom'])->updated; + + // Store the rights + $this->sac_rights = sac_clean($sac_dr->children($sac_ns['atom'])->rights); + + // Store the format namespace + $this->sac_packaging = $sac_dr->children($sac_ns['sword'])->packaging; + + // Store the generator + $this->sac_generator = sac_clean($sac_dr->children($sac_ns['atom'])->generator); + $sac_gen = $sac_dr->xpath("atom:generator"); + if (!empty($sac_gen)) { $this->sac_generator_uri = $sac_gen[0]['uri']; } + + // Store the user agent + $this->sac_useragent = sac_clean($sac_dr->children($sac_ns['sword'])->userAgent); + + // Store the noOp status + if (strtolower((string)$sac_dr->children($sac_ns['sword'])->noOp) == 'true') { + $this->sac_noOp = true; + } + } +} + +?> diff --git a/lib/swordapp/swordapperrordocument.php b/lib/swordapp/swordapperrordocument.php new file mode 100644 index 00000000000..3065348b30b --- /dev/null +++ b/lib/swordapp/swordapperrordocument.php @@ -0,0 +1,30 @@ +attributes() as $key => $value) { + if ($key == 'href') { + //$this->sac_erroruri = (string)$value; + } + } + $this->sac_erroruri = (string)$sac_dr->attributes()->href; + } +} + +?> diff --git a/lib/swordapp/swordapplibraryversion.php b/lib/swordapp/swordapplibraryversion.php new file mode 100644 index 00000000000..abf5e215f8f --- /dev/null +++ b/lib/swordapp/swordapplibraryversion.php @@ -0,0 +1,3 @@ + diff --git a/lib/swordapp/swordappservicedocument.php b/lib/swordapp/swordappservicedocument.php new file mode 100644 index 00000000000..76d92f85e3d --- /dev/null +++ b/lib/swordapp/swordappservicedocument.php @@ -0,0 +1,82 @@ +sac_url = $sac_theurl; + + // Store the status + $this->sac_status = $sac_newstatus; + + // Store the raw xml + $this->sac_xml = $sac_thexml; + + // Store the status message + switch($this->sac_status) { + case 200: + $this->sac_statusmessage = "OK"; + break; + case 401: + $this->sac_statusmessage = "Unauthorized"; + break; + case 404: + $this->sac_statusmessage = "Service document not found"; + break; + default: + $this->sac_statusmessage = "Unknown erorr (status code " . $this->sac_status . ")"; + break; + } + + // Parse the xml if there is some + if ($sac_thexml != '') { + $sac_xml = @new SimpleXMLElement($sac_thexml); + $sac_ns = $sac_xml->getNamespaces(true); + $this->sac_version = $sac_xml->children($sac_ns['sword'])->version; + $this->sac_verbose = $sac_xml->children($sac_ns['sword'])->verbose; + $this->sac_noop = $sac_xml->children($sac_ns['sword'])->noOp; + $this->sac_maxuploadsize = $sac_xml->children($sac_ns['sword'])->maxUploadSize; + + // Build the workspaces + $sac_ws = $sac_xml->children($sac_ns['app']); + foreach ($sac_ws as $sac_workspace) { + $sac_newworkspace = new Workspace( + $sac_workspace->children($sac_ns['atom'])->title); + $sac_newworkspace->buildhierarchy($sac_workspace->children($sac_ns['app']), $sac_ns); + $this->sac_workspaces[] = $sac_newworkspace; + } + } + } +} + +?> diff --git a/lib/swordapp/utils.php b/lib/swordapp/utils.php new file mode 100644 index 00000000000..98d4489c89d --- /dev/null +++ b/lib/swordapp/utils.php @@ -0,0 +1,13 @@ + diff --git a/lib/swordapp/workspace.php b/lib/swordapp/workspace.php new file mode 100644 index 00000000000..8342b29b0bf --- /dev/null +++ b/lib/swordapp/workspace.php @@ -0,0 +1,67 @@ +sac_workspacetitle = $sac_newworkspacetitle; + } + + // Build the collection hierarchy + function buildhierarchy($sac_colls, $sac_ns) { + // Build the collections + foreach ($sac_colls as $sac_collection) { + // Create the new collection object + $sac_newcollection = new Collection(sac_clean($sac_collection->children($sac_ns['atom'])->title)); + + // The location of the service document + //var_dump($sac_colls); + $href = $sac_collection->xpath("@href"); + $sac_newcollection->sac_href = $href[0]['href']; + + // An array of the accepted deposit types + foreach ($sac_collection->accept as $sac_accept) { + $sac_newcollection->sac_accept[] = $sac_accept; + } + + // An array of the accepted packages + foreach ($sac_collection->xpath("sword:acceptPackaging") as $sac_acceptpackaging) { + $sac_newcollection->addAcceptPackaging($sac_acceptpackaging[0]); + } + + // Add the collection policy + $sac_newcollection->sac_collpolicy = sac_clean($sac_collection->children($sac_ns['sword'])->collectionPolicy); + + // Add the collection abstract + // Check if dcterms is in the known namspaces. If not, might not be an abstract + if (array_key_exists('dcterms', $sac_ns)) { + $sac_newcollection->sac_abstract = sac_clean($sac_collection->children($sac_ns['dcterms'])->abstract); + } + + // Find out if mediation is allowed + if ($sac_collection->children($sac_ns['sword'])->mediation == 'true') { + $sac_newcollection->sac_mediation = true; + } else { + $sac_newcollection->sac_mediation = false; + } + + // Add a nested service document if there is one + $sac_newcollection->sac_service = sac_clean($sac_collection->children($sac_ns['sword'])->service); + + // Add to the collections in this workspace + $this->sac_collections[] = $sac_newcollection; + } + } +} + +?>