KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > portlets > PortletInfoPortlet


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.portal.portlets;
18
19
20 //standard java stuff
21
import java.io.IOException JavaDoc;
22 import java.net.URLEncoder JavaDoc;
23 import java.util.Date JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.text.DateFormat JavaDoc;
26
27 //Element Construction Set
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 //Jetspeed stuff
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 //Turbine
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 JavaDoc THIRDPARTY_PORTLETRENDERER_URL_KEY = "thirdparty.portletrenderer.url";
75     public static final String JavaDoc THIRDPARTY_PORTLETRENDERER_CAPTION_KEY = "thirdparty.portletrenderer.caption";
76
77     /**
78     */

79     public boolean getAllowEdit( RunData rundata ) {
80         //NOTE: it is important that this ALWAYS return false. The
81
//PortletInfoPortlet will try to work with itself and get confused.
82
return false;
83     }
84
85     /**
86     */

87     public boolean getAllowMaximize( RunData rundata ) {
88         //NOTE: it is important that this ALWAYS return false. The
89
//PortletInfoPortlet will try to work with itself and get confused.
90
return false;
91     }
92
93
94     /**
95     */

96     public ConcreteElement getContent( RunData rundata ) {
97
98         String JavaDoc portletName = ((JetspeedRunData)rundata).getPortlet();
99
100         DateFormat JavaDoc df = DateFormat.getDateTimeInstance();
101         
102         if ( portletName == null ) {
103             String JavaDoc 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 JavaDoc 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 JavaDoc(urlUpdated) ) ) );
127                 long urlExpires = JetspeedDiskCache.getInstance().getEntry( url ).getExpirationTime();
128                 t.addElement( this.getRow( "URL expires: " + df.format( new Date JavaDoc(urlExpires) ) ) );
129             } catch ( IOException JavaDoc e ) {
130                 logger.error("Exception", e);
131             }
132         }
133
134         t.addElement( this.getRow( "Portlet last updated: " + df.format( new Date JavaDoc(portlet.getCreationTime()) ) ) );
135
136
137
138         //BEGIN 3RD PARTY REPL
139

140
141         t.addElement( new TR().addElement( new TD()
142             .addElement( new B().addElement( "Actions:" ) ) ) );
143             
144         String JavaDoc internal = null;
145         JetspeedLink jsLink = null;
146
147         try
148         {
149             jsLink = JetspeedLinkFactory.getInstance(rundata);
150             String JavaDoc mtype = rundata.getParameters().getString("mtype");
151             if (mtype != null)
152             {
153                 jsLink.setMediaType(mtype);
154                 jsLink.addQueryData("mtype", mtype);
155             }
156             String JavaDoc js_peid = rundata.getParameters().getString("js_peid");
157             // FIX ME: If the portlet is viewed in Avantgo and then portlet info is restored, the portlet will
158
// be maximized (similar to customizing certain portlet types. The desired effect would be to
159
// set the portlet's mode to normal.
160
internal = jsLink.addPathInfo("js_peid", js_peid).setAction("controls.Maximize").toString();
161         }
162         catch (Exception JavaDoc e)
163         {
164             logger.error("Exception", e);
165         }
166         JetspeedLinkFactory.putInstance(jsLink);
167
168         StringBuffer JavaDoc external = new StringBuffer JavaDoc( getPortletConfig().getInitParameter( THIRDPARTY_PORTLETRENDERER_URL_KEY ) );
169
170         //this is the parameters of what so specify to the 3rd party provider
171
external.append("&title=" + URLEncoder.encode( portlet.getTitle() ) );
172         external.append("&url=" + URLEncoder.encode(internal));
173
174         String JavaDoc 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         //END 3RD PARTY REPL
181

182             
183         // BEGIN MIME TYPE SUPPORT
184
/* RL: Temporarily disable mime support while changing registry
185          t.addElement( new TR().addElement( new TD()
186             .addElement( new B().addElement( "Mime Types:" ) ) ) );
187
188         MimeType[] mts = portlet.getPortletConfig().getCapabilityMap().getMimeTypes();
189             
190         for ( int i = 0; i < mts.length; ++i ) {
191                 
192             t.addElement( new TR()
193                 .addElement( new TD( mts[i].toString() ) ) );
194                 
195         }
196          */

197
198         //END MIME TYPE SUPPORT
199

200         //BEGIN PROPERTIES SECTION
201

202         Iterator JavaDoc names= portlet.getPortletConfig().getInitParameterNames();
203
204         if ( names.hasNext() ) {
205             //OK... add the Properties from the Portet to this info set...
206
t.addElement( new TR().addElement( new TD()
207                 .addElement( new B().addElement( "Properties:" ) ) ) );
208
209         }
210             
211         while ( names.hasNext() ) {
212                 
213             String JavaDoc name = (String JavaDoc)names.next();
214             String JavaDoc value = (String JavaDoc)portlet.getPortletConfig().getInitParameter( name );
215
216             t.addElement( new TR()
217                 .addElement( new TD( name + ": " + value ) ) );
218                 
219         }
220
221         //END PROPERTIES SECTION
222
return t;
223
224     }
225
226     /**
227     Get a row for the output table
228     */

229     private ConcreteElement getRow( String JavaDoc message ) {
230  
231         return new TR()
232                       .addElement( new TD()
233                       .setNoWrap( true )
234                       .addElement( message ) );
235        
236     }
237
238 }
239
Popular Tags