// We aim to have the following process(es) in the pipeline
// WDProcess -> CUP -> [[URLRewriteProcess] | [Pipeline]] -> next
// where URLRewriteProcess is chained to its own CUP setup in
// its setPipeline() method.
XMLProcess nextProcess = next;
// If the configuration has the the 'responseContainsPipelineMarkup'
// flag set, then we need to create a pipeline and insert it before
// the next process (which could be the URLRewriteProcess or next
if (configuration.getResponseContainsPipelineMarkup()) {
XMLPipeline pipeline = getPipelineContext().getPipelineFactory().
createDynamicPipeline(getPipelineContext());
XMLProcess pipelineProcess = pipeline.getPipelineProcess();
pipelineProcess.setNextProcess(nextProcess);
nextProcess = pipelineProcess;
}
if (redirectURL != null) {
if (redirectURL.indexOf("://") == -1) {
// We have been redirected to a relative url. In
// this case there is no need to rewrite relative urls
redirectURL = null;
} else {
// We need to set redirectURL to its prefex i.e.
// remove the resource part if there is one.
if (hasResource(redirectURL)) {
int index = redirectURL.lastIndexOf('/');
redirectURL = redirectURL.substring(0, index);
}
}
}
// We want the URLRewrite process to appear immediately after the
// CUP so that
XMLProcess urlRewriteProcess = createURLRewriterProcess(redirectURL);
if (urlRewriteProcess != null) {
// Only add the url rewriter process to the pipeline if
// the process returned is not null. This process is chained
// to the cup process so that its ouput will be returned
// to the cup.
urlRewriteProcess.setNextProcess(nextProcess);
urlRewriteProcess.setPipeline(getPipeline());
nextProcess = urlRewriteProcess;
}
// Always create the cup process. Note that this won't always be
// the case. See the comments in URLRewriteProcess.
XMLProcess cup = getPipelineContext().
getPipelineFactory().createContextUpdatingProcess();
cup.setPipeline(getPipeline());
// Chain the cup to the next process (which may be the URLRewrite
// process OR Pipeline OR next in that order).
cup.setNextProcess(nextProcess);
setNextProcess(cup);
source.setSystemId(getUrlString());
conditioner.condition(source, cup);
}