Exemplo 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);
 }
Exemplo n.º 2
0
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details. You should have received a copy of the GNU General Public License
 * along with OPUS; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * @category    Application
 * @author      Sascha Szott <*****@*****.**>
 * @copyright   Copyright (c) 2008-2011, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id$
 */
/**
 * Returns the XML representation of the document with given id $id.
 */
if (isset($argv[2]) && !empty($argv[2]) && is_numeric($argv[2])) {
    $id = $argv[2];
} else {
    $id = 91;
}
try {
    $doc = new Opus_Document($id);
} catch (Opus_Model_NotFoundException $e) {
    echo "document with id {$id} does not exist";
    exit;
}
$xmlModel = new Opus_Model_Xml();
$xmlModel->setModel($doc);
$xmlModel->setStrategy(new Opus_Model_Xml_Version1());
$xmlModel->excludeEmptyFields();
echo $xmlModel->getDomDocument()->saveXML();
exit;
Exemplo n.º 3
0
 * OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details. You should have received a copy of the GNU General Public License 
 * along with OPUS; if not, write to the Free Software Foundation, Inc., 51 
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * @category    Application
 * @author      Thoralf Klein <*****@*****.**>
 * @copyright   Copyright (c) 2010, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id: opus-dump-document-xml.php 9015 2011-09-15 16:01:23Z tklein $
 */
// Bootstrapping
require_once dirname(__FILE__) . '/common/bootstrap.php';
// Remove first argument
array_shift($argv);
// Dump given documents
error_log("dumping document(s): " . implode(", ", $argv));
foreach ($argv as $docId) {
    error_log("<!-- dumping document-id {$docId}: -->");
    $d = new Opus_Document($docId);
    $xmlModel = new Opus_Model_Xml();
    $xmlModel->setModel($d);
    $xmlModel->excludeEmptyFields();
    $xmlModel->setStrategy(new Opus_Model_Xml_Version1());
    // $xmlModel->setXmlCache(new Opus_Model_Xml_Cache);
    $d_xml = $xmlModel->getDomDocument();
    $d_xml->formatOutput = true;
    echo $d_xml->saveXml();
}
Exemplo n.º 4
0
 */
/**
 * Tries to export and import all documents.
 */
$docFinder = new Opus_DocumentFinder();
foreach ($docFinder->ids() as $id) {
    $doc = null;
    try {
        $doc = new Opus_Document($id);
    } catch (Opus_Model_NotFoundException $e) {
        // document with id $id does not exist
        continue;
    }
    echo "try to export document {$id} ... ";
    $xmlModelOutput = new Opus_Model_Xml();
    $xmlModelOutput->setModel($doc);
    $xmlModelOutput->setStrategy(new Opus_Model_Xml_Version1());
    $xmlModelOutput->excludeEmptyFields();
    $domDocument = $xmlModelOutput->getDomDocument();
    echo "export of document {$id} was successful.\n";
    echo "try to import document based on the exported dom tree ... ";
    $xmlModelImport = new Opus_Model_Xml();
    $xmlModelImport->setStrategy(new Opus_Model_Xml_Version1());
    $xmlModelImport->setXml($domDocument->saveXML());
    try {
        $doc = $xmlModelImport->getModel();
        $doc->store();
        echo "OK - import of document {$id} was successful.\n";
    } catch (Exception $e) {
        echo "ERR - import of document {$id} was NOT successful.\n";
        echo $e;
Exemplo n.º 5
0
 /**
  * Returns a DOM representation of the filtered model.
  *
  * @param array $excludeFields Array of fields that shall not be serialized.
  * @param Opus_Model_Xml_Strategy $strategy Version of Xml to process
  * @param bool $excludeEmptyFields If set to false, fields with empty values are included in the resulting DOM.
  * @return DomDocument A Dom representation of the model.
  */
 public function toXml(array $excludeFields = null, $strategy = null, $excludeEmptyFields = true)
 {
     if (is_null($excludeFields) === true) {
         $excludeFields = array();
     }
     if (is_null($strategy) === true) {
         $strategy = new Opus_Model_Xml_Version1();
     }
     $xml = new Opus_Model_Xml();
     $xml->setModel($this)->exclude($excludeFields)->setStrategy($strategy);
     if ($excludeEmptyFields === true) {
         $xml->excludeEmptyFields();
     }
     return $xml->getDomDocument();
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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;
 }