Skip to content

Commit

Permalink
#5036# Added swordapp-php library
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Feb 5, 2010
1 parent 4d700bb commit 8ea781a
Show file tree
Hide file tree
Showing 12 changed files with 1,044 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/libraries.txt
Expand Up @@ -19,3 +19,8 @@ PHPUTF8 UTF-8 Character Handling Library
* URL: <http://phputf8.sourceforge.net/>
* Version: 0.5 (Aug 12, 2007)
* License: LGPL

SWORD PHP API Library
* URL: <http://php.swordapp.org>
* Version: 0.9 (Oct 5, 2009)
* License: Modified BSD
33 changes: 33 additions & 0 deletions 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.
149 changes: 149 additions & 0 deletions 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
52 changes: 52 additions & 0 deletions lib/swordapp/collection.php
@@ -0,0 +1,52 @@
<?php

require_once("utils.php");

class Collection {

// The title of the collection
public $sac_colltitle;

// The URL of the collection (where you can deposit to)
public $sac_href;

// The types of content accepted
public $sac_accept;

// The accepted packaging formats
public $sac_acceptpackaging;

// The collection policy
public $sac_collpolicy;

// The colelction abstract (dcterms)
public $sac_abstract;

// Whether mediation is allowed or not
public $sac_mediation;

// A nested service document
public $sac_service;

// Construct a new collection by passing in a title
function __construct($sac_newcolltitle) {
// Store the title
$this->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;
}
}

?>

0 comments on commit 8ea781a

Please sign in to comment.