private AbstractBuilder parseMatcher()

in apache-rat-core/src/main/java/org/apache/rat/configuration/XMLConfigurationReader.java [373:435]


    private AbstractBuilder parseMatcher(final Node matcherNode) {
        final AbstractBuilder builder = MatcherBuilderTracker.getMatcherBuilder(matcherNode.getNodeName());

        try {
            final Description description = DescriptionBuilder.buildMap(builder.getClass());
            if (description == null) {
                throw new ConfigurationException(String.format("Unable to build description for %s", builder.getClass()));
            }
            processBuilderParams(description, builder);

            // process the attributes
            description.setChildren(builder, attributes(matcherNode));

            // check XML child nodes.
            Pair<Boolean, List<Node>> pair = processChildNodes(description, matcherNode,
                    matcherChildNodeProcessor(builder, description));
            boolean foundChildren = pair.getLeft();
            List<Node> children = pair.getRight();

            // check for inline nodes that can accept child nodes.
            List<Description> childDescriptions = description.getChildren().values().stream()
                    .filter(d -> XMLConfig.isInlineNode(description.getCommonName(), d.getCommonName()))
                    .collect(Collectors.toList());

            for (Description childDescription : childDescriptions) {
                if (XMLConfig.isInlineNode(description.getCommonName(), childDescription.getCommonName())) {
                    // can only process text inline if there were no child nodes.
                    if (childDescription.getChildType() == String.class) {
                        if (!foundChildren) {
                            callSetter(childDescription, builder, matcherNode.getTextContent());
                        }
                    } else {
                        Iterator<Node> iter = children.iterator();
                        while (iter.hasNext()) {
                            Node child = iter.next();
                            callSetter(childDescription, builder, parseMatcher(child));
                            iter.remove();
                        }
                    }

                } else {
                    processChildren(description, children, (child, childD) -> {
                        if (childD.getChildType().equals(description.getChildType())) {
                            setValue(childDescription, childD, builder, child);
                            return true;
                        }
                        return false;
                    });
                }

            }

            if (!children.isEmpty()) {
                children.forEach(n -> DefaultLog.getInstance().warn(String.format("unrecognised child node '%s' in node '%s'%n",
                        n.getNodeName(), matcherNode.getNodeName())));
            }

        } catch (DOMException e) {
            DefaultLog.getInstance().error(String.format("Matcher error in: '%s'", nodeText(matcherNode)));
            throw new ConfigurationException(e);
        }
        return builder.hasId() ? new IDRecordingBuilder(matchers, builder) : builder;
    }