1packageorg.apache.jetspeed.services.jsp.tags;
23/*4 * Copyright 2000-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 */1819import javax.servlet.jsp.JspException;
20import javax.servlet.jsp.PageContext;
21import javax.servlet.jsp.tagext.TagSupport;
2223// Turbine Classes24import org.apache.turbine.services.jsp.JspService;
2526import org.apache.ecs.ConcreteElement;
2728// Jetspeed classes29import org.apache.jetspeed.services.PortletFactory;
30import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
31import org.apache.jetspeed.services.logging.JetspeedLogger;
32import org.apache.jetspeed.services.rundata.JetspeedRunData;
33import org.apache.jetspeed.om.profile.Entry;
34import org.apache.jetspeed.om.profile.ProfileLocator;
35import org.apache.jetspeed.om.profile.Profile;
36import org.apache.jetspeed.services.Profiler;
3738/***39 * Supporting class for the portlet tag.40 * Builds the output of a portlet (with conrol) and insert it within the41 * current JSP page42 *43 * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>44 * @version $Id: JetspeedPortletTag.java,v 1.10 2004/02/23 03:59:40 jford Exp $45 */46publicclassJetspeedPortletTagextends TagSupport
47 {
48/***49 * Static initialization of the logger for this class50 */51privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedPortletTag.class.getName());
5253private String name = null;
54private String psml = null;
5556publicvoid setName(String name)
57 {
58this.name = name;
59 }
6061public String getName()
62 {
63returnthis.name;
64 }
6566publicvoid setPsml(String psml)
67 {
68this.psml = psml;
69 }
7071public String getPsml()
72 {
73returnthis.psml;
74 }
7576/***77 * Method called when the tag is encountered to send attributes to the78 * output stream79 *80 * @return SKIP_BODY, as it is intended to be a single tag.81 */82publicint doStartTag() throws JspException
83 {
84JetspeedRunData data = (JetspeedRunData)pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
8586// if called without arguments, use the default request parameter87if (this.name == null)
88 {
89this.name = data.getPortlet();
90 }
9192try93 {
94 pageContext.getOut().flush();
9596 ConcreteElement result = new ConcreteElement();
97Entry entry = null;
9899if (this.psml != null)
100 {
101ProfileLocator baseLocator = Profiler.createLocator();
102 baseLocator.createFromPath(this.psml);
103Profile baseProfile = Profiler.getProfile(baseLocator);
104if (baseProfile != null)
105 {
106 entry = baseProfile.getDocument().getEntry(name);
107if ( logger.isDebugEnabled() )
108 {
109 logger.debug("JetspeedPortletTag: retrieved [" + entry + "] from psml [" + this.psml);
110 }
111 }
112 }
113else114 {
115 entry = data.getProfile().getDocument().getEntry(name);
116if ( logger.isDebugEnabled() )
117 {
118 logger.debug("JetspeedPortletTag: retrieved [" + entry + "] from current psml");
119 }
120 }
121122if (entry != null)
123 {
124 result = PortletFactory.getPortlet(entry).getContent(data);
125 }
126127// Check whether this is an "old" screen (that returns a ConcreteElement)128// or a "new" one that returns null.129if ( result != null )
130 {
131//The ECS element must serialize in the character encoding132// of the response133 result.setCodeSet( data.getResponse().getCharacterEncoding() );
134135 result.output( data.getResponse().getWriter() );
136 }
137138 }
139catch (Exception e)
140 {
141 String message = "Error processing name '" + name + "'.";
142 logger.error(message, e);
143try144 {
145 data.getOut().print("Error processing portlet '" + name + "'. See log for more information.");
146 }
147catch(java.io.IOException ioe) {}
148 }
149return SKIP_BODY;
150 }
151 }