1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portal.portlets;
18
19
20
21 import java.io.IOException;
22 import java.net.URLEncoder;
23 import java.util.Date;
24 import java.util.Iterator;
25 import java.text.DateFormat;
26
27
28 import org.apache.ecs.html.A;
29 import org.apache.ecs.html.B;
30 import org.apache.ecs.html.Table;
31 import org.apache.ecs.html.TD;
32 import org.apache.ecs.html.TR;
33 import org.apache.ecs.ConcreteElement;
34 import org.apache.ecs.StringElement;
35
36
37 import org.apache.jetspeed.portal.Portlet;
38 import org.apache.jetspeed.portal.PortletException;
39 import org.apache.jetspeed.services.PortletFactory;
40 import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
41 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
42 import org.apache.jetspeed.services.logging.JetspeedLogger;
43 import org.apache.jetspeed.services.rundata.JetspeedRunData;
44 import org.apache.jetspeed.util.template.JetspeedLink;
45 import org.apache.jetspeed.util.template.JetspeedLinkFactory;
46
47
48 import org.apache.turbine.util.RunData;
49
50 /***
51 <p>
52 A Portlet which displays info about other Portlets. This really isn't mean't
53 to be used in any other place except the PortletServlet as it is just displays
54 information about another servlet. If in the future this should be used
55 elsewhere it can as it is a 1st class Servlet.
56 </p>
57
58 <p>
59 Note: I decided to leave this Portlet within the cache because it would be
60 expired if it isn't needed.
61 </p>
62
63 @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
64 @version $Id: PortletInfoPortlet.java,v 1.46 2004/02/23 04:03:33 jford Exp $
65 */
66 public class PortletInfoPortlet extends AbstractPortlet
67 {
68
69 /***
70 * Static initialization of the logger for this class
71 */
72 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(PortletInfoPortlet.class.getName());
73
74 public static final String THIRDPARTY_PORTLETRENDERER_URL_KEY = "thirdparty.portletrenderer.url";
75 public static final String THIRDPARTY_PORTLETRENDERER_CAPTION_KEY = "thirdparty.portletrenderer.caption";
76
77 /***
78 */
79 public boolean getAllowEdit( RunData rundata ) {
80
81
82 return false;
83 }
84
85 /***
86 */
87 public boolean getAllowMaximize( RunData rundata ) {
88
89
90 return false;
91 }
92
93
94 /***
95 */
96 public ConcreteElement getContent( RunData rundata ) {
97
98 String portletName = ((JetspeedRunData)rundata).getPortlet();
99
100 DateFormat df = DateFormat.getDateTimeInstance();
101
102 if ( portletName == null ) {
103 String message = "Could not find given entry ";
104 logger.error( message );
105 return new StringElement( message );
106 }
107
108 Portlet portlet = null;
109 try {
110 portlet = PortletFactory.getPortlet( portletName, "0" );
111 } catch (PortletException e) {
112 logger.error("Exception", e);
113 return new StringElement( e.getMessage() );
114 }
115
116 Table t = new Table();
117
118 t.addElement( this.getRow( "Portlet name: " + portlet.getName() ) );
119
120 String url = portlet.getPortletConfig().getURL();
121 if ( url != null ) {
122 t.addElement( this.getRow( "From URL: " + url ) );
123
124 try {
125 long urlUpdated = JetspeedDiskCache.getInstance().getEntry( url ).getLastModified();
126 t.addElement( this.getRow( "URL last updated: " + df.format( new Date(urlUpdated) ) ) );
127 long urlExpires = JetspeedDiskCache.getInstance().getEntry( url ).getExpirationTime();
128 t.addElement( this.getRow( "URL expires: " + df.format( new Date(urlExpires) ) ) );
129 } catch ( IOException e ) {
130 logger.error("Exception", e);
131 }
132 }
133
134 t.addElement( this.getRow( "Portlet last updated: " + df.format( new Date(portlet.getCreationTime()) ) ) );
135
136
137
138
139
140
141 t.addElement( new TR().addElement( new TD()
142 .addElement( new B().addElement( "Actions:" ) ) ) );
143
144 String internal = null;
145 JetspeedLink jsLink = null;
146
147 try
148 {
149 jsLink = JetspeedLinkFactory.getInstance(rundata);
150 String mtype = rundata.getParameters().getString("mtype");
151 if (mtype != null)
152 {
153 jsLink.setMediaType(mtype);
154 jsLink.addQueryData("mtype", mtype);
155 }
156 String js_peid = rundata.getParameters().getString("js_peid");
157
158
159
160 internal = jsLink.addPathInfo("js_peid", js_peid).setAction("controls.Maximize").toString();
161 }
162 catch (Exception e)
163 {
164 logger.error("Exception", e);
165 }
166 JetspeedLinkFactory.putInstance(jsLink);
167
168 StringBuffer external = new StringBuffer( getPortletConfig().getInitParameter( THIRDPARTY_PORTLETRENDERER_URL_KEY ) );
169
170
171 external.append("&title=" + URLEncoder.encode( portlet.getTitle() ) );
172 external.append("&url=" + URLEncoder.encode(internal));
173
174 String message = getPortletConfig().getInitParameter( THIRDPARTY_PORTLETRENDERER_CAPTION_KEY );
175
176 t.addElement( new TR()
177 .addElement( new TD()
178 .addElement( new A( external.toString() ).setTarget("_blank").addElement( message ) ) ) );
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202 Iterator names= portlet.getPortletConfig().getInitParameterNames();
203
204 if ( names.hasNext() ) {
205
206 t.addElement( new TR().addElement( new TD()
207 .addElement( new B().addElement( "Properties:" ) ) ) );
208
209 }
210
211 while ( names.hasNext() ) {
212
213 String name = (String)names.next();
214 String value = (String)portlet.getPortletConfig().getInitParameter( name );
215
216 t.addElement( new TR()
217 .addElement( new TD( name + ": " + value ) ) );
218
219 }
220
221
222 return t;
223
224 }
225
226 /***
227 Get a row for the output table
228 */
229 private ConcreteElement getRow( String message ) {
230
231 return new TR()
232 .addElement( new TD()
233 .setNoWrap( true )
234 .addElement( message ) );
235
236 }
237
238 }