1 16 17 package org.apache.jetspeed.portal.portlets; 18 19 20 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 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 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 import org.apache.turbine.util.RunData; 49 50 66 public class PortletInfoPortlet extends AbstractPortlet 67 { 68 69 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 79 public boolean getAllowEdit( RunData rundata ) { 80 return false; 83 } 84 85 87 public boolean getAllowMaximize( RunData rundata ) { 88 return false; 91 } 92 93 94 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 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 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 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 182 183 197 198 200 202 Iterator names= portlet.getPortletConfig().getInitParameterNames(); 203 204 if ( names.hasNext() ) { 205 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 return t; 223 224 } 225 226 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 } 239 | Popular Tags |