Skip to content

Commit

Permalink
Handle exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoniafriedrich committed Jan 20, 2025
1 parent 472ccce commit 9fd0207
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -930,4 +930,5 @@ pdf.errorbox.test=Test
pdf.errorbox.no.conformity=Keine
pdf.errorbox.specification=Spezifikation
pdf.errorbox.validationerror.message=Leider konnte dieses Dokument aufgrund eines Fehlers nicht validiert werden.
pdf.error.runtimeerror.message=W\u00E4hrend des Lese- oder Validierungsprozesses trat zur Laufzeit ein Fehler auf.
mir.derivate.file.MD5 = MD5 Summe:
Original file line number Diff line number Diff line change
Expand Up @@ -881,4 +881,5 @@ pdf.errorbox.test=Test
pdf.errorbox.no.conformity=None
pdf.errorbox.specification=Specification
pdf.errorbox.validationerror.message=Unfortunately, this document could not be validated due to an error.
pdf.error.runtimeerror.message=An error occurred during the read or validation process at runtime.
78 changes: 56 additions & 22 deletions mir-module/src/main/resources/xsl/metadata/mir-pdf-errorbox.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,19 @@
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="CaughtException">
<xsl:choose>
<xsl:when test="contains($errorMessages,i18n:translate('pdf.error.runtimeerror.message'))">
<xsl:value-of select="'true'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'false'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="validationWasSuccessfull">
<xsl:choose>
<xsl:when test="$couldNotBeValidated='false' and $containsValidationError='false'">
<xsl:when test="$couldNotBeValidated='false' and $containsValidationError='false' and $CaughtException='false'">
<xsl:value-of select="'true'"/>
</xsl:when>
<xsl:otherwise>
Expand All @@ -46,7 +56,7 @@
</xsl:variable>

<xsl:choose>
<xsl:when test="$validationWasSuccessfull='false'">
<xsl:when test="$validationWasSuccessfull='false' and $CaughtException='false'">
<div class="container pdf-validation mb-3 px-0" id="accordion">
<div class="card-header bg-danger text-white">
<div class="list-group list-group-root well p-3">
Expand Down Expand Up @@ -75,18 +85,39 @@
</div>
</div>
</xsl:when>
<xsl:otherwise> <xsl:copy-of select="$errorMessages"/></xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>

<xsl:template match="structure/derobjects/derobject" mode="displayPdfError">
<xsl:variable name="derivateID" select="@xlink:href"/>
<xsl:variable name="result" select="document(concat('pdfAValidator:', $derivateID))"/>
<xsl:if test="not(normalize-space($result))">
<xsl:apply-templates select="$result/derivate/file" mode="displayPdfError"/>
</xsl:if>
<xsl:variable name="result" select="document(concat('catchEx:pdfAValidator:', $derivateID))"/>
<xsl:choose>
<xsl:when test="not(normalize-space($result))">
<xsl:apply-templates select="$result/derivate/file" mode="displayPdfError"/>
</xsl:when>
<xsl:otherwise>
<div class="card text-white bg-danger mb-3 pdfa-runtime-exception">
<div class="card-header">
<xsl:value-of select="concat($derivateID,': ',$result)"/>
</div>
<div class="card-body">
<p class="card-text">
<xsl:value-of select="i18n:translate('pdf.error.runtimeerror.message')"/>
</p>
<p class="card-text font-italic">
<xsl:value-of select="i18n:translate('mir.error.finalLine')"/>
</p>
</div>
</div>

</xsl:otherwise>
</xsl:choose>
</xsl:template>



<xsl:template match="file" mode="displayPdfError">
<xsl:variable name="ValidationError" select="@flavour = 'Validation Error'"/>

Expand Down Expand Up @@ -147,9 +178,11 @@
</xsl:otherwise>
</xsl:choose>

<xsl:variable name="downloadLink" select="concat($ServletsBaseURL, 'MCRFileNodeServlet/', $derivate, '/', mcrxsl:encodeURIPath(@name))"/>
<xsl:variable name="downloadLink"
select="concat($ServletsBaseURL, 'MCRFileNodeServlet/', $derivate, '/', mcrxsl:encodeURIPath(@name))"/>
<div class="w-100 d-flex align-self-center justify-content-center">
<a role="button" href="{$downloadLink}" target="_blank" class="btn btn-primary d-flex justify-content-center align-items-center w-100 py-2">
<a role="button" href="{$downloadLink}" target="_blank"
class="btn btn-primary d-flex justify-content-center align-items-center w-100 py-2">
<xsl:value-of select="concat(i18n:translate('pdf.errorbox.button.download'), ' ')"/>
<i class="fas fa-download ms-2"/>
</a>
Expand Down Expand Up @@ -232,7 +265,9 @@


<xsl:if test="$exception/cause/exception">
<p><strong>Caused by:</strong></p>
<p>
<strong>Caused by:</strong>
</p>
<xsl:text>&#10;</xsl:text>
<li class="alert alert-info" role="alert">
<xsl:value-of select="$exception/cause/exception/message/@message"/>
Expand All @@ -246,22 +281,21 @@
</xsl:if>


<xsl:for-each select="$exception/suppressed/exception">
<li class="alert alert-info" role="alert">
<xsl:value-of select="$exception/suppressed/exception/message/@message"/>
</li>
<li class="text-primary font-italic" style="font-size: 1em;">
<xsl:value-of select="$exception/suppressed/exception/class/@name"/>
</li>
<p>Suppressed:</p>
<xsl:call-template name="render-exception-details">
<xsl:with-param name="exception" select="."/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="$exception/suppressed/exception">
<li class="alert alert-info" role="alert">
<xsl:value-of select="$exception/suppressed/exception/message/@message"/>
</li>
<li class="text-primary font-italic" style="font-size: 1em;">
<xsl:value-of select="$exception/suppressed/exception/class/@name"/>
</li>
<p>Suppressed:</p>
<xsl:call-template name="render-exception-details">
<xsl:with-param name="exception" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>



<xsl:template match="failed" mode="displayPdfError">
<li class="list-group-item d-flex flex-column flex-xl-row flex-grow-1 text-break">
<p class="flex-grow-1 col-xl-8 align-items-center">
Expand Down

0 comments on commit 9fd0207

Please sign in to comment.