1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import java.util.Map ; 19 20 import org.apache.avalon.framework.parameters.Parameters; 21 import org.apache.cocoon.Constants; 22 import org.apache.cocoon.components.pipeline.ProcessingPipeline; 23 import org.apache.cocoon.components.treeprocessor.InvokeContext; 24 import org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode; 25 import org.apache.cocoon.components.treeprocessor.PipelineEventComponentProcessingNode; 26 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 27 import org.apache.cocoon.components.treeprocessor.variables.VariableResolver; 28 import org.apache.cocoon.environment.Environment; 29 import org.apache.cocoon.sitemap.PatternException; 30 36 public class SerializeNode extends PipelineEventComponentProcessingNode implements ParameterizableProcessingNode { 37 38 private String serializerName; 39 40 private VariableResolver source; 41 42 private VariableResolver mimeType; 43 44 private int statusCode; 45 46 private Map parameters; 47 48 49 56 public SerializeNode(String name, VariableResolver source, VariableResolver mimeType, int statusCode) throws PatternException { 57 this.serializerName = name; 58 this.source = source; 59 this.mimeType = mimeType; 60 this.statusCode = statusCode; 61 } 62 63 public void setParameters(Map parameterMap) { 64 this.parameters = parameterMap; 65 } 66 67 public final boolean invoke(Environment env, InvokeContext context) 68 throws Exception { 69 70 if (this.views != null) { 72 73 context.getProcessingPipeline().informBranchPoint(); 75 76 String cocoonView = env.getView(); 77 if (cocoonView != null) { 78 79 ProcessingNode viewNode = (ProcessingNode)this.views.get(cocoonView); 81 82 if (viewNode != null) { 83 if (getLogger().isInfoEnabled()) { 84 getLogger().info("Jumping to view " + cocoonView + " from serializer at " + this.getLocation()); 85 } 86 return viewNode.invoke(env, context); 87 } 88 } 89 } 90 91 Map objectModel = env.getObjectModel(); 92 ProcessingPipeline pipeline = context.getProcessingPipeline(); 93 94 if (objectModel.containsKey(Constants.LINK_OBJECT)) { 96 pipeline.addTransformer("<translator>", null, Parameters.EMPTY_PARAMETERS, Parameters.EMPTY_PARAMETERS); 97 } 98 99 if (objectModel.containsKey(Constants.LINK_COLLECTION_OBJECT) && env.isExternal()) { 100 pipeline.addTransformer("<gatherer>", null, Parameters.EMPTY_PARAMETERS, Parameters.EMPTY_PARAMETERS); 101 } 102 103 pipeline.setSerializer( 104 this.serializerName, 105 source.resolve(context, objectModel), 106 VariableResolver.buildParameters(this.parameters, context, objectModel), 107 this.pipelineHints == null 108 ? Parameters.EMPTY_PARAMETERS 109 : VariableResolver.buildParameters(this.pipelineHints, context, objectModel), 110 this.mimeType.resolve(context, env.getObjectModel()) 111 ); 112 113 if (this.statusCode >= 0) { 115 env.setStatus(this.statusCode); 116 } 117 118 if (! context.isBuildingPipelineOnly()) { 119 return pipeline.process(env); 121 122 } else { 123 return true; 125 } 126 } 127 } 128 | Popular Tags |