Browse Source

Merge branch 'ISLANDORA-121'

pull/105/head
Alexander O'Neill 14 years ago
parent
commit
3663be97d3
  1. 2
      ObjectHelper.inc
  2. 2
      SecurityClass.inc
  3. 163
      XMLDatastream.inc
  4. 82
      fedora_repository.install
  5. 66
      fedora_repository.module

2
ObjectHelper.inc

@ -336,7 +336,7 @@ class ObjectHelper {
'asOfDateTime' => ""
);
try {
$object = $client->__soapCAll('getDatastreamDissemination', array(
$object = $client->__soapCall('getDatastreamDissemination', array(
'parameters' => $params
));
} catch (Exception $e) {

2
SecurityClass.inc

@ -9,7 +9,7 @@
*/
class SecurityClass {
public static $SECURITY_CLASS_SECURITY_STREAM = 'CHILD_SECURITY';
public static $SECURITY_CLASS_SECURITY_STREAM = 'POLICY';
function SecurityClass() {
module_load_include('inc', 'SecurityClass', '');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

163
XMLDatastream.inc

@ -6,17 +6,13 @@ abstract class XMLDatastream {
static $XMLNS = 'http://www.islandora.ca';
static $errors = NULL;
protected $xml = NULL;
private $valid = NULL;
protected $forceSchema = FALSE; // if set, the datastream will be validated against the specified schema in self::$SCHEMA_URI instead of
// reading the schema URI from the datastream.
private $valid = NULL;
protected $forceSchema = FALSE; // if set, the datastream will be validated against the specified schema in self::$SCHEMA_URI instead of
// reading the schema URI from the datastream.
public $pid;
public $dsid;
public $dsid;
/**
* Parses an PID from an identifier.
* @param string $identifier
@ -26,7 +22,6 @@ abstract class XMLDatastream {
return substr($identifier, 0, strpos($identifier, "/"));
}
/**
* validPid
* Validates a fedora PID based on the regexp provided in the fedora
@ -41,11 +36,11 @@ abstract class XMLDatastream {
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;
}
/**
/**
* validDsid
* Validates a fedora Dsid based on the the allowed XML standard NCName.
* The regexp is a "regular" subset of names allowed, it excludes some extended hex characters that are
@ -60,16 +55,14 @@ abstract class XMLDatastream {
if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) {
$valid = TRUE;
}
return $valid;
}
/**
/**
* Parses the DSID from an identifier.
* TODO: combine this method with getPidFromIdentifier?
* @param string $identifier
* @param string $identifier
* @return string $dsid
*/
public static function getDSIDFromIdentifier($identifier) {
@ -77,7 +70,6 @@ abstract class XMLDatastream {
return substr($temp, 1);
}
/**
* Constructs an XMLDatastream object from the XML file specified.
* Returns FALSE on failure.
@ -89,7 +81,6 @@ abstract class XMLDatastream {
return new self(file_get_contents($filename));
}
/**
* Constructor
* NOTE: Use the static constructor methods whenever possible.
@ -100,15 +91,14 @@ abstract class XMLDatastream {
* @return XMLDatastream $cm
*/
public function __construct($xmlStr, $pid = NULL, $dsid = NULL) {
libxml_use_internal_errors(true);
$this->pid=$pid;
$this->dsid=$dsid;
if ($xmlStr !== NULL) {
$this->xml = (is_object($xmlStr) && get_class($xmlStr) == DOMDocument)?$xmlStr : DOMDocument::loadXML($xmlStr);
}
}
libxml_use_internal_errors(true);
$this->pid = $pid;
$this->dsid = $dsid;
if ($xmlStr !== NULL) {
$this->xml = (is_object($xmlStr) && get_class($xmlStr) == DOMDocument) ? $xmlStr : DOMDocument::loadXML($xmlStr);
}
}
/**
* Gets the identifier for this XMLDatastream
@ -119,10 +109,9 @@ abstract class XMLDatastream {
* @return string identifier
*/
public function getIdentifier() {
return ($this->pid != NULL && $this->dsid != NULL) ? $this->pid . '/'. $this->dsid : FALSE;
return ($this->pid != NULL && $this->dsid != NULL) ? $this->pid . '/' . $this->dsid : FALSE;
}
/**
* Dumps the XMLDatastream as an XML String
*
@ -131,12 +120,11 @@ abstract class XMLDatastream {
*/
public function dumpXml() {
if ($this->xml == NULL) {
$this->fetchXml();
$this->fetchXml();
}
return $this->xml->saveXml();
}
/**
* Validates the XMLDatastream against the schema location
* defined by the xmlns:schemaLocation attribute of the root
@ -151,84 +139,79 @@ abstract class XMLDatastream {
* @return boolean $valid
*/
public function validate() {
global $user;
if ($this->valid === NULL) {
$ret = TRUE;
$ret = TRUE;
if ($this->xml == NULL) {
$this->fetchXml();
}
// figure out if we're dealing with a new or old schema
$rootEl = $this->xml->firstChild;
if (!$rootEl->hasAttributes() || $rootEl->attributes->getNamedItem('schemaLocation') === NULL ) {
$this->fetchXml();
}
// figure out if we're dealing with a new or old schema
$rootEl = $this->xml->firstChild;
if (!$rootEl->hasAttributes() || $rootEl->attributes->getNamedItem('schemaLocation') === NULL) {
//$tmpname = substr($this->pid, strpos($this->pid, ':') + 1);
$tmpname = user_password(10);
$this->convertFromOldSchema();
drupal_add_js("fedora_repository_print_new_schema_$tmpname = function(tagID) {
var target = document.getElementById(tagID);
var content = target.innerHTML;
var text = '<html><head><title>Title' +
'</title><body>' + content +'</body></html>';
printerWindow = window.open('', '', 'toolbar=no,location=no,' + 'status=no,menu=no,scrollbars=yes,width=650,height=400');
printerWindow.document.open();
printerWindow.document.write(text);
} ", 'inline');
var target = document.getElementById(tagID);
var content = target.innerHTML;
var text = '<html><head><title>Title' +
'</title><body>' + content +'</body></html>';
printerWindow = window.open('', '', 'toolbar=no,location=no,' + 'status=no,menu=no,scrollbars=yes,width=650,height=400');
printerWindow.document.open();
printerWindow.document.write(text);
}", 'inline');
drupal_set_message('<span id="new_schema_'. $tmpname .'" style="display: none;">'. htmlentities($this->xml->saveXML()) .'</span>Warning: XMLDatastream performed conversion of \''. $this->getIdentifier() .'\' from old schema. Please update the datastream. The new datastream contents are <a href="javascript:fedora_repository_print_new_schema_'. $tmpname .'(\'new_schema_'. $tmpname .'\')">here.</a> ');
$rootEl = $this->xml->firstChild;
if (user_access('administer site configuration')) {
drupal_set_message('<span id="new_schema_' . $tmpname . '" style="display: none;">' . htmlentities($this->xml->saveXML()) . '</span>Warning: XMLDatastream performed conversion of \'' . $this->getIdentifier() . '\' from old schema. Please update the datastream. The new datastream contents are <a href="javascript:fedora_repository_print_new_schema_' . $tmpname . '(\'new_schema_' . $tmpname . '\')">here.</a> ');
}
$rootEl = $this->xml->firstChild;
}
$schemaLocation = NULL;
if ($this->forceSchema) {
// hack because you cant easily get the static property value from
// hack because you cant easily get the static property value from
// a subclass.
$vars = get_class_vars(get_class($this));
$schemaLocation = $vars['SCHEMA_URI'];
}
elseif ($rootEl->attributes->getNamedItem('schemaLocation') !== NULL) {
} elseif ($rootEl->attributes->getNamedItem('schemaLocation') !== NULL) {
//figure out where the schema is located and validate.
list(, $schemaLocation) = preg_split('/\s+/', $rootEl->attributes->getNamedItem('schemaLocation')->nodeValue);
$name = $rootEl->getAttribute('name');
if ($name !== FALSE) {
$this->name = $name;
}
}
$schemaLocation = NULL;
return TRUE;
$schemaLocation = NULL;
return TRUE;
if ($schemaLocation !== NULL) {
if (!$this->xml->schemaValidate($schemaLocation)) {
$ret = FALSE;
$errors=libxml_get_errors();
$errors = libxml_get_errors();
foreach ($errors as $err) {
self::$errors[] = 'XML Error: Line '. $err->line .': '. $err->message;
self::$errors[] = 'XML Error: Line ' . $err->line . ': ' . $err->message;
}
}
else {
$this->name=$rootEl->attributes->getNamedItem('name')->nodeValue;
} else {
$this->name = $rootEl->attributes->getNamedItem('name')->nodeValue;
}
}
else {
} else {
$ret = FALSE;
self::$errors[] = 'Unable to load schema.';
}
$this->valid = $ret;
}
}
return $this->valid;
}
}
/**
* Saves the current XML datastream back to fedora. The XML must validate.
*
* @return boolean $success
*/
*/
public function saveToFedora() {
module_load_include('inc', 'Fedora_Repository', 'api/fedora_item');
if ($this->validate()) {
$item = new Fedora_Item($this->pid);
$item->modify_datastream_by_value($this->dumpXml(), $this->dsid, $this->name, 'application/xml');
return TRUE;
return TRUE;
}
return FALSE;
}
@ -243,32 +226,33 @@ printerWindow.document.write(text);
* @return boolean $valid
*/
public function purgeVersions($start_date, $end_date = NULL) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$fedora_item = new Fedora_Item($this->pid);
return $fedora_item->purge_datastream( $this->dsid, $start_date, $end_date);
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$fedora_item = new Fedora_Item($this->pid);
return $fedora_item->purge_datastream($this->dsid, $start_date, $end_date);
}
/**
* Gets the history of the datastream from fedora.
* Returns false on failure.
*
* @return string[] $ret
*/
*/
public function getHistory() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$fedora_item = new Fedora_Item($this->pid);
$history = $fedora_item->get_datastream_history($this->dsid);
$ret = FALSE;
if ($history !== FALSE) {
$ret = array();
foreach ($history as $version) {
if ($version->versionID !== NULL) $ret[] = array('versionID' => $version->versionID, 'createDate' => $version->createDate);
}
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$fedora_item = new Fedora_Item($this->pid);
$history = $fedora_item->get_datastream_history($this->dsid);
$ret = FALSE;
if ($history !== FALSE) {
$ret = array();
foreach ($history as $version) {
if ($version->versionID !== NULL)
$ret[] = array('versionID' => $version->versionID, 'createDate' => $version->createDate);
}
return $ret;
}
return $ret;
}
/**
* Attempts to convert from the old XML schema to the new by
* traversing the XML DOM and building a new DOM. When done
@ -277,5 +261,4 @@ printerWindow.document.write(text);
* @return void
*/
abstract protected function convertFromOldSchema();
}

82
fedora_repository.install

@ -12,3 +12,85 @@ function fedora_collections_enable() {
//nothing to do as we do not currently touch the drupal database.
//other than the variables table
}
/**
* Implementation of hook_requirements().
*
* @return
* An array describing the status of the site regarding available updates.
* If there is no update data, only one record will be returned, indicating
* that the status of core can't be determined. If data is available, there
* will be two records: one for core, and another for all of contrib
* (assuming there are any contributed modules or themes enabled on the
* site). In addition to the fields expected by hook_requirements ('value',
* 'severity', and optionally 'description'), this array will contain a
* 'reason' attribute, which is an integer constant to indicate why the
* given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or
* UPDATE_UNKNOWN). This is used for generating the appropriate e-mail
* notification messages during update_cron(), and might be useful for other
* modules that invoke update_requirements() to find out if the site is up
* to date or not.
*
* @see _update_message_text()
* @see _update_cron_notify()
*/
function fedora_repository_requirements($phase) {
global $base_url;
$requirements = array();
if ($phase == 'install') {
$requirements['fedora-soap']['title'] = t("PHP SOAP extension library");
if (!class_exists('SoapClient')) {
$requirements['fedora-soap']['value'] = t("Not installed");
$requirements['fedora-soap']['severity'] = REQUIREMENT_ERROR;
$requirements['fedora-soap']['description'] = t('Ensure that the PHP SOAP extension is installed.');
}
else {
$requirements['fedora-soap']['value'] = t("Installed");
$requirements['fedora-soap']['severity'] = REQUIREMENT_OK;
}
}
elseif ($phase == 'runtime') {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$requirements['fedora-repository']['title'] = t("Fedora server");
if (!fedora_available()) {
$requirements['fedora-repository']['value'] = t("Not available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_ERROR;
$requirements['fedora-repository']['description'] = t('Ensure that Fedora is running and that the <a href="@collection-settings">collection settings</a> are correct.',
array('@collection-settings' => $base_url.'/admin/settings/fedora_repository'));
}
else {
$requirements['fedora-repository']['value'] = t("Available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_OK;
}
// Check for ImageMagick
$requirements['fedora-imagemagick']['title'] = t("ImageMagick convert in \$PATH");
system('which convert', $res);
if ($res != 0) {
$requirements['fedora-imagemagick']['value'] = t('Not in $PATH');
$requirements['fedora-imagemagick']['description'] = t('Islandora will not be able to create thumbnails. Ensure that <a href="www.imagemagick.org/">ImageMagick</a> is installed and the convert command is executable by the web server user.');
$requirements['fedora-imagemagick']['severity'] = REQUIREMENT_WARNING;
}
else {
$requirements['fedora-imagemagick']['value'] = t("Available");
$requirements['fedora-imagemagick']['severity'] = REQUIREMENT_OK;
}
$requirements['fedora-kakadu']['title'] = 'Kakadu kdu_compress in $PATH';
system('which kdu_compress', $kdu_res);
if ($kdu_res != 0) {
$requirements['fedora-kakadu']['value'] = ('Not in $PATH');
$requirements['fedora-kakadu']['description'] = t('Islandora cannot convert TIFF image files to JPEG2000 format. Ensure <a href="http://www.kakadusoftware.com/">Kakadu</a> is installed and the kdu_compress command is executable by the web server user.');
$requirements['fedora-kakadu']['severity'] = REQUIREMENT_WARNING;
}
else {
$requirements['fedora-kakadu']['value'] = t("Available");
$requirements['fedora-kakadu']['severity'] = REQUIREMENT_OK;
}
}
return $requirements;
}

66
fedora_repository.module

@ -1759,69 +1759,3 @@ function fedora_repository_display_schema($file) {
return;
}
/**
* Implementation of hook_requirements().
*
* @return
* An array describing the status of the site regarding available updates.
* If there is no update data, only one record will be returned, indicating
* that the status of core can't be determined. If data is available, there
* will be two records: one for core, and another for all of contrib
* (assuming there are any contributed modules or themes enabled on the
* site). In addition to the fields expected by hook_requirements ('value',
* 'severity', and optionally 'description'), this array will contain a
* 'reason' attribute, which is an integer constant to indicate why the
* given status is being returned (UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT, or
* UPDATE_UNKNOWN). This is used for generating the appropriate e-mail
* notification messages during update_cron(), and might be useful for other
* modules that invoke update_requirements() to find out if the site is up
* to date or not.
*
* @see _update_message_text()
* @see _update_cron_notify()
*/
function fedora_repository_requirements($phase) {
global $base_url;
if ($phase == 'runtime') {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$requirements = array();
$requirements['fedora-repository']['title'] = t("Fedora server");
if (!fedora_available()) {
$requirements['fedora-repository']['value'] = t("Not available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_ERROR;
$requirements['fedora-repository']['description'] = t('Ensure that Fedora is running and that the <a href="@collection-settings">collection settings</a> are correct.',
array('@collection-settings' => $base_url.'/admin/settings/fedora_repository'));
}
else {
$requirements['fedora-repository']['value'] = t("Available");
$requirements['fedora-repository']['severity'] = REQUIREMENT_OK;
}
// Check for ImageMagick
$requirements['fedora-imagemagick']['title'] = t("ImageMagick convert in \$PATH");
system('which convert', $res);
if ($res != 0) {
$requirements['fedora-imagemagick']['value'] = t('Not in $PATH');
$requirements['fedora-imagemagick']['description'] = t('Islandora will not be able to create thumbnails. Ensure that <a href="www.imagemagick.org/">ImageMagick</a> is installed and the convert command is executable by the web server user.');
$requirements['fedora-imagemagick']['severity'] = REQUIREMENT_WARNING;
}
else {
$requirements['fedora-imagemagick']['value'] = t("Available");
$requirements['fedora-imagemagick']['severity'] = REQUIREMENT_OK;
}
$requirements['fedora-kakadu']['title'] = 'Kakadu kdu_compress in $PATH';
system('which kdu_compress', $kdu_res);
if ($kdu_res != 0) {
$requirements['fedora-kakadu']['value'] = ('Not in $PATH');
$requirements['fedora-kakadu']['description'] = t('Islandora cannot convert TIFF image files to JPEG2000 format. Ensure <a href="http://www.kakadusoftware.com/">Kakadu</a> is installed and the kdu_compress command is executable by the web server user.');
$requirements['fedora-kakadu']['severity'] = REQUIREMENT_WARNING;
}
else {
$requirements['fedora-kakadu']['value'] = t("Available");
$requirements['fedora-kakadu']['severity'] = REQUIREMENT_OK;
}
}
return $requirements;
}
Loading…
Cancel
Save