KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > jsp > tags > JetspeedForwardTag


1 package org.apache.jetspeed.services.jsp.tags;
2
3 /*
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 at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * 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 and
16  * limitations under the License.
17  */

18
19 // Servlet API
20
import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.PageContext JavaDoc;
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23
24 // Turbine Classes
25
import org.apache.turbine.util.DynamicURI;
26 import org.apache.turbine.services.jsp.JspService;
27
28 // ECS support
29
import org.apache.ecs.ConcreteElement;
30 import org.apache.ecs.StringElement;
31
32 // Jetspeed support
33
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
34 import org.apache.jetspeed.services.logging.JetspeedLogger;
35 import org.apache.jetspeed.services.rundata.JetspeedRunData;
36 import org.apache.jetspeed.services.forward.ForwardService;
37 import org.apache.jetspeed.util.ServiceUtil;
38
39 /**
40  * Supporting class for the forward tag. Enables forwarding navigation to other pages or panes
41  * 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.4b4
49  */

50 public class JetspeedForwardTag extends TagSupport JavaDoc
51 {
52     /**
53      * Static initialization of the logger for this class
54      */

55     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedForwardTag.class.getName());
56     
57     private String JavaDoc name = null;
58     private String JavaDoc target = null;
59
60     public void setName(String JavaDoc name)
61     {
62         this.name = name;
63     }
64
65     public String JavaDoc getName()
66     {
67         return this.name;
68     }
69
70     public void setTarget(String JavaDoc target)
71     {
72         this.target = target;
73     }
74
75     public String JavaDoc getTarget()
76     {
77         return this.target;
78     }
79
80     /**
81      * Method called when the tag is encountered to send attributes to the
82      * output stream
83      *
84      * @return SKIP_BODY, as it is intended to be a single tag.
85      */

86     public int doStartTag() throws JspException JavaDoc
87     {
88         JetspeedRunData data = (JetspeedRunData) pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
89         
90         try
91         {
92             ConcreteElement result = null;
93             DynamicURI uri = null;
94             ForwardService service = (ForwardService) ServiceUtil.getServiceByName(ForwardService.SERVICE_NAME);
95
96             if (this.name != null && this.target != null)
97             {
98                 uri = service.forward(data, this.name, this.target);
99             }
100             else if (this.getName() != null)
101             {
102                 uri = service.forward(data, this.name);
103             }
104             if (uri != null)
105             {
106                 result = new StringElement(uri.toString());
107             }
108
109             // Output the result
110
if (result != null)
111             {
112                 pageContext.getOut().print(result);
113             }
114
115         }
116         catch (Exception JavaDoc e)
117         {
118             String JavaDoc message = "Error processing name '" + name + "'.";
119             logger.error(message, e);
120             try
121             {
122                 data.getOut().print("Error processing forward name '" + name + "'. See log for more information.");
123             }
124             catch (java.io.IOException JavaDoc ioe)
125             {
126             }
127         }
128         return EVAL_BODY_INCLUDE;
129     }
130 }
131
Popular Tags