Ejemplo n.º 1
0
 /**
  * @param boolean $useCache
  * @return DOMNode Opus_Document node
  */
 public function getNode($useCache = true)
 {
     $xmlModel = new Opus_Model_Xml();
     $xmlModel->setModel($this->_document);
     $xmlModel->excludeEmptyFields();
     // needed for preventing handling errors
     $xmlModel->setStrategy(new Opus_Model_Xml_Version1());
     if ($useCache) {
         $xmlModel->setXmlCache(new Opus_Model_Xml_Cache());
     }
     $result = $xmlModel->getDomDocument();
     return $result->getElementsByTagName('Opus_Document')->item(0);
 }
Ejemplo n.º 2
0
 /**
  *
  * @param Opus_Document $document
  * @return DOMNode
  * @throws Exception
  */
 private function getDocumentXmlDomNode($document)
 {
     if (!in_array($document->getServerState(), $this->_deliveringDocumentStates)) {
         $message = 'Trying to get a document in server state "' . $document->getServerState() . '"';
         Zend_Registry::get('Zend_Log')->err($message);
         throw new Exception($message);
     }
     $xmlModel = new Opus_Model_Xml();
     $xmlModel->setModel($document);
     $xmlModel->excludeEmptyFields();
     $xmlModel->setStrategy(new Opus_Model_Xml_Version1());
     $xmlModel->setXmlCache(new Opus_Model_Xml_Cache());
     return $xmlModel->getDomDocument()->getElementsByTagName('Opus_Document')->item(0);
 }
Ejemplo n.º 3
0
 /**
  * Returns an xml representation of the given document in the format that is
  * expected by Solr.
  *
  * @param Opus_Document $doc
  * @return DOMDocument
  */
 private function getSolrXmlDocument(Opus_Document $doc)
 {
     // Set up caching xml-model and get XML representation of document.
     $caching_xml_model = new Opus_Model_Xml();
     $caching_xml_model->setModel($doc);
     $caching_xml_model->excludeEmptyFields();
     $caching_xml_model->setStrategy(new Opus_Model_Xml_Version1());
     $cache = new Opus_Model_Xml_Cache($doc->hasPlugin('Opus_Document_Plugin_Index'));
     $caching_xml_model->setXmlCache($cache);
     $config = Zend_Registry::get('Zend_Config');
     $modelXml = $caching_xml_model->getDomDocument();
     // extract fulltext from file and append it to the generated xml.
     $this->attachFulltextToXml($modelXml, $doc->getFile(), $doc->getId());
     // Set up XSLT stylesheet
     $xslt = new DomDocument();
     if (isset($config->searchengine->solr->xsltfile)) {
         $xsltFilePath = $config->searchengine->solr->xsltfile;
         if (!file_exists($xsltFilePath)) {
             throw new Application_Exception('Solr XSLT file not found.');
         }
         $xslt->load($xsltFilePath);
     }
     // Set up XSLT processor
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xslt);
     $solrXmlDocument = new DOMDocument();
     $solrXmlDocument->preserveWhiteSpace = false;
     $solrXmlDocument->loadXML($proc->transformToXML($modelXml));
     if (isset($config->log->prepare->xml) && $config->log->prepare->xml) {
         $modelXml->formatOutput = true;
         $this->log->debug("input xml\n" . $modelXml->saveXML());
         $solrXmlDocument->formatOutput = true;
         $this->log->debug("transformed solr xml\n" . $solrXmlDocument->saveXML());
     }
     return $solrXmlDocument;
 }