KickJava   Java API By Example, From Geeks To Geeks.

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


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.om.profile.ProfileLocator;
37 import org.apache.jetspeed.om.profile.Profile;
38 import org.apache.jetspeed.services.Profiler;
39 import org.apache.jetspeed.util.template.JetspeedLink;
40 import org.apache.jetspeed.util.template.JetspeedLinkFactory;
41
42 /**
43  * Supporting class for the portlet link tag.
44  * Builds a link to displaying a portlet in specified view and insert it within the
45  * current JSP page. If js_peid is specified it is used as is. Otherwise, the js_peid
46  * is derived from the first portlet in profile matching specified portlet name.
47  *
48  * @author <a HREF="mailto:morciuch@apache.org">Mark Orciuch</a>
49  * @version $Id: JetspeedPortletLinkTag.java,v 1.4 2004/02/23 03:59:40 jford Exp $
50  */

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

56     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedPortletLinkTag.class.getName());
57     
58     private String JavaDoc name = null;
59     private String JavaDoc jspeid = null;
60     private String JavaDoc psml = null;
61     private String JavaDoc action = null;
62
63     public void setName(String JavaDoc name)
64     {
65         this.name = name;
66     }
67
68     public String JavaDoc getName()
69     {
70         return this.name;
71     }
72
73     public void setPsml(String JavaDoc psml)
74     {
75         this.psml = psml;
76     }
77
78     public String JavaDoc getPsml()
79     {
80         return this.psml;
81     }
82
83     public void setJspeid(String JavaDoc value)
84     {
85         this.jspeid = value;
86     }
87
88     public String JavaDoc getJspeid()
89     {
90         return this.jspeid;
91     }
92
93     public void setAction(String JavaDoc value)
94     {
95         this.action = value;
96     }
97
98     public String JavaDoc getAction()
99     {
100         return this.action;
101     }
102
103     /**
104      * Method called when the tag is encountered to send attributes to the
105      * output stream
106      *
107      * @return SKIP_BODY, as it is intended to be a single tag.
108      */

109     public int doStartTag() throws JspException JavaDoc
110     {
111         JetspeedRunData data = (JetspeedRunData) pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
112         
113         try
114         {
115             ConcreteElement result = null;
116             Profile baseProfile = null;
117             ProfileLocator baseLocator = Profiler.createLocator();
118             int rootType = JetspeedLink.DEFAULT;
119             String JavaDoc rootValue = null;
120             int elementType = JetspeedLink.DEFAULT;
121             String JavaDoc elementValue = null;
122
123             // Create locator to retrieve profile settings
124
if (this.psml != null)
125             {
126                baseLocator.createFromPath(this.psml);
127                if (baseLocator.getUser() != null)
128                {
129                    rootType = JetspeedLink.USER;
130                    rootValue = baseLocator.getUserName();
131                }
132                else if (baseLocator.getRole() != null)
133                {
134                    rootType = JetspeedLink.ROLE;
135                    rootValue = baseLocator.getRoleName();
136                }
137                else if (baseLocator.getGroup() != null)
138                {
139                    rootType = JetspeedLink.GROUP;
140                    rootValue = baseLocator.getGroupName();
141                }
142             }
143             else
144             {
145                rootType = JetspeedLink.CURRENT;
146                rootValue = "";
147                baseProfile = data.getProfile();
148                baseLocator.createFromPath(baseProfile.getPath());
149             }
150
151             // Determine search method
152
if (baseLocator != null)
153             {
154                 // search by portlet name
155
if (this.name != null)
156                 {
157                     elementType = JetspeedLink.PORTLET_ID_QUERY;
158                     elementValue = this.name;
159                 }
160                 else if (this.jspeid != null)
161                 {
162                     elementType = JetspeedLink.PORTLET_ID;
163                     elementValue = this.jspeid;
164                 }
165                 // Build the link
166
JetspeedLink link = JetspeedLinkFactory.getInstance(data);
167                 DynamicURI uri = link.getLink(rootType,
168                                               rootValue,
169                                               baseLocator.getName(),
170                                               elementType,
171                                               elementValue,
172                                               this.action == null ? "controls.Maximize" : this.action,
173                                               null,
174                                               baseLocator.getMediaType(),
175                                               baseLocator.getLanguage(),
176                                               baseLocator.getCountry());
177                 result = new StringElement(uri.toString());
178                 JetspeedLinkFactory.putInstance(link);
179             }
180
181             // Output the result
182
if (result != null)
183             {
184                 pageContext.getOut().print(result);
185             }
186
187         }
188         catch (Exception JavaDoc e)
189         {
190             String JavaDoc message = "Error processing name '" + name + "'.";
191             logger.error(message, e);
192             try
193             {
194                 data.getOut().print("Error processing portlet '" + name + "'. See log for more information.");
195             }
196             catch (java.io.IOException JavaDoc ioe)
197             {
198             }
199         }
200         return EVAL_BODY_INCLUDE;
201     }
202 }
203
Popular Tags