1 16 17 package org.apache.jetspeed.portal.portlets; 18 19 import java.util.Enumeration ; 21 import java.util.Hashtable ; 22 import java.util.Iterator ; 23 24 import org.apache.ecs.html.Comment; 26 import org.apache.ecs.ConcreteElement; 27 import org.apache.ecs.ElementContainer; 28 29 import org.apache.jetspeed.portal.PortletConfig; 31 import org.apache.jetspeed.portal.PortletException; 32 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 33 import org.apache.jetspeed.services.logging.JetspeedLogger; 34 35 import org.apache.turbine.util.RunData; 37 import org.apache.turbine.modules.ScreenLoader; 38 39 64 public class TurbineScreenPortlet extends AbstractPortlet 65 { 66 69 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(TurbineScreenPortlet.class.getName()); 70 71 private String screen = null; 72 private String bgcolor = null; 73 private String classes = null; 74 private Hashtable paramSet = null; 75 76 static final public String BGCOLOR = "bgcolor"; 77 static final public String CLASSES = "classes"; 78 static final public String SCREEN = "display.screen"; 79 80 82 public ConcreteElement getContent( RunData rundata ) 83 { 84 ElementContainer content = new ElementContainer(); 85 try 86 { 87 rundata = setParams( rundata ); 88 content.addElement( new Comment( "BEGIN TurbineScreenPortlet" ) ); 89 content.addElement( ScreenLoader.getInstance().eval( rundata, screen ) ); 90 content.addElement( new Comment( "END TurbineScreenPortlet" ) ); 91 } 92 catch ( Exception e ) 93 { 94 String message = "TurbineScreenPortlet: " + e.getMessage(); 95 logger.error( message, e ); 96 content.addElement( message ); 97 } 98 return ( content ); 99 } 100 101 103 public void init() throws PortletException 104 { 105 PortletConfig pc = getPortletConfig(); 106 ConcreteElement myContent = null; 107 try 108 { 109 screen = ( String ) pc.getInitParameter( SCREEN ); 110 if ( screen == null ) 112 { 113 throw new IllegalArgumentException ("Missing screen parameter"); 114 } 115 116 if ( screen == null ) 118 { 119 throw new PortletException( "You need to specify a " + SCREEN + " parameter for this portlet" ); 120 } 121 122 123 String param = null; 124 String value = null; 125 java.util.Map dict = pc.getInitParameters(); 126 Iterator en = dict.keySet().iterator(); 127 int index = -1; 128 String tParam = screen + ".param"; 129 String newParam = null; 130 paramSet = new Hashtable (); 131 while ( en.hasNext() ) 132 { 133 param = ( String ) en.next(); 134 index = param.indexOf( tParam ); 135 if ( index != -1 ) 136 { 137 value = ( String ) dict.get( param ); 138 if ( value == null ) 139 { 140 throw new PortletException( "Could not retrieve value for " + param ); 141 } 142 newParam = param.substring( index + tParam.length() + 1 ); 143 paramSet.put( newParam, value ); 144 } 145 } 146 147 bgcolor = this.getPortletConfig().getPortletSkin().getBackgroundColor(); 148 classes = "WEB-INF/classes"; 149 } 150 catch ( Exception e ) 151 { 152 String message = "TurbineScreenPortlet: " + e.getMessage(); 153 logger.error( message, e ); 154 } 155 } 156 157 159 public boolean getAllowEdit( RunData rundata ) 160 { 161 return false; 162 } 163 164 166 public boolean getAllowMaximize( RunData rundata ) 167 { 168 return true; 169 } 170 171 173 private RunData setParams( RunData data ) 174 { 175 data.getParameters().add( BGCOLOR, bgcolor ); 176 data.getParameters().add( CLASSES, classes ); 177 178 Enumeration en = paramSet.keys(); 179 String param = null; 180 while ( en.hasMoreElements() ) 181 { 182 param = ( String ) en.nextElement(); 183 data.getParameters().add( param, ( String ) paramSet.get( param ) ); 184 } 185 return ( data ); 186 } 187 } 188 | Popular Tags |