01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.treeprocessor.sitemap;
18:
19: import org.apache.cocoon.components.treeprocessor.AbstractProcessingNode;
20: import org.apache.cocoon.components.treeprocessor.InvokeContext;
21: import org.apache.cocoon.components.treeprocessor.variables.VariableResolver;
22: import org.apache.cocoon.environment.Environment;
23: import org.apache.cocoon.environment.Redirector;
24: import org.apache.cocoon.environment.PermanentRedirector;
25: import org.apache.cocoon.sitemap.PatternException;
26:
27: /**
28: *
29: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
30: * @version CVS $Id: RedirectToURINode.java 433543 2006-08-22 06:22:54Z crossley $
31: */
32:
33: public class RedirectToURINode extends AbstractProcessingNode {
34:
35: // TODO: It can implement ParameterizableProcessingNode to pass redirect parameters
36: // Those parameters will be URL-encoded and appended to the redirect URI
37:
38: /** The 'uri' attribute */
39: private VariableResolver uri;
40:
41: private boolean createSession;
42:
43: private boolean global;
44:
45: private boolean permanent;
46:
47: public RedirectToURINode(VariableResolver uri,
48: boolean createSession, boolean global, boolean permanent)
49: throws PatternException {
50: this .global = global;
51: this .uri = uri;
52: this .createSession = createSession;
53: this .permanent = permanent;
54: }
55:
56: public final boolean invoke(Environment env, InvokeContext context)
57: throws Exception {
58: String resolvedURI = uri.resolve(context, env.getObjectModel());
59:
60: if (getLogger().isInfoEnabled()) {
61: getLogger().info(
62: "Redirecting to '" + resolvedURI + "' at "
63: + this .getLocation());
64: }
65:
66: final Redirector redirector = context.getRedirector();
67:
68: if (this .global) {
69: redirector.globalRedirect(this .createSession, resolvedURI);
70: } else if (this .permanent
71: && redirector instanceof PermanentRedirector) {
72: ((PermanentRedirector) redirector).permanentRedirect(
73: this .createSession, resolvedURI);
74: } else {
75: redirector.redirect(this .createSession, resolvedURI);
76: }
77:
78: return true;
79: }
80: }
|