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 import javax.servlet.jsp.JspException;
20 import javax.servlet.jsp.PageContext;
21 import javax.servlet.jsp.tagext.TagSupport;
22
23
24 import org.apache.turbine.services.jsp.JspService;
25
26 import org.apache.ecs.ConcreteElement;
27
28
29 import org.apache.jetspeed.services.PortletFactory;
30 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
31 import org.apache.jetspeed.services.logging.JetspeedLogger;
32 import org.apache.jetspeed.services.rundata.JetspeedRunData;
33 import org.apache.jetspeed.om.profile.Entry;
34 import org.apache.jetspeed.om.profile.ProfileLocator;
35 import org.apache.jetspeed.om.profile.Profile;
36 import org.apache.jetspeed.services.Profiler;
37
38 /***
39 * Supporting class for the portlet tag.
40 * Builds the output of a portlet (with conrol) and insert it within the
41 * current JSP page
42 *
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 */
46 public class JetspeedPortletTag extends TagSupport
47 {
48 /***
49 * Static initialization of the logger for this class
50 */
51 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedPortletTag.class.getName());
52
53 private String name = null;
54 private String psml = null;
55
56 public void setName(String name)
57 {
58 this.name = name;
59 }
60
61 public String getName()
62 {
63 return this.name;
64 }
65
66 public void setPsml(String psml)
67 {
68 this.psml = psml;
69 }
70
71 public String getPsml()
72 {
73 return this.psml;
74 }
75
76 /***
77 * Method called when the tag is encountered to send attributes to the
78 * output stream
79 *
80 * @return SKIP_BODY, as it is intended to be a single tag.
81 */
82 public int doStartTag() throws JspException
83 {
84 JetspeedRunData data = (JetspeedRunData)pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
85
86
87 if (this.name == null)
88 {
89 this.name = data.getPortlet();
90 }
91
92 try
93 {
94 pageContext.getOut().flush();
95
96 ConcreteElement result = new ConcreteElement();
97 Entry entry = null;
98
99 if (this.psml != null)
100 {
101 ProfileLocator baseLocator = Profiler.createLocator();
102 baseLocator.createFromPath(this.psml);
103 Profile baseProfile = Profiler.getProfile(baseLocator);
104 if (baseProfile != null)
105 {
106 entry = baseProfile.getDocument().getEntry(name);
107 if ( logger.isDebugEnabled() )
108 {
109 logger.debug("JetspeedPortletTag: retrieved [" + entry + "] from psml [" + this.psml);
110 }
111 }
112 }
113 else
114 {
115 entry = data.getProfile().getDocument().getEntry(name);
116 if ( logger.isDebugEnabled() )
117 {
118 logger.debug("JetspeedPortletTag: retrieved [" + entry + "] from current psml");
119 }
120 }
121
122 if (entry != null)
123 {
124 result = PortletFactory.getPortlet(entry).getContent(data);
125 }
126
127
128
129 if ( result != null )
130 {
131
132
133 result.setCodeSet( data.getResponse().getCharacterEncoding() );
134
135 result.output( data.getResponse().getWriter() );
136 }
137
138 }
139 catch (Exception e)
140 {
141 String message = "Error processing name '" + name + "'.";
142 logger.error(message, e);
143 try
144 {
145 data.getOut().print("Error processing portlet '" + name + "'. See log for more information.");
146 }
147 catch(java.io.IOException ioe) {}
148 }
149 return SKIP_BODY;
150 }
151 }