1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import org.apache.avalon.framework.parameters.Parameters; 19 20 import org.apache.cocoon.components.pipeline.ProcessingPipeline; 21 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode; 22 import org.apache.cocoon.components.treeprocessor.InvokeContext; 23 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 24 import org.apache.cocoon.components.treeprocessor.variables.VariableResolver; 25 import org.apache.cocoon.environment.Environment; 26 import org.apache.cocoon.sitemap.ContentAggregator; 27 28 import java.util.Map ; 29 30 50 public class AggregateNode extends AbstractProcessingNode { 51 52 private VariableResolver element; 53 private VariableResolver nsURI; 54 private VariableResolver nsPrefix; 55 56 57 private Part[] allParts; 58 59 60 private Map viewParts; 61 62 63 private Map viewNodes; 64 65 public AggregateNode(VariableResolver element, VariableResolver nsURI, VariableResolver nsPrefix) { 66 this.element = element; 67 this.nsURI = nsURI; 68 this.nsPrefix = nsPrefix; 69 } 70 71 public void setParts(Part[] allParts, Map viewParts) { 72 this.allParts = allParts; 73 this.viewParts = viewParts; 74 } 75 76 public void setViewNodes(Map viewNodes) { 77 this.viewNodes = viewNodes; 78 } 79 80 public boolean invoke(Environment env, InvokeContext context) 81 throws Exception { 82 final boolean infoEnabled = getLogger().isInfoEnabled(); 83 84 Map objectModel = env.getObjectModel(); 85 86 ProcessingPipeline processingPipeline = context.getProcessingPipeline(); 88 processingPipeline.setGenerator("<aggregator>", null, Parameters.EMPTY_PARAMETERS, Parameters.EMPTY_PARAMETERS); 89 90 ContentAggregator aggregator = (ContentAggregator) processingPipeline.getGenerator(); 91 aggregator.setRootElement(this.element.resolve(context, objectModel), 92 this.nsURI.resolve(context, objectModel), 93 this.nsPrefix.resolve(context, objectModel)); 94 95 Part[] actualParts; 97 98 String cocoonView = env.getView(); 99 if (cocoonView == null) { 100 actualParts = this.allParts; 102 103 } else { 104 actualParts = (Part[])this.viewParts.get(cocoonView); 106 107 if (actualParts == null) { 109 actualParts = this.allParts; 110 } 111 } 112 113 for (int i = 0; i < actualParts.length; i++) { 115 Part part = actualParts[i]; 116 if (part != null) { 117 aggregator.addPart( 118 part.source.resolve(context, objectModel), 119 part.element.resolve(context, objectModel), 120 part.nsURI.resolve(context, objectModel), 121 part.stripRoot.resolve(context, objectModel), 122 part.nsPrefix.resolve(context, objectModel) 123 ); 124 } 125 } 126 127 if (actualParts != this.allParts) { 129 ProcessingNode viewNode = (ProcessingNode)this.viewNodes.get(cocoonView); 130 if (viewNode != null) { 131 if (infoEnabled) { 132 getLogger().info("Jumping to view '" + cocoonView + "' from aggregate part at " + this.getLocation()); 133 } 134 return viewNode.invoke(env, context); 135 } 136 } 137 138 if (cocoonView != null && this.viewNodes != null) { 140 ProcessingNode viewNode = (ProcessingNode)this.viewNodes.get(cocoonView); 141 if (viewNode != null) { 142 if (infoEnabled) { 143 getLogger().info("Jumping to view '" + cocoonView + "' from aggregate at " + this.getLocation()); 144 } 145 return viewNode.invoke(env, context); 146 } 147 } 148 149 return false; 151 } 152 153 public static class Part { 154 protected VariableResolver source; 155 protected VariableResolver element; 156 protected VariableResolver nsURI; 157 protected VariableResolver nsPrefix; 158 protected VariableResolver stripRoot; 159 160 public Part(VariableResolver source, 161 VariableResolver element, 162 VariableResolver nsURI, 163 VariableResolver nsPrefix, 164 VariableResolver stripRoot) { 165 this.source = source; 166 this.element = element; 167 this.nsURI = nsURI; 168 this.nsPrefix = nsPrefix; 169 this.stripRoot = stripRoot; 170 } 171 } 172 } 173 | Popular Tags |