Ejemplo n.º 1
0
$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;
    }
    echo "\n\n";
}
exit;
Ejemplo n.º 2
0
 * LICENCE
 * OPUS is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the Licence, or any later version.
 * 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      Sascha Szott <*****@*****.**>
 * @copyright   Copyright (c) 2008-2011, OPUS 4 development team
 * @license     http://www.gnu.org/licenses/gpl.html General Public License
 * @version     $Id$
 */
/**
 * Imports the XML representation from stdin and creates a new OPUS 4
 * document (with a new ID).
 */
$xml = '';
while (FALSE !== ($line = fgets(STDIN))) {
    $xml .= $line;
}
$xmlModel = new Opus_Model_Xml();
$xmlModel->setStrategy(new Opus_Model_Xml_Version1());
$xmlModel->setXml($xml);
$doc = $xmlModel->getModel();
$doc->store();
exit;
Ejemplo n.º 3
0
 /**
  * Instantiates an Opus_Model from xml as delivered by the toXml() method.
  *
  * @param  DomDocument|string  $xml                The xml representing the model.
  * @param  Opus_Model_Xml      $customDeserializer (Optional) Specify a custom deserializer object.
  * @return Opus_Model_Abstract The Opus_Model derived from xml.
  */
 public static function fromXml($xml, Opus_Model_Xml $customDeserializer = null)
 {
     if (is_null($customDeserializer)) {
         $customDeserializer = new Opus_Model_Xml();
     }
     if ($xml instanceof DomDocument) {
         $customDeserializer->setDomDocument($xml);
     } else {
         if (is_string($xml)) {
             $customDeserializer->setXml($xml);
         } else {
             throw new Opus_Model_Exception('Either DomDocument or xml string must be passed.');
         }
     }
     return $customDeserializer->getModel();
 }