List of usage examples for javax.servlet.jsp PageContext PAGE_SCOPE
int PAGE_SCOPE
To view the source code for javax.servlet.jsp PageContext PAGE_SCOPE.
Click Source Link
From source file:org.apache.sling.scripting.jsp.taglib.IncludeTagHandler.java
/** * Gets the int code for a valid scope, must be one of 'page', 'request', * 'session' or 'application'. If an invalid or no scope is specified page * scope is returned.//w w w . j a va 2s . c o m * * @param scope * @return */ private Integer validScope(String scope) { scope = (scope != null && scope.trim().length() > 0 ? scope.trim().toUpperCase() : null); if (scope == null) { return PageContext.PAGE_SCOPE; } String[] scopes = { "PAGE", "REQUEST", "SESSION", "APPLICATION" }; Integer[] iaScopes = { PageContext.PAGE_SCOPE, PageContext.REQUEST_SCOPE, PageContext.SESSION_SCOPE, PageContext.APPLICATION_SCOPE }; for (int ndx = 0, len = scopes.length; ndx < len; ndx++) { if (scopes[ndx].equals(scope)) { return iaScopes[ndx]; } } return PageContext.PAGE_SCOPE; }
From source file:org.apache.struts.taglib.bean.DefineTag.java
/** * Retrieve the required property and expose it as a scripting variable. * * @throws JspException if a JSP exception has occurred */// www . j a v a 2 s.c o m public int doEndTag() throws JspException { // Enforce restriction on ways to declare the new value int n = 0; if (this.body != null) { n++; } if (this.name != null) { n++; } if (this.value != null) { n++; } if (n > 1) { JspException e = new JspException(messages.getMessage("define.value", id)); TagUtils.getInstance().saveException(pageContext, e); throw e; } // Retrieve the required property value Object value = this.value; if ((value == null) && (name != null)) { value = TagUtils.getInstance().lookup(pageContext, name, property, scope); } if ((value == null) && (body != null)) { value = body; } if (value == null) { JspException e = new JspException(messages.getMessage("define.null", id)); TagUtils.getInstance().saveException(pageContext, e); throw e; } // Expose this value as a scripting variable int inScope = PageContext.PAGE_SCOPE; try { if (toScope != null) { inScope = TagUtils.getInstance().getScope(toScope); } } catch (JspException e) { log.warn("toScope was invalid name so we default to PAGE_SCOPE", e); } pageContext.setAttribute(id, value, inScope); // Continue processing this page return (EVAL_PAGE); }
From source file:org.apache.struts.taglib.TagUtils.java
/** * Returns true if the custom tags are in XHTML mode. */// w w w.j a va 2 s . c o m public boolean isXhtml(PageContext pageContext) { String xhtml = (String) pageContext.getAttribute(Globals.XHTML_KEY, PageContext.PAGE_SCOPE); return "true".equalsIgnoreCase(xhtml); }
From source file:org.apache.struts.taglib.TagUtils.java
/** * Returns the appropriate MessageResources object for the current module * and the given bundle./* w ww . j ava 2 s . c om*/ * * @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 = 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) { ModuleConfig moduleConfig = getModuleConfig(pageContext); resources = (MessageResources) pageContext.getAttribute(bundle + moduleConfig.getPrefix(), PageContext.APPLICATION_SCOPE); } if (resources == null) { resources = (MessageResources) pageContext.getAttribute(bundle, 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:org.apache.struts.taglib.TestTagUtils.java
public void donttestMessagePageBadKey() { putBundleInScope(PageContext.PAGE_SCOPE, true); String val = null; try {//from ww w. ja v a 2s .c om val = tagutils.message(pageContext, null, null, "foo.bar.does.not.exist"); fail("val should be null"); } catch (JspException e) { assertNull(val); } }
From source file:org.apache.struts.taglib.tiles.util.TagUtils.java
/** * Retrieve bean from page context, using specified scope. * If scope is not set, use <code>findAttribute()</code>. * * @param beanName Name of bean to retrieve. * @param scopeName Scope or <code>null</code>. If <code>null</code>, bean is searched using * findAttribute()./*from w w w . j a va2 s . c o m*/ * @param pageContext Current pageContext. * @return Requested bean or <code>null</code> if not found. * @throws JspException Scope name is not recognized as a valid scope. */ public static Object retrieveBean(String beanName, String scopeName, PageContext pageContext) throws JspException { if (scopeName == null) { return findAttribute(beanName, pageContext); } // Default value doesn't matter because we have already check it int scope = getScope(scopeName, PageContext.PAGE_SCOPE); //return pageContext.getAttribute( beanName, scope ); return getAttribute(beanName, scope, pageContext); }
From source file:org.apache.struts.taglib.tiles.util.TagUtils.java
/** * Store bean in requested context./*from w ww . j a va 2s.c o m*/ * If scope is <code>null</code>, save it in REQUEST_SCOPE context. * * @param pageContext Current pageContext. * @param name Name of the bean. * @param scope Scope under which bean is saved (page, request, session, application) * or <code>null</code> to store in <code>request()</code> instead. * @param value Bean value to store. * * @exception JspException Scope name is not recognized as a valid scope */ public static void setAttribute(PageContext pageContext, String name, Object value, String scope) throws JspException { if (scope == null) pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE); else if (scope.equalsIgnoreCase("page")) pageContext.setAttribute(name, value, PageContext.PAGE_SCOPE); else if (scope.equalsIgnoreCase("request")) pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE); else if (scope.equalsIgnoreCase("session")) pageContext.setAttribute(name, value, PageContext.SESSION_SCOPE); else if (scope.equalsIgnoreCase("application")) pageContext.setAttribute(name, value, PageContext.APPLICATION_SCOPE); else { throw new JspException("Error - bad scope name '" + scope + "'"); } }
From source file:org.apache.tiles.jsp.taglib.AttributeTagSupport.java
/** {@inheritDoc} */ @Override/* w w w . jav a 2 s . c om*/ protected void reset() { super.reset(); scopeName = null; scope = PageContext.PAGE_SCOPE; ignore = false; attribute = null; attributeValue = null; attributeContext = null; }
From source file:org.apache.tiles.jsp.taglib.AttributeTagSupport.java
/** * Get scope value from string value./*from w ww . java 2 s . com*/ * * @return Scope as an <code>int</code>, or <code>defaultValue</code> if scope is <code>null</code>. * @throws TilesJspException Scope name is not recognized as a valid scope. */ public int getScopeId() throws TilesJspException { if (scopeName == null) { return PageContext.PAGE_SCOPE; } return getScope(scopeName); }
From source file:org.apache.webapp.admin.AttributeTag.java
/** * Render the JMX MBean attribute identified by this tag * * @exception JspException if a processing exception occurs *///w ww . j a v a 2 s . c o m public int doEndTag() throws JspException { // Retrieve the object name identified by our attributes Object bean = null; if (scope == null) { bean = pageContext.findAttribute(name); } else if ("page".equalsIgnoreCase(scope)) { bean = pageContext.getAttribute(name, PageContext.PAGE_SCOPE); } else if ("request".equalsIgnoreCase(scope)) { bean = pageContext.getAttribute(name, PageContext.REQUEST_SCOPE); } else if ("session".equalsIgnoreCase(scope)) { bean = pageContext.getAttribute(name, PageContext.SESSION_SCOPE); } else if ("application".equalsIgnoreCase(scope)) { bean = pageContext.getAttribute(name, PageContext.APPLICATION_SCOPE); } else { throw new JspException("Invalid scope value '" + scope + "'"); } if (bean == null) { throw new JspException("No bean '" + name + "' found"); } if (property != null) { try { bean = PropertyUtils.getProperty(bean, property); } catch (Throwable t) { throw new JspException("Exception retrieving property '" + property + "': " + t); } if (bean == null) { throw new JspException("No property '" + property + "' found"); } } // Convert to an object name as necessary ObjectName oname = null; try { if (bean instanceof ObjectName) { oname = (ObjectName) bean; } else if (bean instanceof String) { oname = new ObjectName((String) bean); } else { oname = new ObjectName(bean.toString()); } } catch (Throwable t) { throw new JspException("Exception creating object name for '" + bean + "': " + t); } // Acquire a reference to our MBeanServer MBeanServer mserver = (MBeanServer) pageContext.getAttribute("org.apache.catalina.MBeanServer", PageContext.APPLICATION_SCOPE); if (mserver == null) throw new JspException("MBeanServer is not available"); // Retrieve the specified attribute from the specified MBean Object value = null; try { value = mserver.getAttribute(oname, attribute); } catch (Throwable t) { throw new JspException("Exception retrieving attribute '" + attribute + "'"); } // Render this value to our current output writer if (value != null) { JspWriter out = pageContext.getOut(); try { out.print(value); } catch (IOException e) { throw new JspException("IOException: " + e); } } // Evaluate the remainder of this page return (EVAL_PAGE); }