4 # FILE: Scout--OAIServer.php
10 # AUTHOR: Edward Almasy
12 # Copyright 2002-2004 Internet Scout Project
13 # http://scout.wisc.edu
18 # ---- PUBLIC INTERFACE --------------------------------------------------
23 # save DB handle for our use
26 # save repository description
29 # save supported option settings
33 # normalize repository description values
34 $this->RepDescr[
"IDPrefix"] =
35 preg_replace(
"/[^0-9a-z]/i",
"", $this->RepDescr[
"IDPrefix"]);
40 # load OAI request type and arguments
43 # set default indent size
44 $this->IndentSize = 4;
46 # start with empty list of formats
47 $this->FormatDescrs = array();
49 # initialize description of mandatory format
50 $OaidcNamespaceList = array(
51 "oai_dc" =>
"http://www.openarchives.org/OAI/2.0/oai_dc/",
52 "dc" =>
"http://purl.org/dc/elements/1.1/",
54 $OaidcElements = array(
71 $OaidcQualifiers = array();
73 "http://www.openarchives.org/OAI/2.0/oai_dc/"
74 .
" http://www.openarchives.org/OAI/2.0/oai_dc.xsd",
76 $OaidcNamespaceList, $OaidcElements, $OaidcQualifiers);
79 # add metadata format to export
80 function AddFormat($Name, $TagName, $SchemaLocation, $SchemaVersion, $NamespaceList, $ElementList, $QualifierList)
82 # find highest current format ID
84 foreach ($this->FormatDescrs as $FormatName => $FormatDescr)
86 if ($FormatDescr[
"FormatId"] > $HighestFormatId)
88 $HighestFormatId = $FormatDescr[
"FormatId"];
92 # set new format ID to next value
93 $this->FormatDescrs[$Name][
"FormatId"] = $HighestFormatId + 1;
96 $this->FormatDescrs[$Name][
"TagName"] = $TagName;
97 $this->FormatDescrs[$Name][
"SchemaLocation"] = $SchemaLocation;
98 $this->FormatDescrs[$Name][
"SchemaVersion"] = $SchemaVersion;
99 $this->FormatDescrs[$Name][
"ElementList"] = $ElementList;
100 $this->FormatDescrs[$Name][
"QualifierList"] = $QualifierList;
101 $this->FormatDescrs[$Name][
"NamespaceList"] = $NamespaceList;
103 # start out with empty mappings list
104 if (!isset($this->FieldMappings[$Name]))
106 $this->FieldMappings[$Name] = array();
110 # return list of formats
114 foreach ($this->FormatDescrs as $FormatName => $FormatDescr)
116 $FList[$FormatDescr[
"FormatId"]] = $FormatName;
121 # return list of elements for a given format
124 return $this->FormatDescrs[$FormatName][
"ElementList"];
127 # return list of qualifiers for a given format
130 return $this->FormatDescrs[$FormatName][
"QualifierList"];
133 # get/set mapping of local field to OAI field
136 # return stored value
137 if (isset($this->FieldMappings[$FormatName][$LocalFieldName]))
139 return $this->FieldMappings[$FormatName][$LocalFieldName];
148 $this->FieldMappings[$FormatName][$LocalFieldName] = $OAIFieldName;
151 # get/set mapping of local qualifier to OAI qualifier
154 # return stored value
155 if (isset($this->QualifierMappings[$FormatName][$LocalQualifierName]))
157 return $this->QualifierMappings[$FormatName][$LocalQualifierName];
166 $this->QualifierMappings[$FormatName][$LocalQualifierName] = $OAIQualifierName;
171 # call appropriate method based on request type
172 switch (strtoupper($this->Args[
"verb"]))
182 case "LISTIDENTIFIERS":
190 case "LISTMETADATAFORMATS":
199 # return "bad argument" response
202 $Response .= $this->
GetErrorTag(
"badVerb",
"Bad or unknown request type.");
207 # return generated response to caller
212 # ---- PRIVATE INTERFACE -------------------------------------------------
227 # ---- response generation methods
231 # initialize response
234 # add request info tag
237 # open response type tag
238 $Response .= $this->
FormatTag(
"Identify");
240 # add repository info tags
241 $Response .= $this->
FormatTag(
"repositoryName", $this->RepDescr[
"Name"]);
242 $Response .= $this->
FormatTag(
"baseURL", $this->RepDescr[
"BaseURL"]);
243 $Response .= $this->
FormatTag(
"protocolVersion",
"2.0");
244 foreach ($this->RepDescr[
"AdminEmail"] as $AdminEmail)
246 $Response .= $this->
FormatTag(
"adminEmail", $AdminEmail);
248 $Response .= $this->
FormatTag(
"earliestDatestamp", $this->RepDescr[
"EarliestDate"]);
249 $Response .= $this->
FormatTag(
"deletedRecord",
"no");
250 $Response .= $this->
FormatTag(
"granularity",
251 (strtoupper($this->RepDescr[
"DateGranularity"]) ==
"DATETIME")
252 ?
"YYYY-MM-DDThh:mm:ssZ" :
"YYYY-MM-DD");
254 # add repository description section
255 $Response .= $this->
FormatTag(
"description");
257 "xmlns" =>
"http://www.openarchives.org/OAI/2.0/oai-identifier",
258 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
259 "xsi:schemaLocation" =>
"http://www.openarchives.org/OAI/2.0/oai-identifier http://www.openarchives.org/OAI/2.0/oai-identifier.xsd",
261 $Response .= $this->
FormatTag(
"oai-identifier", NULL, $Attribs);
262 $Response .= $this->
FormatTag(
"scheme",
"oai");
263 $Response .= $this->
FormatTag(
"repositoryIdentifier", $this->RepDescr[
"IDDomain"]);
264 $Response .= $this->
FormatTag(
"delimiter",
":");
269 # close response type tag
275 # return response to caller
281 # initialize response
284 # if arguments were bad
285 if (isset($this->Args[
"identifier"]))
293 if (isset($this->Args[
"metadataPrefix"]))
295 $MetadataFormat = $this->Args[
"metadataPrefix"];
299 $MetadataFormat = NULL;
301 if (($ItemId == NULL) || ($MetadataFormat == NULL) || !is_array($this->FieldMappings[$MetadataFormat]))
303 # add request info tag with no attributes
307 $Response .= $this->
GetErrorTag(
"badArgument",
"Bad argument found.");
311 # add request info tag
312 $ReqArgList = array(
"identifier",
"metadataPrefix");
315 # attempt to load item corresponding to record
322 $Response .= $this->
GetErrorTag(
"idDoesNotExist",
"No item found for specified ID.");
326 # open response type tag
327 $Response .= $this->
FormatTag(
"GetRecord");
329 # add tags for record
332 # close response type tag
340 # return response to caller
347 if ($IncludeMetadata)
349 $Request =
"ListRecords";
353 $Request =
"ListIdentifiers";
356 # initialize response
359 # if resumption token supplied
360 if (isset($this->Args[
"resumptionToken"]))
362 # set expected argument lists
363 $ReqArgList = array(
"resumptionToken");
366 # parse into list parameters
371 # set expected argument lists
372 $ReqArgList = array(
"metadataPrefix");
373 $OptArgList = array(
"from",
"until",
"set");
375 # get list parameters from incoming arguments
378 # set list starting point to beginning
379 $Args[
"ListStartPoint"] = 0;
382 # if resumption token was supplied and was bad
385 # add request info tag
386 $Response .= $this->
GetRequestTag($Request, $ReqArgList, $OptArgList);
388 # add error tag indicating bad resumption token
389 $Response .= $this->
GetErrorTag(
"badResumptionToken",
"Bad resumption token.");
391 # if other parameter also supplied
392 if (count($this->Args) > 2)
394 # add error tag indicating exclusive argument error
395 $Response .= $this->
GetErrorTag(
"badArgument",
"Resumption token is exclusive argument.");
398 # else if resumption token supplied and other arguments also supplied
399 elseif (isset($this->Args[
"resumptionToken"]) && (count($this->Args) > 2))
401 # add error tag indicating exclusive argument error
403 $Response .= $this->
GetErrorTag(
"badArgument",
"Resumption token is exclusive argument.");
405 # else if metadata format was not specified
406 elseif (empty(
$Args[
"metadataPrefix"]))
408 # add request info tag with no attributes
411 # add error tag indicating bad argument
412 $Response .= $this->
GetErrorTag(
"badArgument",
"No metadata format specified.");
414 # else if from or until date is specified but bad
418 # add request info tag with no attributes
421 # add error tag indicating bad argument
422 $Response .= $this->
GetErrorTag(
"badArgument",
"Bad date format.");
426 # add request info tag
427 $Response .= $this->
GetRequestTag($Request, $ReqArgList, $OptArgList);
429 # if set requested and we do not support sets
430 if (isset(
$Args[
"set"]) && ($this->SetsSupported != TRUE))
432 # add error tag indicating that we don't support sets
433 $Response .= $this->
GetErrorTag(
"noSetHierarchy",
"This repository does not support sets.");
435 # else if requested metadata format is not supported
436 elseif (empty($this->FormatDescrs[
$Args[
"metadataPrefix"]]))
438 # add error tag indicating that format is not supported
439 $Response .= $this->
GetErrorTag(
"cannotDisseminateFormat",
"Metadata format \"".$Args[
"metadataPrefix"].
"\" not supported by this repository.");
444 if (isset($Args[
"set"]))
446 # if OAI-SQ supported and set represents OAI-SQ query
447 if ($this->OaisqSupported && $this->
IsOaisqQuery($Args[
"set"]))
449 # parse OAI-SQ search parameters out of set name
450 $SearchParams = $this->
ParseOaisqQuery($Args[
"set"], $Args[
"metadataPrefix"]);
452 # if search parameters found
453 if (count($SearchParams))
455 # perform search for items that match OAI-SQ request
458 (isset($Args[
"from"]) ? $Args[
"from"] : NULL),
459 (isset($Args[
"until"]) ? $Args[
"until"] : NULL));
469 # get list of items in set that matches incoming criteria
472 (isset($Args[
"from"]) ? $Args[
"from"] : NULL),
473 (isset($Args[
"until"]) ? $Args[
"until"] : NULL));
478 # get list of items that matches incoming criteria
480 (isset($Args[
"from"]) ? $Args[
"from"] : NULL),
481 (isset($Args[
"until"]) ? $Args[
"until"] : NULL));
485 if (count($ItemIds) == 0)
487 # add error tag indicating that no records found that match spec
488 $Response .= $this->
GetErrorTag(
"noRecordsMatch",
"No records were found that match the specified parameters.");
492 # open response type tag
495 # initialize count of processed items
499 foreach ($ItemIds as $ItemId)
501 # if item is within range
502 if ($ListIndex >= $Args[
"ListStartPoint"])
507 # add record for item
508 $Response .= $this->
GetRecordTags($Item, $Args[
"metadataPrefix"], $IncludeMetadata);
511 # increment count of processed items
514 # stop processing if we have processed max number of items in a pass
515 $MaxItemsPerPass = 20;
516 if (($ListIndex - $Args[
"ListStartPoint"]) >= $MaxItemsPerPass) {
break; }
519 # if items left unprocessed
520 if ($ListIndex < count($ItemIds))
522 # add resumption token tag
524 (isset($Args[
"until"]) ? $Args[
"until"] : NULL),
525 (isset($Args[
"metadataPrefix"]) ? $Args[
"metadataPrefix"] : NULL),
526 (isset($Args[
"set"]) ? $Args[
"set"] : NULL),
528 $Response .= $this->
FormatTag(
"resumptionToken", $Token);
532 # if we started with a resumption token tag
533 if (isset($this->Args[
"resumptionToken"]))
535 # add empty resumption token tag to indicate end of set
536 $Response .= $this->
FormatTag(
"resumptionToken",
"");
540 # close response type tag
549 # return response to caller
555 # initialize response
558 # if arguments were bad
559 $Arg = isset($this->Args[
"identifier"]) ? $this->Args[
"identifier"] : NULL;
561 if (isset($this->Args[
"identifier"]) && ($ItemId == NULL))
565 $Response .= $this->
GetErrorTag(
"idDoesNotExist",
"Identifier unknown or illegal.");
569 # add request info tag
570 $OptArgList = array(
"identifier");
571 $Response .= $this->
GetRequestTag(
"ListMetadataFormats", NULL, $OptArgList);
573 # open response type tag
574 $Response .= $this->
FormatTag(
"ListMetadataFormats");
576 # for each supported format
577 foreach ($this->FormatDescrs as $FormatName => $FormatDescr)
580 $Response .= $this->
FormatTag(
"metadataFormat");
582 # add tags describing format
583 $Response .= $this->
FormatTag(
"metadataPrefix", $FormatName);
584 $Pieces = preg_split(
"/[\s]+/", $FormatDescr[
"SchemaLocation"]);
585 $Response .= $this->
FormatTag(
"schema", $Pieces[1]);
586 $Response .= $this->
FormatTag(
"metadataNamespace", $FormatDescr[
"NamespaceList"][$FormatName]);
592 # close response type tag
599 # return response to caller
605 # initialize response
608 # add request info tag
609 $OptArgList = array(
"resumptionToken");
610 $Response .= $this->
GetRequestTag(
"ListSets", NULL, $OptArgList);
612 # retrieve list of supported sets
613 $SetList = $this->SetsSupported ? $this->
ItemFactory->GetListOfSets() : array();
615 # if sets not supported or we have no sets
616 if ((!$this->SetsSupported) || (!count($SetList) && !$this->OaisqSupported))
618 # add error tag indicating that we do not support sets
619 $Response .= $this->
GetErrorTag(
"noSetHierarchy",
"This repository does not support sets.");
623 # open response type tag
624 $Response .= $this->
FormatTag(
"ListSets");
626 # if OAI-SQ is enabled
627 if ($this->OaisqSupported)
629 # add OAI-SQ to list of sets
630 $SetList[
"OAI-SQ"] =
"OAI-SQ";
631 $SetList[
"OAI-SQ-F"] =
"OAI-SQ-F";
634 # for each supported set
635 foreach ($SetList as $SetName => $SetSpec)
640 # add set spec and set name
641 $Response .= $this->
FormatTag(
"setSpec", $SetSpec);
642 $Response .= $this->
FormatTag(
"setName", $SetName);
648 # close response type tag
655 # return response to caller
660 # ---- common private methods
664 # start with XML declaration
665 $Tags =
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
667 # add OAI-PMH root element begin tag
668 $Tags .=
"<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\"\n"
669 .
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
670 .
" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/\n"
671 .
" http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">\n";
673 # add response timestamp
674 $Tags .=
" <responseDate>".date(
"Y-m-d\\TH:i:s\\Z").
"</responseDate>\n";
676 # return tags to caller
682 # close out OAI-PMH root element
683 $Tags =
"</OAI-PMH>\n";
685 # return tags to caller
689 function GetRequestTag($RequestType = NULL, $ReqArgList = NULL, $OptArgList = NULL)
691 # build attribute array
692 $AttributeList = array();
693 if ($RequestType !== NULL)
695 $AttributeList[
"verb"] = $RequestType;
697 if ($ReqArgList != NULL)
699 foreach ($ReqArgList as $ArgName)
701 if (isset($this->Args[$ArgName]))
703 $AttributeList[$ArgName] = $this->Args[$ArgName];
707 if ($OptArgList != NULL)
709 foreach ($OptArgList as $ArgName)
711 if (isset($this->Args[$ArgName]))
713 $AttributeList[$ArgName] = $this->Args[$ArgName];
718 # generate formatted tag
720 $this->RepDescr[
"BaseURL"],
723 # return tag to caller
729 return $this->
FormatTag(
"error", $ErrorMessage, array(
"code" => $ErrorCode));
734 # if more than identifiers requested
735 if ($IncludeMetadata)
742 # just initialize tag string with empty value
746 # add header with identifier, datestamp, and set tags
750 $Tags .= $this->
FormatTag(
"datestamp", $Item->GetDatestamp());
751 $Sets = $Item->GetSets();
752 foreach ($Sets as $Set)
754 $Tags .= $this->
FormatTag(
"setSpec", $Set);
758 # if more than identifiers requested
759 if ($IncludeMetadata)
764 # set up attributes for metadata format tag
765 $MFAttribs[
"xsi:schemaLocation"] = $this->FormatDescrs[$MetadataFormat][
"SchemaLocation"];
766 if (strlen($this->FormatDescrs[$MetadataFormat][
"SchemaVersion"]) > 0)
768 $MFAttribs[
"schemaVersion"] = $this->FormatDescrs[$MetadataFormat][
"SchemaVersion"];
770 $MFAttribs[
"xmlns:xsi"] =
"http://www.w3.org/2001/XMLSchema-instance";
771 foreach ($this->FormatDescrs[$MetadataFormat][
"NamespaceList"] as $NamespaceName => $NamespaceURI)
773 $MFAttribs[
"xmlns:".$NamespaceName] = $NamespaceURI;
776 # open metadata format tag
777 $Tags .= $this->
FormatTag($this->FormatDescrs[$MetadataFormat][
"TagName"], NULL, $MFAttribs);
779 # for each field mapping for this metadata format
780 foreach ($this->FieldMappings[$MetadataFormat] as $LocalFieldName => $OAIFieldName)
782 # if field looks like it has been mapped
783 if (strlen($OAIFieldName) > 0)
785 # retrieve content for field
786 $Content = $Item->GetValue($LocalFieldName);
788 # retrieve qualifiers for content
789 $Qualifier = $Item->GetQualifier($LocalFieldName);
791 # if content is array
792 if (is_array($Content))
794 # for each element of array
795 foreach ($Content as $ContentIndex => $ContentValue)
797 # if element has content
798 if (strlen($ContentValue) > 0)
800 # generate tag for element
801 if (isset($Qualifier[$ContentIndex]) && strlen($Qualifier[$ContentIndex]))
803 if (isset($this->QualifierMappings[$MetadataFormat][$Qualifier[$ContentIndex]])
804 && (strlen($this->QualifierMappings[$MetadataFormat][$Qualifier[$ContentIndex]]) > 0))
806 $ContentAttribs[
"xsi:type"] = $this->QualifierMappings[$MetadataFormat][$Qualifier[$ContentIndex]];
811 $ContentAttribs = NULL;
814 utf8_encode(htmlspecialchars(preg_replace(
"/[\\x00-\\x1F]+/",
"", $ContentValue))),
821 # if field has content
822 if (strlen($Content) > 0)
824 # generate tag for field
825 if (strlen($Qualifier) > 0)
827 if (isset($this->QualifierMappings[$MetadataFormat][$Qualifier])
828 && (strlen($this->QualifierMappings[$MetadataFormat][$Qualifier]) > 0))
830 $ContentAttribs[
"xsi:type"] = $this->QualifierMappings[$MetadataFormat][$Qualifier];
835 $ContentAttribs = NULL;
838 utf8_encode(htmlspecialchars(preg_replace(
"/[\\x00-\\x1F]+/",
"", $Content))),
845 # close metadata format tag
851 # if there is additional search info about this item
852 $SearchInfo = $Item->GetSearchInfo();
853 if (count($SearchInfo))
855 # open about and search info tags
858 "xmlns" =>
"http://scout.wisc.edu/XML/searchInfo/",
859 "xmlns:xsi" =>
"http://www.w3.org/2001/XMLSchema-instance",
860 "xsi:schemaLocation" =>
"http://scout.wisc.edu/XML/searchInfo/ http://scout.wisc.edu/XML/searchInfo.xsd",
862 $Tags .= $this->
FormatTag(
"searchInfo", NULL, $Attribs);
864 # for each piece of additional info
865 foreach ($SearchInfo as $InfoName => $InfoValue)
869 utf8_encode(htmlspecialchars(preg_replace(
"/[\\x00-\\x1F]+/",
"", $InfoValue))));
872 # close about and search info tags
878 # if more than identifiers requested
879 if ($IncludeMetadata)
885 # return tags to caller
891 # return encoded value to caller
892 return "oai:".$this->RepDescr[
"IDDomain"]
893 .
":".$this->RepDescr[
"IDPrefix"].
"-".$ItemId;
898 # assume that decode will fail
901 # split ID into component pieces
902 $Pieces = split(
":", $Identifier);
904 # if pieces look okay
905 if (($Pieces[0] ==
"oai") && ($Pieces[1] == $this->RepDescr[
"IDDomain"]))
908 $Pieces = split(
"-", $Pieces[2]);
910 # if identifier prefix looks okay
911 if ($Pieces[0] == $this->RepDescr[
"IDPrefix"])
913 # decoded value is final piece
918 # return decoded value to caller
924 # concatenate values to create token
925 $Token = $StartingDate.
"-_-".$EndingDate.
"-_-".$MetadataFormat.
"-_-"
926 .$SetSpec.
"-_-".$ListStartPoint;
928 # return token to caller
934 # split into component pieces
935 $Pieces = preg_split(
"/-_-/", $ResumptionToken);
937 # if we were unable to split token
938 if (count($Pieces) != 5)
945 # assign component pieces to list parameters
946 if (strlen($Pieces[0]) > 0) {
$Args[
"from"] = $Pieces[0]; }
947 if (strlen($Pieces[1]) > 0) {
$Args[
"until"] = $Pieces[1]; }
948 if (strlen($Pieces[2]) > 0) {
$Args[
"metadataPrefix"] = $Pieces[2]; }
949 if (strlen($Pieces[3]) > 0) {
$Args[
"set"] = $Pieces[3]; }
950 if (strlen($Pieces[4]) > 0) {
$Args[
"ListStartPoint"] = $Pieces[4]; }
953 # return list parameter array to caller
959 # if date is null or matches required format
960 if (empty($Date) || preg_match(
"/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $Date))
972 function FormatTag($Name = NULL, $Content = NULL, $Attributes = NULL, $NewIndentLevel = NULL)
974 static $IndentLevel = 1;
975 static $OpenTagStack = array();
977 # reset indent level if requested
978 if ($NewIndentLevel !== NULL)
980 $IndentLevel = $NewIndentLevel;
983 # if tag name supplied
986 # start out with appropriate indent
987 $Tag = str_repeat(
" ", ($IndentLevel * $this->IndentSize));
992 # if attributes supplied
993 if ($Attributes !== NULL)
996 foreach ($Attributes as $AttributeName => $AttributeValue)
998 $Tag .=
" ".$AttributeName.
"=\"".$AttributeValue.
"\"";
1002 # if content supplied
1003 if ($Content !== NULL)
1012 $Tag .=
"</".$Name.
">\n";
1019 # increase indent level
1022 # add tag to open tag stack
1023 array_push($OpenTagStack, $Name);
1028 # decrease indent level
1029 if ($IndentLevel > 0) { $IndentLevel--; }
1031 # pop last entry off of open tag stack
1032 $LastName = array_pop($OpenTagStack);
1034 # start out with appropriate indent
1035 $Tag = str_repeat(
" ", ($IndentLevel * $this->IndentSize));
1037 # add end tag to match last open tag
1038 $Tag .=
"</".$LastName.
">\n";
1041 # return formatted tag to caller
1047 # if request type available via POST variables
1048 if (isset($_POST[
"verb"]))
1050 # retrieve arguments from POST variables
1051 $this->Args = $_POST;
1053 # else if request type available via GET variables
1054 elseif (isset($_GET[
"verb"]))
1056 # retrieve arguments from GET variables
1057 $this->Args = $_GET;
1059 # strip off page designator GET parameter
1060 if (isset($this->Args[
"P"])) { unset($this->Args[
"P"]); }
1069 # ---- methods to support OAI-SQ
1073 return ((strpos($SetString,
"OAI-SQ|") === 0)
1074 || (strpos($SetString,
"OAI-SQ!") === 0)
1075 || (strpos($SetString,
"OAI-SQ-F|") === 0)
1076 || (strpos($SetString,
"OAI-SQ-F!") === 0)
1083 for ($Index = 0; $Index < count($Pieces); $Index++)
1085 # replace escaped chars with equivalents
1086 $Pieces[$Index] = preg_replace_callback(
1087 "/~[a-fA-F0-9]{2,2}/",
1090 'for ($Index = 0; $Index < count($Matches); $Index++)'
1092 .
' $Replacements = chr(intval(substr($Matches[$Index], 1, 2), 16));'
1094 .
'return $Replacements;'
1099 # return translated array of pieces to caller
1105 # if OAI-SQ fielded search requested
1106 if (strpos($SetString,
"OAI-SQ-F") === 0)
1108 # split set string into field names and values
1109 $Pieces = explode(substr($SetString, 8, 1), $SetString);
1111 # discard first piece (OAI-SQ designator)
1112 array_shift($Pieces);
1114 # if set string contains escaped characters
1115 if (preg_match(
"/~[a-fA-F0-9]{2,2}/", $SetString))
1120 # for every two pieces
1121 $SearchParams = array();
1122 $NumPairedPieces = round(count($Pieces) / 2) * 2;
1123 for ($Index = 0; $Index < $NumPairedPieces; $Index += 2)
1125 # retrieve local field mapping
1126 $LocalFieldName = array_search($Pieces[$Index], $this->FieldMappings[$FormatName]);
1128 # if local field mapping found
1129 if (strlen($LocalFieldName))
1131 # add mapped values to search parameters
1132 $SearchParams[$LocalFieldName] = $Pieces[$Index + 1];
1138 # split set string to trim off query designator
1139 $Pieces = explode(substr($SetString, 6, 1), $SetString, 2);
1141 # if set string contains escaped characters
1142 if (preg_match(
"/~[a-fA-F0-9]{2,2}/", $SetString))
1147 # remainder of set string is keyword search string
1148 $SearchParams[
"X-KEYWORD-X"] = $Pieces[1];
1151 # return array of search parameters to caller
1152 return $SearchParams;
1158 # ---- PUBLIC INTERFACE --------------------------------------------------
1160 # object constructor
1165 function GetItem($ItemId) { exit(
"OAIItemFactory method GetItem() not implemented"); }
1166 function GetItems($StartingDate = NULL, $EndingDate = NULL)
1168 exit(
"OAIItemFactory method GetItems() not implemented");
1171 # retrieve IDs of items that matches set spec (only needed if sets supported)
1174 exit(
"OAIItemFactory method GetItemsInSet() not implemented");
1177 # return array containing all set specs (with human-readable set names as keys)
1178 # (only needed if sets supported)
1181 exit(
"OAIItemFactory method GetListOfSets() not implemented");
1184 # retrieve IDs of items that match search parameters (only needed if OAI-SQ supported)
1187 exit(
"OAIItemFactory method SearchForItems() not implemented");
1193 # ---- PUBLIC INTERFACE --------------------------------------------------
1195 # object constructor
1200 function GetId() { exit(
"OAIItem method GetId() not implemented"); }
1201 function GetDatestamp() { exit(
"OAIItem method GetDatestamp() not implemented"); }
1202 function GetValue($ElementName) { exit(
"OAIItem method GetValue() not implemented"); }
1203 function GetQualifier($ElementName) { exit(
"OAIItem method GetQualifiers() not implemented"); }
1204 function GetSets() { exit(
"OAIItem method GetSets() not implemented"); }
1206 function Status() { exit(
"OAIItem method Status() not implemented"); }
GetQualifier($ElementName)
FormatElementList($FormatName)
FormatQualifierList($FormatName)
OAIServer(&$DB, $RepDescr, &$ItemFactory, $SetsSupported=FALSE, $OaisqSupported=FALSE)
GetRecordTags($Item, $MetadataFormat, $IncludeMetadata=TRUE)
ParseOaisqQuery($SetString, $FormatName)
ProcessListMetadataFormats()
SearchForItems($SearchParams, $StartingDate=NULL, $EndingDate=NULL)
AddFormat($Name, $TagName, $SchemaLocation, $SchemaVersion, $NamespaceList, $ElementList, $QualifierList)
GetItem($ItemId)
Retrieve item by item ID.
GetFieldMapping($FormatName, $LocalFieldName)
EncodeIdentifier($ItemId)
GetRequestTag($RequestType=NULL, $ReqArgList=NULL, $OptArgList=NULL)
DecodeResumptionToken($ResumptionToken)
GetItems($StartingDate=NULL, $EndingDate=NULL)
OAIItem($ItemId, $ExtraItemInfo=NULL)
GetQualifierMapping($FormatName, $LocalQualifierName)
GetErrorTag($ErrorCode, $ErrorMessage)
SetQualifierMapping($FormatName, $LocalQualifierName, $OAIQualifierName)
ProcessListRecords($IncludeMetadata)
FormatTag($Name=NULL, $Content=NULL, $Attributes=NULL, $NewIndentLevel=NULL)
GetItems($SqlCondition=NULL)
Retrieve items.
Common factory class for item manipulation.
EncodeResumptionToken($StartingDate, $EndingDate, $MetadataFormat, $SetSpec, $ListStartPoint)
SetFieldMapping($FormatName, $LocalFieldName, $OAIFieldName)
DecodeIdentifier($Identifier)
TranslateOaisqEscapes($Pieces)
GetItemsInSet($SetSpec, $StartingDate=NULL, $EndingDate=NULL)