connectioncontext.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,389 行 · 第 1/5 页
JAVA
2,389 行
for (int i = startIndex; i < constraints.size(); i++) { _windowContext.setConstraintIndex(i + 1); Constraint constraint = constraints.get(i); int result = constraint.check(getPortletRequest(), getPortletResponse()); if (result == Constraint.SC_PASS) { } else if (result == Constraint.SC_EXCLUDE) { _windowContext.setExcluded(); if (log.isLoggable(Level.FINER)) log(Level.FINE, "constraint excludes window"); return; } else { _windowContext.setConstraintFailure(constraint, result); if (log.isLoggable(Level.FINER)) log(Level.FINE, "constraint failed: " + constraint.getClass().getName()); return; } } } /** * See if the Window can handle the constraint. Return true * if the constraint has been handled in some way. * * Side-effect: might set isExcluded to true */ protected boolean handleConstraintFailure() throws PortletException, IOException { final Constraint constraint = _windowContext.getConstraintFailureConstraint(); if (constraint == null) return true; if (log.isLoggable(Level.FINEST)) log(Level.FINEST, "handling constraint failure: " + constraint.getClass().getName()); final WindowContext windowContext = _windowContext; final int code = _windowContext.getConstraintFailureCode(); ConstraintFailureEvent event = new ConstraintFailureEvent() { public Constraint getConstraint() { return constraint; } public int getStatusCode() { return code; } public void setHandled(boolean hideWindow) { windowContext.setConstraintFailure(null, 0); if (hideWindow) windowContext.setExcluded(); } public boolean isHandled() { return !windowContext.isConstraintFailure(); } public boolean isHideWindow() { return windowContext.isExcluded(); } }; Window window = getWindow(); window.handleConstraintFailure( getRenderRequest(), getRenderResponse(), event ); return !windowContext.isConstraintFailure(); } private boolean startActionOrRender( Window window, String namespace, boolean isActionStage ) throws PortletException, IOException { if (log.isLoggable(Level.FINEST)) { log(Level.FINER, "portlet `" + window.getPortletConfig().getPortletName() + "' for namespace `" + namespace + "'"); } if (_windowContext != null && (_windowContext.isExcluded() || _windowContext.getException() != null || _windowContext.isConstraintFailure())) { if (log.isLoggable(Level.FINER)) { if (_windowContext.isExcluded()) log(Level.FINER, "child `" + namespace + "' excluded because parent is excluded"); else if (_windowContext.isException()) log(Level.FINER, "child `" + namespace + "' excluded because parent has exception"); else if (_windowContext.isConstraintFailure()) log(Level.FINER, "child `" + namespace + "' excluded because parent has constraint failure"); } return false; } boolean fail = true; try { boolean isTopLevel = _windowContextStack.size() == 0; // reuse a WindowContext prepared in a previous stage or create a new one WindowContext windowContext = namespace == null ? null : _windowContextMap.get(namespace); if (windowContext != null) { if (isActionStage) throw new PortletException( "duplicate namespace `" + namespace + "'"); else if (windowContext.getWindow() != window) throw new PortletException( "cannot have different Window" + " in render stage for namespace `" + namespace + "'"); // check if windowContext was excluded in previous stage if (windowContext.isExcluded()) { if (log.isLoggable(Level.FINER)) { if (_windowContext.isExcluded()) log(Level.FINER, "child `" + namespace + "' excluded in previous stage"); } fail = false; return false; } } else { windowContext = new WindowContext(); windowContext.start(window, namespace); if (windowContext.getNamespace() != null) { _windowContextMap.put(windowContext.getNamespace(), windowContext); // prepare invocation Invocation invocation = getInvocationFactory().getInvocation(namespace); windowContext.setInvocation(invocation); if (invocation.isActionTarget()) { log(Level.FINER, "action target"); Map<String, String[]> actionMap = invocation.releaseParameterMap(); windowContext.setActionMap(actionMap); } } } // set the Context to work on the new namespace pushStack(windowContext); if (_windowContext.getNamespace() == null && log.isLoggable(Level.FINER)) log(Level.FINER, "no invocation for null namespace"); if (isActionStage) { checkConstraints(); if (_windowContext.isConstraintFailure() || _windowContext.isExcluded()) { popStack(); fail = false; return false; } } fail = false; } catch (PortletException ex) { setConnectionFailed(ex); throw ex; } catch (RuntimeException ex) { setConnectionFailed(ex); throw new PortletException(ex); } finally { if (fail) { setConnectionFailed(); return false; } } return true; } public PortletRequest getPortletRequest() { return _portletRequest; } public PortletResponse getPortletResponse() { return _portletResponse; } public Action getAction( Window window, String namespace ) throws PortletException, IOException { if (isConnectionFailed()) return null; if (_stage == STAGE_START) { if (log.isLoggable(Level.FINER)) log(Level.FINER, "starting action stage"); _stage = STAGE_ACTION; } else if (_stage != STAGE_ACTION) { IllegalStateException ex = new IllegalStateException("missing finish()? " + _stage); setConnectionFailed(ex); throw ex; } if (!startActionOrRender(window, namespace, true)) return null; return getCurrentAction(); } public Action getCurrentAction() { return _stage == STAGE_ACTION ? _action : null; } public boolean isTarget() { return ( _stage == STAGE_ACTION && _windowContext.getActionMap() != null && !_windowContext.isExcluded() ); } public ActionRequest getActionRequest() { if ( _stage != STAGE_ACTION || _windowContext.isExcluded() ) return null; else return _actionRequest; } public ActionResponse getActionResponse() { if ( _stage != STAGE_ACTION || _windowContext.isExcluded() ) return null; else return _actionResponse; } public void processAction(Portlet portlet) { if ( _stage != STAGE_ACTION ) throw new IllegalStateException("not in action stage"); if (log.isLoggable(Level.FINEST)) log(Level.FINEST, "processAction()"); try { portlet.processAction(_actionRequest, _actionResponse); } catch (Exception ex) { if (log.isLoggable(Level.FINE)) log(Level.FINE, ex.toString(), ex); _windowContext.setException(ex); } } void finishAction() throws IOException, PortletException { boolean fail = true; try { if (_windowContext == null) { throw new IllegalStateException( "cannot finish action, at top of stack"); } if (_stage != STAGE_ACTION && _stage != STAGE_DONEACTION) { throw new IllegalStateException( "cannot finish action for " + _windowContext.getNamespace() + ", stage is " + _stage); } popStack(); if (_windowContext == null) { _stage = STAGE_DONEACTION; if (log.isLoggable(Level.FINER)) log(Level.FINER, "finishing action stage"); } fail = false; } catch (RuntimeException ex) { setConnectionFailed(ex); throw ex; } finally { if (fail) setConnectionFailed(); } } // XXX: this is bogus, see comments in CacheKey.java // about how the cache key should be built up. // Basically, every WindowContext that has an expirationCache !=0 // should have a CacheKey that get's filled with the invocation // for itself _and_ every child WindowContext during the action phase. private CacheKey getCacheKey() { CacheKey cacheKey = null; if (cacheKey == null) cacheKey = new CacheKey(); else cacheKey.reset(); WindowContext windowContext = _windowContext; if (windowContext.getNamespace() == null) return null; cacheKey.setNamespace(windowContext.getNamespace()); cacheKey.setPortletMode(getPortletMode()); cacheKey.setWindowState(getWindowState()); cacheKey.setContentType(getResponseContentType()); cacheKey.setLocale(getResponseLocale()); cacheKey.setPrivate(windowContext.isPrivate()); cacheKey.setRequestedSessionId(_connection.getRequestedSessionId()); return null; // XXX: } /** * Reset window specific attributes to null and return a map of the old * values */ private Map<String, String> resetWindowRequestAttributes() { Map<String, String> attr = null; attr = getAttribute(attr, "javax.portlet.title", true); attr = getAttribute(attr, "javax.portlet.short-title", true); attr = getAttribute(attr, "javax.portlet.keywords", true); attr = getAttribute(attr, "javax.portlet.description", true); return attr; } /** * Return a map of window specific request attributes, attributes with null * values are not included, the return may be null. */ private Map<String, String> getWindowRequestAttributes() { Map<String, String> attr = null; attr = getAttribute(attr, "javax.portlet.title", false); getAttribute(attr, "javax.portlet.short-title", false); getAttribute(attr, "javax.portlet.keywords", false); getAttribute(attr, "javax.portlet.description", false); return attr; } private Map<String, String> getAttribute( Map<String, String> map, String name, boolean isReset ) { String value = (String) _connection.getAttribute(name); if (isReset || value != null) { if (map == null) map = new LinkedHashMap<String, String>(); map.put(name, value); if (isReset) _connection.removeAttribute(name); } return map; } private void restoreWindowRequestAttributes(Map<String, String> map) { if (map != null && !map.isEmpty()) { Iterator<Map.Entry<String, String>> iter = map.entrySet().iterator(); do { Map.Entry<String, String> entry = iter.next(); _connection.setAttribute(entry.getKey(), entry.getValue()); } while (iter.hasNext()); } } public Render getRender( Window window, String namespace ) throws PortletException, IOException { if (isConnectionFailed()) return null; if (_stage == STAGE_START || _stage == STAGE_DONEACTION) { if (log.isLoggable(Level.FINER)) log(Level.FINER, "starting render stage"); _stage = STAGE_RENDER; _connection.setAttribute("javax.portlet.renderRequest", _renderRequest); _connection.setAttribute("javax.portlet.renderResponse", _renderResponse); } else if (_stage != STAGE_RENDER) { IllegalStateException ex = new IllegalStateException("missing finish()? " + _stage); setConnectionFailed(ex); throw ex; } checkAlwaysWriteOrStream(); ResponseHandler parentResponseHandler = _windowContext == null ? _topLevelResponseHandler : _windowContext.getResponseHandler(); if (!startActionOrRender(window, namespace, false)) return null;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?