1 package org.apache.jetspeed.services.jsp.tags;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import javax.servlet.jsp.JspException;
21 import javax.servlet.jsp.PageContext;
22 import javax.servlet.jsp.tagext.TagSupport;
23
24
25 import org.apache.turbine.util.DynamicURI;
26 import org.apache.turbine.services.jsp.JspService;
27
28
29 import org.apache.ecs.ConcreteElement;
30 import org.apache.ecs.StringElement;
31
32
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
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 name = null;
59 private String jspeid = null;
60 private String psml = null;
61 private String action = null;
62
63 public void setName(String name)
64 {
65 this.name = name;
66 }
67
68 public String getName()
69 {
70 return this.name;
71 }
72
73 public void setPsml(String psml)
74 {
75 this.psml = psml;
76 }
77
78 public String getPsml()
79 {
80 return this.psml;
81 }
82
83 public void setJspeid(String value)
84 {
85 this.jspeid = value;
86 }
87
88 public String getJspeid()
89 {
90 return this.jspeid;
91 }
92
93 public void setAction(String value)
94 {
95 this.action = value;
96 }
97
98 public String 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
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 rootValue = null;
120 int elementType = JetspeedLink.DEFAULT;
121 String elementValue = null;
122
123
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
152 if (baseLocator != null)
153 {
154
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
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
182 if (result != null)
183 {
184 pageContext.getOut().print(result);
185 }
186
187 }
188 catch (Exception e)
189 {
190 String 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 ioe)
197 {
198 }
199 }
200 return EVAL_BODY_INCLUDE;
201 }
202 }