Skip to content

Commit f9c25c0

Browse files
committed
Pull request #178: Development
Merge in ITB/xml-validator from development to master * commit '1577b744e89ea6f88074ec6d503bf91429b71a1f': Quality fixes Upgrade Spring Boot to v3.5.4 and Tika to v3.2.1 Support for domain aliases Unable to embed a results-only view of the validator in iframes
2 parents 0d41b21 + 1577b74 commit f9c25c0

11 files changed

Lines changed: 214 additions & 203 deletions

File tree

NOTICE.md

Lines changed: 169 additions & 169 deletions
Large diffs are not rendered by default.

xmlvalidator-common/src/main/java/eu/europa/ec/itb/xml/validation/DocumentNamespaceContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
/**
2727
* A namespace context to lookup and map namespaces based on prefix and URI.
28-
*
28+
* <p>
2929
* Implementation based on source found <a href="http://www.ibm.com/developerworks/library/x-nmspccontext/">here</a>.
3030
*/
3131
public class DocumentNamespaceContext implements NamespaceContext {

xmlvalidator-common/src/main/java/eu/europa/ec/itb/xml/validation/XSDFileResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId
124124
try {
125125
return new LSInputImpl(publicId, systemId, baseURI, new InputStreamReader(new FileInputStream(referencedSchemaFile)));
126126
} catch (FileNotFoundException e) {
127-
LOG.error("The referenced schema with system ID ["+systemId+"] could not be located at ["+referencedSchemaFile.getAbsolutePath()+"].", e);
127+
LOG.error("The referenced schema with system ID [{}] could not be located at [{}].", systemId, referencedSchemaFile.getAbsolutePath(), e);
128128
throw new IllegalStateException("The referenced schema with system ID ["+systemId+"] could not be located.", e);
129129
}
130130
}

xmlvalidator-common/src/main/java/eu/europa/ec/itb/xml/validation/XSDReportHandler.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public XSDReportHandler() {
5656
@Override
5757
public void warning(SAXParseException exception) throws SAXException {
5858
if (logger.isDebugEnabled()) {
59-
logger.debug("warning: <"+exception.getLineNumber() + "," +
60-
exception.getColumnNumber() + ">" + exception.getMessage());
59+
logger.debug("warning: <{},{}>{}", exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage());
6160
}
6261
BAR warning = new BAR();
6362
warning.setDescription( exception.getMessage());
@@ -75,8 +74,7 @@ public void warning(SAXParseException exception) throws SAXException {
7574
@Override
7675
public void error(SAXParseException exception) throws SAXException {
7776
if (logger.isDebugEnabled()) {
78-
logger.debug("error: <" + exception.getLineNumber() + "," +
79-
exception.getColumnNumber() + ">" + exception.getMessage());
77+
logger.debug("error: <{},{}>{}", exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage());
8078
}
8179
report.setResult(TestResultType.FAILURE);
8280
BAR error = new BAR();
@@ -95,8 +93,7 @@ public void error(SAXParseException exception) throws SAXException {
9593
@Override
9694
public void fatalError(SAXParseException exception) throws SAXException {
9795
if (logger.isDebugEnabled()) {
98-
logger.debug("fatal error: <" + exception.getLineNumber() + "," +
99-
exception.getColumnNumber() + ">" + exception.getMessage());
96+
logger.debug("fatal error: <{},{}>{}", exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage());
10097
}
10198
report.setResult(TestResultType.FAILURE);
10299
BAR error = new BAR();

xmlvalidator-common/src/test/java/eu/europa/ec/itb/xml/util/UtilsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import static eu.europa.ec.itb.xml.util.Utils.secureSchemaValidation;
99
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1010
import static org.junit.jupiter.api.Assertions.assertThrows;
11-
import static org.mockito.ArgumentMatchers.any;
1211
import static org.mockito.Mockito.*;
1312

1413
class UtilsTest {

xmlvalidator-jar/src/main/java/eu/europa/ec/itb/xml/standalone/ValidationRunner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected void bootstrapInternal(String[] args, File parentFolder) {
155155
contextFileInfo = processContextFiles(domainConfig, validationType, contextFileInputs, parentFolder);
156156
} catch (ValidatorException e) {
157157
LOGGER_FEEDBACK.info("\nInvalid arguments provided: {}\n", e.getMessageForDisplay(new LocalisationHelper(Locale.ENGLISH)));
158-
LOGGER.error(String.format("Invalid arguments provided: %s", e.getMessageForLog()), e);
158+
LOGGER.error("Invalid arguments provided: {}", e.getMessageForLog(), e);
159159
inputs.clear();
160160
} catch (Exception e) {
161161
LOGGER_FEEDBACK.info("\nAn error occurred while processing the provided arguments.\n");
@@ -218,12 +218,12 @@ protected void bootstrapInternal(String[] args, File parentFolder) {
218218
}
219219
} catch (ValidatorException e) {
220220
LOGGER_FEEDBACK.info("\nAn error occurred while executing the validation: {}", e.getMessageForDisplay(localiser));
221-
LOGGER.error(String.format("An error occurred while executing the validation: %s", e.getMessageForLog()), e);
221+
LOGGER.error("An error occurred while executing the validation: {}", e.getMessageForLog(), e);
222222
break;
223223

224224
} catch (Exception e) {
225225
LOGGER_FEEDBACK.info("\nAn error occurred while executing the validation.");
226-
LOGGER.error(String.format("An error occurred while executing the validation: %s", e.getMessage()), e);
226+
LOGGER.error("An error occurred while executing the validation: {}", e.getMessage(), e);
227227
break;
228228
}
229229
i++;

xmlvalidator-web/src/main/java/eu/europa/ec/itb/xml/upload/UploadController.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ public UploadResult<Translations> handleUpload(@PathVariable("domain") String do
243243
var localisationHelper = new LocalisationHelper(config, localeResolver.resolveLocale(request, response, config, appConfig));
244244
var result = new UploadResult<>();
245245

246-
if (StringUtils.isBlank(validationType)) {
247-
validationType = config.getType().get(0);
246+
if (!isOwnSubmission(request)) {
247+
validationType = inputHelper.determineValidationType(validationType, domain, config);
248248
}
249+
validationType = inputHelper.validateValidationType(config, validationType);
249250
if (config.hasMultipleValidationTypes() && (validationType == null || !config.getType().contains(validationType))) {
250251
// A validation type is required.
251252
result.setMessage(localisationHelper.localise("validator.label.exception.providedValidationTypeNotValid"));
@@ -261,7 +262,7 @@ public UploadResult<Translations> handleUpload(@PathVariable("domain") String do
261262
result.setMessage(localisationHelper.localise("validator.label.exception.providedInputNotXML"));
262263
}
263264
} catch (IOException e) {
264-
logger.error("Error while reading uploaded file [" + e.getMessage() + "]", e);
265+
logger.error("Error while reading uploaded file [{}]", e.getMessage(), e);
265266
result.setMessage(localisationHelper.localise("validator.label.exception.errorInUpload", e.getMessage()));
266267
proceedToValidate = false;
267268
}
@@ -276,7 +277,7 @@ public UploadResult<Translations> handleUpload(@PathVariable("domain") String do
276277
} catch (ValidatorException e) {
277278
throw e;
278279
} catch (Exception e) {
279-
logger.error("Error while reading uploaded file [" + e.getMessage() + "]", e);
280+
logger.error("Error while reading uploaded file [{}]", e.getMessage(), e);
280281
result.setMessage(localisationHelper.localise("validator.label.exception.errorInUpload", e.getMessage()));
281282
proceedToValidate = false;
282283
}
@@ -316,7 +317,7 @@ public UploadResult<Translations> handleUpload(@PathVariable("domain") String do
316317
fileName, report, aggregateReport,
317318
new Translations(localisationHelper, report, config));
318319
} catch (IOException e) {
319-
logger.error("Error generating detailed report [" + e.getMessage() + "]", e);
320+
logger.error("Error generating detailed report [{}]", e.getMessage(), e);
320321
result.setMessage(localisationHelper.localise("validator.label.exception.errorGeneratingDetailedReport", e.getMessage()));
321322
}
322323
}
@@ -325,7 +326,7 @@ public UploadResult<Translations> handleUpload(@PathVariable("domain") String do
325326
logger.error(e.getMessageForLog(), e);
326327
result.setMessage(e.getMessageForDisplay(localisationHelper));
327328
} catch (Exception e) {
328-
logger.error("An error occurred during the validation [" + e.getMessage() + "]", e);
329+
logger.error("An error occurred during the validation [{}]", e.getMessage(), e);
329330
if (e.getMessage() != null) {
330331
result.setMessage(localisationHelper.localise("validator.label.exception.unexpectedErrorDuringValidationWithParams", e.getMessage()));
331332
} else {
@@ -417,15 +418,15 @@ public UploadResult<Translations> handleUploadMinimal(@PathVariable("domain") St
417418
@RequestParam(value = "validationType", defaultValue = "") String validationType,
418419
@RequestParam(value = "contentType", defaultValue = "") String contentType,
419420
@RequestParam(value = "contentType-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false, defaultValue = "") String[] externalSchema,
420-
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required= false) MultipartFile[] externalSchemaFiles,
421+
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false) MultipartFile[] externalSchemaFiles,
421422
@RequestParam(value = "uri-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false, defaultValue = "") String[] externalSchemaUri,
422423
@RequestParam(value = "text-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false, defaultValue = "") String[] externalSchemaString,
423424
@RequestParam(value = "contentType-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false, defaultValue = "") String[] externalSch,
424-
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required= false) MultipartFile[] externalSchFiles,
425+
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false) MultipartFile[] externalSchFiles,
425426
@RequestParam(value = "uri-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false, defaultValue = "") String[] externalSchUri,
426427
@RequestParam(value = "text-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false, defaultValue = "") String[] externalSchString,
427428
@RequestParam(value = "contentType-contextFile", required = false, defaultValue = "") String[] contextFileTypes,
428-
@RequestParam(value = "inputFile-contextFile", required= false) MultipartFile[] contextFileFiles,
429+
@RequestParam(value = "inputFile-contextFile", required = false) MultipartFile[] contextFileFiles,
429430
@RequestParam(value = "uri-contextFile", required = false, defaultValue = "") String[] contextFileUris,
430431
@RequestParam(value = "text-contextFile", required = false, defaultValue = "") String[] contextFileStrings,
431432
RedirectAttributes redirectAttributes,
@@ -447,15 +448,15 @@ public ModelAndView handleUploadEmbedded(@PathVariable("domain") String domain,
447448
@RequestParam(value = "validationType", defaultValue = "") String validationType,
448449
@RequestParam(value = "contentType", defaultValue = "") String contentType,
449450
@RequestParam(value = "contentType-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false, defaultValue = "") String[] externalSchema,
450-
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required= false) MultipartFile[] externalSchemaFiles,
451+
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false) MultipartFile[] externalSchemaFiles,
451452
@RequestParam(value = "uri-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false, defaultValue = "") String[] externalSchemaUri,
452453
@RequestParam(value = "text-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false, defaultValue = "") String[] externalSchemaString,
453454
@RequestParam(value = "contentType-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false, defaultValue = "") String[] externalSch,
454-
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required= false, defaultValue = "") MultipartFile[] externalSchFiles,
455+
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false) MultipartFile[] externalSchFiles,
455456
@RequestParam(value = "uri-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false, defaultValue = "") String[] externalSchUri,
456457
@RequestParam(value = "text-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false, defaultValue = "") String[] externalSchString,
457458
@RequestParam(value = "contentType-contextFile", required = false, defaultValue = "") String[] contextFileTypes,
458-
@RequestParam(value = "inputFile-contextFile", required= false) MultipartFile[] contextFileFiles,
459+
@RequestParam(value = "inputFile-contextFile", required = false) MultipartFile[] contextFileFiles,
459460
@RequestParam(value = "uri-contextFile", required = false, defaultValue = "") String[] contextFileUris,
460461
@RequestParam(value = "text-contextFile", required = false, defaultValue = "") String[] contextFileStrings,
461462
RedirectAttributes redirectAttributes,
@@ -480,15 +481,15 @@ public ModelAndView handleUploadMinimalEmbedded(@PathVariable("domain") String d
480481
@RequestParam(value = "validationType", defaultValue = "") String validationType,
481482
@RequestParam(value = "contentType", defaultValue = "") String contentType,
482483
@RequestParam(value = "contentType-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false, defaultValue = "") String[] externalSchema,
483-
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required= false, defaultValue = "") MultipartFile[] externalSchemaFiles,
484+
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required= false) MultipartFile[] externalSchemaFiles,
484485
@RequestParam(value = "uri-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false, defaultValue = "") String[] externalSchemaUri,
485486
@RequestParam(value = "text-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMA, required = false, defaultValue = "") String[] externalSchemaString,
486487
@RequestParam(value = "contentType-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false, defaultValue = "") String[] externalSch,
487-
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required= false) MultipartFile[] externalSchFiles,
488+
@RequestParam(value = "inputFile-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false) MultipartFile[] externalSchFiles,
488489
@RequestParam(value = "uri-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false, defaultValue = "") String[] externalSchUri,
489490
@RequestParam(value = "text-external_"+DomainConfig.ARTIFACT_TYPE_SCHEMATRON, required = false, defaultValue = "") String[] externalSchString,
490491
@RequestParam(value = "contentType-contextFile", required = false, defaultValue = "") String[] contextFileTypes,
491-
@RequestParam(value = "inputFile-contextFile", required= false) MultipartFile[] contextFileFiles,
492+
@RequestParam(value = "inputFile-contextFile", required = false) MultipartFile[] contextFileFiles,
492493
@RequestParam(value = "uri-contextFile", required = false, defaultValue = "") String[] contextFileUris,
493494
@RequestParam(value = "text-contextFile", required = false, defaultValue = "") String[] contextFileStrings,
494495
RedirectAttributes redirectAttributes,

xmlvalidator-ws/src/main/java/eu/europa/ec/itb/xml/rest/RestValidationController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ public ResponseEntity<StreamingResponseBody> validate(
164164
HttpServletRequest request
165165
) {
166166
DomainConfig domainConfig = validateDomain(domain);
167+
// Consider the case that we have a cross-domain alias and resolve the validation type accordingly.
168+
in.setValidationType(inputHelper.determineValidationType(in.getValidationType(), domain, domainConfig));
167169
/*
168170
* Important: We call executeValidationProcess here and not in the return statement because the StreamingResponseBody
169171
* uses a separate thread. Doing so would break the ThreadLocal used in the statistics reporting.
@@ -306,6 +308,8 @@ public Output[] validateMultiple(
306308
var outputs = new ArrayList<Output>(inputs.length);
307309
for (Input input: inputs) {
308310
Output output = new Output();
311+
// Consider the case that we have a cross-domain alias and resolve the validation type accordingly.
312+
input.setValidationType(inputHelper.determineValidationType(input.getValidationType(), domain, domainConfig));
309313
var report = executeValidationProcess(input, domainConfig);
310314
try (var bos = new ByteArrayOutputStream()) {
311315
var wrapReportDataInCDATA = Objects.requireNonNullElse(input.getWrapReportDataInCDATA(), false);

0 commit comments

Comments
 (0)