1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
<?php
/**
* @file METSExportPlugin.inc.php
*
* Copyright (c) 2003-2009 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class PubMedExportPlugin
* @ingroup plugins
*
* @brief METS/MODS XML metadata export plugin
*/
// $Id$
import('classes.plugins.ImportExportPlugin');
class METSExportPlugin extends ImportExportPlugin {
/**
* Called as a plugin is registered to the registry
* @param $category String Name of category plugin was registered to
* @return boolean True if plugin initialized successfully; if false,
* the plugin will not be registered.
*/
function register($category, $path) {
$success = parent::register($category, $path);
$this->addLocaleData();
return $success;
}
/**
* Get the name of this plugin. The name must be unique within
* its category.
* @return String name of plugin
*/
function getName() {
return 'METSExportPlugin';
}
function getDisplayName() {
return Locale::translate('plugins.importexport.METSExport.displayName');
}
function getDescription() {
return Locale::translate('plugins.importexport.METSExport.description');
}
function display(&$args) {
$templateMgr =& TemplateManager::getManager();
parent::display($args);
$issueDao =& DAORegistry::getDAO('IssueDAO');
$journal =& Request::getJournal();
switch (array_shift($args)) {
case 'exportIssues':
$issueIds = Request::getUserVar('issueId');
if (!isset($issueIds)) $issueIds = array();
$issues = array();
foreach ($issueIds as $issueId) {
$issue =& $issueDao->getIssueById($issueId);
if (!$issue) Request::redirect();
$issues[] =& $issue;
}
$this->exportIssues($journal, $issues);
break;
case 'exportIssue':
$issueId = array_shift($args);
$issue =& $issueDao->getIssueById($issueId);
if (!$issue) Request::redirect();
$issues = array($issue);
$this->exportIssues($journal, $issues);
break;
case 'issues':
// Display a list of issues for export
$this->setBreadcrumbs(array(), true);
$issueDao =& DAORegistry::getDAO('IssueDAO');
$issues =& $issueDao->getIssues($journal->getJournalId(), Handler::getRangeInfo('issues'));
$siteDao =& DAORegistry::getDAO('SiteDAO');
$site = $siteDao->getSite();
$organization = $site->getSiteTitle();
$templateMgr->assign_by_ref('issues', $issues);
$templateMgr->assign_by_ref('organization', $organization);
$templateMgr->display($this->getTemplatePath() . 'issues.tpl');
break;
default:
$this->setBreadcrumbs();
$templateMgr->display($this->getTemplatePath() . 'index.tpl');
}
}
function exportIssues(&$journal, &$issues){
$this->import('MetsExportDom');
$doc =& XMLCustomWriter::createDocument('', null);
$root =& XMLCustomWriter::createElement($doc, 'METS:mets');
XMLCustomWriter::setAttribute($root, 'xmlns:METS', 'http://www.loc.gov/METS/');
XMLCustomWriter::setAttribute($root, 'xmlns:xlink', 'http://www.w3.org/TR/xlink');
XMLCustomWriter::setAttribute($root, 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
XMLCustomWriter::setAttribute($root, 'PROFILE', 'Australian METS Profile 1.0');
XMLCustomWriter::setAttribute($root, 'TYPE', 'journal');
XMLCustomWriter::setAttribute($root, 'OBJID', 'J-'.$journal->getJournalId());
XMLCustomWriter::setAttribute($root, 'xsi:schemaLocation', 'http://www.loc.gov/METS/ http://www.loc.gov/mets/mets.xsd');
$headerNode =& MetsExportDom::createmetsHdr($doc);
XMLCustomWriter::appendChild($root, $headerNode);
MetsExportDom::generateJournalDmdSecDom($doc, $root, $journal);
$fileSec =& XMLCustomWriter::createElement($doc, 'METS:fileSec');
$fileGrpOriginal =& XMLCustomWriter::createElement($doc, 'METS:fileGrp');
XMLCustomWriter::setAttribute($fileGrpOriginal, 'USE', 'original');
$fileGrpDerivative =& XMLCustomWriter::createElement($doc, 'METS:fileGrp');
XMLCustomWriter::setAttribute($fileGrpDerivative, 'USE', 'derivative');
foreach ($issues as $issue) {
MetsExportDom::generateIssueDmdSecDom($doc, $root, $issue, $journal);
MetsExportDom::generateIssueFileSecDom($doc, $fileGrpOriginal, $issue, $journal);
MetsExportDom::generateIssueHtmlGalleyFileSecDom($doc, $fileGrpDerivative, $issue, $journal);
}
$amdSec =& MetsExportDom::createmetsamdSec($doc, $root, $journal);
XMLCustomWriter::appendChild($root, $amdSec);
XMLCustomWriter::appendChild($fileSec, $fileGrpOriginal);
XMLCustomWriter::appendChild($fileSec, $fileGrpDerivative);
XMLCustomWriter::appendChild($root, $fileSec);
MetsExportDom::generateStructMap($doc, $root, $journal, $issues);
XMLCustomWriter::appendChild($doc, $root);
header("Content-Type: application/xml");
header("Cache-Control: private");
header("Content-Disposition: attachment; filename=\"".$journal->getPath()."-mets.xml\"");
XMLCustomWriter::printXML($doc);
return true;
}
}
?>
|