https://github.com/itplr-kosit/validator/issues/56 trim namespaces and other strings when reading the scenarios

This commit is contained in:
Andreas Penski (init) 2020-10-02 10:06:29 +02:00
parent 9838508f41
commit ef1ce56f2a
4 changed files with 42 additions and 5 deletions

View file

@ -47,6 +47,7 @@ import lombok.extern.slf4j.Slf4j;
import de.kosit.validationtool.api.ResolvingConfigurationStrategy;
import de.kosit.validationtool.impl.Scenario.Transformation;
import de.kosit.validationtool.impl.xml.RelativeUriResolver;
import de.kosit.validationtool.impl.xml.StringTrimAdapter;
import de.kosit.validationtool.model.scenarios.NamespaceType;
import de.kosit.validationtool.model.scenarios.ResourceType;
import de.kosit.validationtool.model.scenarios.ScenarioType;
@ -284,13 +285,13 @@ public class ContentRepository {
public XPathExecutable createMatchExecutable(final ScenarioType s) {
final Map<String, String> namespaces = s.getNamespace().stream()
.collect(Collectors.toMap(NamespaceType::getPrefix, NamespaceType::getValue));
.collect(Collectors.toMap(NamespaceType::getPrefix, ns -> StringTrimAdapter.trim(ns.getValue())));
return createXPath(s.getMatch(), namespaces);
}
public XPathExecutable createAccepptExecutable(final ScenarioType s) {
final Map<String, String> namespaces = s.getNamespace().stream()
.collect(Collectors.toMap(NamespaceType::getPrefix, NamespaceType::getValue));
.collect(Collectors.toMap(NamespaceType::getPrefix, ns -> StringTrimAdapter.trim(ns.getValue())));
return createXPath(s.getAcceptMatch(), namespaces);
}

View file

@ -0,0 +1,29 @@
package de.kosit.validationtool.impl.xml;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class StringTrimAdapter extends XmlAdapter<String, String> {
@Override
public String unmarshal(final String v) {
if (v == null) {
return null;
}
return v.trim();
}
@Override
public String marshal(final String v) {
if (v == null) {
return null;
}
return v.trim();
}
public static String trim(final String v) {
if (v == null) {
return null;
}
return v.trim();
}
}