// The test file to deposit $testfile = "test-files/sword-article.zip"; // The content type of the test file $testcontenttype = "application/zip"; // The packaing format of the test fifle $testformat = "http://purl.org/net/sword-types/METSDSpaceSIP"; require "swordappclient.php"; $testsac = new SWORDAPPClient(); if (true) { print "About to request servicedocument from " . $testurl . "\n"; if (empty($testuser)) { print "As: anonymous\n"; } else { print "As: " . $testuser . "\n"; } $testsdr = $testsac->servicedocument($testurl, $testuser, $testpw, $testobo); print "Received HTTP status code: " . $testsdr->sac_status . " (" . $testsdr->sac_statusmessage . ")\n"; if ($testsdr->sac_status == 200) { print " - Version: " . $testsdr->sac_version . "\n"; print " - Supports Verbose: " . $testsdr->sac_verbose . "\n"; print " - Supports NoOp: " . $testsdr->sac_noop . "\n"; print " - Maximum uplaod size: "; if (!empty($testsdr->sac_maxuploadsize)) { print $testsdr->sac_maxuploadsize . " kB\n"; } else { print "undefined\n"; } $workspaces = $testsdr->sac_workspaces; foreach ($testsdr->sac_workspaces as $workspace) { $wstitle = $workspace->sac_workspacetitle; echo " - Workspace: " . $wstitle . "\n";
function display(&$args, $request) { $templateMgr =& TemplateManager::getManager(); parent::display($args, $request); $this->setBreadcrumbs(); $journal =& Request::getJournal(); $plugin =& $this->getSwordPlugin(); $swordUrl = Request::getUserVar('swordUrl'); $depositPointKey = Request::getUserVar('depositPoint'); $depositPoints = $plugin->getSetting($journal->getId(), 'depositPoints'); $username = Request::getUserVar('swordUsername'); $password = Request::getUserVar('swordPassword'); if (isset($depositPoints[$depositPointKey])) { $selectedDepositPoint = $depositPoints[$depositPointKey]; if ($selectedDepositPoint['username'] != '') { $username = $selectedDepositPoint['username']; } if ($selectedDepositPoint['password'] != '') { $password = $selectedDepositPoint['password']; } } $swordDepositPoint = Request::getUserVar('swordDepositPoint'); $depositEditorial = Request::getUserVar('depositEditorial'); $depositGalleys = Request::getUserVar('depositGalleys'); switch (array_shift($args)) { case 'deposit': $depositIds = array(); try { foreach (Request::getUserVar('articleId') as $articleId) { $depositIds[] = $this->deposit($swordDepositPoint, $username, $password, $articleId, $depositEditorial, $depositGalleys); } } catch (Exception $e) { // Deposit failed $templateMgr->assign(array('pageTitle' => 'plugins.importexport.sword.depositFailed', 'messageTranslated' => $e->getMessage(), 'backLink' => Request::url(null, null, null, array('plugin', $this->getName()), array('swordUrl' => $swordUrl, 'swordUsername' => $username, 'swordDepositPoint' => $swordDepositPoint, 'depositEditorial' => $depositEditorial, 'depositGalleys' => $depositGalleys)), 'backLinkLabel' => 'common.back')); return $templateMgr->display('common/message.tpl'); } // Deposit was successful $templateMgr->assign(array('pageTitle' => 'plugins.importexport.sword.depositSuccessful', 'message' => 'plugins.importexport.sword.depositSuccessfulDescription', 'backLink' => Request::url(null, null, null, array('plugin', $this->getName()), array('swordUrl' => $swordUrl, 'swordUsername' => $username, 'swordDepositPoint' => $swordDepositPoint, 'depositEditorial' => $depositEditorial, 'depositGalleys' => $depositGalleys)), 'backLinkLabel' => 'common.continue')); return $templateMgr->display('common/message.tpl'); break; default: $journal =& Request::getJournal(); $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO'); $rangeInfo = Handler::getRangeInfo('articles'); $articleIds = $publishedArticleDao->getPublishedArticleIdsAlphabetizedByJournal($journal->getId(), false); $totalArticles = count($articleIds); if ($rangeInfo->isValid()) { $articleIds = array_slice($articleIds, $rangeInfo->getCount() * ($rangeInfo->getPage() - 1), $rangeInfo->getCount()); } import('lib.pkp.classes.core.VirtualArrayIterator'); $iterator = new VirtualArrayIterator(ArticleSearch::formatResults($articleIds), $totalArticles, $rangeInfo->getPage(), $rangeInfo->getCount()); foreach (array('swordUrl', 'swordUsername', 'swordPassword', 'depositEditorial', 'depositGalleys', 'swordDepositPoint') as $var) { $templateMgr->assign($var, Request::getUserVar($var)); } $templateMgr->assign('depositPoints', $depositPoints); if (!empty($swordUrl)) { $client = new SWORDAPPClient(); $doc = $client->servicedocument($swordUrl, $username, $password, ''); $depositPoints = array(); if (is_array($doc->sac_workspaces)) { foreach ($doc->sac_workspaces as $workspace) { if (is_array($workspace->sac_collections)) { foreach ($workspace->sac_collections as $collection) { $depositPoints["{$collection->sac_href}"] = "{$collection->sac_colltitle}"; } } } } $templateMgr->assign_by_ref('swordDepositPoints', $depositPoints); } $templateMgr->assign_by_ref('articles', $iterator); $templateMgr->display($this->getTemplatePath() . 'articles.tpl'); break; } }
// Store the values if (isset($_POST['sdurl'])) { $_SESSION['sdurl'] = $_POST['sdurl']; } if (isset($_POST['u'])) { $_SESSION['u'] = $_POST['u']; } if (isset($_POST['p'])) { $_SESSION['p'] = $_POST['p']; } if (isset($_POST['obo'])) { $_SESSION['obo'] = $_POST['obo']; } // Try and load the service document $client = new SWORDAPPClient(); $response = $client->servicedocument($_SESSION['sdurl'], $_SESSION['u'], $_SESSION['p'], $_SESSION['obo']); if ($response->sac_status != 200) { $error = 'Unable to load service document. HTTP response code: ' . $response->sac_status . ' - ' . $response->sac_statusmessage; $_SESSION['error'] = $error; header('Location: ../../'); die; } else { $_SESSION['error'] = ''; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>SWORD v2 exerciser - GET the Service Document</title> <link rel='stylesheet' type='text/css' media='all' href='../../css/style.css' /> </head>
require_once '../../swordappclient.php'; // Settings $atom = 'atom.xml'; $contentzip = 'content.zip'; $metadatazip = 'metadata.zip'; $servicedocument = 'http://demo.dspace.org/swordv2/servicedocument'; $depositlocation = 'http://demo.dspace.org/swordv2/collection/10673/11'; $dspacerest = 'https://demo.dspace.org/rest'; $user = '******'; $password = '******'; // Initiatiate the SWORD client $sword = new SWORDAPPClient(); // Get the service document print "About to request servicedocument from " . $servicedocument . "\n"; $sd = $sword->servicedocument($servicedocument, $user, $password, ''); print "Received HTTP status code: " . $sd->sac_status . " (" . $sd->sac_statusmessage . ")\n"; if ($sd->sac_status == 200) { $sd->toString(); } print "\n\n"; // Create the item by depositing an atom document print "About to create new item at " . $depositlocation . "\n"; $response = $sword->depositAtomEntry($depositlocation, $user, $password, '', $atom, $sac_inprogress = true); print "Received HTTP status code: " . $response->sac_status . " (" . $response->sac_statusmessage . ")\n"; if ($response->sac_status >= 200 || $response->sac_status < 300) { $response->toString(); } $edit_iri = $response->sac_edit_iri; $edit_media = $response->sac_edit_media_iri; $statement_atom = $response->sac_state_iri_atom;
function _getservicedocument($str) { // Clear out old session data related to the service document $_SESSION['servicedocumenturl'] = ''; $_SESSION['servicedocumentxml'] = ''; $_SESSION['servicedocumentstatuscode'] = ''; // Try and get the service document // If we succeed, store the xml in the SESSION for future steps // If we fail, report so try { $swordappclient = new SWORDAPPClient(); $urls = $this->config->item('easydeposit_selectrepository_list'); if (!empty($_POST['otherurl'])) { $url = $_POST['otherurl']; } else { if (isset($_POST['url'])) { $url = $_POST['url']; $url = str_replace('/client/client/', '/client/', $url); if (is_numeric($_POST['url'])) { $url = $urls[$_POST['url']]; } } else { $this->form_validation->set_message('_getservicedocument', 'No Service Document URL provided'); return FALSE; } } $servicedocument = $swordappclient->servicedocument($url, $_POST['username'], $_POST['password'], $_POST['obo']); if ($servicedocument->sac_status == 200) { // Store the service document in the session $_SESSION['servicedocumenturl'] = $url; $_SESSION['servicedocumentxml'] = $servicedocument->sac_xml; $_SESSION['servicedocumentstatuscode'] = $servicedocument->sac_status; // Store the username / password / obo in the session $_SESSION['sword-username'] = $_POST['username']; $_SESSION['sword-password'] = $_POST['password']; $_SESSION['sword-obo'] = $_POST['obo']; return TRUE; } else { $this->form_validation->set_message('_getservicedocument', $servicedocument->sac_statusmessage); return FALSE; } } catch (Exception $e) { $this->form_validation->set_message('_getservicedocument', 'An error occurred when trying to parse the service document: ' . $e); return FALSE; } }
function _getDepositableDepositPoints() { import('classes.sword.OJSSwordDeposit'); $depositPoints = $this->swordPlugin->getSetting($this->article->getJournalId(), 'depositPoints'); foreach ($depositPoints as $key => $depositPoint) { $type = $depositPoint['type']; if ($type == SWORD_DEPOSIT_TYPE_OPTIONAL_SELECTION) { // Get a list of supported deposit points $client = new SWORDAPPClient(); $doc = $client->servicedocument($depositPoint['url'], $depositPoint['username'], $depositPoint['password'], ''); $points = array(); foreach ($doc->sac_workspaces as $workspace) { foreach ($workspace->sac_collections as $collection) { $points["{$collection->sac_href}"] = "{$collection->sac_colltitle}"; } } unset($client); unset($doc); $depositPoints[$key]['depositPoints'] = $points; } elseif ($type == SWORD_DEPOSIT_TYPE_OPTIONAL_FIXED) { // Don't need to do anything special } else { unset($depositPoints[$key]); } } return $depositPoints; }