KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > treeprocessor > sitemap > RedirectToURINode


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.components.treeprocessor.sitemap;
17
18 import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
19 import org.apache.cocoon.components.treeprocessor.InvokeContext;
20 import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
21 import org.apache.cocoon.environment.Environment;
22 import org.apache.cocoon.environment.Redirector;
23 import org.apache.cocoon.environment.PermanentRedirector;
24 import org.apache.cocoon.sitemap.PatternException;
25
26 /**
27  *
28  * @author <a HREF="mailto:sylvain@apache.org">Sylvain Wallez</a>
29  * @version CVS $Id: RedirectToURINode.java 37174 2004-08-29 16:29:31Z cziegeler $
30  */

31
32 public class RedirectToURINode extends AbstractProcessingNode {
33
34     // TODO: It can implement ParameterizableProcessingNode to pass redirect parameters
35
// Those parameters will be URL-encoded and appended to the redirect URI
36

37     /** The 'uri' attribute */
38     private VariableResolver uri;
39
40     private boolean createSession;
41
42     private boolean global;
43
44     private boolean permanent;
45
46     public RedirectToURINode(VariableResolver uri, boolean createSession, boolean global, boolean permanent )
47     throws PatternException {
48         this.global = global;
49         this.uri = uri;
50         this.createSession = createSession;
51         this.permanent = permanent;
52     }
53
54     public final boolean invoke(Environment env, InvokeContext context)
55       throws Exception JavaDoc {
56         String JavaDoc resolvedURI = uri.resolve(context, env.getObjectModel());
57
58         if (getLogger().isInfoEnabled()) {
59             getLogger().info("Redirecting to '" + resolvedURI + "' at " + this.getLocation());
60         }
61
62         final Redirector redirector = context.getRedirector();
63
64         if( this.global ) {
65             redirector.globalRedirect(this.createSession, resolvedURI);
66         } else if (this.permanent && redirector instanceof PermanentRedirector) {
67             ((PermanentRedirector)redirector).permanentRedirect(this.createSession, resolvedURI);
68         } else {
69             redirector.redirect(this.createSession, resolvedURI);
70         }
71
72         return true;
73     }
74 }
75
Popular Tags