1 16 17 package org.apache.jetspeed.portal.controllers; 18 19 import org.apache.turbine.util.DynamicURI; 21 import org.apache.turbine.util.RunData; 22 23 import org.apache.jetspeed.portal.Portlet; 25 import org.apache.jetspeed.portal.PanedPortletController; 26 import org.apache.jetspeed.util.template.JetspeedLink; 27 import org.apache.jetspeed.util.template.JetspeedLinkFactory; 28 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 29 import org.apache.jetspeed.services.logging.JetspeedLogger; 30 import org.apache.jetspeed.services.statemanager.SessionState; 31 import org.apache.jetspeed.services.rundata.JetspeedRunData; 32 import org.apache.jetspeed.services.resources.JetspeedResources; 33 34 44 45 public class VelocityPanedPortletController extends VelocityPortletController 46 implements PanedPortletController 47 { 48 49 52 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(VelocityPanedPortletController.class.getName()); 53 54 public static final String DEFAULT_PARAMETER = "pane"; 55 56 60 public String getPaneParameter() 61 { 62 return JetspeedResources.PATH_PANEID_KEY; 63 } 64 65 66 74 public boolean isSelected( Portlet p, RunData rundata ) 75 { 76 String peid = rundata.getParameters().getString( getPaneParameter() ); 77 String pname = rundata.getParameters().getString(JetspeedResources.PATH_PANENAME_KEY); 78 String last = retrievePaneIDFromSession(rundata); 79 80 if (pname != null && pname.equals(p.getName())) 82 { 83 return true; 84 } 85 86 if (peid == null) 87 { 88 if (last == null) 89 { 90 return (getPortlets().getPortletAt( 0 ) == p); 91 } 92 else 93 { 94 if (pname == null) 95 { 96 return (p.getID().equals(last)); 97 } 98 else 99 { 100 return (getPortlets().getPortletByName(pname) == null && p.getID().equals(last)); 105 } 106 } 107 } 108 else 109 { 110 String subPane = null; 111 int index = peid.indexOf(JetspeedResources.PATH_SUBPANE_SEPARATOR); 112 if (index > -1) 113 { 114 subPane = peid.substring(index + 1); 115 peid = peid.substring(0, index); 116 } 117 118 if ( p.getID().equals(peid) ) { 120 return true; 121 } 122 123 if (subPane!=null && p.getID().equals(subPane)) 125 { 126 if(!p.getAttribute("_menustate", "open", rundata).equals("closed")) { 130 SessionState state = ((JetspeedRunData)rundata).getPortletSessionState(getPortlets().getID()); 131 state.setAttribute(JetspeedResources.PATH_PANEID_KEY, subPane); 132 } 133 134 return true; 135 } 136 137 if (getPortlets().getPortletByID(peid) != null) 139 { 140 return false; 142 } 143 if (subPane == null) 144 { 145 if (last == null) 146 { 147 return (getPortlets().getPortletAt( 0 ) == p); 148 } 149 else 150 { 151 return (p.getID().equals(last)); 152 } 153 } 154 else 155 { 156 if (p.getID().equals( subPane )) 157 { 158 if(!p.getAttribute("_menustate", "open", rundata).equals("closed")) 162 { 163 SessionState state = 164 ((JetspeedRunData)rundata).getPortletSessionState(getPortlets().getID()); 165 state.setAttribute(JetspeedResources.PATH_PANEID_KEY, subPane); 166 } 167 return true; 168 } 169 } 170 } 171 return false; 172 } 173 174 181 public DynamicURI getPortletURI( Portlet portlet, RunData rundata ) 182 { 183 JetspeedLink jsLink = null; 184 try 185 { 186 jsLink = JetspeedLinkFactory.getInstance(rundata); 187 } 188 catch( Exception e) 189 { 190 logger.error("Exception", e); 191 } 192 DynamicURI uri = jsLink.getPaneById(portlet.getID()); 193 JetspeedLinkFactory.putInstance(jsLink); 194 195 return uri; 196 } 197 198 206 public String retrievePaneID(RunData rundata, boolean byParameter) 207 { 208 if (false == byParameter) 209 return retrievePaneIDFromSession(rundata); 210 211 String pane = rundata.getParameters().getString( getPaneParameter() ); 212 213 if (pane == null) 214 { 215 String id = getPortlets().getID(); 217 pane = retrievePaneIDFromSession(rundata); 218 } 219 220 if(pane != null) 221 { 222 int index = pane.indexOf(JetspeedResources.PATH_SUBPANE_SEPARATOR); 223 if (index > -1) 224 { 225 return pane.substring(0, index); 227 } 228 } 229 230 return pane; 231 } 232 233 240 protected String retrievePaneIDFromSession(RunData rundata) 241 { 242 SessionState state = ((JetspeedRunData)rundata).getPortletSessionState(getPortlets().getID()); 244 245 String pane = (String ) state.getAttribute(JetspeedResources.PATH_PANEID_KEY); 247 248 if (pane == null) 250 { 251 if(getPortlets().size() > 0) 253 { 254 pane = getPortlets().getPortletAt(0).getID(); 255 } 256 } 257 258 return pane; 259 } 260 261 267 public void savePaneID( RunData data, String id ) 268 { 269 SessionState state = ((JetspeedRunData)data).getPortletSessionState(getPortlets().getID()); 271 272 state.setAttribute(JetspeedResources.PATH_PANEID_KEY, id); 274 } 275 276 284 public void setParameterName( String name ) 285 { 286 getConfig().setInitParameter( "parameter", name ); 287 } 288 289 294 public String getParameterName() 295 { 296 return getConfig().getInitParameter( "parameter", DEFAULT_PARAMETER ) 297 + getPortlets().getName(); 298 } 299 300 306 public String retrievePaneName(RunData rundata) 307 { 308 String pane = rundata.getParameters().getString( getParameterName() ); 309 310 if (pane == null) 311 { 312 pane = (String )rundata.getUser().getTemp( "pane-"+getParameterName() ); 314 315 if (pane == null) 316 { 317 pane = getConfig().getInitParameter( "defaultpane", "0" ); 319 } 320 } 321 322 return pane; 323 } 324 325 333 public void savePaneName( RunData data, String name ) 334 { 335 data.getUser().setTemp( "pane-"+getParameterName(), name ); 336 } 337 338 } 339 340 | Popular Tags |