sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1777332 - in /sling/trunk/contrib/extensions/rewriter/src: main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java
Date Wed, 04 Jan 2017 16:14:53 GMT
Author: justin
Date: Wed Jan  4 16:14:53 2017
New Revision: 1777332

URL: http://svn.apache.org/viewvc?rev=1777332&view=rev
Log:
Merge branch 'issue/force-rewriter-pipeline'

Modified:
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
    sling/trunk/contrib/extensions/rewriter/src/test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java?rev=1777332&r1=1777331&r2=1777332&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImpl.java
Wed Jan  4 16:14:53 2017
@@ -65,6 +65,8 @@ public class ProcessorConfigurationImpl
 
     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 @@ public class ProcessorConfigurationImpl
 
     private final String descString;
 
+    private final String name;
+
     /**
      * This is the constructor for a pipeline
      */
@@ -126,6 +130,7 @@ public class ProcessorConfigurationImpl
                                       ProcessingComponentConfiguration[] transformerConfigs,
                                       ProcessingComponentConfiguration serializerConfig,
                                       boolean processErrorResponse) {
+        this.name = null;
         this.contentTypes = contentTypes;
         this.resourceTypes = resourceTypes;
         this.unwrapResources = unwrapResources;
@@ -160,6 +165,7 @@ public class ProcessorConfigurationImpl
      * 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 @@ public class ProcessorConfigurationImpl
     }
 
     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 @@ public class ProcessorConfigurationImpl
         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 ) {

Modified: sling/trunk/contrib/extensions/rewriter/src/test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java?rev=1777332&r1=1777331&r2=1777332&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/test/java/org/apache/sling/rewriter/impl/ProcessorConfigurationImplTest.java
Wed Jan  4 16:14:53 2017
@@ -175,4 +175,18 @@ public class ProcessorConfigurationImplT
         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"}));
+    }
+
 }



Mime
View raw message