1 16 package org.apache.cocoon.components.treeprocessor.sitemap; 17 18 import org.apache.avalon.framework.configuration.Configuration; 19 import org.apache.avalon.framework.configuration.ConfigurationException; 20 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNodeBuilder; 21 import org.apache.cocoon.components.treeprocessor.CategoryNode; 22 import org.apache.cocoon.components.treeprocessor.CategoryNodeBuilder; 23 import org.apache.cocoon.components.treeprocessor.LinkedProcessingNodeBuilder; 24 import org.apache.cocoon.components.treeprocessor.ProcessingNode; 25 import org.apache.cocoon.components.treeprocessor.variables.VariableResolverFactory; 26 27 import java.util.HashMap ; 28 import java.util.Map ; 29 30 35 36 public class RedirectToNodeBuilder extends AbstractProcessingNodeBuilder 37 implements LinkedProcessingNodeBuilder { 38 39 private CallNode callNode; 40 private String resourceName; 41 42 43 protected boolean hasParameters() { 44 return false; 45 } 46 47 public ProcessingNode buildNode(Configuration config) throws Exception { 48 49 if (((SitemapLanguage)this.treeBuilder).isBuildingErrorHandler()) { 50 throw new ConfigurationException("'map:redirect' is forbidden inside a 'map:handle-errors', at " 51 + config.getLocation()); 52 } 53 54 this.resourceName = config.getAttribute("resource", null); 56 if (this.resourceName != null) { 57 58 getLogger().warn("Redirect to resource is deprecated. Use map:call instead at " + 59 config.getLocation()); 60 61 this.callNode = new CallNode(); 62 this.treeBuilder.setupNode(this.callNode, config); 63 64 String target = config.getAttribute("target", null); 65 if (target != null) { 66 Map params = new HashMap (1); 67 params.put("target", VariableResolverFactory.getResolver(target, this.manager)); 68 this.callNode.setParameters(params); 69 } 70 return this.callNode; 71 72 } else { 73 ProcessingNode URINode = new RedirectToURINode( 74 VariableResolverFactory.getResolver(config.getAttribute("uri"), this.manager), 75 config.getAttributeAsBoolean("session", false), 76 config.getAttributeAsBoolean("global", false), 77 config.getAttributeAsBoolean("permanent", false) 78 ); 79 return this.treeBuilder.setupNode(URINode, config); 80 81 } 82 } 83 84 public void linkNode() throws Exception { 85 86 if (this.callNode != null) { 87 CategoryNode resources = CategoryNodeBuilder.getCategoryNode(this.treeBuilder, "resources"); 88 89 if (resources == null) { 90 String msg = "This sitemap contains no resources. Cannot redirect at " + 91 this.callNode.getLocation(); 92 throw new ConfigurationException(msg); 93 } 94 95 this.callNode.setResource( 96 resources, 97 this.resourceName 98 ); 99 } 100 } 101 } 102 | Popular Tags |