@Override public int getAttributesScope(String name) { if (getAttribute(name) != null) { return PAGE_SCOPE; } else if (getAttribute(name, REQUEST_SCOPE) != null) { return REQUEST_SCOPE; } else if (getAttribute(name, SESSION_SCOPE) != null) { return SESSION_SCOPE; } else if (getAttribute(name, APPLICATION_SCOPE) != null) { return APPLICATION_SCOPE; } else { return 0; } }
@Override @Nullable public Object findAttribute(String name) { Object value = getAttribute(name); if (value == null) { value = getAttribute(name, REQUEST_SCOPE); if (value == null) { value = getAttribute(name, SESSION_SCOPE); if (value == null) { value = getAttribute(name, APPLICATION_SCOPE); } } } return value; }
@Override @Nullable public Object getAttribute(String name, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: return getAttribute(name); case REQUEST_SCOPE: return this.request.getAttribute(name); case SESSION_SCOPE: HttpSession session = this.request.getSession(false); return (session != null ? session.getAttribute(name) : null); case APPLICATION_SCOPE: return this.servletContext.getAttribute(name); default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
@Test public void setAttributeWithNoScopeUsesPageScope() throws Exception { ctx.setAttribute(key, value); assertEquals(value, ctx.getAttribute(key, PageContext.PAGE_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.REQUEST_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.SESSION_SCOPE)); }
@Test public void removeAttributeWithNoScopeSpecifiedRemovesValueFromAllScopes() throws Exception { ctx.setAttribute(key, value, PageContext.APPLICATION_SCOPE); ctx.removeAttribute(key); assertNull(ctx.getAttribute(key, PageContext.PAGE_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.REQUEST_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.SESSION_SCOPE)); }
@Override public Object findAttribute(String name) { Object value = getAttribute(name); if (value == null) { value = getAttribute(name, REQUEST_SCOPE); if (value == null) { value = getAttribute(name, SESSION_SCOPE); if (value == null) { value = getAttribute(name, APPLICATION_SCOPE); } } } return value; }
@Override public int getAttributesScope(String name) { if (getAttribute(name) != null) { return PAGE_SCOPE; } else if (getAttribute(name, REQUEST_SCOPE) != null) { return REQUEST_SCOPE; } else if (getAttribute(name, SESSION_SCOPE) != null) { return SESSION_SCOPE; } else if (getAttribute(name, APPLICATION_SCOPE) != null) { return APPLICATION_SCOPE; } else { return 0; } }
@Override public int getAttributesScope(String name) { if (getAttribute(name) != null) { return PAGE_SCOPE; } else if (getAttribute(name, REQUEST_SCOPE) != null) { return REQUEST_SCOPE; } else if (getAttribute(name, SESSION_SCOPE) != null) { return SESSION_SCOPE; } else if (getAttribute(name, APPLICATION_SCOPE) != null) { return APPLICATION_SCOPE; } else { return 0; } }
@Override @Nullable public Object findAttribute(String name) { Object value = getAttribute(name); if (value == null) { value = getAttribute(name, REQUEST_SCOPE); if (value == null) { value = getAttribute(name, SESSION_SCOPE); if (value == null) { value = getAttribute(name, APPLICATION_SCOPE); } } } return value; }
@Override public Object getAttribute(String name, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: return getAttribute(name); case REQUEST_SCOPE: return this.request.getAttribute(name); case SESSION_SCOPE: HttpSession session = this.request.getSession(false); return (session != null ? session.getAttribute(name) : null); case APPLICATION_SCOPE: return this.servletContext.getAttribute(name); default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
@Override @Nullable public Object getAttribute(String name, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: return getAttribute(name); case REQUEST_SCOPE: return this.request.getAttribute(name); case SESSION_SCOPE: HttpSession session = this.request.getSession(false); return (session != null ? session.getAttribute(name) : null); case APPLICATION_SCOPE: return this.servletContext.getAttribute(name); default: throw new IllegalArgumentException("Invalid scope: " + scope); } }