Skip to content

Commit

Permalink
Fix missing finding aid logo, refs #13458
Browse files Browse the repository at this point in the history
- Add "{{ app_root }}" template variables to pdf-logo href
- Add "{{ app_root }}" to helper-functions.xsl href
- Replace template vars with AtoM application path at run time

Fix invalid FO XSL elements in ead-pdf-inventory-summary.xsl:
- Remove unused title "<xsl:when>" conditional
- Add missing closing tags
- Remove unnecessary opening tags
- Remove duplicate templates
  • Loading branch information
djjuhasz committed Apr 30, 2021
1 parent 0aa21e1 commit d5e272f
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 111 deletions.
35 changes: 30 additions & 5 deletions lib/job/arFindingAidJob.class.php
Expand Up @@ -31,6 +31,7 @@ class arFindingAidJob extends arBaseJob
protected $extraRequiredParameters = ['objectId'];

private $resource;
private $appRoot;

public function runJob($parameters)
{
Expand Down Expand Up @@ -129,7 +130,7 @@ private function generate()
{
$this->info($this->i18n->__('Generating finding aid (%1)...', ['%1' => $this->resource->slug]));

$appRoot = rtrim(sfConfig::get('sf_root_dir'), '/');
$this->appRoot = rtrim(sfConfig::get('sf_root_dir'), '/');

$eadFileHandle = tmpfile();
$foFileHandle = tmpfile();
Expand All @@ -156,7 +157,7 @@ private function generate()
// Call generate EAD task
$slug = $this->resource->slug;
$output = [];
exec(PHP_BINARY." {$appRoot}/symfony export:bulk --single-slug=\"{$slug}\" {$public} {$eadFilePath} 2>&1", $output, $exitCode);
exec(PHP_BINARY." {$this->appRoot}/symfony export:bulk --single-slug=\"{$slug}\" {$public} {$eadFilePath} 2>&1", $output, $exitCode);

if ($exitCode > 0) {
$this->error($this->i18n->__('Exporting EAD has failed.'));
Expand All @@ -171,17 +172,24 @@ private function generate()
$findingAidModel = $setting->getValue(['sourceCulture' => true]);
}

$eadXslFilePath = $appRoot.'/lib/task/pdf/ead-pdf-'.$findingAidModel.'.xsl';
$saxonPath = $appRoot.'/lib/task/pdf/saxon9he.jar';
$eadXslFilePath = $this->appRoot.'/lib/task/pdf/ead-pdf-'.$findingAidModel.'.xsl';
$saxonPath = $this->appRoot.'/lib/task/pdf/saxon9he.jar';

// Crank the XML through XSL stylesheet and fix header / fonds URL
$eadFileString = file_get_contents($eadFilePath);
$eadFileString = $this->fixHeader($eadFileString, sfConfig::get('app_site_base_url', null));
file_put_contents($eadFilePath, $eadFileString);

// Replace {{ app_root }} placeholder var with the $this->appRoot value, and
// return the temp XSL file path for Saxon processing
$xslTmpPath = $this->renderXsl(
$eadXslFilePath,
['app_root' => $this->appRoot]
);

// Transform EAD file with Saxon
$pdfPath = sfConfig::get('sf_web_dir').DIRECTORY_SEPARATOR.self::getFindingAidPath($this->resource->id);
$cmd = sprintf("java -jar '%s' -s:'%s' -xsl:'%s' -o:'%s' 2>&1", $saxonPath, $eadFilePath, $eadXslFilePath, $foFilePath);
$cmd = sprintf("java -jar '%s' -s:'%s' -xsl:'%s' -o:'%s' 2>&1", $saxonPath, $eadFilePath, $xslTmpPath, $foFilePath);
$this->info(sprintf('Running: %s', $cmd));
$output = [];
exec($cmd, $output, $exitCode);
Expand Down Expand Up @@ -238,6 +246,23 @@ private function generate()
return true;
}

private function renderXsl($filename, $vars)
{
// Get XSL file contents
$content = file_get_contents($filename);

// Replace placeholder vars (e.g. "{{ app_root }}")
foreach ($vars as $key => $val) {
$content = str_replace("{{ {$key} }}", $val, $content);
}

// Write contents to temp file for processing with Saxon
$tmpFilePath = tempnam(sys_get_temp_dir(), 'ATM');
file_put_contents($tmpFilePath, $content);

return $tmpFilePath;
}

private function upload($path)
{
$this->info($this->i18n->__('Uploading finding aid (%1)...', ['%1' => $this->resource->slug]));
Expand Down
45 changes: 16 additions & 29 deletions lib/task/pdf/ead-pdf-full-details.xsl
Expand Up @@ -3,20 +3,20 @@
<!--
*******************************************************************
* *
* VERSION: 1.0 *
* VERSION: 1.0 *
* *
* AUTHOR: Winona Salesky *
* wsalesky@gmail.com *
* AUTHOR: Winona Salesky *
* wsalesky@gmail.com *
* *
* MODIFIED BY: mikeg@artefactual.com *
* MODIFIED BY: mikeg@artefactual.com *
* *
* DATE: 2013-08-21 *
* DATE: 2013-08-21 *
* *
*******************************************************************
-->
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<!-- Calls a stylesheet with local functions and lookup lists for languages and subject authorities -->
<xsl:include href="helper-functions.xsl"/>
<xsl:include href="{{ app_root }}/lib/task/pdf/helper-functions.xsl"/>
<xsl:strip-space elements="*"/>
<!-- The following attribute sets are reusabe styles used throughout the stylesheet. -->
<!-- Headings -->
Expand Down Expand Up @@ -251,28 +251,16 @@
<!-- Cover page templates -->
<!-- Builds title -->
<xsl:template match="ead:titlestmt" mode="pageHeader">
<!-- Uses filing type title if present -->
<xsl:choose>
<xsl:when test="ead:titleproper[@type='filing']">
<xsl:apply-templates select="ead:titleproper[@type='filing']"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="ead:titleproper[1]"/>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="ead:titleproper[1]"/>
</xsl:template>
<xsl:template match="ead:titlestmt" mode="coverPage">
<!-- Calls template with links to archive icon -->
<fo:block border-bottom="1pt solid #666" margin-top="0in" id="cover-page">
<fo:block xsl:use-attribute-sets="h1" linefeed-treatment="preserve">
<xsl:choose>
<xsl:when test="ead:titleproper[@type='filing']">
Finding Aid - <xsl:apply-templates select="ead:titleproper[@type='filing']"/>
</xsl:when>
<xsl:otherwise><fo:external-graphic src="images/pdf-logo.png" height="4cm" width="3.5cm" content-width="scale-to-fit" content-height="scale-to-fit"/><xsl:text> </xsl:text><xsl:apply-templates select="(//ead:repository/ead:corpname)[1]"/><fo:block/>
Finding Aid - <xsl:apply-templates select="ead:titleproper[1]"/> (<xsl:value-of select="//ead:eadid"/>)
</xsl:otherwise>
</xsl:choose>
<fo:external-graphic src="{{ app_root }}/images/pdf-logo.png" height="4cm" width="3.5cm" content-width="scale-to-fit" content-height="scale-to-fit"/>
<xsl:text> </xsl:text>
<xsl:apply-templates select="(//ead:repository/ead:corpname)[1]"/>
Finding Aid - <xsl:apply-templates select="ead:titleproper[1]"/> (<xsl:value-of select="//ead:eadid"/>)
</fo:block>
<xsl:if test="ead:subtitle">
<fo:block font-size="16" font-weight="bold">
Expand All @@ -286,8 +274,6 @@
<fo:block margin-top="8pt">
<xsl:apply-templates select="/ead:ead/ead:eadheader/ead:filedesc/ead:editionstmt"/>
</fo:block>
<!-- Logo in middle of cover page: -->
<!-- Atom: <xsl:call-template name="icon"/>-->
</xsl:template>
<xsl:template match="ead:publicationstmt" mode="coverPage">
<fo:block margin="0 0.3in">
Expand Down Expand Up @@ -552,8 +538,8 @@
</xsl:if>
<xsl:apply-templates select="(child::*/ead:unittitle[not(ead:bibseries)])[1]"/>
<xsl:if test="(child::*/ead:unitdate)[1]">
(<xsl:apply-templates select="(child::*/ead:unitdate)[1]" mode="did"/>)
</xsl:if>
(<xsl:apply-templates select="(child::*/ead:unitdate)[1]" mode="did"/>)
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</fo:basic-link>
Expand Down Expand Up @@ -1312,8 +1298,9 @@
</fo:block>
</xsl:template>
<!--
Calls the clevel template passes the calculates the level of current component in xml tree and passes it to clevel template via the level parameter
Adds a row to with a link to top if level series
Calls the clevel template passes the calculates the level of current
component in xml tree and passes it to clevel template via the level
parameter. Adds a row to with a link to top if level series
-->
<xsl:template match="ead:c | ead:c01 | ead:c02 | ead:c03 | ead:c04 | ead:c05 | ead:c06 | ead:c07 | ead:c08 | ead:c09 | ead:c10 | ead:c11 | ead:c12">
<xsl:variable name="findClevel" select="count(ancestor::*[not(ead:dsc or ead:archdesc or ead:ead)])"/>
Expand Down

0 comments on commit d5e272f

Please sign in to comment.