00001 <?php
00002
00015
00016
00017
00018 import('classes.plugins.ImportExportPlugin');
00019
00020 class METSExportPlugin extends ImportExportPlugin {
00027 function register($category, $path) {
00028 $success = parent::register($category, $path);
00029 $this->addLocaleData();
00030 return $success;
00031 }
00032
00038 function getName() {
00039 return 'METSExportPlugin';
00040 }
00041
00042 function getDisplayName() {
00043 return Locale::translate('plugins.importexport.METSExport.displayName');
00044 }
00045
00046 function getDescription() {
00047 return Locale::translate('plugins.importexport.METSExport.description');
00048 }
00049
00050 function display(&$args) {
00051 $templateMgr = &TemplateManager::getManager();
00052 parent::display($args);
00053 $issueDao = &DAORegistry::getDAO('IssueDAO');
00054 $journal = &Request::getJournal();
00055 switch (array_shift($args)) {
00056 case 'exportIssues':
00057 $issueIds = Request::getUserVar('issueId');
00058 if (!isset($issueIds)) $issueIds = array();
00059 $issues = array();
00060 foreach ($issueIds as $issueId) {
00061 $issue = &$issueDao->getIssueById($issueId);
00062 if (!$issue) Request::redirect();
00063 $issues[] = &$issue;
00064 }
00065 $this->exportIssues($journal, $issues);
00066 break;
00067 case 'exportIssue':
00068 $issueId = array_shift($args);
00069 $issue = &$issueDao->getIssueById($issueId);
00070 if (!$issue) Request::redirect();
00071 $issues = array($issue);
00072 $this->exportIssues($journal, $issues);
00073 break;
00074 case 'issues':
00075
00076 $this->setBreadcrumbs(array(), true);
00077 $issueDao = &DAORegistry::getDAO('IssueDAO');
00078 $issues = &$issueDao->getIssues($journal->getJournalId(), Handler::getRangeInfo('issues'));
00079
00080 $siteDao = &DAORegistry::getDAO('SiteDAO');
00081 $site = $siteDao->getSite();
00082 $organization = $site->getSiteTitle();
00083
00084 $templateMgr->assign_by_ref('issues', $issues);
00085 $templateMgr->assign_by_ref('organization', $organization);
00086 $templateMgr->display($this->getTemplatePath() . 'issues.tpl');
00087 break;
00088 default:
00089 $this->setBreadcrumbs();
00090 $templateMgr->display($this->getTemplatePath() . 'index.tpl');
00091 }
00092 }
00093
00094 function exportIssues(&$journal, &$issues){
00095 $this->import('MetsExportDom');
00096 $doc = &XMLCustomWriter::createDocument('', null);
00097 $root = &XMLCustomWriter::createElement($doc, 'METS:mets');
00098 XMLCustomWriter::setAttribute($root, 'xmlns:METS', 'http://www.loc.gov/METS/');
00099 XMLCustomWriter::setAttribute($root, 'xmlns:xlink', 'http://www.w3.org/TR/xlink');
00100 XMLCustomWriter::setAttribute($root, 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
00101 XMLCustomWriter::setAttribute($root, 'PROFILE', 'Australian METS Profile 1.0');
00102 XMLCustomWriter::setAttribute($root, 'TYPE', 'journal');
00103 XMLCustomWriter::setAttribute($root, 'OBJID', 'J-'.$journal->getJournalId());
00104 XMLCustomWriter::setAttribute($root, 'xsi:schemaLocation', 'http://www.loc.gov/METS/ http://www.loc.gov/mets/mets.xsd');
00105 $HeaderNode = &MetsExportDom::createmetsHdr($doc);
00106 XMLCustomWriter::appendChild($root, $HeaderNode);
00107 MetsExportDom::generateJournalDmdSecDom($doc, $root, $journal);
00108 $fileSec = &XMLCustomWriter::createElement($doc, 'METS:fileSec');
00109 $fileGrpOriginal = &XMLCustomWriter::createElement($doc, 'METS:fileGrp');
00110 XMLCustomWriter::setAttribute($fileGrpOriginal, 'USE', 'original');
00111 $fileGrpDerivative = &XMLCustomWriter::createElement($doc, 'METS:fileGrp');
00112 XMLCustomWriter::setAttribute($fileGrpDerivative, 'USE', 'derivative');
00113 foreach ($issues as $issue) {
00114 MetsExportDom::generateIssueDmdSecDom($doc, $root, $issue, $journal);
00115 MetsExportDom::generateIssueFileSecDom($doc, $fileGrpOriginal, $issue);
00116 MetsExportDom::generateIssueHtmlGalleyFileSecDom($doc, $fileGrpDerivative, $issue);
00117 }
00118 $amdSec = &MetsExportDom::createmetsamdSec($doc, $root, $journal);
00119 XMLCustomWriter::appendChild($root, $amdSec);
00120 XMLCustomWriter::appendChild($fileSec, $fileGrpOriginal);
00121 XMLCustomWriter::appendChild($fileSec, $fileGrpDerivative);
00122 XMLCustomWriter::appendChild($root, $fileSec);
00123 MetsExportDom::generateStructMap($doc, $root, $journal, $issues);
00124 XMLCustomWriter::appendChild($doc, $root);
00125 header("Content-Type: application/xml");
00126 header("Cache-Control: private");
00127 header("Content-Disposition: attachment; filename=\"".$journal->getPath()."-mets.xml\"");
00128 XMLCustomWriter::printXML($doc);
00129 return true;
00130 }
00131
00132 }
00133 ?>