| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.portlet; |
| 17 | |
|
| 18 | |
import java.io.IOException; |
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.Enumeration; |
| 21 | |
import java.util.HashMap; |
| 22 | |
import java.util.Iterator; |
| 23 | |
import java.util.List; |
| 24 | |
import java.util.Map; |
| 25 | |
|
| 26 | |
import javax.faces.FactoryFinder; |
| 27 | |
import javax.faces.application.FacesMessage; |
| 28 | |
import javax.faces.application.StateManager; |
| 29 | |
import javax.faces.context.ExternalContext; |
| 30 | |
import javax.faces.context.FacesContext; |
| 31 | |
import javax.faces.context.FacesContextFactory; |
| 32 | |
import javax.faces.internal.WebAppUtil; |
| 33 | |
import javax.faces.internal.WindowIdUtil; |
| 34 | |
import javax.faces.internal.scope.PageScope; |
| 35 | |
import javax.faces.internal.scope.RedirectScope; |
| 36 | |
import javax.faces.lifecycle.Lifecycle; |
| 37 | |
import javax.faces.lifecycle.LifecycleFactory; |
| 38 | |
import javax.faces.webapp.FacesServlet; |
| 39 | |
import javax.portlet.ActionRequest; |
| 40 | |
import javax.portlet.ActionResponse; |
| 41 | |
import javax.portlet.GenericPortlet; |
| 42 | |
import javax.portlet.PortletContext; |
| 43 | |
import javax.portlet.PortletException; |
| 44 | |
import javax.portlet.PortletRequest; |
| 45 | |
import javax.portlet.PortletSession; |
| 46 | |
import javax.portlet.RenderRequest; |
| 47 | |
import javax.portlet.RenderResponse; |
| 48 | |
import javax.servlet.ServletException; |
| 49 | |
|
| 50 | |
import org.seasar.framework.log.Logger; |
| 51 | |
import org.seasar.teeda.core.JsfConstants; |
| 52 | |
import org.seasar.teeda.core.util.DIContainerUtil; |
| 53 | |
import org.seasar.teeda.core.util.ErrorPageManager; |
| 54 | |
import org.seasar.teeda.core.util.NullErrorPageManagerImpl; |
| 55 | |
import org.seasar.teeda.core.util.PortletUtil; |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | 0 | public class FacesPortlet extends GenericPortlet { |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | 0 | private static final Logger logger = Logger.getLogger(FacesPortlet.class); |
| 66 | |
|
| 67 | |
public static final String PORTLET_CONFIG = "javax.portlet.PortletConfig"; |
| 68 | |
|
| 69 | 0 | public static final String VIEW_ID = FacesPortlet.class.getName() + |
| 70 | |
".VIEW_ID"; |
| 71 | |
|
| 72 | 0 | public static final String DEFAULT_PAGE = FacesPortlet.class.getName() + |
| 73 | |
".DEFAULT_PAGE"; |
| 74 | |
|
| 75 | |
public static final String DEFAULT_VIEW_PAGE = "view-page"; |
| 76 | |
|
| 77 | |
public static final String DEFAULT_EDIT_PAGE = "edit-page"; |
| 78 | |
|
| 79 | |
public static final String DEFAULT_HELP_PAGE = "help-page"; |
| 80 | |
|
| 81 | 0 | public static final String FACES_PORTLET_STATE_PREFIX = FacesPortlet.class |
| 82 | |
.getName() + |
| 83 | |
".FACES_PORTLET_STATE" + "-"; |
| 84 | |
|
| 85 | 0 | public static final String PREVIOUS_PORTLET_MODE = FacesPortlet.class |
| 86 | |
.getName() + |
| 87 | |
".PREVIOUS_PORTLET_MODE"; |
| 88 | |
|
| 89 | 0 | public static final String CURRENT_PORTLET_MODE = FacesPortlet.class |
| 90 | |
.getName() + |
| 91 | |
".CURRENT_PORTLET_MODE"; |
| 92 | |
|
| 93 | 0 | public static final String EXCLUDED_ATTRIBUTE_LIST = FacesPortlet.class |
| 94 | |
.getName() + |
| 95 | |
".EXCLUDED_ATTRIBUTE_LIST"; |
| 96 | |
|
| 97 | 0 | public static final String REDEPLOYED_PORTLET = FacesPortlet.class |
| 98 | |
.getName() + |
| 99 | |
".REDEPLOYED_PORTLET"; |
| 100 | |
|
| 101 | 0 | public static final String RENDER_PARAMETER = FacesPortlet.class.getName() + |
| 102 | |
".RENDER_PARAMETER"; |
| 103 | |
|
| 104 | |
protected FacesContextFactory facesContextFactory; |
| 105 | |
|
| 106 | |
protected Lifecycle lifecycle; |
| 107 | |
|
| 108 | 0 | private String defaultViewPage = null; |
| 109 | |
|
| 110 | 0 | private String defaultEditPage = null; |
| 111 | |
|
| 112 | 0 | private String defaultHelpPage = null; |
| 113 | |
|
| 114 | |
public void init() throws PortletException { |
| 115 | 0 | super.init(); |
| 116 | |
|
| 117 | |
|
| 118 | 0 | defaultViewPage = getPortletConfig() |
| 119 | |
.getInitParameter(DEFAULT_VIEW_PAGE); |
| 120 | 0 | defaultEditPage = getPortletConfig() |
| 121 | |
.getInitParameter(DEFAULT_EDIT_PAGE); |
| 122 | 0 | defaultHelpPage = getPortletConfig() |
| 123 | |
.getInitParameter(DEFAULT_HELP_PAGE); |
| 124 | 0 | if (null == defaultViewPage) { |
| 125 | |
|
| 126 | 0 | throw new PortletException("Portlet " + |
| 127 | |
getPortletConfig().getPortletName() + |
| 128 | |
" is incorrectly configured. No default View page is defined."); |
| 129 | |
} |
| 130 | 0 | if (null == defaultEditPage) { |
| 131 | 0 | defaultEditPage = defaultViewPage; |
| 132 | |
} |
| 133 | 0 | if (null == defaultHelpPage) { |
| 134 | 0 | defaultHelpPage = defaultViewPage; |
| 135 | |
} |
| 136 | |
|
| 137 | |
|
| 138 | |
LifecycleFactory lifecycleFactory; |
| 139 | |
try { |
| 140 | 0 | facesContextFactory = (FacesContextFactory) WebAppUtil |
| 141 | |
.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); |
| 142 | 0 | lifecycleFactory = (LifecycleFactory) WebAppUtil |
| 143 | |
.getFactory(FactoryFinder.LIFECYCLE_FACTORY); |
| 144 | 0 | String lifecycleId = getLifecycleId(getPortletContext()); |
| 145 | 0 | lifecycle = lifecycleFactory.getLifecycle(lifecycleId); |
| 146 | 0 | } catch (ServletException e) { |
| 147 | 0 | throw new PortletException(e); |
| 148 | 0 | } |
| 149 | 0 | } |
| 150 | |
|
| 151 | |
protected String getLifecycleId(PortletContext portletContext) { |
| 152 | 0 | String lifecycleId = portletContext |
| 153 | |
.getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR); |
| 154 | 0 | if (lifecycleId == null) { |
| 155 | 0 | lifecycleId = LifecycleFactory.DEFAULT_LIFECYCLE; |
| 156 | |
} |
| 157 | 0 | return lifecycleId; |
| 158 | |
} |
| 159 | |
|
| 160 | |
public void destroy() { |
| 161 | 0 | super.destroy(); |
| 162 | 0 | FactoryFinder.releaseFactories(); |
| 163 | 0 | facesContextFactory = null; |
| 164 | 0 | lifecycle = null; |
| 165 | 0 | defaultViewPage = null; |
| 166 | 0 | defaultEditPage = null; |
| 167 | 0 | defaultHelpPage = null; |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
protected void doEdit(RenderRequest request, RenderResponse response) |
| 175 | |
throws PortletException, IOException { |
| 176 | 0 | setContentType(request, response); |
| 177 | 0 | setDefaultPage(request, defaultEditPage); |
| 178 | 0 | renderFaces(request, response); |
| 179 | 0 | } |
| 180 | |
|
| 181 | |
protected void doHelp(RenderRequest request, RenderResponse response) |
| 182 | |
throws PortletException, IOException { |
| 183 | 0 | setContentType(request, response); |
| 184 | 0 | setDefaultPage(request, defaultHelpPage); |
| 185 | 0 | renderFaces(request, response); |
| 186 | 0 | } |
| 187 | |
|
| 188 | |
protected void doView(RenderRequest request, RenderResponse response) |
| 189 | |
throws PortletException, IOException { |
| 190 | 0 | setContentType(request, response); |
| 191 | 0 | setDefaultPage(request, defaultViewPage); |
| 192 | 0 | renderFaces(request, response); |
| 193 | 0 | } |
| 194 | |
|
| 195 | |
protected void setContentType(RenderRequest request, RenderResponse response) { |
| 196 | |
|
| 197 | 0 | if (response.getContentType() == null) { |
| 198 | 0 | String portalPreferredContentType = request |
| 199 | |
.getResponseContentType(); |
| 200 | 0 | if (portalPreferredContentType != null) { |
| 201 | 0 | response.setContentType(portalPreferredContentType); |
| 202 | |
} else { |
| 203 | 0 | response.setContentType("text/html"); |
| 204 | |
} |
| 205 | |
} |
| 206 | 0 | } |
| 207 | |
|
| 208 | |
protected void setDefaultPage(PortletRequest request, String page) { |
| 209 | 0 | if (request.getAttribute(DEFAULT_PAGE) == null) { |
| 210 | 0 | request.setAttribute(DEFAULT_PAGE, page); |
| 211 | |
} |
| 212 | 0 | } |
| 213 | |
|
| 214 | |
private void storePortletConfig(PortletRequest request) { |
| 215 | 0 | request.setAttribute(PORTLET_CONFIG, getPortletConfig()); |
| 216 | 0 | } |
| 217 | |
|
| 218 | |
private void setCurrentPortletMode(PortletRequest request) { |
| 219 | 0 | request.setAttribute(CURRENT_PORTLET_MODE, request.getPortletMode() |
| 220 | |
.toString()); |
| 221 | 0 | } |
| 222 | |
|
| 223 | |
protected void renderFaces(RenderRequest request, RenderResponse response) |
| 224 | |
throws PortletException, java.io.IOException { |
| 225 | 0 | if (logger.isDebugEnabled()) { |
| 226 | 0 | logger.debug("called renderFaces.."); |
| 227 | |
} |
| 228 | |
|
| 229 | |
|
| 230 | 0 | createExcludedAttributeList(request); |
| 231 | |
|
| 232 | |
|
| 233 | 0 | restoreErrorInfo(request); |
| 234 | |
|
| 235 | 0 | storePortletConfig(request); |
| 236 | 0 | setCurrentPortletMode(request); |
| 237 | |
|
| 238 | 0 | FacesContext facesContext = facesContextFactory.getFacesContext( |
| 239 | |
getPortletContext(), request, response, lifecycle); |
| 240 | 0 | request.setAttribute(JsfConstants.FACES_CONTEXT, facesContext); |
| 241 | |
|
| 242 | 0 | String redirectPath = null; |
| 243 | |
try { |
| 244 | 0 | WindowIdUtil.setupWindowId(facesContext.getExternalContext()); |
| 245 | 0 | final Map pageScope = PageScope.getOrCreateContext(facesContext); |
| 246 | 0 | synchronized (pageScope) { |
| 247 | 0 | restoreFacesState(facesContext); |
| 248 | 0 | lifecycle.render(facesContext); |
| 249 | 0 | } |
| 250 | 0 | saveFacesState(facesContext); |
| 251 | 0 | } catch (Throwable e) { |
| 252 | 0 | handleException(facesContext, e); |
| 253 | 0 | } finally { |
| 254 | 0 | redirectPath = RedirectScope.getRedirectingPath(facesContext); |
| 255 | 0 | if (redirectPath != null) { |
| 256 | |
|
| 257 | 0 | RedirectScope.removeContext(facesContext); |
| 258 | |
} |
| 259 | 0 | facesContext.release(); |
| 260 | 0 | request.getPortletSession().setAttribute(PREVIOUS_PORTLET_MODE, |
| 261 | |
request.getPortletMode().toString()); |
| 262 | 0 | request.getPortletSession().setAttribute(REDEPLOYED_PORTLET, |
| 263 | |
Boolean.FALSE); |
| 264 | 0 | } |
| 265 | |
|
| 266 | |
|
| 267 | 0 | if (redirectPath != null) { |
| 268 | 0 | redirectRenderFaces(request, response, redirectPath); |
| 269 | |
} |
| 270 | |
|
| 271 | |
|
| 272 | 0 | clearErrorInfo(request); |
| 273 | 0 | } |
| 274 | |
|
| 275 | |
protected void redirectRenderFaces(RenderRequest request, |
| 276 | |
RenderResponse response, String viewId) throws PortletException, |
| 277 | |
java.io.IOException { |
| 278 | 0 | if (logger.isDebugEnabled()) { |
| 279 | 0 | logger.debug("called redirectRenderFaces.. viewId is " + viewId); |
| 280 | |
} |
| 281 | |
|
| 282 | 0 | List excludedNameList = (List) request |
| 283 | |
.getAttribute(EXCLUDED_ATTRIBUTE_LIST); |
| 284 | |
|
| 285 | 0 | for (Enumeration e = request.getAttributeNames(); e.hasMoreElements();) { |
| 286 | 0 | String key = (String) e.nextElement(); |
| 287 | 0 | if (!excludedNameList.contains(key)) { |
| 288 | 0 | request.removeAttribute(key); |
| 289 | |
} |
| 290 | |
} |
| 291 | |
|
| 292 | 0 | request.getPortletSession().removeAttribute( |
| 293 | |
FacesPortlet.PREVIOUS_PORTLET_MODE); |
| 294 | 0 | request.setAttribute(FacesPortlet.DEFAULT_PAGE, viewId); |
| 295 | 0 | renderFaces(request, response); |
| 296 | |
|
| 297 | 0 | } |
| 298 | |
|
| 299 | |
protected void restoreFacesState(FacesContext facesContext) { |
| 300 | |
|
| 301 | 0 | Map sessionMap = facesContext.getExternalContext().getSessionMap(); |
| 302 | 0 | Map requestMap = facesContext.getExternalContext().getRequestMap(); |
| 303 | |
|
| 304 | 0 | String currentPortletMode = (String) requestMap |
| 305 | |
.get(CURRENT_PORTLET_MODE); |
| 306 | 0 | String previousPortletMode = (String) sessionMap |
| 307 | |
.get(PREVIOUS_PORTLET_MODE); |
| 308 | |
|
| 309 | 0 | FacesPortletState state = null; |
| 310 | 0 | if (previousPortletMode != null && |
| 311 | |
previousPortletMode.equals(currentPortletMode)) { |
| 312 | 0 | state = (FacesPortletState) sessionMap |
| 313 | |
.get(FACES_PORTLET_STATE_PREFIX + currentPortletMode); |
| 314 | 0 | if (state == null) { |
| 315 | |
|
| 316 | 0 | Map requestParameterMap = facesContext.getExternalContext() |
| 317 | |
.getRequestParameterMap(); |
| 318 | 0 | String viewId = (String) requestParameterMap.get(VIEW_ID); |
| 319 | 0 | if (viewId != null && !checkSessionState(facesContext)) { |
| 320 | 0 | requestMap.put(VIEW_ID, viewId); |
| 321 | |
} |
| 322 | |
|
| 323 | 0 | restoreView(facesContext); |
| 324 | 0 | return; |
| 325 | |
} else { |
| 326 | |
|
| 327 | 0 | String viewId = state.getViewId(); |
| 328 | 0 | requestMap.put(VIEW_ID, viewId); |
| 329 | |
|
| 330 | |
|
| 331 | 0 | restoreView(facesContext); |
| 332 | |
|
| 333 | |
|
| 334 | 0 | Iterator clientIds = state.getClientIds(); |
| 335 | 0 | while (clientIds.hasNext()) { |
| 336 | 0 | String clientId = (String) clientIds.next(); |
| 337 | 0 | Iterator msgs = state.getMessages(clientId); |
| 338 | 0 | while (msgs.hasNext()) { |
| 339 | 0 | facesContext.addMessage(clientId, (FacesMessage) msgs |
| 340 | |
.next()); |
| 341 | |
} |
| 342 | |
} |
| 343 | |
|
| 344 | |
|
| 345 | 0 | copyMap(state.getRequestMap(), facesContext |
| 346 | |
.getExternalContext().getRequestMap(), new ArrayList()); |
| 347 | |
|
| 348 | |
|
| 349 | 0 | Object s = state.getState(); |
| 350 | 0 | if (s != null) { |
| 351 | 0 | facesContext.getViewRoot().processRestoreState( |
| 352 | |
facesContext, s); |
| 353 | |
} |
| 354 | |
|
| 355 | |
} |
| 356 | |
} else { |
| 357 | |
|
| 358 | 0 | restoreDefaultFacesState(facesContext); |
| 359 | |
} |
| 360 | |
|
| 361 | 0 | } |
| 362 | |
|
| 363 | |
protected void restoreDefaultFacesState(FacesContext facesContext) { |
| 364 | 0 | ExternalContext externalContext = facesContext.getExternalContext(); |
| 365 | 0 | Map requestMap = externalContext.getRequestMap(); |
| 366 | |
|
| 367 | 0 | String viewId = (String) externalContext.getRequestMap().get( |
| 368 | |
DEFAULT_PAGE); |
| 369 | 0 | requestMap.put(VIEW_ID, viewId); |
| 370 | |
|
| 371 | |
|
| 372 | 0 | for (Iterator i = externalContext.getSessionMap().entrySet().iterator(); i |
| 373 | 0 | .hasNext();) { |
| 374 | 0 | Map.Entry e = (Map.Entry) i.next(); |
| 375 | 0 | if (e.getKey() instanceof String) { |
| 376 | 0 | String key = (String) e.getKey(); |
| 377 | 0 | if (key.startsWith(FACES_PORTLET_STATE_PREFIX)) { |
| 378 | 0 | externalContext.getSessionMap().remove(key); |
| 379 | |
} |
| 380 | |
} |
| 381 | |
} |
| 382 | |
|
| 383 | |
|
| 384 | 0 | if (RedirectScope.isRedirecting(facesContext)) { |
| 385 | 0 | RedirectScope.removeContext(facesContext); |
| 386 | |
} |
| 387 | |
|
| 388 | 0 | restoreView(facesContext); |
| 389 | 0 | } |
| 390 | |
|
| 391 | |
private void restoreView(FacesContext facesContext) { |
| 392 | 0 | facesContext.renderResponse(); |
| 393 | |
|
| 394 | 0 | lifecycle.execute(facesContext); |
| 395 | 0 | } |
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
public void processAction(ActionRequest request, ActionResponse response) |
| 402 | |
throws PortletException, IOException { |
| 403 | 0 | if (logger.isDebugEnabled()) { |
| 404 | 0 | logger.debug("called processAction.."); |
| 405 | |
} |
| 406 | |
|
| 407 | |
|
| 408 | 0 | if (checkSessionState(request)) { |
| 409 | 0 | return; |
| 410 | |
} |
| 411 | |
|
| 412 | 0 | String viewId = request.getParameter(VIEW_ID); |
| 413 | 0 | if (viewId != null) { |
| 414 | 0 | request.setAttribute(VIEW_ID, viewId); |
| 415 | 0 | executeFaces(request, response); |
| 416 | |
} else { |
| 417 | 0 | if (logger.isDebugEnabled()) { |
| 418 | 0 | logger.debug("skip processAction because viewId is null."); |
| 419 | |
} |
| 420 | |
} |
| 421 | 0 | } |
| 422 | |
|
| 423 | |
protected void executeFaces(ActionRequest request, ActionResponse response) |
| 424 | |
throws PortletException, IOException { |
| 425 | |
|
| 426 | 0 | storePortletConfig(request); |
| 427 | 0 | setCurrentPortletMode(request); |
| 428 | |
|
| 429 | |
|
| 430 | 0 | createExcludedAttributeList(request); |
| 431 | |
|
| 432 | 0 | FacesContext facesContext = facesContextFactory.getFacesContext( |
| 433 | |
getPortletContext(), request, response, lifecycle); |
| 434 | |
|
| 435 | |
try { |
| 436 | 0 | WindowIdUtil.setupWindowId(facesContext.getExternalContext()); |
| 437 | 0 | final Map pageScope = PageScope.getOrCreateContext(facesContext); |
| 438 | 0 | synchronized (pageScope) { |
| 439 | 0 | lifecycle.execute(facesContext); |
| 440 | 0 | } |
| 441 | 0 | } catch (Throwable e) { |
| 442 | 0 | handleException(facesContext, e); |
| 443 | 0 | } finally { |
| 444 | 0 | if (!facesContext.getResponseComplete()) { |
| 445 | 0 | request.setAttribute(VIEW_ID, facesContext.getViewRoot() |
| 446 | |
.getViewId()); |
| 447 | 0 | saveFacesState(facesContext); |
| 448 | 0 | if (request.getParameter(RENDER_PARAMETER) != null) { |
| 449 | 0 | setRenderParameters(request, response); |
| 450 | |
} |
| 451 | 0 | } else if (RedirectScope.isRedirecting(facesContext)) { |
| 452 | 0 | saveFacesState(facesContext); |
| 453 | |
} |
| 454 | |
|
| 455 | 0 | facesContext.release(); |
| 456 | 0 | } |
| 457 | 0 | } |
| 458 | |
|
| 459 | |
protected void saveFacesState(FacesContext facesContext) { |
| 460 | 0 | Map sessionMap = facesContext.getExternalContext().getSessionMap(); |
| 461 | 0 | Map requestMap = facesContext.getExternalContext().getRequestMap(); |
| 462 | |
|
| 463 | |
|
| 464 | 0 | String currentPortletMode = (String) requestMap |
| 465 | |
.get(CURRENT_PORTLET_MODE); |
| 466 | 0 | sessionMap.put(PREVIOUS_PORTLET_MODE, currentPortletMode); |
| 467 | |
|
| 468 | 0 | FacesPortletState state = new FacesPortletState(); |
| 469 | |
|
| 470 | 0 | if (!PortletUtil.isRender(facesContext)) { |
| 471 | |
|
| 472 | 0 | Iterator clientIds = facesContext.getClientIdsWithMessages(); |
| 473 | 0 | while (clientIds.hasNext()) { |
| 474 | 0 | String clientId = (String) clientIds.next(); |
| 475 | 0 | Iterator msgs = facesContext.getMessages(clientId); |
| 476 | 0 | while (msgs.hasNext()) { |
| 477 | 0 | state.addMessage(clientId, (FacesMessage) msgs.next()); |
| 478 | |
} |
| 479 | |
} |
| 480 | |
} |
| 481 | |
|
| 482 | 0 | String redirectPath = RedirectScope.getRedirectingPath(facesContext); |
| 483 | 0 | if (redirectPath == null) { |
| 484 | 0 | state.setViewId(facesContext.getViewRoot().getViewId()); |
| 485 | |
|
| 486 | 0 | List excludedNameList = (List) requestMap |
| 487 | |
.get(EXCLUDED_ATTRIBUTE_LIST); |
| 488 | |
|
| 489 | 0 | Map map = new HashMap(); |
| 490 | 0 | copyMap(requestMap, map, excludedNameList); |
| 491 | 0 | state.setRequestMap(map); |
| 492 | |
|
| 493 | |
|
| 494 | 0 | StateManager stateManager = facesContext.getApplication() |
| 495 | |
.getStateManager(); |
| 496 | 0 | stateManager.saveSerializedView(facesContext); |
| 497 | |
|
| 498 | |
|
| 499 | 0 | state.setState(facesContext.getViewRoot().processSaveState( |
| 500 | |
facesContext)); |
| 501 | |
} else { |
| 502 | |
|
| 503 | 0 | state.setViewId(redirectPath); |
| 504 | |
|
| 505 | |
|
| 506 | 0 | Map map = new HashMap(); |
| 507 | 0 | state.setRequestMap(map); |
| 508 | |
|
| 509 | |
|
| 510 | 0 | state.setState(null); |
| 511 | |
} |
| 512 | |
|
| 513 | |
|
| 514 | 0 | sessionMap.put(FACES_PORTLET_STATE_PREFIX + currentPortletMode, state); |
| 515 | |
|
| 516 | 0 | } |
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | |
protected void handleException(FacesContext context, Throwable e) |
| 523 | |
throws PortletException, IOException { |
| 524 | 0 | ErrorPageManager errorPageManager = null; |
| 525 | |
try { |
| 526 | 0 | errorPageManager = (ErrorPageManager) DIContainerUtil |
| 527 | |
.getComponent(ErrorPageManager.class); |
| 528 | 0 | } catch (Exception e1) { |
| 529 | 0 | } |
| 530 | 0 | if (errorPageManager == null) { |
| 531 | 0 | errorPageManager = new NullErrorPageManagerImpl(); |
| 532 | |
} |
| 533 | |
|
| 534 | 0 | ExternalContext extContext = context.getExternalContext(); |
| 535 | 0 | if (errorPageManager.handleException(e, context, extContext)) { |
| 536 | 0 | context.responseComplete(); |
| 537 | |
} else { |
| 538 | 0 | if (e instanceof IOException) { |
| 539 | 0 | throw (IOException) e; |
| 540 | 0 | } else if (e instanceof PortletException) { |
| 541 | 0 | throw (PortletException) e; |
| 542 | 0 | } else if (e.getMessage() != null) { |
| 543 | 0 | throw new PortletException(e.getMessage(), e); |
| 544 | |
} |
| 545 | 0 | throw new PortletException(e); |
| 546 | |
} |
| 547 | 0 | } |
| 548 | |
|
| 549 | |
protected boolean checkSessionState(PortletRequest request) { |
| 550 | 0 | return request.getPortletSession(false) == null || |
| 551 | |
(request.getPortletSession().getAttribute(REDEPLOYED_PORTLET) == null); |
| 552 | |
} |
| 553 | |
|
| 554 | |
protected boolean checkSessionState(FacesContext context) { |
| 555 | 0 | return context.getExternalContext().getSession(false) == null || |
| 556 | |
(context.getExternalContext().getSessionMap().get( |
| 557 | |
REDEPLOYED_PORTLET) == null); |
| 558 | |
} |
| 559 | |
|
| 560 | |
protected void createExcludedAttributeList(PortletRequest request) { |
| 561 | |
|
| 562 | 0 | ArrayList excludedNameList = new ArrayList(); |
| 563 | 0 | Enumeration enu = request.getAttributeNames(); |
| 564 | 0 | while (enu.hasMoreElements()) { |
| 565 | 0 | excludedNameList.add(enu.nextElement()); |
| 566 | |
} |
| 567 | |
|
| 568 | 0 | excludedNameList.add(EXCLUDED_ATTRIBUTE_LIST); |
| 569 | 0 | excludedNameList.add(JsfConstants.FACES_CONTEXT); |
| 570 | 0 | request.setAttribute(EXCLUDED_ATTRIBUTE_LIST, excludedNameList); |
| 571 | 0 | } |
| 572 | |
|
| 573 | |
private void copyMap(Map fromMap, Map toMap, List excludedNameList) { |
| 574 | 0 | for (Iterator i = fromMap.entrySet().iterator(); i.hasNext();) { |
| 575 | 0 | Map.Entry e = (Map.Entry) i.next(); |
| 576 | 0 | if (!toMap.containsKey((String) e.getKey()) && |
| 577 | |
!excludedNameList.contains((String) e.getKey())) { |
| 578 | 0 | toMap.put(e.getKey(), e.getValue()); |
| 579 | |
} |
| 580 | |
} |
| 581 | 0 | } |
| 582 | |
|
| 583 | |
protected void setRenderParameters(ActionRequest request, |
| 584 | |
ActionResponse response) { |
| 585 | 0 | Enumeration enu = request.getParameterNames(); |
| 586 | 0 | while (enu.hasMoreElements()) { |
| 587 | 0 | String key = (String) enu.nextElement(); |
| 588 | 0 | response.setRenderParameter(key, request.getParameter(key)); |
| 589 | |
} |
| 590 | 0 | } |
| 591 | |
|
| 592 | |
protected void restoreErrorInfo(PortletRequest request) { |
| 593 | 0 | PortletSession portletSession = request.getPortletSession(); |
| 594 | 0 | Throwable exception = (Throwable) portletSession |
| 595 | |
.getAttribute(JsfConstants.ERROR_EXCEPTION); |
| 596 | 0 | if (exception != null) { |
| 597 | 0 | request.setAttribute(JsfConstants.ERROR_EXCEPTION, exception); |
| 598 | 0 | request.setAttribute(JsfConstants.ERROR_EXCEPTION_TYPE, exception |
| 599 | |
.getClass()); |
| 600 | 0 | request.setAttribute(JsfConstants.ERROR_MESSAGE, exception |
| 601 | |
.getMessage()); |
| 602 | |
} |
| 603 | 0 | } |
| 604 | |
|
| 605 | |
protected void clearErrorInfo(PortletRequest request) { |
| 606 | 0 | request.getPortletSession().removeAttribute( |
| 607 | |
JsfConstants.ERROR_EXCEPTION); |
| 608 | 0 | } |
| 609 | |
} |