Improve error handling in class.tx_dlf_oai.php

This commit is contained in:
Sebastian Meyer 2011-09-15 10:25:08 +02:00
parent 1c55d8b297
commit 800fec7287
2 changed files with 29 additions and 6 deletions

View File

@ -116,7 +116,7 @@ class tx_dlf_oai extends tx_dlf_plugin {
$this->error = TRUE;
$error = $this->oai->createElementNS('http://www.openarchives.org/OAI/2.0/', 'error', $this->pi_getLL($type, $type, TRUE));
$error = $this->oai->createElementNS('http://www.openarchives.org/OAI/2.0/', 'error', htmlspecialchars($this->pi_getLL($type, $type, FALSE), ENT_NOQUOTES, 'UTF-8'));
$error->setAttribute('code', $type);
@ -342,16 +342,37 @@ class tx_dlf_oai extends tx_dlf_plugin {
*/
protected function getMetsData(array $metadata) {
$mets = NULL;
// Load METS file.
$xml = new DOMDocument();
$xml->load($metadata['location']);
if ($xml->load($metadata['location'])) {
// Get root element.
$root = $xml->getElementsByTagNameNS($this->formats['mets']['namespace'], 'mets');
// Get root element.
$root = $xml->getElementsByTagNameNS($this->formats['mets']['namespace'], 'mets');
// Import node into DOMDocument.
$mets = $this->oai->importNode($root->item(0), TRUE);
if ($root->item(0) instanceof DOMNode) {
// Import node into DOMDocument.
$mets = $this->oai->importNode($root->item(0), TRUE);
} else {
trigger_error('No METS node found in file "'.$location.'"', E_USER_ERROR);
}
} else {
trigger_error('Could not load file "'.$location.'"', E_USER_ERROR);
}
if ($mets === NULL) {
$mets = $this->oai->createElementNS('http://goobi.org/', 'goobi:error', htmlspecialchars($this->pi_getLL('error', 'Error!', FALSE), ENT_NOQUOTES, 'UTF-8'));
}
return $mets;

View File

@ -21,6 +21,7 @@
<label index="noRecordsMatch">The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list.</label>
<label index="noMetadataFormats">There are no metadata formats available for the specified item.</label>
<label index="noSetHierarchy">The repository does not support sets or the value of the set argument is invalid.</label>
<label index="error">An error occured, please try again later. If this happens consistently, please contact the administrator.</label>
</languageKey>
<languageKey index="de" type="array">
<label index="tt_content.pi_flexform.sheet_general">Einstellungen</label>
@ -38,6 +39,7 @@
<label index="noRecordsMatch">Die Anfrage ergab eine leere Treffermenge.</label>
<label index="noMetadataFormats">Für den gewünschten Datensatz werden keine Datenformate unterstützt.</label>
<label index="noSetHierarchy">Das Repository unterstützt keine Sets oder der Wert des Parameters "set" ist ungültig.</label>
<label index="error">Ein Fehler ist aufgetreten. Bitte versuchen Sie es später noch einmal. Sollte der Fehler dauerhaft auftreten, kontaktieren Sie bitte den Administrator.</label>
</languageKey>
</data>
</T3locallang>