Пример #1
0
 /**
  * Creates a preview of the given metadata and returns it
  *
  * @param string $metadata The metadata to process
  * @param string $format   Metadata format
  * @param string $source   Source identifier
  *
  * @return array Solr record fields
  */
 public function preview($metadata, $format, $source)
 {
     if (!$source) {
         $source = "_preview";
     }
     /* Process data source preTransformation XSL if present
        TODO: duplicates code from RecordManager, refactor? */
     $settings = $this->settings[$source];
     if (isset($settings['preTransformation']) && $settings['preTransformation']) {
         $style = new DOMDocument();
         $style->load($this->basePath . '/transformations/' . $settings['preTransformation']);
         $xslt = new XSLTProcessor();
         $xslt->importStylesheet($style);
         $xslt->setParameter('', 'source_id', $source);
         $xslt->setParameter('', 'institution', $settings['institution']);
         $xslt->setParameter('', 'format', $format);
         $xslt->setParameter('', 'id_prefix', isset($settings['idPrefix']) && $settings['idPrefix'] ? $settings['idPrefix'] : $source);
         $doc = new DOMDocument();
         $doc->loadXML($metadata);
         $metadata = $xslt->transformToXml($doc);
     }
     $record = ['format' => $format, 'original_data' => $metadata, 'normalized_data' => $metadata, 'source_id' => $source, 'linking_id' => '', 'oai_id' => '_preview', '_id' => '_preview', 'created' => new MongoDate(), 'date' => new MongoDate()];
     // Normalize the record
     $this->normalizationXSLT = isset($settings['normalization']) && $settings['normalization'] ?: null;
     if (isset($settings['normalization'])) {
         $basePath = substr(__FILE__, 0, strrpos(__FILE__, DIRECTORY_SEPARATOR));
         $basePath = substr($basePath, 0, strrpos($basePath, DIRECTORY_SEPARATOR));
         $params = ['source_id' => $source, 'institution' => 'Preview', 'format' => $format, 'id_prefix' => ''];
         $normalizationXSLT = new XslTransformation($basePath . '/transformations', $settings['normalization'], $params);
         $record['normalized_data'] = $normalizationXSLT->transform($metadata, ['oai_id' => $record['oai_id']]);
     }
     $metadataRecord = RecordFactory::createRecord($record['format'], $record['normalized_data'], $record['oai_id'], $record['source_id']);
     $metadataRecord->normalize();
     $record['normalized_data'] = $metadataRecord->serialize();
     $record['_id'] = $source . '.' . $metadataRecord->getID();
     return $this->createSolrArray($record, $componentParts);
 }
Пример #2
0
 /**
  * Load XML into a DOM
  *
  * @param string $xml XML string
  *
  * @return DOMDocument
  */
 protected function loadXML($xml)
 {
     $doc = new DOMDocument();
     if (!$doc->loadXML($xml, LIBXML_PARSEHUGE)) {
         return false;
     }
     if ($this->transformation) {
         return $this->transformation->transformToDoc($doc);
     }
     return $doc;
 }