Skip to content

Commit 74dfe13

Browse files
committed
REST API option to add report data in CDATA blocks or not.
1 parent 8aa22bb commit 74dfe13

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

jsonvalidator-service/src/main/java/eu/europa/ec/itb/json/rest/RestValidationController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public ResponseEntity<StreamingResponseBody> validate(
8585
if (MediaType.APPLICATION_JSON.equals(reportType)) {
8686
writeReportAsJson(outputStream, report, domainConfig);
8787
} else {
88-
fileManager.saveReport(report, outputStream, domainConfig);
88+
var wrapInputInCDATA = Objects.requireNonNullElse(in.getWrapReportDataInCDATA(), true);
89+
fileManager.saveReport(report, outputStream, domainConfig, wrapInputInCDATA);
8990
}
9091
});
9192
}
@@ -154,7 +155,8 @@ public Output[] validateMultiple(
154155
Output output = new Output();
155156
var report = executeValidationProcess(input, domainConfig);
156157
try (var bos = new ByteArrayOutputStream()) {
157-
fileManager.saveReport(report, bos, domainConfig);
158+
var wrapInputInCDATA = Objects.requireNonNullElse(input.getWrapReportDataInCDATA(), true);
159+
fileManager.saveReport(report, bos, domainConfig, wrapInputInCDATA);
158160
output.setReport(Base64.getEncoder().encodeToString(bos.toByteArray()));
159161
outputs.add(output);
160162
} catch (IOException e) {

jsonvalidator-service/src/main/java/eu/europa/ec/itb/json/rest/model/Input.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class Input {
2929
private Boolean locationAsPointer;
3030
@Schema(description = "Whether to include the validated input in the resulting report's context section.", defaultValue = "false")
3131
private Boolean addInputToReport;
32+
@Schema(description = "Whether to wrap the input (see addInputToReport) in a CDATA block if producing an XML report. False results in adding the input via XML escaping.", defaultValue = "true")
33+
private Boolean wrapReportDataInCDATA;
3234
@Schema(description = "Locale (language code) to use for reporting of results. If the provided locale is not supported by the validator the default locale will be used instead (e.g. 'fr', 'fr_FR').")
3335
private String locale;
3436

@@ -124,6 +126,20 @@ public void setAddInputToReport(Boolean addInputToReport) {
124126
this.addInputToReport = addInputToReport;
125127
}
126128

129+
/**
130+
* @return Whether to wrap the input (see addInputToReport) in a CDATA block if producing an XML report. False results in adding the input via XML escaping.
131+
*/
132+
public Boolean getWrapReportDataInCDATA() {
133+
return wrapReportDataInCDATA;
134+
}
135+
136+
/**
137+
* @param wrapReportDataInCDATA Whether to wrap the input (see addInputToReport) in a CDATA block if producing an XML report. False results in adding the input via XML escaping.
138+
*/
139+
public void setWrapReportDataInCDATA(Boolean wrapReportDataInCDATA) {
140+
this.wrapReportDataInCDATA = wrapReportDataInCDATA;
141+
}
142+
127143
/**
128144
* @return The locale string.
129145
*/

0 commit comments

Comments
 (0)