|
|
|
@ -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. |
|
|
|
|
|
|
|
|
|
public $pid; |
|
|
|
|
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 |
|
|
|
@ -64,8 +59,6 @@ abstract class XMLDatastream {
|
|
|
|
|
return $valid; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Parses the DSID from an identifier. |
|
|
|
|
* TODO: combine this method with getPidFromIdentifier? |
|
|
|
@ -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. |
|
|
|
@ -109,7 +100,6 @@ abstract class XMLDatastream {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets the identifier for this XMLDatastream |
|
|
|
|
* Returns FALSE on failure. |
|
|
|
@ -122,7 +112,6 @@ abstract class XMLDatastream {
|
|
|
|
|
return ($this->pid != NULL && $this->dsid != NULL) ? $this->pid . '/' . $this->dsid : FALSE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Dumps the XMLDatastream as an XML String |
|
|
|
|
* |
|
|
|
@ -136,7 +125,6 @@ abstract class XMLDatastream {
|
|
|
|
|
return $this->xml->saveXml(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Validates the XMLDatastream against the schema location |
|
|
|
|
* defined by the xmlns:schemaLocation attribute of the root |
|
|
|
@ -151,6 +139,7 @@ abstract class XMLDatastream {
|
|
|
|
|
* @return boolean $valid |
|
|
|
|
*/ |
|
|
|
|
public function validate() { |
|
|
|
|
global $user; |
|
|
|
|
if ($this->valid === NULL) { |
|
|
|
|
$ret = TRUE; |
|
|
|
|
if ($this->xml == NULL) { |
|
|
|
@ -172,7 +161,10 @@ abstract class XMLDatastream {
|
|
|
|
|
printerWindow.document.write(text); |
|
|
|
|
}", 'inline'); |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -182,15 +174,9 @@ printerWindow.document.write(text);
|
|
|
|
|
// 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; |
|
|
|
@ -201,12 +187,10 @@ printerWindow.document.write(text);
|
|
|
|
|
foreach ($errors as $err) { |
|
|
|
|
self::$errors[] = 'XML Error: Line ' . $err->line . ': ' . $err->message; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else { |
|
|
|
|
$this->name = $rootEl->attributes->getNamedItem('name')->nodeValue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
} else { |
|
|
|
|
$ret = FALSE; |
|
|
|
|
self::$errors[] = 'Unable to load schema.'; |
|
|
|
|
} |
|
|
|
@ -217,7 +201,6 @@ printerWindow.document.write(text);
|
|
|
|
|
return $this->valid; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Saves the current XML datastream back to fedora. The XML must validate. |
|
|
|
|
* |
|
|
|
@ -263,7 +246,8 @@ printerWindow.document.write(text);
|
|
|
|
|
if ($history !== FALSE) { |
|
|
|
|
$ret = array(); |
|
|
|
|
foreach ($history as $version) { |
|
|
|
|
if ($version->versionID !== NULL) $ret[] = array('versionID' => $version->versionID, 'createDate' => $version->createDate); |
|
|
|
|
if ($version->versionID !== NULL) |
|
|
|
|
$ret[] = array('versionID' => $version->versionID, 'createDate' => $version->createDate); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return $ret; |
|
|
|
@ -277,5 +261,4 @@ printerWindow.document.write(text);
|
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
abstract protected function convertFromOldSchema(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|