List of usage examples for javax.servlet.jsp PageContext SESSION_SCOPE
int SESSION_SCOPE
To view the source code for javax.servlet.jsp PageContext SESSION_SCOPE.
Click Source Link
From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java
@Override public Object getAttribute(String key, int scope) { switch (scope) { case PageContext.REQUEST_SCOPE: return request.getAttribute(key); case PageContext.APPLICATION_SCOPE: return servletCtx.getAttribute(key); case PageContext.SESSION_SCOPE: if (session != null) { return session.getAttribute(key); }// w ww . ja v a2 s. c o m return null; default: return pageAttributes.get(key); } }
From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*from w w w. j a v a2s .c o m*/ public Enumeration getAttributeNamesInScope(int scope) { switch (scope) { case PageContext.REQUEST_SCOPE: return request.getAttributeNames(); case PageContext.SESSION_SCOPE: if (session != null) { return session.getAttributeNames(); } return IteratorUtils.asEnumeration(IteratorUtils.EMPTY_ITERATOR); case PageContext.APPLICATION_SCOPE: return servletCtx.getAttributeNames(); default: return IteratorUtils.asEnumeration(pageAttributes.keySet().iterator()); } }
From source file:de.micromata.genome.gwiki.page.gspt.StandAlonePageContext.java
private static void assertValidScope(int scope, boolean allowSession, boolean allowApplication) { if ((scope < PageContext.PAGE_SCOPE) || (scope > PageContext.APPLICATION_SCOPE)) { throw new IllegalArgumentException("scope " + scope + " not supported"); }// ww w . ja va2 s . c om if ((allowSession == false) && (scope == PageContext.SESSION_SCOPE)) { throw new IllegalArgumentException("session scope not supported"); } }
From source file:org.openmrs.web.taglib.RequireTagTest.java
/** * @see RequireTag#doStartTag()/* ww w . jav a 2 s . c o m*/ */ @Test @SkipBaseSetup @Verifies(value = "should set the right session attributes if the authenticated user misses some privileges", method = "doStartTag()") public void doStartTag_shouldSetTheRightSessionAttributesIfTheAuthenticatedUserMissesSomePrivileges() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/RequireTagTest.xml"); Context.authenticate("whirleygiguser", "test"); RequireTag tag = new RequireTag(); MockPageContext pageContext = new MockPageContext(); final String referer = "/denied.htm"; ((MockHttpServletRequest) pageContext.getRequest()).addHeader("Referer", referer); tag.setPageContext(pageContext); tag.setAllPrivileges("Manage WhirleyGigs,Manage Thingamajigs"); String redirect = "/myRedirect.html"; tag.setRedirect(redirect); Assert.assertEquals(Tag.SKIP_PAGE, tag.doStartTag()); Assert.assertEquals(true, pageContext.getAttribute(WebConstants.INSUFFICIENT_PRIVILEGES, PageContext.SESSION_SCOPE)); Assert.assertNotNull(pageContext.getAttribute(WebConstants.REQUIRED_PRIVILEGES, PageContext.SESSION_SCOPE)); Assert.assertEquals(redirect, pageContext.getAttribute(WebConstants.DENIED_PAGE, PageContext.SESSION_SCOPE).toString()); Context.logout(); }
From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java
@Override public int getAttributesScope(String key) { if (pageAttributes.containsKey(key) == true) return PageContext.PAGE_SCOPE; if (contains(request.getAttributeNames(), key) == true) return PageContext.REQUEST_SCOPE; if (session != null) { if (contains(session.getAttributeNames(), key) == true) { return PageContext.SESSION_SCOPE; }/*from w w w .j a v a2 s. c o m*/ } if (contains(servletCtx.getAttributeNames(), key) == true) return PageContext.APPLICATION_SCOPE; return 0; }
From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java
@Override public void setAttribute(String key, Object value, int scope) { if (value == null) { removeAttribute(key, scope);// w w w . j a va 2 s . co m return; } switch (scope) { case PageContext.PAGE_SCOPE: pageAttributes.put(key, value); break; case PageContext.REQUEST_SCOPE: request.setAttribute(key, value); break; case PageContext.SESSION_SCOPE: if (session != null) { session.setAttribute(key, value); } break; case PageContext.APPLICATION_SCOPE: servletCtx.setAttribute(key, value); break; default: break; } }
From source file:eionet.cr.util.Util.java
/** * * @param pageContext/*from ww w .j a va 2 s .c om*/ * @param objectClass * @return */ public static Object findInAnyScope(PageContext pageContext, Class objectClass) { if (pageContext == null || objectClass == null) { return null; } int[] scopes = { PageContext.APPLICATION_SCOPE, PageContext.PAGE_SCOPE, PageContext.REQUEST_SCOPE, PageContext.SESSION_SCOPE }; for (int i = 0; i < scopes.length; i++) { Enumeration attrs = pageContext.getAttributeNamesInScope(scopes[i]); while (attrs != null && attrs.hasMoreElements()) { String name = (String) attrs.nextElement(); Object o = pageContext.getAttribute(name, scopes[i]); if (o != null && objectClass.isInstance(o)) { return o; } } } return null; }
From source file:com.geemvc.taglib.GeemvcTagSupport.java
protected Object attribute(String name) { Object bean = jspContext.getAttribute(name, PageContext.PAGE_SCOPE); if (bean == null) bean = jspContext.getAttribute(name, PageContext.REQUEST_SCOPE); if (bean == null) bean = jspContext.getAttribute(name, PageContext.SESSION_SCOPE); return bean;/* w w w . j a v a2 s. co m*/ }
From source file:org.openmrs.web.taglib.RequireTagTest.java
/** * @see RequireTag#doStartTag()//from w w w . j av a 2 s .c om */ @Test @SkipBaseSetup @Verifies(value = "should set the referer as the denied page url if no redirect url is specified", method = "doStartTag()") public void doStartTag_shouldSetTheRefererAsTheDeniedPageUrlIfNoRedirectUrlIsSpecified() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/RequireTagTest.xml"); Context.authenticate("whirleygiguser", "test"); RequireTag tag = new RequireTag(); MockPageContext pageContext = new MockPageContext(); final String referer = "/denied.htm"; ((MockHttpServletRequest) pageContext.getRequest()).addHeader("Referer", referer); tag.setPageContext(pageContext); tag.setAllPrivileges("Manage WhirleyGigs,Manage Thingamajigs"); tag.setRedirect(""); Assert.assertEquals(Tag.SKIP_PAGE, tag.doStartTag()); Assert.assertEquals(true, pageContext.getAttribute(WebConstants.INSUFFICIENT_PRIVILEGES, PageContext.SESSION_SCOPE)); Assert.assertNotNull(pageContext.getAttribute(WebConstants.REQUIRED_PRIVILEGES, PageContext.SESSION_SCOPE)); Assert.assertEquals(referer, pageContext.getAttribute(WebConstants.DENIED_PAGE, PageContext.SESSION_SCOPE).toString()); Context.logout(); }
From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java
@Override public void removeAttribute(String key, int scope) { switch (scope) { case PageContext.PAGE_SCOPE: pageAttributes.remove(key);/*from w ww .j a v a2 s. c o m*/ break; case PageContext.REQUEST_SCOPE: request.removeAttribute(key); break; case PageContext.SESSION_SCOPE: if (session != null) { session.removeAttribute(key); } break; case PageContext.APPLICATION_SCOPE: servletCtx.removeAttribute(key); break; default: break; } }