use of org.apache.sling.rewriter.PipelineConfiguration in project sling by apache.
the class PipelineImpl method init.
/**
* @see org.apache.sling.rewriter.Processor#init(org.apache.sling.rewriter.ProcessingContext, org.apache.sling.rewriter.ProcessorConfiguration)
*/
public void init(ProcessingContext processingContext, ProcessorConfiguration c) throws IOException {
LOGGER.debug("Setting up pipeline...");
final PipelineConfiguration config = (PipelineConfiguration) c;
final ProcessingComponentConfiguration[] transformerConfigs = config.getTransformerConfigurations();
// create components and initialize them
// lets get custom rewriter transformers
final Transformer[][] rewriters = this.factoryCache.getGlobalTransformers(processingContext);
final ProcessingComponentConfiguration generatorConfig = config.getGeneratorConfiguration();
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];
for (int i = 0; i < rewriters[0].length; i++) {
transformers[index] = rewriters[0][i];
LOGGER.debug("Using pre transformer: {}.", transformers[index]);
transformers[index].init(processingContext, ProcessingComponentConfigurationImpl.EMPTY);
index++;
}
if (transformerConfigs != null) {
for (int i = 0; i < transformerConfigs.length; i++) {
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++) {
transformers[index] = rewriters[1][i];
LOGGER.debug("Using post transformer: {}.", transformers[index]);
transformers[index].init(processingContext, ProcessingComponentConfigurationImpl.EMPTY);
index++;
}
} else {
transformers = EMPTY_TRANSFORMERS;
}
final ProcessingComponentConfiguration serializerConfig = config.getSerializerConfiguration();
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 = index; i > 0; i--) {
transformers[i - 1].setContentHandler(pipelineComponent);
pipelineComponent = transformers[i - 1];
}
this.firstContentHandler = pipelineComponent;
generator.setContentHandler(this.firstContentHandler);
LOGGER.debug("Finished pipeline setup.");
}
use of org.apache.sling.rewriter.PipelineConfiguration in project sling by apache.
the class ProcessorManagerImpl method getProcessor.
/**
* @see org.apache.sling.rewriter.ProcessorManager#getProcessor(org.apache.sling.rewriter.ProcessorConfiguration, org.apache.sling.rewriter.ProcessingContext)
*/
@Override
public Processor getProcessor(ProcessorConfiguration configuration, ProcessingContext context) {
if (configuration == null) {
throw new IllegalArgumentException("Processor configuration is missing.");
}
if (context == null) {
throw new IllegalArgumentException("Processor context is missing.");
}
boolean isPipeline = false;
if (configuration instanceof ProcessorConfigurationImpl) {
isPipeline = ((ProcessorConfigurationImpl) configuration).isPipeline();
} else {
isPipeline = configuration instanceof PipelineConfiguration;
}
try {
if (isPipeline) {
final PipelineImpl pipeline = new PipelineImpl(this.factoryCache);
pipeline.init(context, configuration);
return pipeline;
}
final Processor processor = new ProcessorWrapper(configuration, this.factoryCache);
processor.init(context, configuration);
return processor;
} catch (final IOException ioe) {
throw new SlingException("Unable to setup processor: " + ioe.getMessage(), ioe);
}
}
Aggregations