1 package org.apache.jetspeed.portal.portlets;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import org.apache.jetspeed.portal.Portlet;
21 import org.apache.jetspeed.services.PortletFactory;
22 import org.apache.jetspeed.portal.PortletControl;
23 import org.apache.jetspeed.services.PortalToolkit;
24 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
25 import org.apache.jetspeed.services.logging.JetspeedLogger;
26 import org.apache.jetspeed.services.rundata.JetspeedRunData;
27 import org.apache.jetspeed.util.template.JetspeedLink;
28 import org.apache.jetspeed.util.template.JetspeedLinkFactory;
29
30
31 import org.apache.jetspeed.util.JetspeedClearElement;
32 import org.apache.ecs.ConcreteElement;
33
34
35 import org.apache.turbine.util.RunData;
36 import org.apache.turbine.services.velocity.TurbineVelocity;
37 import org.apache.velocity.context.Context;
38
39 /***
40 * Preview portlet. Displays content of potlet
41 * defined in parameter "previewedPortletName".
42 *
43 * @version $Id: PreviewPortlet.java,v 1.5 2004/02/23 04:03:33 jford Exp $
44 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
45 * @author <a href="mailto:mark_orciuch@ngsltd.com">Mark Orciuch</a>
46 */
47 public class PreviewPortlet extends AbstractPortlet
48 {
49
50 /***
51 * Static initialization of the logger for this class
52 */
53 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(PreviewPortlet.class.getName());
54
55 /***
56 * @param rundata The RunData object for the current request
57 */
58 public ConcreteElement getContent(RunData rundata)
59 {
60
61 Context context = TurbineVelocity.getContext(rundata);
62 context.put( "data", rundata);
63 TurbineVelocity.getContext(rundata).put("jetspeed", new org.apache.jetspeed.util.template.JetspeedTool(rundata));
64
65 ConcreteElement result = null;
66 String controlName = rundata.getParameters().getString("previewedControlName");
67 String portletName = rundata.getParameters().getString("previewedPortletName");
68 if ( portletName == null )
69 {
70 JetspeedLink jsLink = null;
71
72 try
73 {
74 jsLink = JetspeedLinkFactory.getInstance(rundata);
75 rundata.setRedirectURI(
76 jsLink.setUser(
77 rundata.getUser().getUserName(), "default.psml")
78 .addPathInfo("template", "Customize")
79 .addPathInfo("media-type", "html")
80 .toString()
81 );
82 JetspeedLinkFactory.putInstance(jsLink);
83 jsLink = null;
84 return new JetspeedClearElement("");
85 } catch (Exception e)
86 {
87 logger.error("Exception", e);
88 rundata.setScreenTemplate("Home");
89 return new JetspeedClearElement("");
90 }
91
92 }
93 Portlet portlet = null;
94
95 try
96 {
97 portlet = PortletFactory.getPortlet(portletName, "PreviewPortlet");
98 PortletControl control = controlName == null ? PortalToolkit.getControl((String)null) :
99 PortalToolkit.getControl(controlName);
100 control = null;
101 if ( control != null )
102 {
103 JetspeedRunData jdata = (JetspeedRunData)rundata;
104
105
106 control.setPortlet(portlet);
107 control.init();
108 result = control.getContent(rundata);
109 }
110 else if ( portlet != null )
111 {
112 result = portlet.getContent(rundata);
113 }
114
115 if ( result != null && !result.toString().equals("") )
116 {
117
118
119
120
121
122 }
123 else
124 {
125
126 result = new JetspeedClearElement("");
127 }
128
129 }
130 catch ( Exception e )
131 {
132 logger.error("Exception", e);
133 result = new JetspeedClearElement("This resource is temporarily unavailable");
134 }
135
136 rundata.setLayout("preview");
137 return result;
138 }
139
140 }