Skip to content

Commit

Permalink
GFORMS-3069 - Production/Accessibility PDF issue- org.xml.sax.SAXPars… (
Browse files Browse the repository at this point in the history
  • Loading branch information
DursunGundogan authored Dec 17, 2024
1 parent 810d5f4 commit 1e239b7
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 43 deletions.
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/gform/summary/SummaryRenderingService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,10 @@ object SummaryRenderingService {
)(implicit messages: Messages, l: LangADT, sse: SmartStringEvaluator) =
summaryDataList.map {
case pageData: PageData => summaryPage(pageData)
case AddToListData(title, summary, pageGroups, _) =>
case AddToListData(title, summary, pageGroups, id) =>
val summaryValues = summary.values.zipWithIndex.map { case (v, idx) => (idx + 1) -> v }
val addToListSummaryPage = addToListSummary(summaryValues)
addToList(title, Some(summary.title), addToListSummaryPage, pageGroups)
addToList(id, title, Some(summary.title), addToListSummaryPage, pageGroups)
}

def renderPageField(field: PageField): XmlFormat.Appendable = field match {
Expand Down
15 changes: 13 additions & 2 deletions app/uk/gov/hmrc/gform/views/summary/pdf/PdfHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,27 @@ import play.twirl.api.{ Html, XmlFormat }
import uk.gov.hmrc.gform.views.xml.summary.pdf.simpleField

object PdfHelper {
private val replacements =
Map('<' -> "&lt;", '>' -> "&gt;", '&' -> "&#38;", ']' -> "&#93;", '\'' -> "&#39;", '"' -> "&#34;")

def renderHtml(value: String): XmlFormat.Appendable = {
val newLineDelimiters = List("<br>", "\n\n")
val maybeDelimiter = newLineDelimiters.find(value.contains)

val lines = maybeDelimiter match {
case Some(delimiter) => value.split(delimiter)
case None => return XmlFormat.raw(StringEscapeUtils.unescapeXml(value))
case None => return XmlFormat.raw(sanitizeContent(value))
}

simpleField(lines.map(StringEscapeUtils.unescapeXml).map(Html(_)).toList)
simpleField(lines.map(sanitizeContent).map(Html(_)).toList)
}

def sanitizeContent(content: String): String =
StringEscapeUtils.unescapeXml(content.foldLeft("") { (acc, char) =>
replacements.getOrElse(char, char.toString) match {
case replacement: String => acc + replacement
case _ => acc
}
})

}
14 changes: 9 additions & 5 deletions app/uk/gov/hmrc/gform/views/summary/pdf/addToList.scala.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
@import play.twirl.api.XmlFormat
@import uk.gov.hmrc.gform.pdf.model.PDFModel.{ AddToListSummary, AddToListPageGroup }
@import uk.gov.hmrc.gform.summary.SummaryRenderingService
@import uk.gov.hmrc.gform.views.summary.pdf.PdfHelper

@(title: String, summaryTitle: Option[String], summaryValue: XmlFormat.Appendable, pageGroups: List[AddToListPageGroup])(implicit messages: Messages, l:LangADT, sse: SmartStringEvaluator)
@(id: String, title: String, summaryTitle: Option[String], summaryValue: XmlFormat.Appendable, pageGroups: List[AddToListPageGroup])(implicit messages: Messages, l:LangADT, sse: SmartStringEvaluator)
<fo:block role="Div" padding-before="1cm">
<fo:block role="H2"
<fo:block id="@id"
role="H2"
font-size="16px"
font-family="arial-bold"
font-weight="bold"
Expand All @@ -22,7 +24,8 @@
</fo:list-block>
@pageGroups.map { pageGroup =>
<fo:block role="Div">
<fo:block role="H3"
<fo:block id="@{pageGroup.id}"
role="H3"
font-size="14px"
font-family="arial-bold"
font-weight="bold"
Expand All @@ -33,14 +36,15 @@
@pageGroup.pages.map { page =>
<fo:block role="Div">
@if(page.title.isDefined){
<fo:block role="H4"
<fo:block id="@{page.id}"
role="H4"
font-size="12px"
font-family="arial-bold"
font-weight="bold"
line-height="12pt"
padding-bottom="5mm"
padding-before="1cm">
@page.title.map(t => unescapeXml(t))
@page.title.map(t => PdfHelper.sanitizeContent(t))
</fo:block>
} else {
<fo:block> </fo:block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
font-weight="bold"
font-size="11pt"
line-height="11pt">
<fo:inline>
<fo:wrapper role="artifact">
@value._1 -
</fo:wrapper>
</fo:inline>
<fo:inline>@value._1.</fo:inline>
</fo:block>
</fo:list-item-label>
<fo:list-item-body role="LBody" start-indent="0.8cm" >
<fo:block>
@{SummaryRenderingService.renderAddToListSummaryItemBody(value._2)}
<fo:block margin-left="-5px" padding-left="-5px">
@{SummaryRenderingService.renderAddToListSummaryItemBody(value._2)}
</fo:block>
</fo:list-item-body>
</fo:list-item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
@import play.twirl.api.XmlFormat

@(boldText: String, normalText: XmlFormat.Appendable)
<fo:block role="Div">
<fo:inline role="P"
font-size="11px"
font-family="arial-bold"
font-weight="bold"
line-height="11pt">
@boldText
<fo:inline font-size="11px"
font-family="arial"
font-weight="normal"
line-height="11pt">
@normalText
</fo:inline>
<fo:inline font-size="11px"
font-family="arial-bold"
font-weight="bold"
line-height="11pt">@boldText
<fo:inline font-size="11px"
font-family="arial"
font-weight="normal"
line-height="11pt">@normalText
</fo:inline>
</fo:block>
</fo:inline>
33 changes: 33 additions & 0 deletions app/uk/gov/hmrc/gform/views/summary/pdf/bookmarkTree.scala.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@import uk.gov.hmrc.gform.pdf.model.PDFModel._

@(formName: Option[String], summaryDatas: List[SummaryData])
<fo:bookmark-tree>
<fo:bookmark internal-destination="title">
@formName.map{ title =>
<fo:bookmark-title>@title</fo:bookmark-title>
}
@for(summaryData <- summaryDatas) {
@summaryData match {
case p: PageData => {
@for(title <- p.title) {
<fo:bookmark internal-destination="@{p.id}">
<fo:bookmark-title>@{title}</fo:bookmark-title>
</fo:bookmark>
}
}
case AddToListData(title, _, pageGroups, id) => {
@if(title.nonEmpty) {
<fo:bookmark internal-destination="@{id}">
<fo:bookmark-title>@{title}</fo:bookmark-title>
@for(pageGroup <- pageGroups) {
<fo:bookmark internal-destination="@{pageGroup.id}">
<fo:bookmark-title>@{title}</fo:bookmark-title>
</fo:bookmark>
}
</fo:bookmark>
}
}
}
}
</fo:bookmark>
</fo:bookmark-tree>
6 changes: 4 additions & 2 deletions app/uk/gov/hmrc/gform/views/summary/pdf/choiceField.scala.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import uk.gov.hmrc.gform.views.summary.pdf.PdfHelper

@(values: List[Html])
@if(values.size > 1) {
<fo:inline>
Expand All @@ -23,7 +25,7 @@
font-family="arial"
font-weight="normal"
line-height="11pt">
@unescapeXml(value.body)
@PdfHelper.sanitizeContent(value.body)
</fo:block>
</fo:list-item-body>
</fo:list-item>
Expand All @@ -33,7 +35,7 @@
} else {
@values.map{ value =>
<fo:block role="P">
@unescapeXml(value.body)
@PdfHelper.sanitizeContent(value.body)
</fo:block>
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import uk.gov.hmrc.gform.views.summary.pdf.PdfHelper

@(values: List[Html])
@if(values.size > 1) {
<fo:inline>
Expand All @@ -24,7 +26,7 @@
font-family="arial"
font-weight="normal"
line-height="11pt">
@unescapeXml(value.body)
@PdfHelper.sanitizeContent(value.body)
</fo:block>
</fo:list-item-body>
</fo:list-item>
Expand All @@ -34,7 +36,7 @@
} else {
@values.map{ value =>
<fo:block role="P">
@unescapeXml(value.body)
@PdfHelper.sanitizeContent(value.body)
</fo:block>
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import uk.gov.hmrc.gform.views.summary.pdf.PdfHelper

@(label: String, value: String)
<fo:list-item role="LI"
space-before="0.5cm"
Expand All @@ -6,9 +8,9 @@
font-weight="normal"
line-height="9pt">
<fo:list-item-label role="Lbl" end-indent="label-end()">
<fo:block font-family="arial-bold" font-weight="bold">@{unescapeXml(label)}</fo:block>
<fo:block font-family="arial-bold" font-weight="bold">@{PdfHelper.sanitizeContent(label)}</fo:block>
</fo:list-item-label>
<fo:list-item-body role="LBody" start-indent="body-start()" end-indent="5mm" >
<fo:block wrap-option="wrap">@{unescapeXml(value)}</fo:block>
<fo:block wrap-option="wrap">@{PdfHelper.sanitizeContent(value)}</fo:block>
</fo:list-item-body>
</fo:list-item>
5 changes: 4 additions & 1 deletion app/uk/gov/hmrc/gform/views/summary/pdf/summary.scala.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
</fo:declarations>
<!-- end Document metadata -->

@bookmarkTree(maybeFormName, summaryDataList)


<!-- start page-sequence
here comes the text (contained in flow objects)
Expand Down Expand Up @@ -119,7 +121,8 @@
<!-- form name -->
@maybeFormName.map{ formName =>
<fo:block role="Div" space-before="0.5cm">
<fo:block role="H1"
<fo:block id="title"
role="H1"
font-size="22px"
font-family="arial-bold"
font-weight="bold"
Expand Down
6 changes: 4 additions & 2 deletions app/uk/gov/hmrc/gform/views/summary/pdf/summaryPage.scala.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
@import uk.gov.hmrc.gform.sharedmodel.formtemplate._
@import uk.gov.hmrc.gform.eval.smartstring.SmartStringEvaluator
@import uk.gov.hmrc.gform.summary.SummaryRenderingService
@import uk.gov.hmrc.gform.views.summary.pdf.PdfHelper

@(pageData: PageData)(implicit messages: Messages, l:LangADT, sse: SmartStringEvaluator)
@if(pageData.title.isDefined){
<fo:block role="Div"
padding-before="0.8cm">
}
<fo:block role="Div">
<fo:block id="@{pageData.id}"
role="Div">
@if(pageData.title.isDefined){
<fo:block role="H2"
font-size="16px"
Expand All @@ -19,7 +21,7 @@
padding-after="0.1cm"
border-color="#D3D3D3"
linefeed-treatment="treat-as-space">
@pageData.title.map(t => unescapeXml(t))
@pageData.title.map(t => PdfHelper.sanitizeContent(t))
</fo:block>
} else {
<fo:block> </fo:block>
Expand Down
4 changes: 0 additions & 4 deletions app/uk/gov/hmrc/gform/views/summary/pdf/unescapeXml.scala.xml

This file was deleted.

0 comments on commit 1e239b7

Please sign in to comment.