Open Journal Systems  3.3.0
PKPOAIMetadataFormat_DC.inc.php
1 <?php
2 
20  function toXml($dataObject, $format = null) {
21  import('plugins.metadata.dc11.schema.Dc11Schema');
22  $dcDescription = $dataObject->extractMetadata(new Dc11Schema());
23 
24  $response = "<oai_dc:dc\n" .
25  "\txmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\"\n" .
26  "\txmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" .
27  "\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" .
28  "\txsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/\n" .
29  "\thttp://www.openarchives.org/OAI/2.0/oai_dc.xsd\">\n";
30 
31  foreach($dcDescription->getProperties() as $propertyName => $property) { /* @var $property MetadataProperty */
32  if ($dcDescription->hasStatement($propertyName)) {
33  if ($property->getTranslated()) {
34  $values = $dcDescription->getStatementTranslations($propertyName);
35  } else {
36  $values = $dcDescription->getStatement($propertyName);
37  }
38  $response .= $this->formatElement($propertyName, $values, $property->getTranslated());
39  }
40  }
41 
42  $response .= "</oai_dc:dc>\n";
43 
44  return $response;
45  }
46 
53  function formatElement($propertyName, $values, $multilingual = false) {
54  if (!is_array($values)) $values = array($values);
55 
56  // Translate the property name to XML syntax.
57  $openingElement = str_replace(array('[@', ']'), array(' ',''), $propertyName);
58  $closingElement = PKPString::regexp_replace('/\[@.*/', '', $propertyName);
59 
60  // Create the actual XML entry.
61  $response = '';
62  foreach ($values as $key => $value) {
63  if ($multilingual) {
64  $key = str_replace('_', '-', $key);
65  assert(is_array($value));
66  foreach ($value as $subValue) {
67  if ($key == METADATA_DESCRIPTION_UNKNOWN_LOCALE) {
68  $response .= "\t<$openingElement>" . OAIUtils::prepOutput($subValue) . "</$closingElement>\n";
69  } else {
70  $response .= "\t<$openingElement xml:lang=\"$key\">" . OAIUtils::prepOutput($subValue) . "</$closingElement>\n";
71  }
72  }
73  } else {
74  assert(is_scalar($value));
75  $response .= "\t<$openingElement>" . OAIUtils::prepOutput($value) . "</$closingElement>\n";
76  }
77  }
78  return $response;
79  }
80 }
81 
82 
PKPString\regexp_replace
static regexp_replace($pattern, $replacement, $subject, $limit=-1)
Definition: PKPString.inc.php:279
Dc11Schema
OJS-specific implementation of the Dc11Schema.
Definition: Dc11Schema.inc.php:21
OAIMetadataFormat
Definition: OAIStruct.inc.php:183
OAIUtils\prepOutput
static prepOutput(&$data)
Definition: OAIUtils.inc.php:99
PKPOAIMetadataFormat_DC\toXml
toXml($dataObject, $format=null)
Definition: PKPOAIMetadataFormat_DC.inc.php:20
PKPOAIMetadataFormat_DC
OAI metadata format class – Dublin Core.
Definition: PKPOAIMetadataFormat_DC.inc.php:16
PKPOAIMetadataFormat_DC\formatElement
formatElement($propertyName, $values, $multilingual=false)
Definition: PKPOAIMetadataFormat_DC.inc.php:53