diff --git a/pom.xml b/pom.xml
index b4b9329..b5697be 100644
--- a/pom.xml
+++ b/pom.xml
@@ -190,7 +190,7 @@
org.smooks.cartridges
smooks-rules-cartridge
- 2.0.0
+ 2.0.1-SNAPSHOT
org.smooks.cartridges
diff --git a/src/main/java/org/smooks/cartridges/validation/ValidationSink.java b/src/main/java/org/smooks/cartridges/validation/ValidationSink.java
index 63a3026..1880f81 100644
--- a/src/main/java/org/smooks/cartridges/validation/ValidationSink.java
+++ b/src/main/java/org/smooks/cartridges/validation/ValidationSink.java
@@ -42,8 +42,8 @@
*/
package org.smooks.cartridges.validation;
+import org.smooks.api.io.Sink;
import org.smooks.assertion.AssertArgument;
-import org.smooks.io.sink.FilterSink;
import java.util.ArrayList;
import java.util.Collection;
@@ -58,7 +58,7 @@
*
* @author Daniel Bevenius
*/
-public class ValidationSink extends FilterSink {
+public class ValidationSink implements Sink {
/**
* The validation result Map, keyed by OnFail Type.
*/
diff --git a/src/main/java/org/smooks/cartridges/validation/Validator.java b/src/main/java/org/smooks/cartridges/validation/Validator.java
index d3ab6f3..47897d0 100644
--- a/src/main/java/org/smooks/cartridges/validation/Validator.java
+++ b/src/main/java/org/smooks/cartridges/validation/Validator.java
@@ -49,6 +49,7 @@
import org.smooks.api.ExecutionContext;
import org.smooks.api.SmooksConfigException;
import org.smooks.api.SmooksException;
+import org.smooks.api.io.Sink;
import org.smooks.api.resource.config.ResourceConfig;
import org.smooks.api.resource.visitor.VisitAfterReport;
import org.smooks.api.resource.visitor.VisitBeforeReport;
@@ -62,7 +63,6 @@
import org.smooks.engine.memento.TextAccumulatorVisitorMemento;
import org.smooks.engine.resource.config.xpath.IndexedSelectorPath;
import org.smooks.engine.resource.config.xpath.step.AttributeSelectorStep;
-import org.smooks.io.sink.FilterSink;
import org.smooks.resource.URIResourceLocator;
import org.smooks.support.DomUtils;
import org.smooks.support.FreeMarkerTemplate;
@@ -75,6 +75,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
@@ -280,14 +281,11 @@ private OnFailResultImpl _validate(final String text, final ExecutionContext exe
}
private ValidationSink getValidationResult(ExecutionContext executionContext) {
- ValidationSink validationResult = (ValidationSink) FilterSink.getSink(executionContext, ValidationSink.class);
- // Create a new ValidationResult if one was not available in the execution context.
- // This would be the case for example if one as not specified to Smooks filter method.
- if (validationResult == null) {
- validationResult = new ValidationSink();
- }
+ Optional validationSink = executionContext.getOrDefault(Sink.SINKS_TYPED_KEY, Collections.emptyList()).stream().filter(s -> ValidationSink.class.isAssignableFrom(s.getClass())).findFirst();
- return validationResult;
+ // Create a new ValidationSink if one was not available in the execution context.
+ // This would be the case for example if one as not specified to Smooks filter method.
+ return validationSink.map(sink -> (ValidationSink) sink).orElseGet(ValidationSink::new);
}
private synchronized void setRuleProvider(ExecutionContext executionContext) {
diff --git a/src/test/java/org/smooks/cartridges/validation/ValidatorTestCase.java b/src/test/java/org/smooks/cartridges/validation/ValidatorTestCase.java
index edf7055..a2f3158 100644
--- a/src/test/java/org/smooks/cartridges/validation/ValidatorTestCase.java
+++ b/src/test/java/org/smooks/cartridges/validation/ValidatorTestCase.java
@@ -46,16 +46,17 @@
import org.junit.jupiter.api.Test;
import org.smooks.Smooks;
import org.smooks.api.ApplicationContext;
+import org.smooks.api.io.Sink;
import org.smooks.cartridges.rules.RuleProviderAccessor;
import org.smooks.cartridges.rules.regex.RegexProvider;
import org.smooks.engine.DefaultApplicationContextBuilder;
-import org.smooks.io.sink.FilterSink;
import org.smooks.io.source.StringSource;
import org.smooks.testkit.MockApplicationContext;
import org.smooks.testkit.MockExecutionContext;
import org.xml.sax.SAXException;
import java.io.IOException;
+import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
@@ -96,7 +97,7 @@ public void testValidateWarn() {
final ValidationSink sink = new ValidationSink();
MockExecutionContext executionContext = new MockExecutionContext();
- FilterSink.setSinks(executionContext, sink);
+ executionContext.put(Sink.SINKS_TYPED_KEY, Collections.singletonList(sink));
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
@@ -116,7 +117,7 @@ public void testValidateOks() {
final ValidationSink sink = new ValidationSink();
MockExecutionContext executionContext = new MockExecutionContext();
- FilterSink.setSinks(executionContext, sink);
+ executionContext.put(Sink.SINKS_TYPED_KEY, Collections.singletonList(sink));
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
@@ -136,7 +137,7 @@ public void testValidateErrors() {
final ValidationSink sink = new ValidationSink();
MockExecutionContext executionContext = new MockExecutionContext();
- FilterSink.setSinks(executionContext, sink);
+ executionContext.put(Sink.SINKS_TYPED_KEY, Collections.singletonList(sink));
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
validator.validate("xyz", executionContext);
@@ -208,7 +209,7 @@ public Class> loadClass(String name) throws ClassNotFoundException {
ValidationSink sink = new ValidationSink();
MockExecutionContext executionContext = new MockExecutionContext();
- FilterSink.setSinks(executionContext, sink);
+ executionContext.put(Sink.SINKS_TYPED_KEY, Collections.singletonList(sink));
try {
validator.validate("xyz", executionContext);
switch (onFail) {