View Javadoc

1   /*
2    * Copyright 2000-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.portals.bridges.frameworks;
17  
18  import java.io.IOException;
19  
20  import javax.portlet.RenderRequest;
21  import javax.portlet.RenderResponse;
22  import javax.servlet.jsp.JspWriter;
23  import javax.servlet.jsp.tagext.TagSupport;
24  
25  import org.apache.portals.bridges.frameworks.model.PortletApplicationModel;
26  
27  
28  /***
29   * ForwardTag
30   * 
31   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
32   * @version $Id: ForwardTag.java 187900 2004-11-05 23:34:23 +0100 (Fri, 05 Nov 2004) taylor $
33   */
34  public class ForwardTag extends TagSupport
35  {
36      private String view = null;
37      private String action = null;
38      private String forward = null;
39      
40      public int doStartTag()
41      {
42          String content;
43          try
44          {
45              RenderRequest request = (RenderRequest)
46                  pageContext.getRequest().getAttribute("javax.portlet.request");
47              RenderResponse response = (RenderResponse) 
48                  pageContext.getRequest().getAttribute("javax.portlet.response");
49              
50              if (request == null || response == null)
51              {
52                  JspWriter out = pageContext.getOut();
53                  out.print("request response not found");
54                  return SKIP_BODY;
55              }
56              PortletApplicationModel model = (PortletApplicationModel)request.getAttribute(FrameworkConstants.MODEL_TOOL);
57              if (model == null)
58              {
59                  JspWriter out = pageContext.getOut();
60                  out.print("model not found");
61                  return SKIP_BODY;
62              }
63                                                  
64              Forwarder forwarder = new Forwarder(model, request, response);
65              if (view != null)
66              {
67                  content = forwarder.getView(view).toString();
68              }
69              else if (forward != null)
70              {
71                  if (action != null)
72                  {
73                      content = forwarder.getLink(forward, action).toString();
74                  }
75                  else
76                  {
77                      content = forwarder.getLink(forward).toString();                    
78                  }
79              }
80              else
81              {
82                  content = forwarder.toString();
83              }
84              JspWriter out = pageContext.getOut();
85              out.print(content);            
86          }
87          catch (IOException e)
88          {
89              System.err.println("Error printing tag: " + e);
90          }
91          return SKIP_BODY;
92      }
93      
94      
95      /***
96       * @return Returns the action.
97       */
98      public String getAction()
99      {
100         return action;
101     }
102     /***
103      * @param action The action to set.
104      */
105     public void setAction(String action)
106     {
107         this.action = action;
108     }
109     /***
110      * @return Returns the view.
111      */
112     public String getView()
113     {
114         return view;
115     }
116     /***
117      * @param view The view to set.
118      */
119     public void setView(String view)
120     {
121         this.view = view;
122     }
123     /***
124      * @return Returns the forward.
125      */
126     public String getForward()
127     {
128         return forward;
129     }
130     /***
131      * @param forward The forward to set.
132      */
133     public void setForward(String forward)
134     {
135         this.forward = forward;
136     }
137 }