function srwDiagnostics($diagCode, $diagDetails, $exportStylesheet) { global $contentTypeCharset; // defined in 'ini.inc.php' // Map SRU/W diagnostic numbers to their corresponding messages: $diagMessages = mapSRWDiagnostics(); // function 'mapSRWDiagnostics()' is defined in 'webservice.inc.php' if (isset($diagMessages[$diagCode])) { $diagMessage = $diagMessages[$diagCode]; } else { $diagMessage = "Unknown error"; } $srwCollectionDoc = new XMLDocument(); $srwCollectionDoc->setEncoding($contentTypeCharset); $srwCollection = srwGenerateBaseTags("searchRetrieveResponse"); $diagnosticsBranch = new XMLBranch("srw:diagnostics"); // since we've defined the 'diag' namespace in the <searchRetrieveResponse> element (see function 'srwGenerateBaseTags()'), // we can simply use '<diag:diagnostic>' below; otherwise we should use '<diagnostic xmlns="http://www.loc.gov/zing/srw/diagnostic/">': // addNewBranch($diagnosticsBranch, "diagnostic", array("xmlns" => "http://www.loc.gov/zing/srw/diagnostic/"), ""); $diagnosticsBranch->setTagContent("info:srw/diagnostic/1/" . $diagCode, "srw:diagnostics/diag:diagnostic/uri"); $diagnosticsBranch->setTagContent($diagMessage, "srw:diagnostics/diag:diagnostic/message"); if (!empty($diagDetails)) { $diagnosticsBranch->setTagContent(encodeHTMLspecialchars($diagDetails), "srw:diagnostics/diag:diagnostic/details"); } $srwCollection->addXMLBranch($diagnosticsBranch); $srwCollectionDoc->setXML($srwCollection); $srwCollectionString = $srwCollectionDoc->getXMLString(); // Add the XML Stylesheet definition: // Note that this is just a hack (that should get fixed) since I don't know how to do it properly using the ActiveLink PHP XML Package ?:-/ if (!empty($exportStylesheet)) { $srwCollectionString = preg_replace("/(?=\\<srw:searchRetrieveResponse)/i", "<?xml-stylesheet type=\"text/xsl\" href=\"" . $exportStylesheet . "\"?>\n", $srwCollectionString); } return $srwCollectionString; }
function openSearchDiagnostics($diagCode, $diagDetails, $exportStylesheet) { global $contentTypeCharset; // defined in 'ini.inc.php' // Map SRU/W diagnostic numbers to their corresponding messages: // (i.e., for OpenSearch diagnostics, we simply re-use the SRU/W diagnostics) $diagMessages = mapSRWDiagnostics(); // function 'mapSRWDiagnostics()' is defined in 'webservice.inc.php' if (isset($diagMessages[$diagCode])) { $diagMessage = $diagMessages[$diagCode]; } else { $diagMessage = "Unknown error"; } $atomCollectionDoc = new XMLDocument(); $atomCollectionDoc->setEncoding($contentTypeCharset); $atomCollection = openSearchGenerateBaseTags("Error"); // add feed-level tags: // - 'id': addNewBranch($atomCollection, "id", array(), "info:srw/diagnostic/1/"); // could something else be used as diagnostics feed ID instead? // - OpenSearch elements: addNewBranch($atomCollection, "opensearch:totalResults", array(), "1"); addNewBranch($atomCollection, "openSearch:startIndex", array(), "1"); addNewBranch($atomCollection, "openSearch:itemsPerPage", array(), "1"); $diagnosticsBranch = new XMLBranch("entry"); // add entry-level tags: addNewBranch($diagnosticsBranch, "title", array(), $diagMessage); // addNewBranch($atomCollection, "link", array("href" => ""), ""); // TODO (what could be used as link for a diagnostics entry?) addNewBranch($diagnosticsBranch, "updated", array(), generateISO8601TimeStamp()); // function 'generateISO8601TimeStamp()' is defined in 'include.inc.php' addNewBranch($diagnosticsBranch, "id", array(), "info:srw/diagnostic/1/" . $diagCode); $diagContent = $diagMessage; if (!empty($diagDetails)) { $diagContent .= ": " . $diagDetails; } addNewBranch($diagnosticsBranch, "content", array("type" => "text"), "Error " . $diagCode . ": " . $diagContent); // TODO: I18n $atomCollection->addXMLBranch($diagnosticsBranch); $atomCollectionDoc->setXML($atomCollection); $atomCollectionString = $atomCollectionDoc->getXMLString(); return $atomCollectionString; }