Merge branch 'issue/force-rewriter-pipeline'
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1777332 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java b/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
index 6cd46b9..980a161 100644
--- a/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
+++ b/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
@@ -65,6 +65,8 @@
static final String PROPERTY_PROCESS_ERROR = "processError";
+ static final String ATTR_PIPELINE = "org.apache.sling.rewriter.pipeline";
+
/** For which content types should this processor be applied. */
private final String[] contentTypes;
@@ -112,6 +114,8 @@
private final String descString;
+ private final String name;
+
/**
* This is the constructor for a pipeline
*/
@@ -126,6 +130,7 @@
ProcessingComponentConfiguration[] transformerConfigs,
ProcessingComponentConfiguration serializerConfig,
boolean processErrorResponse) {
+ this.name = null;
this.contentTypes = contentTypes;
this.resourceTypes = resourceTypes;
this.unwrapResources = unwrapResources;
@@ -160,6 +165,7 @@
* This constructor reads the configuration from the specified resource.
*/
public ProcessorConfigurationImpl(final Resource resource) {
+ this.name = resource.getName();
final ValueMap properties = ResourceUtil.getValueMap(resource);
this.contentTypes = properties.get(PROPERTY_CONTENT_TYPES, String[].class);
this.resourceTypes = properties.get(PROPERTY_RESOURCE_TYPES, String[].class);
@@ -198,6 +204,10 @@
}
void printConfiguration(final PrintWriter pw) {
+ if ( this.name != null ) {
+ pw.print("Name : ");
+ pw.println(this.name);
+ }
if ( this.contentTypes != null ) {
pw.print("Content Types : ");
pw.println(Arrays.toString(this.contentTypes));
@@ -370,6 +380,12 @@
if ( !this.processErrorResponse && processContext.getRequest().getAttribute("javax.servlet.error.status_code") != null ) {
return false;
}
+
+ final Object pipelineName = processContext.getRequest().getAttribute(ATTR_PIPELINE);
+ if (pipelineName != null && !pipelineName.equals(this.name)) {
+ return false;
+ }
+
String contentType = processContext.getContentType();
// if no content type is supplied, we assume html
if ( contentType == null ) {
diff --git a/src/test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java b/src/test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java
index 9e65e3c..7d6af9d 100644
--- a/src/test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java
+++ b/src/test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java
@@ -175,4 +175,18 @@
assertMatch(ImmutableMap.<String,Object>of(PROPERTY_SELECTORS, new String[] {"sel1"}));
}
+ @Test
+ public void testNoMatchRequestAttribute() {
+ context.request().setAttribute(ProcessorConfigurationImpl.ATTR_PIPELINE, "config2");
+ context.requestPathInfo().setResourcePath("/content/test");
+ assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_PATHS, new String[] {"/apps","/content"}));
+ }
+
+ @Test
+ public void testNoMatchRequestAttributeIfConditionsDoNotMatch() {
+ context.request().setAttribute(ProcessorConfigurationImpl.ATTR_PIPELINE, "config");
+ context.requestPathInfo().setResourcePath("/content/test");
+ assertNoMatch(ImmutableMap.<String,Object>of(PROPERTY_PATHS, new String[] {"/apps"}));
+ }
+
}