|
This is because when you end a pipeline with the map:redirect, nothing
else gets executed. The redirect happens when the pipeline is setup.
We've had need for similar pipelines where processing is done, then a
redirect is performed. We wrote a redirect transformer that we'd be
glad to contribute. It takes a url in XML or as a sitemap parameter.
Instead of doing a redirect during setup, it does it when endDocument
is called. David PS. coding credits to Daniel McOrmond of D.O.Tech Dean Cording wrote:
|
package com.dotech.cocoon.transformation; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.parameters.ParameterException; import org.apache.cocoon.environment.http.HttpResponse; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.transformation.AbstractSAXTransformer; import org.apache.cocoon.ProcessingException; import org.xml.sax.SAXException; import org.xml.sax.Attributes; import org.xml.sax.helpers.AttributesImpl;
import java.io.IOException; import java.util.Map; /** * The Redirect Transformer * * redirects the user to another url. You can specify the new url within an xml file * and it can also be specified as a transformer parameter in the sitemap. <i>A redirect url * specified in the xml takes higher precendence than a redirect url specified in the sitemap</i>. * * <br/><br/> * XML Example: * <pre> * <redirect xmlns="http://dotech.com/redirect/1.0">http://www.dotech.com</redirect> * </pre> * * <b>The url can be either fully qualified or relative</b>. * <br/><br/> * Sitemap Example: * <pre> * <map:transformer type="redirect"> * <map:parameter name="redirectURL" value="http://www.dotech.com"/> * </map:transformer> * </pre> * * If an url is not specified in either place, this transformer acts as if it didn't exist. The * sitemap execution passes on to the next component. * * @author <a href="mailto:[EMAIL PROTECTED]">Daniel McOrmond</a> * @version $Revision: 1.2 $ $Date: 2003/07/22 02:41:34 $ */ public class RedirectTransformer extends AbstractSAXTransformer { public static final String NAMESPACE = "http://dotech.com/redirect/1.0"; private String redirectLocation; public RedirectTransformer() { this.namespaceURI = NAMESPACE; } public void setupTransforming() throws IOException, ProcessingException, SAXException { super.setupTransforming(); redirectLocation = parameters.getParameter("redirectURL", ""); getLogger().debug("redirect URL set from param : "+redirectLocation); } public void endDocument() throws SAXException { if (redirectLocation != null && !redirectLocation.trim().equals("")) { HttpResponse hr = (HttpResponse)response; try { getLogger().debug("about to set redirect on response object : "+redirectLocation); hr.sendRedirect( redirectLocation ); } catch( Exception e ) { getLogger().error( "some error", e ); } response = hr; } } public void startTransformingElement(String uri, String name, String raw, Attributes attr) throws ProcessingException, IOException, SAXException { if( name.toLowerCase().equals("redirect") ) { startTextRecording(); } } public void endTransformingElement(String uri, String name, String raw) throws ProcessingException, IOException, SAXException { if( name.toLowerCase().equals("redirect") ) { redirectLocation = endTextRecording(); getLogger().debug("redirect URL set from xml : "+redirectLocation); } } } //RedirectTransformer
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
