connectioncontext.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,389 行 · 第 1/5 页
JAVA
2,389 行
// discard preferences from action stage LinkingPortletPreferences pref = _windowContext.getPreferences(); if (pref != null) pref.discard(); // response handler _windowContext.setParentResponseHandler(parentResponseHandler); ResponseHandler responseHandler = parentResponseHandler; Renderer renderer = _windowContext.getWindow().getRenderer(); if (renderer != null) { BufferFactory bufferFactory = getPortal().getBufferFactory(); int rendererBufferSize = renderer.getBufferSize(); if (bufferFactory != null && rendererBufferSize != 0) { responseHandler = new BufferedResponseHandler( responseHandler, bufferFactory, rendererBufferSize ); } responseHandler = new RendererResponseHandler( this, responseHandler, renderer, getRenderRequest(), getRenderResponse(), namespace ); } int bufferSize = _windowContext.getWindow().getBufferSize(); if (bufferSize != 0) { BufferFactory bufferFactory = getPortal().getBufferFactory(); if (bufferFactory != null) { responseHandler = new BufferedResponseHandler( responseHandler, bufferFactory, bufferSize ); } } _windowContext.setResponseHandler(responseHandler); boolean isPrivate = _windowContext.getWindow().isPrivate(); if (isPrivate) { _windowContext.setPrivate(); setConnectionPrivate(); } // set request attributes _connection.setAttribute( "javax.portlet.portletConfig", getWindow().getPortletConfig()); Map<String, String> requestAttributes = resetWindowRequestAttributes(); _windowContext.setWindowRequestAttributes(requestAttributes); // check for exception failures from previous stage if (_windowContext.isException()) { if (log.isLoggable(Level.FINE)) log(Level.FINE, "previous exception"); finishRender(); return null; } // constraints if (!_windowContext.isConstraintFailure()) checkConstraints(); if (_windowContext.isConstraintFailure()) { if (!handleConstraintFailure()) { if (log.isLoggable(Level.FINE)) log(Level.FINE, "constraint failure unhandled, propagating to parent"); } else { if (log.isLoggable(Level.FINER)) { if (_windowContext.isExcluded()) log(Level.FINER, "constraint failure handled, excluding"); else log(Level.FINER, "constraint failure handled by window"); } } finishRender(); return null; } // XXX: cache caching int expirationCache = _windowContext.getExpirationCache(); if (expirationCache != 0 && (!isPrivate || getRequestedSessionId() != null)) { _windowContext.setExpirationCache(expirationCache); } Cache cache = getPortal().getCache(); CacheKey cacheKey = null; if (cache != null) cacheKey = getCacheKey(); if (cacheKey != null) { int result = cache.respondFromCache( cacheKey, getRenderRequest(), getRenderResponse() ); if (result != 0) { updateConnectionExpirationCache(result); return null; } CachingResponseHandler cacheResponseHandler = new CachingResponseHandler( _windowContext.getResponseHandler(), cache, _windowContext.getNamespace(), _windowContext.getExpirationCache(), _windowContext.isPrivate() ); _windowContext.setResponseHandler(cacheResponseHandler); } return getCurrentRender(); } public RenderRequest getRenderRequest() { if (_stage != STAGE_RENDER || _windowContext.isExcluded() ) return null; else return _renderRequest; } public RenderResponse getRenderResponse() { if (_stage != STAGE_RENDER || _windowContext.isExcluded() ) return null; else return _renderResponse; } public void render(Portlet portlet) throws PortletException, IOException { if ( _stage != STAGE_RENDER ) throw new IllegalStateException("not in render stage"); if (log.isLoggable(Level.FINEST)) log(Level.FINEST, "render()"); if (_windowContext.getException() == null && !_windowContext.isExcluded() && !_windowContext.isConstraintFailure()) { try { portlet.render(getRenderRequest(), getRenderResponse()); } catch (Exception ex) { if (log.isLoggable(Level.FINE)) log(Level.FINE, ex.toString(), ex); _windowContext.setException(ex); } } } public Render getCurrentRender() { return _stage == STAGE_RENDER ? _render : null; } void finishRender() throws IOException, PortletException { boolean fail = true; try { if (_windowContext == null) { throw new IllegalStateException( "cannot finish render, at top of stack"); } Map<String, String> requestAttributes = _windowContext.getWindowRequestAttributes(); if (_stage != STAGE_RENDER && _stage != STAGE_DONE) { throw new IllegalStateException( "cannot finish render for " + _windowContext.getNamespace() + ", stage is " + _stage); } if (_windowContext.isException()) { try { reset(false); // do not resetRenderer handleException(); if (log.isLoggable(Level.FINE)) { if (_windowContext.isException()) log(Level.FINE, "exception unhandled, propagating to parent"); else if (_windowContext.isExcluded()) log(Level.FINER, "exception handled, excluding"); else log(Level.FINER, "exception handled by window"); } } catch (Exception ex) { log.log(Level.WARNING, ex.toString(), ex); } } Exception exception = _windowContext.getException(); boolean isException = exception != null; boolean isConstraintFailure = _windowContext.isConstraintFailure(); Constraint constraintFailureConstraint = _windowContext.getConstraintFailureConstraint(); int constraintFailureCode = _windowContext.getConstraintFailureCode(); boolean killResponse = _windowContext.isExcluded() || isConstraintFailure || isException; if (killResponse) { if (log.isLoggable(Level.FINEST)) { if (isException) log(Level.FINEST, "killResponse due to exception"); else if (_windowContext.isConstraintFailure()) log(Level.FINEST, "killResponse due to constraintFailure"); else log(Level.FINEST, "killResponse"); } reset(true); // resetRenderer } // unwind the write streams and finish() them ResponseHandler parentResponseHandler = _windowContext.getParentResponseHandler(); CachingResponseHandler cacheResponseHandler = null; ResponseHandler next = _windowContext.getResponseHandler(); while ( next != null && next != parentResponseHandler ) { ResponseHandler responseHandler = next; next = next.getSuccessor(); try { if (!killResponse && !isException) { responseHandler.flushBuffer(); } if (responseHandler instanceof CachingResponseHandler) cacheResponseHandler = (CachingResponseHandler) responseHandler; else responseHandler.finish(); } catch (Exception ex) { if (!isException) { isException = true; exception = ex; } else { if (log.isLoggable(Level.FINEST)) { log(Level.FINEST, "exception while finishing response handlers: " + ex.toString(), ex); } } } } String expirationCacheAttribute = (String) _connection.getAttribute(EXPIRATION_CACHE); _connection.removeAttribute(EXPIRATION_CACHE); // caching if (cacheResponseHandler != null) { if (killResponse) { cacheResponseHandler.finish( 0, null, null ); } else { try { int expirationCache = _windowContext.getExpirationCache(); CacheKey cacheKey = null; if (expirationCache != 0 && expirationCacheAttribute != null) expirationCache = Integer.parseInt(expirationCacheAttribute); if (expirationCache != 0) cacheKey = getCacheKey(); cacheResponseHandler.finish( expirationCache, cacheKey, getWindowRequestAttributes() ); } catch (Exception ex) { if (!isException) { isException = true; exception = ex; } } } } WindowContext windowContext = _windowContext; String namespace = _windowContext.getNamespace(); try { popStack(); } finally { windowContext.finish(); } if (isConstraintFailure) { if (_windowContext != null) { if (log.isLoggable(Level.FINEST)) log(namespace, Level.FINEST, "propagating constraint failure " + constraintFailureConstraint.getClass().getName() + " to parent"); _windowContext.setConstraintFailure( constraintFailureConstraint, constraintFailureCode ); } else { if (log.isLoggable(Level.FINEST)) log(namespace, Level.FINEST, "propagating constraint failure " + constraintFailureConstraint.getClass().getName() + " to connection"); boolean handled = _connection.handleConstraintFailure( constraintFailureConstraint, constraintFailureCode ); if (!handled && !isException) { isException = true; exception = new PortletException( "Constraint failure " + constraintFailureConstraint.getClass().getName() + "(" + constraintFailureCode + ")"); } } } if (isException) { if (_windowContext != null) { if (log.isLoggable(Level.FINEST)) log(namespace, Level.FINEST, "propagating exception " + exception.getClass().getName() + " to parent"); _windowContext.setException(exception); } else { if (log.isLoggable(Level.FINEST)) log(namespace, Level.FINEST, "propagating exception " + exception.getClass().getName() + " to connection"); try { boolean handled = _connection.handleException( exception ); if (!handled) setConnectionFailed(exception); } catch (Exception ex) { setConnectionFailed(exception); log.log(Level.WARNING, ex.toString(), ex); } } } if (_windowContext == null) { if (log.isLoggable(Level.FINER)) log(Level.FINER, "finishing render stage"); _stage = STAGE_DONE; _connection.setAttribute( "javax.portlet.portletConfig", null ); } else { _connection.setAttribute( "javax.portlet.portletConfig", getWindow().getPortletConfig()); } restoreWindowRequestAttributes(requestAttributes); fail = false; } catch (RuntimeException ex) { setConnectionFailed(ex); throw ex; } finally { if (fail) setConnectionFailed(); } } /** * @throws IllegalStateException if the window with the namespace * has already been processed as the target of an action, or already * renderered. * * @throws IllegalArgumentException if the window with the namespace * is not found */ protected void checkWindowMutable(String namespace) throws IllegalStateException, IllegalArgumentException { WindowContext windowContext = _windowContextMap.get(namespace); if (windowContext == null) throw new IllegalArgumentException( "namespace `" + namespace + "' not known"); if (windowContext.getActionMap() != null && !namespace.equals(getNamespace())) throw new IllegalStateException( "already did processAction() for namespace `" + namespace + "'"); if (windowContext.getNamespace() == null) throw new IllegalStateException( "already did render() for namespace `" + namespace + "'"); } protected Window getWindow() { return _windowContext.getWindow(); } protected Window getWindow(String namespace) { WindowContext windowContext = _windowContextMap.get(namespace); return windowContext == null ? null : windowContext.getWindow(); } protected String getNamespace() { return _windowContext.getNamespace(); } protected Renderer getRenderer() { return _windowContext.getWindow().getRenderer(); } protected Renderer getRenderer(String namespace) { WindowContext windowContext = _windowContextMap.get(namespace);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?