List of usage examples for javax.servlet.jsp PageContext getAttribute
abstract public Object getAttribute(String name, int scope);
From source file:org.sakaiproject.iclicker.tool.ToolController.java
@SuppressWarnings("unchecked") public static String[] getMessages(PageContext context, String key) { if (context == null || key == null) { throw new IllegalArgumentException( "context (" + context + ") and key (" + key + ") must both not be null"); }// w ww.ja v a 2 s . co m String[] messages; String keyVal = ICLICKER_MESSAGES + key; if (context.getAttribute(keyVal, PageContext.REQUEST_SCOPE) == null) { messages = new String[] {}; } else { List<String> l = (List<String>) context.getAttribute(keyVal, PageContext.REQUEST_SCOPE); messages = l.toArray(new String[l.size()]); } return messages; }
From source file:javax.faces.webapp.UIComponentTag.java
/** * Return the nearest JSF tag that encloses this tag. *//* www . j av a 2 s . c o m*/ public static UIComponentTag getParentUIComponentTag(PageContext pageContext) { // Question: why not just walk up the _parent chain testing for // instanceof UIComponentTag rather than maintaining a separate // stack with the pushTag and popTag methods? List list = (List) pageContext.getAttribute(COMPONENT_STACK_ATTR, PageContext.REQUEST_SCOPE); if (list != null) { return (UIComponentTag) list.get(list.size() - 1); } return null; }
From source file:com.feilong.taglib.util.TagUtils.java
/** * Locate and return the specified bean, from an optionally specified scope, in the specified page context. If no such bean is found, * return <code>null</code> instead. If an exception is thrown, it will have already been saved via a call to * <code>saveException()</code>. * /*w w w .ja v a 2 s. co m*/ * @param pageContext * Page context to be searched * @param name * Name of the bean to be retrieved * @param scopeName * Scope to be searched (page, request, session, application) or <code>null</code> to use <code>findAttribute()</code> * instead * @return JavaBean in the specified page context * @throws JspException * if an invalid scope name is requested */ public Object lookup(PageContext pageContext, String name, String scopeName) throws JspException { if (scopeName == null) { return pageContext.findAttribute(name); } try { return pageContext.getAttribute(name, instance.getScope(scopeName)); } catch (JspException e) { throw e; } }
From source file:com.adito.core.CoreUtil.java
/** * Dump tile attributes to {@link System#err}. * /*from ww w .j a v a 2 s . c om*/ * @param pageContext page context from which to get tile. */ public static void dumpTileScope(PageContext pageContext) { ComponentContext compContext = (ComponentContext) pageContext .getAttribute(ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE); System.err.println("Tile attributes"); for (Iterator i = compContext.getAttributeNames(); i.hasNext();) { String n = (String) i.next(); System.err.println(" " + n + " = " + compContext.getAttribute(n)); } }
From source file:com.adito.core.CoreUtil.java
/** * @param pageContext/*from ww w . ja va 2 s . c om*/ */ public static void dumpComponentContext(PageContext pageContext) { ComponentContext compContext = (ComponentContext) pageContext .getAttribute(ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE); if (log.isInfoEnabled()) log.info("Component context dump"); for (Iterator e = compContext.getAttributeNames(); e.hasNext();) { String n = (String) e.next(); Object value = compContext.getAttribute(n); if (log.isInfoEnabled()) log.info(" " + n + " = " + value); } }
From source file:eionet.cr.util.Util.java
/** * * @param pageContext//w ww . j a va2 s . c o m * @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.glaf.core.tag.TagUtils.java
/** * Locate and return the specified bean, from an optionally specified scope, * in the specified page context. If no such bean is found, return * <code>null</code> instead. If an exception is thrown, it will have * already been saved via a call to <code>saveException()</code>. * /* www. j av a 2s . co m*/ * @param pageContext * Page context to be searched * @param name * Name of the bean to be retrieved * @param scopeName * Scope to be searched (page, request, session, application) or * <code>null</code> to use <code>findAttribute()</code> instead * @return JavaBean in the specified page context * @throws JspException * if an invalid scope name is requested */ public Object lookup(PageContext pageContext, String name, String scopeName) throws JspException { if (scopeName == null) { return pageContext.findAttribute(name); } try { return pageContext.getAttribute(name, instance.getScope(scopeName)); } catch (JspException e) { saveException(pageContext, e); throw e; } }
From source file:com.glaf.core.tag.TagUtils.java
/** * Returns the appropriate MessageResources object for the current module * and the given bundle./*from w w w . ja va 2 s .c o m*/ * * @param pageContext * Search the context's scopes for the resources. * @param bundle * The bundle name to look for. If this is <code>null</code>, the * default bundle name is used. * @param checkPageScope * Whether to check page scope * @return MessageResources The bundle's resources stored in some scope. * @throws JspException * if the MessageResources object could not be found. */ public MessageResources retrieveMessageResources(PageContext pageContext, String bundle, boolean checkPageScope) throws JspException { MessageResources resources = null; if (bundle == null) { bundle = conf.get("i18n.messages_key"); } if (bundle == null) { bundle = Globals.MESSAGES_KEY; } if (checkPageScope) { resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.PAGE_SCOPE); } if (resources == null) { resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.REQUEST_SCOPE); } if (resources == null) { resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.APPLICATION_SCOPE); } if (resources == null) { resources = (MessageResources) pageContext.getAttribute(Globals.DEFAULT_RESOURCE_NAME, PageContext.APPLICATION_SCOPE); if (resources == null) { resources = PropertyMessageResourcesFactory.createFactory() .createResources(Globals.DEFAULT_RESOURCE_NAME); pageContext.setAttribute(Globals.DEFAULT_RESOURCE_NAME, resources, PageContext.APPLICATION_SCOPE); } } if (resources == null) { JspException e = new JspException(messages.getMessage("message.bundle", bundle)); saveException(pageContext, e); throw e; } return resources; }
From source file:de.innovationgate.wgpublisher.WGACore.java
public static WGACore retrieve(PageContext pageContext) { return (WGACore) pageContext.getAttribute(ATTRIB_CORE, PageContext.APPLICATION_SCOPE); }
From source file:org.apache.struts.taglib.TagUtils.java
/** * Return the form action converted into a server-relative URL. *//*from w w w. j a v a 2 s. c o m*/ public String getActionMappingURL(String action, String module, PageContext pageContext, boolean contextRelative) { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String contextPath = request.getContextPath(); StringBuffer value = new StringBuffer(); // Avoid setting two slashes at the beginning of an action: // the length of contextPath should be more than 1 // in case of non-root context, otherwise length==1 (the slash) if (contextPath.length() > 1) { value.append(contextPath); } ModuleConfig moduleConfig = getModuleConfig(module, pageContext); if ((moduleConfig != null) && (!contextRelative)) { value.append(moduleConfig.getPrefix()); } // Use our servlet mapping, if one is specified String servletMapping = (String) pageContext.getAttribute(Globals.SERVLET_KEY, PageContext.APPLICATION_SCOPE); if (servletMapping != null) { String queryString = null; int question = action.indexOf("?"); if (question >= 0) { queryString = action.substring(question); } String actionMapping = getActionMappingName(action); if (servletMapping.startsWith("*.")) { value.append(actionMapping); value.append(servletMapping.substring(1)); } else if (servletMapping.endsWith("/*")) { value.append(servletMapping.substring(0, servletMapping.length() - 2)); value.append(actionMapping); } else if (servletMapping.equals("/")) { value.append(actionMapping); } if (queryString != null) { value.append(queryString); } } // Otherwise, assume extension mapping is in use and extension is // already included in the action property else { if (!action.startsWith("/")) { value.append("/"); } value.append(action); } return value.toString(); }