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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.portal.portlets;
181920//standard java stuff21import java.io.IOException;
22import java.net.URLEncoder;
23import java.util.Date;
24import java.util.Iterator;
25import java.text.DateFormat;
2627//Element Construction Set28import org.apache.ecs.html.A;
29import org.apache.ecs.html.B;
30import org.apache.ecs.html.Table;
31import org.apache.ecs.html.TD;
32import org.apache.ecs.html.TR;
33import org.apache.ecs.ConcreteElement;
34import org.apache.ecs.StringElement;
3536//Jetspeed stuff37import org.apache.jetspeed.portal.Portlet;
38import org.apache.jetspeed.portal.PortletException;
39import org.apache.jetspeed.services.PortletFactory;
40import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
41import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
42import org.apache.jetspeed.services.logging.JetspeedLogger;
43import org.apache.jetspeed.services.rundata.JetspeedRunData;
44import org.apache.jetspeed.util.template.JetspeedLink;
45import org.apache.jetspeed.util.template.JetspeedLinkFactory;
4647//Turbine48import org.apache.turbine.util.RunData;
4950/***51<p>52A Portlet which displays info about other Portlets. This really isn't mean't53to be used in any other place except the PortletServlet as it is just displays54information about another servlet. If in the future this should be used55elsewhere it can as it is a 1st class Servlet.56</p>5758<p>59Note: I decided to leave this Portlet within the cache because it would be60expired if it isn't needed.61</p>6263@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*/66publicclassPortletInfoPortletextendsAbstractPortlet67 {
6869/***70 * Static initialization of the logger for this class71 */72privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(PortletInfoPortlet.class.getName());
7374publicstaticfinal String THIRDPARTY_PORTLETRENDERER_URL_KEY = "thirdparty.portletrenderer.url";
75publicstaticfinal String THIRDPARTY_PORTLETRENDERER_CAPTION_KEY = "thirdparty.portletrenderer.caption";
7677/***78 */79publicboolean getAllowEdit( RunData rundata ) {
80//NOTE: it is important that this ALWAYS return false. The81//PortletInfoPortlet will try to work with itself and get confused.82return false;
83 }
8485/***86 */87publicboolean getAllowMaximize( RunData rundata ) {
88//NOTE: it is important that this ALWAYS return false. The89//PortletInfoPortlet will try to work with itself and get confused.90return false;
91 }
929394/***95 */96public ConcreteElement getContent( RunData rundata ) {
9798 String portletName = ((JetspeedRunData)rundata).getPortlet();
99100 DateFormat df = DateFormat.getDateTimeInstance();
101102if ( portletName == null ) {
103 String message = "Could not find given entry ";
104 logger.error( message );
105returnnew StringElement( message );
106 }
107108Portlet portlet = null;
109try {
110 portlet = PortletFactory.getPortlet( portletName, "0" );
111 } catch (PortletException e) {
112 logger.error("Exception", e);
113returnnew StringElement( e.getMessage() );
114 }
115116 Table t = new Table();
117118 t.addElement( this.getRow( "Portlet name: " + portlet.getName() ) );
119120 String url = portlet.getPortletConfig().getURL();
121if ( url != null ) {
122 t.addElement( this.getRow( "From URL: " + url ) );
123124try {
125long urlUpdated = JetspeedDiskCache.getInstance().getEntry( url ).getLastModified();
126 t.addElement( this.getRow( "URL last updated: " + df.format( new Date(urlUpdated) ) ) );
127long 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 }
133134 t.addElement( this.getRow( "Portlet last updated: " + df.format( new Date(portlet.getCreationTime()) ) ) );
135136137138//BEGIN 3RD PARTY REPL139140141 t.addElement( new TR().addElement( new TD()
142 .addElement( new B().addElement( "Actions:" ) ) ) );
143144 String internal = null;
145JetspeedLink jsLink = null;
146147try148 {
149 jsLink = JetspeedLinkFactory.getInstance(rundata);
150 String mtype = rundata.getParameters().getString("mtype");
151if (mtype != null)
152 {
153 jsLink.setMediaType(mtype);
154 jsLink.addQueryData("mtype", mtype);
155 }
156 String 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 will158// 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 }
162catch (Exception e)
163 {
164 logger.error("Exception", e);
165 }
166 JetspeedLinkFactory.putInstance(jsLink);
167168 StringBuffer external = new StringBuffer( getPortletConfig().getInitParameter( THIRDPARTY_PORTLETRENDERER_URL_KEY ) );
169170//this is the parameters of what so specify to the 3rd party provider171 external.append("&title=" + URLEncoder.encode( portlet.getTitle() ) );
172 external.append("&url=" + URLEncoder.encode(internal));
173174 String message = getPortletConfig().getInitParameter( THIRDPARTY_PORTLETRENDERER_CAPTION_KEY );
175176 t.addElement( new TR()
177 .addElement( new TD()
178 .addElement( new A( external.toString() ).setTarget("_blank").addElement( message ) ) ) );
179180//END 3RD PARTY REPL181182183// BEGIN MIME TYPE SUPPORT184/* RL: Temporarily disable mime support while changing registry185 t.addElement( new TR().addElement( new TD()186 .addElement( new B().addElement( "Mime Types:" ) ) ) );187188 MimeType[] mts = portlet.getPortletConfig().getCapabilityMap().getMimeTypes();189190 for ( int i = 0; i < mts.length; ++i ) {191192 t.addElement( new TR()193 .addElement( new TD( mts[i].toString() ) ) );194195 }196 */197198//END MIME TYPE SUPPORT199200//BEGIN PROPERTIES SECTION201202 Iterator names= portlet.getPortletConfig().getInitParameterNames();
203204if ( 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:" ) ) ) );
208209 }
210211while ( names.hasNext() ) {
212213 String name = (String)names.next();
214 String value = (String)portlet.getPortletConfig().getInitParameter( name );
215216 t.addElement( new TR()
217 .addElement( new TD( name + ": " + value ) ) );
218219 }
220221//END PROPERTIES SECTION222return t;
223224 }
225226/***227 Get a row for the output table228 */229private ConcreteElement getRow( String message ) {
230231returnnew TR()
232 .addElement( new TD()
233 .setNoWrap( true )
234 .addElement( message ) );
235236 }
237238 }