private Collection validateGenericJcrData()

in vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/ValidationExecutor.java [297:363]


    private Collection<ValidationViolation> validateGenericJcrData(@Nullable InputStream input, @NotNull Path filePath, @NotNull Path basePath) throws IOException {
        Map<String, Integer> nodePathsAndLineNumbers = new LinkedHashMap<>();
        Collection<ValidationViolation> enrichedMessages = new LinkedList<>();
        
        boolean isDocViewXml = true;
        if (input != null) {
            InputStream currentInput = input;
            ResettableInputStream resettableInputStream = null;
            try {
                // make sure the docviewparser always comes first
                for (Map.Entry<String, GenericJcrDataValidator> entry : genericJcrDataValidators.entrySet()) {
                    try {
                        GenericJcrDataValidator validator = entry.getValue();
                        log.debug("Validate {} with validator '{}'", filePath, validator.getClass().getName());
                        if (validator.shouldValidateJcrData(filePath, basePath)) {
                            if (resettableInputStream == null) {
                                boolean isAnotherValidatorInterested = genericJcrDataValidators.values().stream().filter(t-> !t.equals(validator)).anyMatch(x -> x.shouldValidateJcrData(filePath, basePath));
                                if (isAnotherValidatorInterested) {
                                    currentInput = resettableInputStream = new ResettableInputStream(input);
                                }
                            } else {
                                resettableInputStream.reset();
                            }
                            enrichedMessages.add(new ValidationViolation(entry.getKey(), ValidationMessageSeverity.DEBUG, "Validate..."));
                            Collection<ValidationMessage> messages = validator.validateJcrData(currentInput, filePath, basePath, nodePathsAndLineNumbers);
                            if (messages != null && !messages.isEmpty()) {
                                enrichedMessages.addAll(ValidationViolation.wrapMessages(entry.getKey(), messages, filePath, basePath, null, 0, 0));
                            }
                        } 
                        // if we haven't collected node paths from a previous run the input is no docview xml
                        if (nodePathsAndLineNumbers.isEmpty()) {
                            // convert file name to node path
                            String nodePath = filePathToNodePath(filePath);
                            log.debug("Found non-docview node '{}'", nodePath);
                            isDocViewXml = false;
                            nodePathsAndLineNumbers.put(nodePath, 0);
                        }
                    } catch (RuntimeException e) {
                        if (!(e instanceof ValidatorException)) {
                            throw new ValidatorException(entry.getKey(), filePath, e);
                        } else {
                            throw e;
                        }
                    }
                }
            } finally {
                if (resettableInputStream != null) {
                    resettableInputStream.close();
                }
            }
        } else {
            // collect node path for folder only
            nodePathsAndLineNumbers.put(filePathToNodePath(filePath), 0);
        }

        if (!jcrPathValidators.isEmpty() || !nodePathValidators.isEmpty()) {
            NodeContext nodeContext = new NodeContextImpl(nodePathsAndLineNumbers.keySet().stream().findFirst().orElseThrow(() -> new IllegalStateException("No node paths have been collected")), filePath, basePath);
            for (Map.Entry<String, JcrPathValidator> entry : jcrPathValidators.entrySet()) {
                Collection<ValidationMessage> messages = entry.getValue().validateJcrPath(nodeContext, input == null, isDocViewXml);
                if (messages != null && !messages.isEmpty()) {
                    enrichedMessages.addAll(ValidationViolation.wrapMessages(entry.getKey(), messages, filePath, basePath, null, 0, 0));
                }
            }
            enrichedMessages.addAll(validateNodePaths(filePath, basePath, nodePathsAndLineNumbers));
        }
        return enrichedMessages;
    }