1packageorg.apache.jetspeed.services.jsp.tags;
23/*4 * Copyright 2000-2001,2004 The Apache Software Foundation.5 * 6 * Licensed under the Apache License, Version 2.0 (the "License");7 * you may not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 * 10 * http://www.apache.org/licenses/LICENSE-2.011 * 12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819// Servlet API20import javax.servlet.jsp.JspException;
21import javax.servlet.jsp.PageContext;
22import javax.servlet.jsp.tagext.TagSupport;
2324// Turbine Classes25import org.apache.turbine.util.DynamicURI;
26import org.apache.turbine.services.jsp.JspService;
2728// ECS support29import org.apache.ecs.ConcreteElement;
30import org.apache.ecs.StringElement;
3132// Jetspeed support33import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
34import org.apache.jetspeed.services.logging.JetspeedLogger;
35import org.apache.jetspeed.services.rundata.JetspeedRunData;
36import org.apache.jetspeed.services.forward.ForwardService;
37import org.apache.jetspeed.util.ServiceUtil;
3839/***40 * Supporting class for the forward tag. Enables forwarding navigation to other pages or panes41 * in the portal. If "name" and "target" are both specified, the "name" is assumed to be a portlet.42 * If only "name" is specified, the name is assumed to be a logical forward name.43 * 44 * @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>45 * @version $Id: JetspeedForwardTag.java,v 1.3 2004/02/23 03:59:40 jford Exp $46 * @see org.apache.jetspeed.services.forward.ForwardService#forward(RunData rundata, String forwardName)47 * @see org.apache.jetspeed.services.forward.ForwardService#forward(RunData rundata, String portlet, String target)48 * @since 1.4b449 */50publicclassJetspeedForwardTagextends TagSupport
51 {
52/***53 * Static initialization of the logger for this class54 */55privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedForwardTag.class.getName());
5657private String name = null;
58private String target = null;
5960publicvoid setName(String name)
61 {
62this.name = name;
63 }
6465public String getName()
66 {
67returnthis.name;
68 }
6970publicvoid setTarget(String target)
71 {
72this.target = target;
73 }
7475public String getTarget()
76 {
77returnthis.target;
78 }
7980/***81 * Method called when the tag is encountered to send attributes to the82 * output stream83 *84 * @return SKIP_BODY, as it is intended to be a single tag.85 */86publicint doStartTag() throws JspException
87 {
88JetspeedRunData data = (JetspeedRunData) pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
8990try91 {
92 ConcreteElement result = null;
93 DynamicURI uri = null;
94ForwardService service = (ForwardService) ServiceUtil.getServiceByName(ForwardService.SERVICE_NAME);
9596if (this.name != null && this.target != null)
97 {
98 uri = service.forward(data, this.name, this.target);
99 }
100elseif (this.getName() != null)
101 {
102 uri = service.forward(data, this.name);
103 }
104if (uri != null)
105 {
106 result = new StringElement(uri.toString());
107 }
108109// Output the result110if (result != null)
111 {
112 pageContext.getOut().print(result);
113 }
114115 }
116catch (Exception e)
117 {
118 String message = "Error processing name '" + name + "'.";
119 logger.error(message, e);
120try121 {
122 data.getOut().print("Error processing forward name '" + name + "'. See log for more information.");
123 }
124catch (java.io.IOException ioe)
125 {
126 }
127 }
128return EVAL_BODY_INCLUDE;
129 }
130 }