1 16 21 package org.apache.jetspeed.modules.actions.portlets; 22 23 import org.apache.jetspeed.portal.Portlet; 24 import org.apache.jetspeed.portal.PortletInstance; 25 import org.apache.jetspeed.portal.portlets.GenericMVCContext; 26 import org.apache.jetspeed.portal.portlets.GenericMVCPortlet; 27 import org.apache.jetspeed.services.JetspeedSecurity; 28 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 29 import org.apache.jetspeed.services.logging.JetspeedLogger; 30 import org.apache.jetspeed.services.persistence.PersistenceManager; 31 import org.apache.jetspeed.services.persistence.PortalPersistenceException; 32 import org.apache.jetspeed.services.rundata.JetspeedRunData; 33 import org.apache.jetspeed.util.PortletSessionState; 34 import org.apache.turbine.util.RunData; 35 import org.apache.velocity.context.Context; 36 37 38 47 public class GenericMVCAction 48 extends PortletAction 49 { 50 51 54 protected static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(GenericMVCAction.class.getName()); 55 56 57 public GenericMVCAction() 58 { 59 60 } 62 63 protected void perform(RunData rundata) 65 throws Exception 66 { 67 68 Context context = getContext(rundata); 69 70 if ((context != null) && (rundata.getParameters().getString("action") != null)) 71 { 72 73 logger.debug("Action detected with action + context"); 76 doPerform(rundata, context); 77 } 78 else 79 { 80 81 if (context == null) 83 { 84 logger.debug("Action: building action context"); 85 context = new GenericMVCContext(); 86 rundata.getTemplateInfo().setTemplateContext("VelocityActionContext", context); 87 } 88 89 try 90 { 91 92 logger.debug("Action: try executing events"); 94 95 GenericMVCPortlet portlet = (GenericMVCPortlet) context.get("portlet"); 96 97 if (portlet != null) 98 { 99 100 if (rundata.getParameters().getString("js_peid") == null || PortletSessionState.isMyRequest(rundata, portlet)) 104 { 105 executeEvents(rundata, context); 106 } 107 else 108 { 109 logger.debug("Action: calling doPerform"); 110 doPerform(rundata, context); 111 } 112 } 113 else 114 { 115 executeEvents(rundata, context); 116 } 117 } 118 catch (NoSuchMethodException e) 119 { 120 121 logger.debug("Action: calling doPerform"); 123 124 } 125 126 doPerform(rundata, context); 127 } 128 } 129 130 public void doPerform(RunData rundata, Context context) 131 throws Exception 132 { 133 134 GenericMVCPortlet portlet = null; 135 JetspeedRunData jdata = (JetspeedRunData) rundata; 136 logger.debug("GenericMVCAction: retrieved context: " + context); 137 138 if (context != null) 139 { 140 portlet = (GenericMVCPortlet) context.get("portlet"); 141 } 142 143 logger.debug("GenericMVCAction: retrieved portlet: " + portlet); 144 145 if (portlet != null) 146 { 147 148 if ((jdata.getMode() == JetspeedRunData.CUSTOMIZE) && (portlet.getName().equals(jdata.getCustomized().getName()))) 152 { 153 logger.debug("GenericMVCAction: building customize"); 154 buildConfigureContext(portlet, context, rundata); 155 156 return; 157 } 158 159 if (jdata.getMode() == JetspeedRunData.MAXIMIZE) 161 { 162 logger.debug("GenericMVCAction: building maximize"); 163 buildMaximizedContext(portlet, context, rundata); 164 165 return; 166 } 167 168 logger.debug("GenericMVCAction: building normal"); 169 buildNormalContext(portlet, context, rundata); 170 } 171 } 172 173 178 protected void buildMaximizedContext(Portlet portlet, Context context, RunData rundata) 179 throws Exception 180 { 181 buildNormalContext(portlet, context, rundata); 182 } 183 184 189 protected void buildConfigureContext(Portlet portlet, Context context, RunData rundata) 190 throws Exception 191 { 192 193 } 195 196 200 protected void buildNormalContext(Portlet portlet, Context context, RunData rundata) 201 throws Exception 202 { 203 } 204 205 211 public PortletInstance getPortletInstance(Context context) 212 { 213 return getPortlet(context).getInstance((RunData) context.get("data")); 214 } 215 216 224 public String getAttribute(String attrName, Context context) 225 { 226 return getPortletInstance(context).getAttribute(attrName); 227 } 228 229 238 public String getAttribute(String attrName, String defaultValue, Context context) 239 { 240 return getPortletInstance(context).getAttribute(attrName, defaultValue); 241 } 242 250 public void setAttribute(String attrName, String value, Context context) 251 throws PortalPersistenceException 252 { 253 PortletInstance instance = getPortletInstance(context); 254 instance.setAttribute(attrName, value); 255 PersistenceManager.store(instance); 256 } 257 258 264 public void checkAdministrativeAction(RunData data) throws SecurityException 265 { 266 if (!JetspeedSecurity.hasAdminRole(data.getUser())) 267 { 268 if (logger.isWarnEnabled()) 269 { 270 logger.warn( 271 "User [" 272 + data.getUser().getUserName() 273 + "] attempted to perform administrative action"); 274 } 275 throw new SecurityException ( 276 "User [" 277 + data.getUser().getUserName() 278 + "] must be an administrator to perform this action"); 279 } 280 } 281 } 282 | Popular Tags |