Skip to content

Commit

Permalink
Include Stacktrace on page
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoniafriedrich committed Nov 4, 2024
1 parent b3e9341 commit 4457ac9
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -925,4 +925,4 @@ pdf.errorbox.clause=Paragraph
pdf.errorbox.test=Test
pdf.errorbox.no.conformity=Keine
pdf.errorbox.specification=Spezifikation
pdf.errorbox.validationerror.message=Leider konnte dieses Dokument aufgrund eines unbekannten Fehlers nicht validiert werden.
pdf.errorbox.validationerror.message=Leider konnte dieses Dokument aufgrund eines Fehlers nicht validiert werden.
Original file line number Diff line number Diff line change
Expand Up @@ -877,4 +877,4 @@ pdf.errorbox.clause=Clause
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 unknown error.
pdf.errorbox.validationerror.message=Unfortunately, this document could not be validated due to an error.
170 changes: 122 additions & 48 deletions mir-module/src/main/resources/xsl/metadata/mir-pdf-errorbox.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,70 @@
<xsl:variable name="errorMessages">
<xsl:apply-templates select="structure/derobjects/derobject" mode="displayPdfError"/>
</xsl:variable>
<xsl:if test="string-length(normalize-space($errorMessages)) >0">
<xsl:variable name="couldNotBeValidated">
<xsl:choose>
<xsl:when test="contains($errorMessages,i18n:translate('pdf.errorbox.validationerror.message'))">
<xsl:value-of select="'true'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'false'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="containsValidationError">
<xsl:choose>
<xsl:when test="contains($errorMessages,i18n:translate('pdf.errorbox.clause'))">
<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:value-of select="'true'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'false'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:choose>
<xsl:when test="contains($errorMessages,i18n:translate('pdf.errorbox.clause')) or
contains($errorMessages,i18n:translate('pdf.errorbox.validationerror.message'))">
<div class="container pdf-validation mb-3 px-0" id="accordion">
<div class="card-header bg-danger text-white">
<xsl:choose>
<xsl:when test="$validationWasSuccessfull='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">
<p class="h5">
<xsl:value-of select="i18n:translate('pdf.errorbox.warning.heading')"/>
</p>
<p>
<xsl:value-of select="i18n:translate('pdf.errorbox.warning.message')"/>
</p>
</div>
</div>
<div class="card-body border-left border-right border-bottom">
<xsl:copy-of select="$errorMessages"/>
</div>
</div>
</xsl:when>
<xsl:when test="$validationWasSuccessfull='true'">
<div class="card-header bg-success text-white mb-3">
<div class="list-group list-group-root well p-3">
<p class="h5">
<xsl:value-of select="i18n:translate('pdf.errorbox.warning.heading')"/>
<xsl:value-of select="i18n:translate('pdf.errorbox.success.heading')"/>
</p>
<p>
<xsl:value-of select="i18n:translate('pdf.errorbox.warning.message')"/>
<xsl:value-of select="i18n:translate('pdf.errorbox.success.message')"/>
</p>
</div>
</div>
<div class="card-body border-left border-right border-bottom">
<xsl:copy-of select="$errorMessages"/>
</div>
</div>
</xsl:when>
<xsl:when test="string-length(normalize-space($errorMessages)) >0 and
not(contains($errorMessages,i18n:translate('pdf.errorbox.validationerror.message')))">
<div class="card-header bg-success text-white mb-3">
<div class="list-group list-group-root well p-3">
<p class="h5">
<xsl:value-of select="i18n:translate('pdf.errorbox.success.heading')"/>
</p>
<p>
<xsl:value-of select="i18n:translate('pdf.errorbox.success.message')"/>
</p>
</div>
</div>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:template>

<xsl:template match="structure/derobjects/derobject" mode="displayPdfError">
Expand All @@ -58,33 +88,35 @@
</xsl:template>

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

<xsl:variable name="derivate" select="../@id"/>
<xsl:variable name="name">
<xsl:call-template name="pdfError.getFilename">
<xsl:with-param name="filePath" select="@name"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="badgecolor">
<xsl:choose>
<xsl:when test="failed[@clause='Validation error!']">warning</xsl:when>
<xsl:when test="$ValidationError">warning</xsl:when>
<xsl:when test="failed">danger</xsl:when>
<xsl:otherwise>success</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="uniqueFileId" select="generate-id(.)"/>
<div id="{$derivate}{$uniqueFileId}" class="font-weight-bold d-flex list-group list-group-root">
<a onclick="$('#{$derivate}{$uniqueFileId}cbButton').toggleClass('fa-chevron-right fa-chevron-down');"
data-toggle="collapse" href="#collapse{$derivate}{$uniqueFileId}"
class="text-left d-flex flex-md-row flex-grow-1 list-group-item align-items-center">
class="text-left d-flex flex-md-row flex-grow-1 list-group-item align-items-center">
<i id="{$derivate}{$uniqueFileId}cbButton" class="fa fa-chevron-right ml-auto mr-1"/>
<span class="flex-grow-1 font-weight-bold text-break">
<xsl:value-of select="$name"/>
</span>
<span class="badge badge-{$badgecolor} badge-pill align-self-center">
<xsl:choose>
<xsl:when test="$badgecolor = 'warning'">
!
</xsl:when>
<xsl:when test="$badgecolor = 'warning'">!</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(failed)"/>
</xsl:otherwise>
Expand All @@ -95,40 +127,83 @@
<ul class="list-group collapse" id="collapse{$derivate}{$uniqueFileId}">
<li class="list-group-item d-flex flex-column flex-xl-row flex-grow-2 text-break">
<xsl:choose>
<xsl:when test="failed[@clause='Validation error!']">
<xsl:when test="$ValidationError">
<xsl:apply-templates select="failed" mode="displayValidationError"/>
<span class="flex-grow-1 col-xl-8 align-items-center">
<p class="text-danger mb-2">
<xsl:value-of select="i18n:translate('pdf.errorbox.validationerror.message')"/>
</p>
</span>
</xsl:when>
<xsl:otherwise>
<p class="flex-grow-1 col-xl-8 align-items-center">
<span class="text-muted pdf-term">
<xsl:value-of select="concat(i18n:translate('pdf.errorbox.conformity.level'),': ')"/>
<xsl:value-of select="concat(i18n:translate('pdf.errorbox.conformity.level'), ': ')"/>
</span>
<span class="pdf-value">
<xsl:value-of select="concat('PDF/A-',@flavour)"/>
<xsl:value-of select="concat('PDF/A-', @flavour)"/>
</span>
</p>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="downloadLink">
<xsl:value-of
select="concat($ServletsBaseURL,'MCRFileNodeServlet/',$derivate,'/',
mcrxsl:encodeURIPath(@name))"/>
</xsl:variable>

<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">
<xsl:value-of select="concat(i18n:translate('pdf.errorbox.button.download'),' ')"/>
<i class="fas fa-download ms-2"></i>
<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>
</div>

</li>
<xsl:if test="not(@flavour='0')">
<xsl:apply-templates select="failed" mode="displayPdfError"/>
</xsl:if>

<xsl:choose>
<xsl:when test="not($ValidationError)">
<xsl:apply-templates select="failed" mode="displayPdfError"/>
</xsl:when>
<xsl:when test="$ValidationError">
<xsl:apply-templates select="exceptions">
<xsl:with-param name="uniqueName" select="concat($derivate, $uniqueFileId)"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</ul>
</xsl:template>

<xsl:template match="exceptions">
<xsl:param name="uniqueName" select="'uniqueStacktraceName'"/>
<a onclick="$('#{$uniqueName}stacktracecbButton').toggleClass('fa-chevron-right fa-chevron-down');"
data-toggle="collapse" href="#collapse{$uniqueName}stacktrace"
class="text-left text-dark d-flex flex-md-row flex-grow-1 list-group-item align-items-center"
style="text-decoration: none;">
<i id="{$uniqueName}stacktracecbButton" class="fa fa-chevron-right ml-auto mr-1"></i>
<span class="flex-grow-1 font-weight-bold text-break">
<xsl:value-of select="'Stack trace'"/>
</span>
</a>
<div id="collapse{$uniqueName}stacktrace" class="collapse list-group-item text-center"
style="overflow-x: auto;">
<xsl:for-each select="exception">
<ul class="list-unstyled pl-3">
<li class="alert alert-info" role="alert">
<xsl:value-of select="message/@message"/>
</li>
<li class="text-primary font-italic" style="font-size: 1em;">
<xsl:value-of select="class/@name"/>
</li>
<pre style="font-size: 0.8em;">
<code>
<xsl:for-each select="stackTrace/frame">
<xsl:value-of select="@text"/>
<xsl:text>&#10;</xsl:text>
</xsl:for-each>
</code>
</pre>
</ul>
</xsl:for-each>
</div>
</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 Expand Up @@ -198,5 +273,4 @@
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 4457ac9

Please sign in to comment.