public Writer pipeline(String pipeTemplates[],Object rootMap,Writer writer) throws PipeException {
try {
Map globalContext = new HashMap();
for(int i = 0; i < pipeTemplates.length; i++) {
String templateName = pipeTemplates[i];
boolean isLastTemplate = i == pipeTemplates.length - 1;
try {
Template template = conf.getTemplate(templateName);
if(isLastTemplate) {
Environment env = template.createProcessingEnvironment(rootMap, writer);
env.getCurrentNamespace().putAll(globalContext);
env.process();
}else {
Writer tempOutput = new StringWriter(bufferSize);
Environment env = template.createProcessingEnvironment(rootMap, tempOutput);
env.getCurrentNamespace().putAll(globalContext);
env.process();
globalContext.putAll(env.getCurrentNamespace().toMap());
globalContext.put(Pipeline.PIPELINE_CONTENT_VAR_NAME, tempOutput.toString());
}
}catch(Exception e){
handleException(e,templateName,isLastTemplate);
}
}
return writer;
}catch(Exception e) {
throw new PipeException("process FreeMarker template occer exception,pipeTemplates:"+StringUtils.join(pipeTemplates," | "),e);
}
}