incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1004546 - in /sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter: ProcessingComponentConfiguration.java impl/PipelineImpl.java impl/RewriterResponse.java
Date Tue, 05 Oct 2010 07:20:53 GMT
Author: cziegeler
Date: Tue Oct  5 07:20:52 2010
New Revision: 1004546

URL: http://svn.apache.org/viewvc?rev=1004546&view=rev
Log:
Support optional pipeline components

Modified:
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessingComponentConfiguration.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java
    sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessingComponentConfiguration.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessingComponentConfiguration.java?rev=1004546&r1=1004545&r2=1004546&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessingComponentConfiguration.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/ProcessingComponentConfiguration.java
Tue Oct  5 07:20:52 2010
@@ -24,6 +24,9 @@ import org.apache.sling.api.resource.Val
  */
 public interface ProcessingComponentConfiguration {
 
+    /** Configuration for an optional component, only transformers support this option. */
+    String CONFIGURATION_COMPONENT_OPTIONAL = "component-optional";
+
     /**
      * The name/type of the component.
      * @return A unique name for this component.

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java?rev=1004546&r1=1004545&r2=1004546&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/PipelineImpl.java
Tue Oct  5 07:20:52 2010
@@ -82,15 +82,15 @@ public class PipelineImpl implements Pro
         final Transformer[][] rewriters = this.factoryCache.getGlobalTransformers(processingContext);
 
         final ProcessingComponentConfiguration generatorConfig = config.getGeneratorConfiguration();
-        this.generator = this.getPipelineComponent(Generator.class, generatorConfig.getType());
+        this.generator = this.getPipelineComponent(Generator.class, generatorConfig.getType(),
false);
         LOGGER.debug("Using generator type {}: {}.", generatorConfig.getType(), generator);
         generator.init(processingContext, generatorConfig);
 
         final int transformerCount = (transformerConfigs == null ? 0 : transformerConfigs.length)
+ rewriters[0].length + rewriters[1].length;
+        int index = 0;
         if ( transformerCount > 0 ) {
             // add all pre rewriter transformers
             transformers = new Transformer[transformerCount];
-            int index = 0;
             for(int i=0; i< rewriters[0].length; i++) {
                 transformers[index] = rewriters[0][i];
                 LOGGER.debug("Using pre transformer: {}.", transformers[index]);
@@ -99,10 +99,15 @@ public class PipelineImpl implements Pro
             }
             if ( transformerConfigs != null ) {
                 for(int i=0; i< transformerConfigs.length;i++) {
-                    transformers[index] = this.getPipelineComponent(Transformer.class, transformerConfigs[i].getType());
-                    LOGGER.debug("Using transformer type {}: {}.", transformerConfigs[i].getType(),
transformers[index]);
-                    transformers[index].init(processingContext, transformerConfigs[i]);
-                    index++;
+                    transformers[index] = this.getPipelineComponent(Transformer.class, transformerConfigs[i].getType(),
+                            transformerConfigs[i].getConfiguration().get(ProcessingComponentConfiguration.CONFIGURATION_COMPONENT_OPTIONAL,
false));
+                    if ( transformers[index] != null ) {
+                        LOGGER.debug("Using transformer type {}: {}.", transformerConfigs[i].getType(),
transformers[index]);
+                        transformers[index].init(processingContext, transformerConfigs[i]);
+                        index++;
+                    } else {
+                        LOGGER.debug("Skipping missing optional transformer of type {}",
transformerConfigs[i].getType());
+                    }
                 }
             }
             for(int i=0; i< rewriters[1].length; i++) {
@@ -116,13 +121,13 @@ public class PipelineImpl implements Pro
         }
 
         final ProcessingComponentConfiguration serializerConfig = config.getSerializerConfiguration();
-        this.serializer = this.getPipelineComponent(Serializer.class, serializerConfig.getType());
+        this.serializer = this.getPipelineComponent(Serializer.class, serializerConfig.getType(),
false);
         LOGGER.debug("Using serializer type {}: {}.", serializerConfig.getType(), serializer);
         serializer.init(processingContext, serializerConfig);
 
         ContentHandler pipelineComponent = serializer;
         // now chain pipeline
-        for(int i=transformers.length; i>0; i--) {
+        for(int i=index; i>0; i--) {
             transformers[i-1].setContentHandler(pipelineComponent);
             pipelineComponent = transformers[i-1];
         }
@@ -136,8 +141,9 @@ public class PipelineImpl implements Pro
      * Lookup a pipeline component.
      */
     @SuppressWarnings("unchecked")
-    private <ComponentType> ComponentType getPipelineComponent(Class<ComponentType>
typeClass,
-                                                               String type)
+    private <ComponentType> ComponentType getPipelineComponent(final Class<ComponentType>
typeClass,
+                                                               final String type,
+                                                               final boolean optional)
     throws IOException {
         final ComponentType component;
         if ( typeClass == Generator.class ) {
@@ -150,7 +156,7 @@ public class PipelineImpl implements Pro
             component = null;
         }
 
-        if ( component == null ) {
+        if ( component == null && !optional ) {
             throw new IOException("Unable to get component of class '" + typeClass + "' with
type '" + type + "'.");
         }
 
@@ -195,7 +201,9 @@ public class PipelineImpl implements Pro
         }
         if ( this.transformers != null ) {
             for(final Transformer transformer : this.transformers ) {
-                transformer.dispose();
+                if ( transformer != null ) {
+                    transformer.dispose();
+                }
             }
         }
         if ( this.serializer != null ) {

Modified: sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java?rev=1004546&r1=1004545&r2=1004546&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java
(original)
+++ sling/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java
Tue Oct  5 07:20:52 2010
@@ -159,13 +159,16 @@ class RewriterResponse
      * Search the first matching processor
      */
     private Processor getProcessor() throws IOException {
+        this.request.getRequestProgressTracker().log("Searching processor");
         final ProcessingContext processorContext = new ServletProcessingContext(this.request,
this, this.getSlingResponse(), this.contentType);
         Processor found = null;
         final List<ProcessorConfiguration> processorConfigs = this.processorManager.getProcessorConfigurations();
         final Iterator<ProcessorConfiguration> i = processorConfigs.iterator();
         while ( found == null && i.hasNext() ) {
             final ProcessorConfiguration config = i.next();
+            this.request.getRequestProgressTracker().log("Checking processor {0}", config);
             if ( config.match(processorContext) ) {
+                this.request.getRequestProgressTracker().log("Settimg up processor {0}",
config);
                 found = this.processorManager.getProcessor(config, processorContext);
                 this.request.getRequestProgressTracker().log("Found processor for post processing
{0}", config);
             }



Mime
View raw message