Skip to content

Commit

Permalink
pkp/pkp-lib#7505 Initial Commit Upload - Delete - Download JATS File
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed Nov 24, 2023
1 parent fb77e91 commit 526820a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion JatsTemplatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function callbackFindJats($hookName, $args) {
$doc =& $args[3];

if (!$doc && empty($candidateFiles)) {
$doc = new Article($record);
$doc = new Article($record);
}

return false;
Expand Down
24 changes: 19 additions & 5 deletions classes/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@

use APP\core\Application;
use DOMException;
use PKP\oai\OAIRecord;

class Article extends \DOMDocument
{
function __construct($record)
function __construct(?OAIRecord $record = null)
{
parent::__construct('1.0', 'UTF-8');
$this->convertToXml($record);

if ($record) {
$this->convertToXml($record);
}
}

/**
Expand All @@ -37,25 +41,34 @@ public function convertToXml($record) :bool|\DOMDocument
$publication = $submission->getCurrentPublication();
$request = Application::get()->getRequest();

$convertedXML = $this->convertSubmission($submission, $journal, $section, $issue, $publication, $request);

return $this->loadXml($convertedXML);
}

/**
* Convert submission metadata to JATS XML
*/
public function convertSubmission($submission, $context, $section, $issue, $publication, $request): string
{
$articleElement = $this->appendChild($this->createElement('article'))
->setAttribute('xmlns:xlink','http://www.w3.org/1999/xlink')->parentNode
->setAttribute('xml:lang', substr($submission->getLocale(), 0, 2))->parentNode
->setAttribute('xmlns:mml','http://www.w3.org/1998/Math/MathML')->parentNode
->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance')->parentNode;

$articleFront = new ArticleFront();
$articleElement->appendChild($this->importNode($articleFront->create($journal, $submission, $section, $issue, $request, $this), true));
$articleElement->appendChild($this->importNode($articleFront->create($context, $submission, $section, $issue, $request, $this), true));

$articleBody = new ArticleBody();
$articleElement->appendChild($this->importNode($articleBody->create($submission), true));

$articleBack = new ArticleBack();
$articleElement->appendChild($this->importNode($articleBack->create($publication), true));

return $this->loadXml($this->saveXML($articleElement));
return $this->saveXML($articleElement);
}


/**
* Map the specific HTML tags in title/ sub title for JATS schema compability
* @see https://jats.nlm.nih.gov/publishing/0.4/xsd/JATS-journalpublishing0.xsd
Expand All @@ -76,4 +89,5 @@ public function mapHtmlTagsForTitle(string $htmlTitle): string

return str_replace(array_keys($mappings), array_values($mappings), $htmlTitle);
}

}
30 changes: 24 additions & 6 deletions classes/ArticleFront.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
namespace APP\plugins\generic\jatsTemplate\classes;

use APP\core\Application;
use APP\core\PageRouter;
use APP\facades\Repo;
use APP\issue\Issue;
use APP\journal\Journal;
use APP\section\Section;
use APP\submission\Submission;
use APP\publication\Publication;
use PKP\core\Dispatcher;
use PKP\core\PKPApplication;
use PKP\core\PKPPageRouter;
use PKP\core\PKPString;
use PKP\db\DAORegistry;
use PKP\plugins\PluginRegistry;
Expand All @@ -27,11 +31,10 @@

class ArticleFront extends \DOMDocument
{

/**
* Create article front element
*/
public function create(Journal $journal, Submission $submission, Section $section,Issue $issue, PKPRequest $request, Article $article): \DOMNode
public function create(Journal $journal, Submission $submission, Section $section, ?Issue $issue, PKPRequest $request, Article $article): \DOMNode
{
return $this->appendChild($this->createElement('front'))
->appendChild($this->createJournalMeta($journal, $request))
Expand Down Expand Up @@ -87,9 +90,15 @@ public function createJournalMeta(Journal $journal, PKPRequest $request): \DOMNo
->appendChild($this->createTextNode($journal->getSetting('printIssn')))->parentNode
->setAttribute('pub-type','ppub');
}

$dispatcher = new Dispatcher();
$dispatcher->setApplication(Application::get());
$dispatcher->addRouterName('\APP\core\PageRouter', PKPApplication::ROUTE_PAGE);

$journalUrl = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $journal->getPath());
$journalMetaElement
->appendChild($this->createElement('self-uri'))
->setAttribute('xlink:href', $request->url($journal->getPath()));
->setAttribute('xlink:href', $journalUrl);

return $journalMetaElement;

Expand Down Expand Up @@ -124,7 +133,7 @@ public function createJournalMetaJournalTitleGroup(Journal $journal): \DOMNode
/**
* Create xml article-meta DOMNode
*/
function createArticleMeta(Submission $submission, Journal $journal, Section $section, Issue $issue, $request, Article $article)
function createArticleMeta(Submission $submission, Journal $journal, Section $section, ?Issue $issue, $request, Article $article)
{
$publication = $submission->getCurrentPublication();

Expand Down Expand Up @@ -186,9 +195,13 @@ function createArticleMeta(Submission $submission, Journal $journal, Section $se
}

$datePublished = $submission->getDatePublished();
if (!$datePublished) $datePublished = $issue->getDatePublished();
if (!$datePublished && $issue) {
$datePublished = $issue->getDatePublished();
}
if ($datePublished) $datePublished = strtotime($datePublished);

if (!$datePublished) $datePublished = strtotime('0001-01-01');

// Include pub dates
if ($submission->getDatePublished()){
$pubDateElement = $articleMetaElement->appendChild($this->createElement('pub-date'))
Expand Down Expand Up @@ -264,10 +277,15 @@ function createArticleMeta(Submission $submission, Journal $journal, Section $se
}
}
}

$dispatcher = new Dispatcher();
$dispatcher->setApplication(Application::get());
$dispatcher->addRouterName('\APP\core\PageRouter', PKPApplication::ROUTE_PAGE);
$url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $journal->getPath(), 'article', 'view', $submission->getBestId(), null, null, true);

$articleMetaElement
->appendChild($this->createElement('self-uri'))
->setAttribute('xlink:href', $request->url($journal->getPath(), 'article', 'view', $submission->getBestArticleId()));
->setAttribute('xlink:href', $url);

$submissionKeywordDao = DAORegistry::getDAO('SubmissionKeywordDAO');
foreach ($submissionKeywordDao->getKeywords($publication->getId(), $journal->getSupportedLocales()) as $locale => $keywords) {
Expand Down

0 comments on commit 526820a

Please sign in to comment.