1 16 17 package org.springframework.web.portlet.mvc; 18 19 import javax.portlet.ActionRequest; 20 import javax.portlet.ActionResponse; 21 import javax.portlet.PortletException; 22 import javax.portlet.PortletSession; 23 import javax.portlet.RenderRequest; 24 import javax.portlet.RenderResponse; 25 import javax.portlet.WindowState; 26 27 import org.springframework.web.portlet.ModelAndView; 28 import org.springframework.web.portlet.handler.PortletContentGenerator; 29 import org.springframework.web.portlet.util.PortletUtils; 30 31 125 public abstract class AbstractController extends PortletContentGenerator implements Controller { 126 127 private boolean synchronizeOnSession = false; 128 129 private boolean renderWhenMinimized = false; 130 131 132 151 public final void setSynchronizeOnSession(boolean synchronizeOnSession) { 152 this.synchronizeOnSession = synchronizeOnSession; 153 } 154 155 158 public final boolean isSynchronizeOnSession() { 159 return synchronizeOnSession; 160 } 161 162 168 public void setRenderWhenMinimized(boolean renderWhenMinimized) { 169 this.renderWhenMinimized = renderWhenMinimized; 170 } 171 172 175 public boolean isRenderWhenMinimized() { 176 return renderWhenMinimized; 177 } 178 179 180 public final void handleActionRequest(ActionRequest request, ActionResponse response) 181 throws Exception { 182 183 check(request, response); 185 186 if (this.synchronizeOnSession) { 188 PortletSession session = request.getPortletSession(false); 189 if (session != null) { 190 synchronized (session) { 191 handleActionRequestInternal(request, response); 192 return; 193 } 194 } 195 } 196 197 handleActionRequestInternal(request, response); 198 } 199 200 public final ModelAndView handleRenderRequest(RenderRequest request, RenderResponse response) 201 throws Exception { 202 203 if (WindowState.MINIMIZED.equals(request.getWindowState()) && !this.renderWhenMinimized) { 205 return null; 206 } 207 208 checkAndPrepare(request, response); 210 211 if (this.synchronizeOnSession) { 213 PortletSession session = request.getPortletSession(false); 214 if (session != null) { 215 Object mutex = PortletUtils.getSessionMutex(session); 216 synchronized (mutex) { 217 return handleRenderRequestInternal(request, response); 218 } 219 } 220 } 221 222 return handleRenderRequestInternal(request, response); 223 } 224 225 226 234 protected void handleActionRequestInternal(ActionRequest request, ActionResponse response) 235 throws Exception { 236 237 throw new PortletException("[" + getClass().getName() + "] does not handle action requests"); 238 } 239 240 248 protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) 249 throws Exception { 250 251 throw new PortletException("[" + getClass().getName() + "] does not handle render requests"); 252 } 253 254 } 255 | Popular Tags |