Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup

  • Loading branch information...
commit 5d027d8011fc940afea643732affa9a8533c480d 1 parent 2c75d68
@bwoodhead bwoodhead authored
View
47 PropertyObject.inc
@@ -1,47 +0,0 @@
-<?php
-
-/**
- * Description of PropertyObject
- *
- * From example code at http://www.php.net/manual/en/language.oop5.properties.php#98267
- */
-abstract class PropertyObject {
- private $_construct = FALSE;
- protected $_populated = TRUE;
- protected function _refresh() {
-
- }
-
- public function __get($name) {
- $var_name = "_$name";
- if ((!property_exists($this, $var_name) || $this->$var_name == NULL) && !$this->_populated) {
- $this->_refresh();
- }
- if (method_exists($this, ($method = 'get_'.$name))) {
- return $this->$method();
- }
- else return;
- }
-
- public function __isset($name) {
- if (method_exists($this, ($method = 'isset_'.$name))){
- return $this->$method();
- }
- else return;
- }
-
- public function __set($name, $value) {
- if (method_exists($this, ($method = 'set_'.$name))) {
- $this->$method($value);
- }
- else {
- $this->$name = $value;
- }
- }
-
- public function __unset($name) {
- if (method_exists($this, ($method = 'unset_'.$name))){
- $this->$method();
- }
- }
-}
View
14 fedora_api.test → Tests/fedora_api.test
@@ -34,19 +34,24 @@ class FedoraAPITestCase extends DrupalWebTestCase {
}
public function testAPIA() {
+
global $base_url;
- $api = new FedoraAPIA();
- $client = new FedoraClient();
-
- $profile = $api->getObjectProfile('islandora:demos');
+
+ //FedoraRepository
+ $api = new FedoraAPIA();
+ $client = new FedoraClient();
+
+ $profile = $api->getObjectProfile('islandora:demos');
if (empty($profile->error)) {
$this->pass('Fedora API-A getObjectProfile passed.');
}
+
$dslist = $api->listDatastreams('islandora:demos');
if (empty($dslist->error)) {
$this->pass('Fedora API-A listDatastreams passed.');
}
+
$methodlist = $api->listMethods('islandora:demos');
if (empty($methodlist->error)) {
$this->pass('Fedora API-A listMethods passed.');
@@ -56,6 +61,7 @@ class FedoraAPITestCase extends DrupalWebTestCase {
if (empty($find_results->error)) {
$this->pass('Fedora API-A findObjects passed.');
}
+
$dc_stream = $api->getDatastreamDissemination("fedora-system:FedoraObject-3.0", "DC", '', 'false');
if (empty($dc_stream->error)) {
if (strpos($dc_stream->data, '<oai_dc:dc') >= 0) {
View
0  test_data/lorem_ipsum.pdf → Tests/test_data/lorem_ipsum.pdf
File renamed without changes
View
0  test_data/test.png → Tests/test_data/test.png
File renamed without changes
View
0  test_data/test_dublin_core.xml → Tests/test_data/test_dublin_core.xml
File renamed without changes
View
0  test_data/test_ingest_foxml.xml → Tests/test_data/test_ingest_foxml.xml
File renamed without changes
View
0  test_data/test_ingest_foxml_2.xml → Tests/test_data/test_ingest_foxml_2.xml
File renamed without changes
View
0  fedora_api.connection.inc → api/FedoraConnection.inc
File renamed without changes
View
0  fedora_api.datastream.inc → api/FedoraDatastream.inc
File renamed without changes
View
2  islandora_fedora_api.object.inc → api/FedoraObject.inc
@@ -44,6 +44,8 @@ class FedoraObject extends PropertyObject {
$this->client = $client;
}
else {
+ module_load_include('repository.inc', 'islandora_fedora_api');
+
// Make a default client using Drupal's variables.
$this->client = new FedoraRepository();
}
View
0  islandora_fedora_api.repository.inc → api/FedoraRepository.inc
File renamed without changes
View
2  FoxmlForm.inc → api/FoxmlForm.inc
@@ -1,7 +1,5 @@
<?php
-// $Id$
-
/**
* @file
*
View
85 api/PropertyObject.inc
@@ -0,0 +1,85 @@
+<?php
+
+/**
+ * @file
+ * Property base class
+ */
+
+/**
+ * Properties base class
+ *
+ * PropertyObject is a workaround to allow you to create real properties in php.
+ * PHP properties act like attributes by allowing you to set the variable instead
+ * of calling a function.
+ *
+ * From details go to: http://www.php.net/manual/en/language.oop5.properties.php#98267
+ */
+abstract class PropertyObject {
+
+ private $_construct = FALSE;
+ protected $_populated = TRUE;
+
+ /**
+ * ?
+ */
+ protected function _refresh() {
+
+ }
+
+ /**
+ * Magic get function that catches a function call
+ * @param type $name The method name ( ie: $obj->a then a is the name )
+ * @return type
+ */
+ public function __get($name) {
+ $var_name = "_$name";
+ if ((!property_exists($this, $var_name) || $this->$var_name == NULL) && !$this->_populated) {
+ $this->_refresh();
+ }
+ if (method_exists($this, ($method = 'get_' . $name))) {
+ return $this->$method();
+ }
+ else {
+ return;
+ }
+ }
+
+ /**
+ * Isset
+ * @param type $name
+ * @return type
+ */
+ public function __isset($name) {
+ if (method_exists($this, ($method = 'isset_' . $name))) {
+ return $this->$method();
+ }
+ else {
+ return;
+ }
+ }
+
+ /**
+ * Magic set function that will catch assignments and call a function using the assignment
+ * @param type $name The name of the variable to assign a value to
+ * @param type $value The value
+ */
+ public function __set($name, $value) {
+ if (method_exists($this, ($method = 'set_' . $name))) {
+ $this->$method($value);
+ }
+ else {
+ $this->$name = $value;
+ }
+ }
+
+ /**
+ * Unset
+ * @param type $name
+ */
+ public function __unset($name) {
+ if (method_exists($this, ($method = 'unset_' . $name))) {
+ $this->$method();
+ }
+ }
+
+}
View
35 fedora_api.exception.inc → ...rror/FedoraAPIObjectNotFoundException.inc
@@ -1,6 +1,11 @@
<?php
/**
+ * @file
+ * Fedora API Exceptions
+ */
+
+/**
* General exception thrown on unexpected REST response.
*/
class FedoraAPIRestException extends Exception {
@@ -33,34 +38,6 @@ class FedoraAPIRestException extends Exception {
$this->pid = $pid;
parent::__construct($http->error, $http->code);
}
-
}
-/**
- * Exception thrown when an Object isn't found in the repository.
- */
-class FedoraAPIObjectNotFoundException extends Exception {
-
- /**
- * The PID of the Object not found.
- *
- * @var string
- */
- public $pid;
-
- /**
- * Construct an Object Not Found exception.
- *
- * @param string $pid
- * The pid of the item not found.
- * @param string $message
- * (Optional) The message to be reported. Defaults to: "Not Found".
- * @param int $code
- * (Optional) Defaults to 404.
- */
- function __construct($pid, $message = 'Not Found.', $code = 404) {
- $this->pid = $pid;
- parent::__construct($message);
- }
-
-}
+?>
View
36 api/error/FedoraAPIRestException.inc
@@ -0,0 +1,36 @@
+<?php
+/**
+ * @file
+ * Fedora API Exceptions
+ */
+
+/**
+ * Exception thrown when an Object isn't found in the repository.
+ */
+class FedoraAPIObjectNotFoundException extends Exception {
+
+ /**
+ * The PID of the Object not found.
+ *
+ * @var string
+ */
+ public $pid;
+
+ /**
+ * Construct an Object Not Found exception.
+ *
+ * @param string $pid
+ * The pid of the item not found.
+ * @param string $message
+ * (Optional) The message to be reported. Defaults to: "Not Found".
+ * @param int $code
+ * (Optional) Defaults to 404.
+ */
+ function __construct($pid, $message = 'Not Found.', $code = 404) {
+ $this->pid = $pid;
+ parent::__construct($message);
+ }
+
+}
+
+?>
View
361 api/impl/FedoraAPIA.inc
@@ -0,0 +1,361 @@
+<?php
+
+/**
+ * @file
+ * Lowest-level wrappers for Fedora Commons's REST API functions.
+ * Functions return the HTTP response directly.
+ *
+ * All of these functions look at the response code of the error and
+ * throw FedoraAPIRestException if the response code isn't success (2XX).
+ *
+ * Much documentation about the API that is wraps can be found here:
+ * https://wiki.duraspace.org/display/FCR30/REST+API
+ */
+
+/**
+ * A low level wrapper on fedora APIA functions
+ */
+class FedoraAPIA {
+
+ /**
+ * The FedoraConnection object for this FedoraAPI.
+ *
+ * @var FedoraConnection
+ */
+ public $connection;
+
+ /**
+ * Constructor for a new FedoraAPI object.
+ *
+ * @param FedoraConnection $connection
+ * (optional) a new one will be created if not supplied.
+ */
+ function __construct($connection = NULL) {
+ if ($connection != NULL) {
+ $this->connection = $connection;
+ }
+ else {
+ // Construct a connection from Drupal's API settings.
+ $this->connection = new FedoraConnection();
+ }
+ }
+
+ /**
+ * Query fedora to return a list of objects.
+ *
+ * @param string $terms
+ * (optional) A phrase represented as a sequence of characters (including the ? and * wildcards) for the search.
+ * If this sequence is found in any of the fields for an object, the object is considered a match. Do NOT use
+ * this parameter in combination with the "query" parameter.
+ * @param string $query
+ * (optional) A sequence of space-separated conditions. A condition consists of a metadata element name followed
+ * directly by an operator, followed directly by a value. Valid element names are (pid, label, state, ownerId,
+ * cDate, mDate, dcmDate, title, creator, subject, description, publisher, contributor, date, type, format,
+ * identifier, source, language, relation, coverage, rights). Valid operators are: contains (), equals (=),
+ * greater than (>), less than (<), greater than or equals (>=), less than or equals (<=). The contains () operator
+ * may be used in combination with the ? and * wildcards to query for simple string patterns. Space-separators
+ * should be encoded in the URL as %20. Operators must be encoded when used in the URL syntax as follows: the (=)
+ * operator must be encoded as %3D, the (>) operator as %3E, the (<) operator as %3C, the (>=) operator
+ * as %3E%3D, the (<=) operator as %3C%3D, and the (~) operator as %7E. Values may be any string. If the string
+ * contains a space, the value should begin and end with a single quote character ('). If all conditions are met
+ * for an object, the object is considered a match. Do NOT use this parameter in combination with the
+ * "terms" parameter.
+ * @param string,int $maxResults
+ * (optional) Default: 25. The maximum number of results that the server should provide at once.
+ * @param string $resultFormat
+ * (optional) Default: XML. The preferred output format. Options: HTML, XML.
+ * @param array $displayFields
+ * (optional) Default: array('pid', 'title'). The fields to be returned.
+ *
+ * @throws FedoraAPIRestException
+ *
+ * @return StdClass HTTP Response object. 'data' has XML set of results
+ * @code
+ * <?xml version="1.0" encoding="UTF-8"?>
+ * <result xmlns="http://www.fedora.info/definitions/1/0/types/">
+ * <resultList>
+ * <objectFields>
+ * <pid>islandora:collectionCModel</pid>
+ * <title>Islandora Collection Content Model</title>
+ * </objectFields>
+ * <objectFields>
+ * <pid>islandora:strict_pdf</pid>
+ * <title>Strict PDF</title>
+ * </objectFields>
+ * </resultList>
+ * </result>
+ * @endcode
+ */
+ public function findObjects($terms = '', $query = '', $maxResults = '',
+ $resultFormat = 'xml', $displayFields = array('pid', 'title')
+ ){
+ $fedora_url = $this->connection->requestURL();
+ $request = "$fedora_url/objects?";
+
+ if (!empty($terms)) {
+ $request .= "terms=" . drupal_encode_path($terms);
+ }
+ else if (!empty($query)) {
+ $request .= "query=" . drupal_encode_path($query);
+ }
+
+ $request .= "&resultFormat=$resultFormat";
+
+ foreach ($displayFields as $displayField) {
+ $request .= "&$displayField=true";
+ }
+ $response = drupal_http_request($request);
+
+ if (!FedoraAPIUtils::testSuccess($response)) {
+ throw new FedoraApiRestException($response);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Get the default dissemination of a datastream. (Get the contents of the datastream.)
+ *
+ * @param String $pid
+ * Persistent identifier of the digital object.
+ * @param String $dsID
+ * Datastream identifier.
+ * @param String $asOfDateTime
+ * (optional) Default: NULL. Indicates that the result should be relative to the digital object as it existed
+ * at the given date and time.
+ * @param String $download
+ * (optional) Default: FALSE. If true, a content-disposition header value "attachment" will be included in the
+ * response, prompting the user to save the datastream as a file. A content-disposition header value "inline"
+ * will be used otherwise. The filename used in the header is generated by examining in order: RELS-INT for the
+ * relationship fedora-model:downloadFilename, the datastream label, and the datastream ID. The file extension
+ * (apart from where the filename is specified in RELS-INT) is determined from the MIMETYPE. The order in which
+ * these filename sources are searched, and whether or not to generate an extension from the MIMETYPE, is
+ * configured in fedora.fcfg. The file used to map between MIMETYPEs and extensions is mime-to-extensions.xml
+ * located in the server config directory.
+ *
+ * @return StdClass HTTP Response object. The direct response from fedora.
+ */
+ public function getDatastreamDissemination($pid, $dsID, $asOfDateTime = NULL, $download = NULL) {
+ $pid = drupal_encode_path($pid);
+ $fedora_url = $this->connection->requestURL();
+ $request = "$fedora_url/objects/$pid/datastreams/$dsID/content";
+ $request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
+ if (!empty($download)) {
+ $request .= (!empty($asOfDateTime) ? '&' : '?');
+ $request .= "download=$download";
+ }
+
+ $response = drupal_http_request($request);
+
+ if(!FedoraAPIUtils::testSuccess($response)) {
+ throw new FedoraApiRestException($response);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Get a datastream dissemination from Fedora.
+ *
+ * @param String $pid
+ * persistent identifier of the digital object
+ * @param String $sdefPid
+ * persistent identifier of the sDef defining the methods
+ * @param String $method
+ * method to invoke
+ * @param String $methodParameters
+ * A key-value paired array of parameters required by the method
+ *
+ * @return StdClass HTTP response object from fedora
+ */
+ public function getDissemination($pid, $sdefPid, $method, $methodParameters = array()) {
+ $pid = drupal_encode_path($pid);
+ $sdefPid = drupal_encode_path($sdefPid);
+
+ $fedora_url = $this->connection->requestURL();
+ $request = "$fedora_url/objects/$pid/methods/$sdefPid/$method?";
+
+ //$request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
+ foreach ($methodParameters as $param_name => $param_value) {
+ $request .= $param_name . (!empty($param_value) ? "=$param_value&" : '&');
+ }
+
+ $response = drupal_http_request($request);
+
+ if(!FedoraAPIUtils::testSuccess($response)) {
+ throw new FedoraApiRestException($response);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Get the change history for the datastream.
+ *
+ * @param String $pid
+ * Persistent identifier of the digital object.
+ * @param String $format
+ * (Optional) Default: XML. The preferred output format (xml, html).
+ *
+ * @return HTTP response object.
+ * @code
+ * $response->data looks like:
+ * <?xml version="1.0" encoding="utf-16"?>
+ * <fedoraObjectHistory xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/
+ * http://localhost:8080/fedoraObjectHistory.xsd" pid="demo:29" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ * <objectChangeDate>2008-07-02T05:09:43.234Z</objectChangeDate>
+ * </fedoraObjectHistory>
+ * @endcode
+ */
+ public function getObjectHistory($pid, $format = 'xml') {
+ $pid = drupal_encode_path($pid);
+ $fedora_url = $this->connection->requestURL();
+
+ $request = "$fedora_url/objects/$pid/versions?format=$format";
+ $response = drupal_http_request($request);
+
+ if(!FedoraAPIUtils::testSuccess($response)) {
+ throw new FedoraApiRestException($response);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Implements the getObjectProfile Fedora API-A method.
+ *
+ * @param String $pid
+ * Persistent identifier of the digital object.
+ * @param String $format
+ * (Optional) Default: XML. The preferred output format. Options: HTML, XML.
+ * @param String $asOfDateTime
+ * (Optional) Indicates that the result should be relative to the digital object as it existed on the given date.
+ * Date Format: yyyy-MM-dd or yyyy-MM-ddTHH:mm:ssZ
+ *
+ * @return StdClass HTTP Response object. 'data' has XML response string
+ * @code
+ * <?xml version="1.0" encoding="utf-16"?>
+ * <objectProfile xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/
+ * http://localhost:8080/objectProfile.xsd" pid="islandora:demos"
+ * xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ * <objLabel>Islandora Demo Collections</objLabel>
+ * <objOwnerId>fedoraAdmin</objOwnerId>
+ * <objModels>
+ * <model>info:fedora/islandora:collectionCModel</model>
+ * <model>info:fedora/fedora-system:FedoraObject-3.0</model>
+ * </objModels>
+ * <objCreateDate>2009-03-10T07:09:53.333Z</objCreateDate>
+ * <objLastModDate>2010-03-20T23:39:58.490Z</objLastModDate>
+ * <objDissIndexViewURL>
+ * http://localhost:8080/fedora/get/islandora:demos/fedora-system:3/viewMethodIndex
+ * </objDissIndexViewURL>
+ * <objItemIndexViewURL>
+ * http://localhost:8080/fedora/get/islandora:demos/fedora-system:3/viewItemIndex
+ * </objItemIndexViewURL>
+ * <objState>A</objState>
+ * </objectProfile>
+ * @endcode
+ */
+ public function getObjectProfile($pid, $format = 'xml', $asOfDateTime = '') {
+ $pid = drupal_encode_path($pid);
+ $fedora_url = $this->connection->requestURL();
+
+ $request = "$fedora_url/objects/$pid?format=$format";
+ $request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
+ $response = drupal_http_request($request);
+
+ if(!FedoraAPIUtils::testSuccess($response)) {
+ throw new FedoraApiRestException($response);
+ }
+
+ return $response;
+ }
+
+ /**
+ * List all the datastreams that are associated with this PID.
+ *
+ * @param <type> $pid
+ * Persistent identifier of the digital object.
+ * @param <type> $format
+ * (optional) Default: XML. The preferred output format. Options: XML, HTML.
+ * @param <type> $asOfDateTime
+ * (optional) Indicates that the result should be relative to the digital object as it existed on the given date.
+ * Date Format: yyyy-MM-dd or yyyy-MM-ddTHH:mm:ssZ
+ *
+ * @return StdClass HTTP Response object. 'data' has XML Response
+ * @code
+ * <?xml version="1.0" encoding="utf-16"?>
+ * <objectDatastreams xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/
+ * http://localhost:8080/listDatastreams.xsd" pid="islandora:demos" baseURL="http://localhost:8080/fedora/"
+ * xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ * <datastream dsid="DC" label="Dublin Core Record for this object" mimeType="text/xml" />
+ * <datastream dsid="RELS-EXT" label="RDF Statements about this object" mimeType="application/rdf+xml" />
+ * <datastream dsid="COLLECTION_POLICY" label="Collection Policy" mimeType="text/xml" />
+ * <datastream dsid="TN" label="Thumbnail.png" mimeType="image/png" />
+ * </objectDatastreams>
+ * @endcode
+ */
+ public function listDatastreams($pid, $format = 'xml', $asOfDateTime = '') {
+ $pid = drupal_encode_path($pid);
+ $fedora_url = $this->connection->requestURL();
+
+ $request = "$fedora_url/objects/$pid/datastreams?format=$format";
+ $request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
+ $response = drupal_http_request($request);
+
+ if(!FedoraAPIUtils::testSuccess($response)) {
+ throw new FedoraApiRestException($response);
+ }
+
+ return $response;
+ }
+
+ /**
+ * Implements the listMethods Fedora API-A method.
+ *
+ * @param String $pid
+ * Persistent identifier of the digital object.
+ * @param String $sdefPid
+ * (Optional) Persistent identifier of the SDef defining the methods.
+ * @param String $format
+ * (Optional) Default: XML. The preferred output format. Options: XML, HTML.
+ * @param String $asOfDateTime
+ * (Optional) Indicates that the result should be relative to the digital object as it existed on the given date.
+ * Date Format: yyyy-MM-dd or yyyy-MM-ddTHH:mm:ssZ
+ *
+ * @return StdClass HTTP Response object. 'data' has response XML.
+ * @code
+ * <?xml version="1.0" encoding="utf-16"?>
+ * <objectMethods xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/
+ * http://localhost:8080/listMethods.xsd" pid="islandora:demos" baseURL="http://localhost:8080/fedora/"
+ * xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ * <sDef pid="fedora-system:3">
+ * <method name="viewObjectProfile"></method>
+ * <method name="viewMethodIndex"></method>
+ * <method name="viewItemIndex"></method>
+ * <method name="viewDublinCore"></method>
+ * </sDef>
+ * </objectMethods>
+ * @endcode
+ */
+ public function listMethods($pid, $sdefPid = '', $format = 'xml', $asOfDateTime = '') {
+ $pid = drupal_encode_path($pid);
+ $fedora_url = $this->connection->requestURL();
+
+ $request = "$fedora_url/objects/$pid/methods";
+ $request .= (!empty($sdefPid) ? "/$sdefPid" : '');
+ $request .= "?format=$format";
+ $request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
+ $response = drupal_http_request($request);
+
+ if(!FedoraAPIUtils::testSuccess($response)) {
+ throw new FedoraApiRestException($response);
+ }
+
+ return $response;
+ }
+}
+
+?>
View
551 islandora_fedora_api.raw.inc → api/impl/FedoraAPIM.inc
@@ -1,4 +1,5 @@
<?php
+
/**
* @file
* Lowest-level wrappers for Fedora Commons's REST API functions.
@@ -12,353 +13,6 @@
*/
/**
- * A low level wrapper on fedora APIA functions
- */
-class FedoraAPIA {
-
- /**
- * The FedoraConnection object for this FedoraAPI.
- *
- * @var FedoraConnection
- */
- public $connection;
-
- /**
- * Constructor for a new FedoraAPI object.
- *
- * @param FedoraConnection $connection
- * (optional) a new one will be created if not supplied.
- */
- function __construct($connection = NULL) {
- if ($connection != NULL) {
- $this->connection = $connection;
- }
- else {
- // Construct a connection from Drupal's API settings.
- $this->connection = new FedoraConnection();
- }
- }
-
- /**
- * Query fedora to return a list of objects.
- *
- * @param string $terms
- * (optional) A phrase represented as a sequence of characters (including the ? and * wildcards) for the search.
- * If this sequence is found in any of the fields for an object, the object is considered a match. Do NOT use
- * this parameter in combination with the "query" parameter.
- * @param string $query
- * (optional) A sequence of space-separated conditions. A condition consists of a metadata element name followed
- * directly by an operator, followed directly by a value. Valid element names are (pid, label, state, ownerId,
- * cDate, mDate, dcmDate, title, creator, subject, description, publisher, contributor, date, type, format,
- * identifier, source, language, relation, coverage, rights). Valid operators are: contains (), equals (=),
- * greater than (>), less than (<), greater than or equals (>=), less than or equals (<=). The contains () operator
- * may be used in combination with the ? and * wildcards to query for simple string patterns. Space-separators
- * should be encoded in the URL as %20. Operators must be encoded when used in the URL syntax as follows: the (=)
- * operator must be encoded as %3D, the (>) operator as %3E, the (<) operator as %3C, the (>=) operator
- * as %3E%3D, the (<=) operator as %3C%3D, and the (~) operator as %7E. Values may be any string. If the string
- * contains a space, the value should begin and end with a single quote character ('). If all conditions are met
- * for an object, the object is considered a match. Do NOT use this parameter in combination with the
- * "terms" parameter.
- * @param string,int $maxResults
- * (optional) Default: 25. The maximum number of results that the server should provide at once.
- * @param string $resultFormat
- * (optional) Default: XML. The preferred output format. Options: HTML, XML.
- * @param array $displayFields
- * (optional) Default: array('pid', 'title'). The fields to be returned.
- *
- * @throws FedoraAPIRestException
- *
- * @return StdClass HTTP Response object. 'data' has XML set of results
- * @code
- * <?xml version="1.0" encoding="UTF-8"?>
- * <result xmlns="http://www.fedora.info/definitions/1/0/types/">
- * <resultList>
- * <objectFields>
- * <pid>islandora:collectionCModel</pid>
- * <title>Islandora Collection Content Model</title>
- * </objectFields>
- * <objectFields>
- * <pid>islandora:strict_pdf</pid>
- * <title>Strict PDF</title>
- * </objectFields>
- * </resultList>
- * </result>
- * @endcode
- */
- public function findObjects($terms = '', $query = '', $maxResults = '',
- $resultFormat = 'xml', $displayFields = array('pid', 'title')
- ){
- $fedora_url = $this->connection->requestURL();
- $request = "$fedora_url/objects?";
-
- if (!empty($terms)) {
- $request .= "terms=" . drupal_encode_path($terms);
- }
- else if (!empty($query)) {
- $request .= "query=" . drupal_encode_path($query);
- }
-
- $request .= "&resultFormat=$resultFormat";
-
- foreach ($displayFields as $displayField) {
- $request .= "&$displayField=true";
- }
- $response = drupal_http_request($request);
-
- if (!FedoraAPIUtils::testSuccess($response)) {
- throw new FedoraApiRestException($response);
- }
-
- return $response;
- }
-
- /**
- * Get the default dissemination of a datastream. (Get the contents of the datastream.)
- *
- * @param String $pid
- * Persistent identifier of the digital object.
- * @param String $dsID
- * Datastream identifier.
- * @param String $asOfDateTime
- * (optional) Default: NULL. Indicates that the result should be relative to the digital object as it existed
- * at the given date and time.
- * @param String $download
- * (optional) Default: FALSE. If true, a content-disposition header value "attachment" will be included in the
- * response, prompting the user to save the datastream as a file. A content-disposition header value "inline"
- * will be used otherwise. The filename used in the header is generated by examining in order: RELS-INT for the
- * relationship fedora-model:downloadFilename, the datastream label, and the datastream ID. The file extension
- * (apart from where the filename is specified in RELS-INT) is determined from the MIMETYPE. The order in which
- * these filename sources are searched, and whether or not to generate an extension from the MIMETYPE, is
- * configured in fedora.fcfg. The file used to map between MIMETYPEs and extensions is mime-to-extensions.xml
- * located in the server config directory.
- *
- * @return StdClass HTTP Response object. The direct response from fedora.
- */
- public function getDatastreamDissemination($pid, $dsID, $asOfDateTime = NULL, $download = NULL) {
- $pid = drupal_encode_path($pid);
- $fedora_url = $this->connection->requestURL();
- $request = "$fedora_url/objects/$pid/datastreams/$dsID/content";
- $request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
- if (!empty($download)) {
- $request .= (!empty($asOfDateTime) ? '&' : '?');
- $request .= "download=$download";
- }
-
- $response = drupal_http_request($request);
-
- if(!FedoraAPIUtils::testSuccess($response)) {
- throw new FedoraApiRestException($response);
- }
-
- return $response;
- }
-
- /**
- * Get a datastream dissemination from Fedora.
- *
- * @param String $pid
- * persistent identifier of the digital object
- * @param String $sdefPid
- * persistent identifier of the sDef defining the methods
- * @param String $method
- * method to invoke
- * @param String $methodParameters
- * A key-value paired array of parameters required by the method
- *
- * @return StdClass HTTP response object from fedora
- */
- public function getDissemination($pid, $sdefPid, $method, $methodParameters = array()) {
- $pid = drupal_encode_path($pid);
- $sdefPid = drupal_encode_path($sdefPid);
-
- $fedora_url = $this->connection->requestURL();
- $request = "$fedora_url/objects/$pid/methods/$sdefPid/$method?";
-
- //$request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
- foreach ($methodParameters as $param_name => $param_value) {
- $request .= $param_name . (!empty($param_value) ? "=$param_value&" : '&');
- }
-
- $response = drupal_http_request($request);
-
- if(!FedoraAPIUtils::testSuccess($response)) {
- throw new FedoraApiRestException($response);
- }
-
- return $response;
- }
-
- /**
- * Get the change history for the datastream.
- *
- * @param String $pid
- * Persistent identifier of the digital object.
- * @param String $format
- * (Optional) Default: XML. The preferred output format (xml, html).
- *
- * @return HTTP response object.
- * @code
- * $response->data looks like:
- * <?xml version="1.0" encoding="utf-16"?>
- * <fedoraObjectHistory xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/
- * http://localhost:8080/fedoraObjectHistory.xsd" pid="demo:29" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- * <objectChangeDate>2008-07-02T05:09:43.234Z</objectChangeDate>
- * </fedoraObjectHistory>
- * @endcode
- */
- public function getObjectHistory($pid, $format = 'xml') {
- $pid = drupal_encode_path($pid);
- $fedora_url = $this->connection->requestURL();
-
- $request = "$fedora_url/objects/$pid/versions?format=$format";
- $response = drupal_http_request($request);
-
- if(!FedoraAPIUtils::testSuccess($response)) {
- throw new FedoraApiRestException($response);
- }
-
- return $response;
- }
-
- /**
- * Implements the getObjectProfile Fedora API-A method.
- *
- * @param String $pid
- * Persistent identifier of the digital object.
- * @param String $format
- * (Optional) Default: XML. The preferred output format. Options: HTML, XML.
- * @param String $asOfDateTime
- * (Optional) Indicates that the result should be relative to the digital object as it existed on the given date.
- * Date Format: yyyy-MM-dd or yyyy-MM-ddTHH:mm:ssZ
- *
- * @return StdClass HTTP Response object. 'data' has XML response string
- * @code
- * <?xml version="1.0" encoding="utf-16"?>
- * <objectProfile xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/
- * http://localhost:8080/objectProfile.xsd" pid="islandora:demos"
- * xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- * <objLabel>Islandora Demo Collections</objLabel>
- * <objOwnerId>fedoraAdmin</objOwnerId>
- * <objModels>
- * <model>info:fedora/islandora:collectionCModel</model>
- * <model>info:fedora/fedora-system:FedoraObject-3.0</model>
- * </objModels>
- * <objCreateDate>2009-03-10T07:09:53.333Z</objCreateDate>
- * <objLastModDate>2010-03-20T23:39:58.490Z</objLastModDate>
- * <objDissIndexViewURL>
- * http://localhost:8080/fedora/get/islandora:demos/fedora-system:3/viewMethodIndex
- * </objDissIndexViewURL>
- * <objItemIndexViewURL>
- * http://localhost:8080/fedora/get/islandora:demos/fedora-system:3/viewItemIndex
- * </objItemIndexViewURL>
- * <objState>A</objState>
- * </objectProfile>
- * @endcode
- */
- public function getObjectProfile($pid, $format = 'xml', $asOfDateTime = '') {
- $pid = drupal_encode_path($pid);
- $fedora_url = $this->connection->requestURL();
-
- $request = "$fedora_url/objects/$pid?format=$format";
- $request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
- $response = drupal_http_request($request);
-
- if(!FedoraAPIUtils::testSuccess($response)) {
- throw new FedoraApiRestException($response);
- }
-
- return $response;
- }
-
- /**
- * List all the datastreams that are associated with this PID.
- *
- * @param <type> $pid
- * Persistent identifier of the digital object.
- * @param <type> $format
- * (optional) Default: XML. The preferred output format. Options: XML, HTML.
- * @param <type> $asOfDateTime
- * (optional) Indicates that the result should be relative to the digital object as it existed on the given date.
- * Date Format: yyyy-MM-dd or yyyy-MM-ddTHH:mm:ssZ
- *
- * @return StdClass HTTP Response object. 'data' has XML Response
- * @code
- * <?xml version="1.0" encoding="utf-16"?>
- * <objectDatastreams xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/
- * http://localhost:8080/listDatastreams.xsd" pid="islandora:demos" baseURL="http://localhost:8080/fedora/"
- * xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- * <datastream dsid="DC" label="Dublin Core Record for this object" mimeType="text/xml" />
- * <datastream dsid="RELS-EXT" label="RDF Statements about this object" mimeType="application/rdf+xml" />
- * <datastream dsid="COLLECTION_POLICY" label="Collection Policy" mimeType="text/xml" />
- * <datastream dsid="TN" label="Thumbnail.png" mimeType="image/png" />
- * </objectDatastreams>
- * @endcode
- */
- public function listDatastreams($pid, $format = 'xml', $asOfDateTime = '') {
- $pid = drupal_encode_path($pid);
- $fedora_url = $this->connection->requestURL();
-
- $request = "$fedora_url/objects/$pid/datastreams?format=$format";
- $request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
- $response = drupal_http_request($request);
-
- if(!FedoraAPIUtils::testSuccess($response)) {
- throw new FedoraApiRestException($response);
- }
-
- return $response;
- }
-
- /**
- * Implements the listMethods Fedora API-A method.
- *
- * @param String $pid
- * Persistent identifier of the digital object.
- * @param String $sdefPid
- * (Optional) Persistent identifier of the SDef defining the methods.
- * @param String $format
- * (Optional) Default: XML. The preferred output format. Options: XML, HTML.
- * @param String $asOfDateTime
- * (Optional) Indicates that the result should be relative to the digital object as it existed on the given date.
- * Date Format: yyyy-MM-dd or yyyy-MM-ddTHH:mm:ssZ
- *
- * @return StdClass HTTP Response object. 'data' has response XML.
- * @code
- * <?xml version="1.0" encoding="utf-16"?>
- * <objectMethods xsi:schemaLocation="http://www.fedora.info/definitions/1/0/access/
- * http://localhost:8080/listMethods.xsd" pid="islandora:demos" baseURL="http://localhost:8080/fedora/"
- * xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- * <sDef pid="fedora-system:3">
- * <method name="viewObjectProfile"></method>
- * <method name="viewMethodIndex"></method>
- * <method name="viewItemIndex"></method>
- * <method name="viewDublinCore"></method>
- * </sDef>
- * </objectMethods>
- * @endcode
- */
- public function listMethods($pid, $sdefPid = '', $format = 'xml', $asOfDateTime = '') {
- $pid = drupal_encode_path($pid);
- $fedora_url = $this->connection->requestURL();
-
- $request = "$fedora_url/objects/$pid/methods";
- $request .= (!empty($sdefPid) ? "/$sdefPid" : '');
- $request .= "?format=$format";
- $request .= (!empty($asOfDateTime) ? "&asOfDateTime=$asOfDateTime" : '');
- $response = drupal_http_request($request);
-
- if(!FedoraAPIUtils::testSuccess($response)) {
- throw new FedoraApiRestException($response);
- }
-
- return $response;
- }
-}
-
-
-/**
* A low level wrapper on fedora APIM functions
*/
class FedoraAPIM {
@@ -914,205 +568,4 @@ class FedoraAPIM {
}
-
-/**
- * A collection of helpful utilities for dealing with fedora.
- *
- * @todo Should this be refactored out into its own file?
- */
-class FedoraAPIUtils {
-
- /**
- * Tests if the given PID fits the general rules for a PID. Must start with a letter, must be less the 64 characters,
- * no special characters, etc. This says nothing about the PID existing, it just tests the string with a regular
- * expression.
- *
- * @param String $pid
- *
- * @return boolean
- *
- * @todo Document where this regex came from. I believe it is in the Fedora documentation somewhere.
- */
- static function validPid($pid) {
- $valid = FALSE;
- if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) {
- $valid = TRUE;
- }
-
- return $valid;
- }
-
- /**
- * Tests if the given DSID is valid. As above, this function is just a regular expression to validate the DSID, it
- * says nothing about the DSID actually existing.
- *
- * @param string $dsid
- *
- * @return boolean
- *
- * @todo As above we should document where this regex came from. I know I have seen it in the Fedora documenation
- * somewhere before.
- */
- static function validDsid($dsid) {
- $valid = FALSE;
- if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) {
- $valid = TRUE;
- }
-
- return $valid;
- }
-
- /**
- * This function takes a string, and returns a string that is a valid DSID. This is very useful if using filenames
- * as DSIDs as most operating systems file names are less restrictive then DSIDs. This matches the Python
- * implementation of this function.
- * The algorithm is:
- * 1) It removes all characters that are unsupported in a DSID.
- * 2) If the string is too long, it takes the last 64 characters of the string.
- * 3) If the string starts with a number, prepend random letter.
- * 4) If string is empty, make is a random 10 character string.
- *
- * @param String $dsid
- * @return String
- * The mangled DSID.
- */
- static function mangleDsid($dsid) {
- $new_dsid = trim($dsid);
-
- $string_array = 'abcdefghijklmnopqustuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
-
- $find = '/[^a-zA-Z0-9\.\_\-]/';
- $replace = '';
- $new_dsid = preg_replace($find, $replace, $new_dsid);
-
- if( strlen($new_dsid) > 64 ) {
- $new_dsid = substr($new_dsid, -64);
- }
-
- if( preg_match('/^[^a-zA-Z]/', $dsid )) {
- if( strlen($new_dsid) == 64 ) {
- $new_dsid = substr($new_dsid, -63);
- }
- $new_dsid = this::randomString() . $new_dsid;
- }
-
- if( strlen($new_dsid) == 0 )
- $new_dsid = this::randomString(10);
-
- return $new_dsid;
- }
-
- // This is defined for the function above
- private static function randomString($length = 1) {
- $array = 'abcdefghijklmnopqustuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
-
- $string = '';
-
- while( $length > 0 ) {
- $string .= $array[rand(0,51)];
- $length--;
- }
-
- return $string;
- }
-
-
- /**
- * Returns TRUE if the http response code in the supplied $http_response is a 2XX success code.
- *
- * @todo make sure this is correct
- * @todo should we be logging here
- * @param StdObject $http_response
- */
- static function testSuccess($http_response, $log = FALSE, $request = '') {
- $code = (string) $http_response->code;
-
- if( $code[0] == '2' ) {
- return TRUE;
- }
- else {
- if( $log == TRUE ) {
- this::logError($http_response, $request);
- }
- return FALSE;
- }
- }
-
- static function logError($http_response, $request) {
- watchdog('fedora api', 'Error executing Fedora REST request %request: %error',
- array('%request' => $request, '%error' => $http_response->error), WATCHDOG_ERROR
- );
- }
-
- static function multipartEncode($boundary, $params) {
- if (empty($params)) {
- return NULL;
- }
-
- $output = "";
- foreach ($params as $key => $value) {
- $output .= "--$boundary\r\n";
- if ($key == 'file') {
- $output .= this::multipartEncodeFile($value);
- }
- elseif ($key == 'foxml_file') {
- $output .= this::multipartEncodeXMLFile($value);
- }
- elseif ($key == 'foxml_string') {
- $output .= this::multipartEncodeXMLString($value);
- }
- else {
- $output .= this::multipartEncodeText($key, $value);
- }
- }
- $output .= "--$boundary--";
- return $output;
- }
-
- protected static function multipartEncodeFile($path) {
- // remove @ at beginning
- if (substr($path, 0, 1) == "@") {
- $path = substr($path, 1);
- }
- $filename = basename($path);
- $mimetype = "application/octet-stream";
- $data = "Content-Disposition: form-data; name=\"file\"; filename=\"$filename\"\r\n";
- $data .= "Content-Transfer-Encoding: binary\r\n";
- $data .= "Content-Type: $mimetype\r\n\r\n";
- $data .= file_get_contents($path) . "\r\n";
- return $data;
- }
-
- protected static function multipartEncodeXMLFile($path) {
- if (substr($path, 0, 1) == "@") {
- $path = substr($path, 1);
- }
- $filename = basename($path);
- $mimetype = "text/xml";
- $data = "Content-Disposition: form-data; name=\"file\"; filename=\"$filename\"\r\n";
- $data .= "Content-Transfer-Encoding: UTF-8\r\n";
- $data .= "Content-Type: $mimetype\r\n\r\n";
- $data .= file_get_contents($path) . "\r\n";
- return $data;
- }
-
- protected static function multipartEncodeXMLString($xml_data) {
- $mimetype = "text/xml";
- $data = "Content-Disposition: form-data; name=\"foxml\"; filename=\"FOXML\"\r\n";
- $data .= "Content-Transfer-Encoding: UTF-8\r\n";
- $data .= "Content-Type: $mimetype\r\n\r\n";
- $data .= $xml_data . "\r\n";
- return $data;
- }
-
- protected static function multipartEncodeText($name, $value) {
- $mimeType = 'text/plain';
- $data = "Content-Disposition: form-data: name=\"$name\" filename=\"$name\"\r\n";
- $data .= "Content-Transfer-Encoding: UTF-8\r\n";
- $data .= "Content-Type: $mimeType\r\n\r\n";
- $data .= "$value\r\n";
- return $data;
- return "Content-Disposition: form-data; name=\"$name\"\r\n\r\n$value\r\n";
- }
-
-}
+?>a
View
215 api/impl/FedoraAPIUtils.inc
@@ -0,0 +1,215 @@
+<?php
+
+/**
+ * @file
+ * Lowest-level wrappers for Fedora Commons's REST API functions.
+ * Functions return the HTTP response directly.
+ *
+ * All of these functions look at the response code of the error and
+ * throw FedoraAPIRestException if the response code isn't success (2XX).
+ *
+ * Much documentation about the API that is wraps can be found here:
+ * https://wiki.duraspace.org/display/FCR30/REST+API
+ */
+
+/**
+ * A collection of helpful utilities for dealing with fedora.
+ *
+ * @todo Should this be refactored out into its own file?
+ */
+class FedoraAPIUtils {
+
+ /**
+ * Tests if the given PID fits the general rules for a PID. Must start with a letter, must be less the 64 characters,
+ * no special characters, etc. This says nothing about the PID existing, it just tests the string with a regular
+ * expression.
+ *
+ * @param String $pid
+ *
+ * @return boolean
+ *
+ * @todo Document where this regex came from. I believe it is in the Fedora documentation somewhere.
+ */
+ static function validPid($pid) {
+ $valid = FALSE;
+ if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) {
+ $valid = TRUE;
+ }
+
+ return $valid;
+ }
+
+ /**
+ * Tests if the given DSID is valid. As above, this function is just a regular expression to validate the DSID, it
+ * says nothing about the DSID actually existing.
+ *
+ * @param string $dsid
+ *
+ * @return boolean
+ *
+ * @todo As above we should document where this regex came from. I know I have seen it in the Fedora documenation
+ * somewhere before.
+ */
+ static function validDsid($dsid) {
+ $valid = FALSE;
+ if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) {
+ $valid = TRUE;
+ }
+
+ return $valid;
+ }
+
+ /**
+ * This function takes a string, and returns a string that is a valid DSID. This is very useful if using filenames
+ * as DSIDs as most operating systems file names are less restrictive then DSIDs. This matches the Python
+ * implementation of this function.
+ * The algorithm is:
+ * 1) It removes all characters that are unsupported in a DSID.
+ * 2) If the string is too long, it takes the last 64 characters of the string.
+ * 3) If the string starts with a number, prepend random letter.
+ * 4) If string is empty, make is a random 10 character string.
+ *
+ * @param String $dsid
+ * @return String
+ * The mangled DSID.
+ */
+ static function mangleDsid($dsid) {
+ $new_dsid = trim($dsid);
+
+ $string_array = 'abcdefghijklmnopqustuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+
+ $find = '/[^a-zA-Z0-9\.\_\-]/';
+ $replace = '';
+ $new_dsid = preg_replace($find, $replace, $new_dsid);
+
+ if( strlen($new_dsid) > 64 ) {
+ $new_dsid = substr($new_dsid, -64);
+ }
+
+ if( preg_match('/^[^a-zA-Z]/', $dsid )) {
+ if( strlen($new_dsid) == 64 ) {
+ $new_dsid = substr($new_dsid, -63);
+ }
+ $new_dsid = this::randomString() . $new_dsid;
+ }
+
+ if( strlen($new_dsid) == 0 )
+ $new_dsid = this::randomString(10);
+
+ return $new_dsid;
+ }
+
+ // This is defined for the function above
+ private static function randomString($length = 1) {
+ $array = 'abcdefghijklmnopqustuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+
+ $string = '';
+
+ while( $length > 0 ) {
+ $string .= $array[rand(0,51)];
+ $length--;
+ }
+
+ return $string;
+ }
+
+
+ /**
+ * Returns TRUE if the http response code in the supplied $http_response is a 2XX success code.
+ *
+ * @todo make sure this is correct
+ * @todo should we be logging here
+ * @param StdObject $http_response
+ */
+ static function testSuccess($http_response, $log = FALSE, $request = '') {
+ $code = (string) $http_response->code;
+
+ if( $code[0] == '2' ) {
+ return TRUE;
+ }
+ else {
+ if( $log == TRUE ) {
+ this::logError($http_response, $request);
+ }
+ return FALSE;
+ }
+ }
+
+ static function logError($http_response, $request) {
+ watchdog('fedora api', 'Error executing Fedora REST request %request: %error',
+ array('%request' => $request, '%error' => $http_response->error), WATCHDOG_ERROR
+ );
+ }
+
+ static function multipartEncode($boundary, $params) {
+ if (empty($params)) {
+ return NULL;
+ }
+
+ $output = "";
+ foreach ($params as $key => $value) {
+ $output .= "--$boundary\r\n";
+ if ($key == 'file') {
+ $output .= this::multipartEncodeFile($value);
+ }
+ elseif ($key == 'foxml_file') {
+ $output .= this::multipartEncodeXMLFile($value);
+ }
+ elseif ($key == 'foxml_string') {
+ $output .= this::multipartEncodeXMLString($value);
+ }
+ else {
+ $output .= this::multipartEncodeText($key, $value);
+ }
+ }
+ $output .= "--$boundary--";
+ return $output;
+ }
+
+ protected static function multipartEncodeFile($path) {
+ // remove @ at beginning
+ if (substr($path, 0, 1) == "@") {
+ $path = substr($path, 1);
+ }
+ $filename = basename($path);
+ $mimetype = "application/octet-stream";
+ $data = "Content-Disposition: form-data; name=\"file\"; filename=\"$filename\"\r\n";
+ $data .= "Content-Transfer-Encoding: binary\r\n";
+ $data .= "Content-Type: $mimetype\r\n\r\n";
+ $data .= file_get_contents($path) . "\r\n";
+ return $data;
+ }
+
+ protected static function multipartEncodeXMLFile($path) {
+ if (substr($path, 0, 1) == "@") {
+ $path = substr($path, 1);
+ }
+ $filename = basename($path);
+ $mimetype = "text/xml";
+ $data = "Content-Disposition: form-data; name=\"file\"; filename=\"$filename\"\r\n";
+ $data .= "Content-Transfer-Encoding: UTF-8\r\n";
+ $data .= "Content-Type: $mimetype\r\n\r\n";
+ $data .= file_get_contents($path) . "\r\n";
+ return $data;
+ }
+
+ protected static function multipartEncodeXMLString($xml_data) {
+ $mimetype = "text/xml";
+ $data = "Content-Disposition: form-data; name=\"foxml\"; filename=\"FOXML\"\r\n";
+ $data .= "Content-Transfer-Encoding: UTF-8\r\n";
+ $data .= "Content-Type: $mimetype\r\n\r\n";
+ $data .= $xml_data . "\r\n";
+ return $data;
+ }
+
+ protected static function multipartEncodeText($name, $value) {
+ $mimeType = 'text/plain';
+ $data = "Content-Disposition: form-data: name=\"$name\" filename=\"$name\"\r\n";
+ $data .= "Content-Transfer-Encoding: UTF-8\r\n";
+ $data .= "Content-Type: $mimeType\r\n\r\n";
+ $data .= "$value\r\n";
+ return $data;
+ return "Content-Disposition: form-data; name=\"$name\"\r\n\r\n$value\r\n";
+ }
+
+}
View
27 islandora_fedora_api.info
@@ -1,15 +1,20 @@
name = Islandora Fedora API
description = Wrapper for the Fedora Commons Repository REST API.
package = Islandora
-version = 7.x-$Format:%h$-dev
+version = 12.0.0
core = 7.x
-files[] = PropertyObject.inc
-files[] = FoxmlForm.inc
-files[] = fedora_api.exception.inc
-files[] = fedora_api.connection.inc
-files[] = fedora_api.datastream.inc
-files[] = islandora_fedora_api.module
-files[] = islandora_fedora_api.object.inc
-files[] = islandora_fedora_api.raw.inc
-files[] = islandora_fedora_api.repository.inc
-files[] = fedora_api.test
+files[] = FedoraAPIObjectNotFoundException.inc
+files[] = FedoraAPIRestException.inc
+
+files[] = FedoraAPIA.inc
+files[] = FedoraAPIM.inc
+files[] = FedoraAPIUtils.inc
+
+files[] = api/FedoraConnection.inc
+files[] = api/FedoraRepository.inc
+files[] = api/FedoraDatastream.inc
+files[] = api/FoxmlForm.inc
+files[] = api/FedoraObject.inc
+files[] = api/PropertyObject.inc
+
+files[] = tests/fedora_api.test
View
1  islandora_fedora_api.module
@@ -14,6 +14,7 @@
*
* @todo Implement namespace restrictions.
* @todo Make sure we save a value for islandora_repository_title
+ * @todo Shouldn't this be implemented using module_invoke_all instead of for alter
*/
function fedora_api_form_islandora_admin_settings_alter(&$form, &$form_state, $form_id) {
Please sign in to comment.
Something went wrong with that request. Please try again.