Skip to content

Commit

Permalink
pkp/pkp-lib#7505 Support for JATS files/content added
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat committed Dec 7, 2023
1 parent fb77e91 commit 01087dd
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 40 deletions.
11 changes: 2 additions & 9 deletions JatsTemplatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@

namespace APP\plugins\generic\jatsTemplate;

use APP\facades\Repo;
use APP\core\Services;
use APP\core\Application;
use APP\plugins\generic\jatsTemplate\classes\Article;
use APP\template\TemplateManager;
use PKP\core\PKPString;
use PKP\db\DAORegistry;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use PKP\plugins\PluginRegistry;
use PKP\search\SearchFileParser;
use PKP\submissionFile\SubmissionFile;
use PKP\config\Config;

class JatsTemplatePlugin extends GenericPlugin {

Expand Down Expand Up @@ -68,7 +60,8 @@ public function callbackFindJats($hookName, $args) {
$doc =& $args[3];

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

return false;
Expand Down
38 changes: 24 additions & 14 deletions classes/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@
namespace APP\plugins\generic\jatsTemplate\classes;

use APP\core\Application;
use DOMException;
use APP\issue\Issue;
use APP\publication\Publication;
use APP\section\Section;
use APP\submission\Submission;
use PKP\context\Context;
use PKP\core\PKPRequest;
use PKP\oai\OAIRecord;

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

/**
* @param $record
* @return bool|\DOMDocument
*
*/
public function convertToXml($record) :bool|\DOMDocument
public function convertOAIToXml(OAIRecord $record): void
{
$submission = $record->getData('article');
$journal = $record->getData('journal');
Expand All @@ -37,25 +41,30 @@ public function convertToXml($record) :bool|\DOMDocument
$publication = $submission->getCurrentPublication();
$request = Application::get()->getRequest();

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

/**
* Convert submission metadata to JATS XML
*/
public function convertSubmission(Submission $submission, Context $context, Section $section, ?Issue $issue = null, ?Publication $publication = null, PKPRequest $request): void
{
$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;
->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, $publication), 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));
}


/**
* 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 +85,5 @@ public function mapHtmlTagsForTitle(string $htmlTitle): string

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

}
42 changes: 30 additions & 12 deletions classes/ArticleFront.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use APP\section\Section;
use APP\submission\Submission;
use APP\publication\Publication;
use PKP\core\PKPApplication;
use PKP\core\PKPString;
use PKP\db\DAORegistry;
use PKP\plugins\PluginRegistry;
Expand All @@ -27,16 +28,15 @@

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, ?Publication $workingPublication = null): \DOMNode
{
return $this->appendChild($this->createElement('front'))
->appendChild($this->createJournalMeta($journal, $request))
->parentNode
->appendChild($this->createArticleMeta($submission, $journal, $section, $issue, $request, $article))
->appendChild($this->createArticleMeta($submission, $journal, $section, $issue, $request, $article, $workingPublication))
->parentNode;
}

Expand Down Expand Up @@ -87,9 +87,14 @@ public function createJournalMeta(Journal $journal, PKPRequest $request): \DOMNo
->appendChild($this->createTextNode($journal->getSetting('printIssn')))->parentNode
->setAttribute('pub-type','ppub');
}

$router = $request->getRouter();
$dispatcher = $router->getDispatcher();

$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,9 +129,12 @@ 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 $workingPublication = null)
{
$publication = $submission->getCurrentPublication();
if ($workingPublication) {
$publication = $workingPublication;
}

$articleMetaElement = $this->appendChild($this->createElement('article-meta'));

Expand Down Expand Up @@ -186,11 +194,16 @@ function createArticleMeta(Submission $submission, Journal $journal, Section $se
}

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

// Include pub dates
if ($submission->getDatePublished()){
if ($datePublished) {
$pubDateElement = $articleMetaElement->appendChild($this->createElement('pub-date'))
->setAttribute('date-type', 'pub')->parentNode
->setAttribute('publication-format','epub')->parentNode;
Expand Down Expand Up @@ -237,9 +250,9 @@ function createArticleMeta(Submission $submission, Journal $journal, Section $se
$pageCount = $matchedPageTo - $matchedPageFrom + 1;
}

$copyrightYear = $submission->getCopyrightYear();
$copyrightHolder = $submission->getLocalizedCopyrightHolder();
$licenseUrl = $submission->getLicenseURL();
$copyrightYear = $publication->getData('copyrightYear');
$copyrightHolder = $publication->getLocalizedData('copyrightHolder');
$licenseUrl = $publication->getData('licenseUrl');
$ccBadge = Application::get()->getCCLicenseBadge($licenseUrl, $submission->getLocale())=== null?'':Application::get()->getCCLicenseBadge($licenseUrl, $submission->getLocale());
if ($copyrightYear || $copyrightHolder || $licenseUrl || $ccBadge) {
$permissionsElement = $articleMetaElement->appendChild($this->createElement('permissions'));
Expand All @@ -264,10 +277,15 @@ function createArticleMeta(Submission $submission, Journal $journal, Section $se
}
}
}

$router = $request->getRouter();
$dispatcher = $router->getDispatcher();

$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
11 changes: 6 additions & 5 deletions tests/functional/ArticleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ private function createOAIRecordMockObject(): OAIRecord
public function testConvertToXml()
{
$record = $this->createOAIRecordMockObject();
$article = new Article($record);
$xml = $article->convertToXml($record);
$article = new Article();
$article->convertOAIToXml($record);
self::assertXmlStringEqualsXmlFile($this->xmlFilePath.'ie1.xml', $article->saveXml());
self::assertTrue($xml);
self::assertTrue($article);
}

/**
Expand All @@ -221,8 +221,9 @@ public function testMapHtmlTagsForTitle(){
$expected = '<bold>test</bold>';
$htmlString = '<b>test</b>';
$record = $this->createOAIRecordMockObject();
$article = new Article($record);
$article = new Article();
$article->convertOAIToXml($record);
$actual = $article->mapHtmlTagsForTitle($htmlString);
self::assertEquals($expected,$actual);
self::assertEquals($expected, $actual);
}
}

0 comments on commit 01087dd

Please sign in to comment.