List of usage examples for javax.servlet.jsp PageContext getAttribute
abstract public Object getAttribute(String name, int scope);
From source file:org.apache.struts.taglib.TagUtils.java
/** * Returns true if the custom tags are in XHTML mode. *//* w w w .j av a 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./*from ww w . j a v a 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.tiles.util.TagUtils.java
/** * Get object from requested context. Return <code>null</code> if not found. * Context can be "component" or normal JSP contexts. * @param beanName Name of bean to retrieve. * @param scope Scope from which bean must be retrieved. * @param pageContext Current pageContext. * @return Requested bean or <code>null</code> if not found. *///from ww w . j a v a 2s . c om public static Object getAttribute(String beanName, int scope, PageContext pageContext) { if (scope == ComponentConstants.COMPONENT_SCOPE) { ComponentContext compContext = ComponentContext.getContext(pageContext.getRequest()); return compContext.getAttribute(beanName); } return pageContext.getAttribute(beanName, scope); }
From source file:org.apache.tiles.jsp.context.JspUtil.java
/** * Returns true if forced include of the result is needed. * * @param context The page context.// w w w .j a va 2 s.c o m * @return If <code>true</code> the include operation must be forced. * @since 2.0.6 */ public static boolean isForceInclude(PageContext context) { Boolean retValue = (Boolean) context.getAttribute(ServletUtil.FORCE_INCLUDE_ATTRIBUTE_NAME, PageContext.REQUEST_SCOPE); return retValue != null && retValue.booleanValue(); }
From source file:org.apache.tiles.jsp.context.JspUtil.java
/** * Returns a specific Tiles container.//from w ww . j ava 2 s .c om * * @param context The page context to use. * @param key The key under which the container is stored. If null, the * default container will be returned. * @return The requested Tiles container. * @since 2.1.2 */ public static TilesContainer getContainer(PageContext context, String key) { if (key == null) { key = TilesAccess.CONTAINER_ATTRIBUTE; } return (TilesContainer) context.getAttribute(key, PageContext.APPLICATION_SCOPE); }
From source file:org.apache.tiles.jsp.context.JspUtil.java
/** * Returns the current container that has been set, or the default one. * * @param context The page context to use. * @return The current Tiles container to use in web pages. * @since 2.1.0/*from ww w . ja va 2 s.co m*/ */ public static TilesContainer getCurrentContainer(PageContext context) { TilesContainer container = (TilesContainer) context .getAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME, PageContext.REQUEST_SCOPE); if (container == null) { container = getContainer(context); context.setAttribute(ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME, container, PageContext.REQUEST_SCOPE); } return container; }
From source file:org.araneaframework.jsp.tag.uilib.form.UiFormKeyboardHandlerTag.java
/** * Given elementId relative wrt the form inside which the tag is located, appends the relevant prefix to it to obtain fullElementId. * @see #setElementId/*from w w w.j av a 2s. com*/ * @param elementId may not be null! */ public static final String elementIdToFullElementId(PageContext pageContext, String elementId) { // Determine the full id. String fullElementId = elementId; String scope = (String) pageContext.getAttribute(UiFormTag.FORM_SCOPED_FULL_ID_KEY_REQUEST, PageContext.REQUEST_SCOPE); if (!StringUtils.isBlank(scope)) fullElementId = scope + "." + elementId; return fullElementId; }
From source file:org.displaytag.util.LookupUtil.java
/** * Read an object from the pagecontext with the specified scope and eventually lookup a property in it. * @param pageContext PageContext//from w ww . ja v a 2s .c o m * @param beanAndPropertyName String expression with bean name and attributes * @param scope One of the following values: * <ul> * <li>PageContext.PAGE_SCOPE</li> * <li>PageContext.REQUEST_SCOPE</li> * <li>PageContext.SESSION_SCOPE</li> * <li>PageContext.APPLICATION_SCOPE</li> * </ul> * @return Object * @throws ObjectLookupException for errors while retrieving a property in the bean */ public static Object getBeanValue(PageContext pageContext, String beanAndPropertyName, int scope) throws ObjectLookupException { if (beanAndPropertyName.indexOf(".") != -1) { // complex: property from a bean String objectName = beanAndPropertyName.substring(0, beanAndPropertyName.indexOf(".")); String beanProperty = beanAndPropertyName.substring(beanAndPropertyName.indexOf(".") + 1); Object beanObject; if (log.isDebugEnabled()) { log.debug("getBeanValue - bean: {" + objectName + "}, property: {" + beanProperty + "}"); } // get the bean beanObject = pageContext.getAttribute(objectName, scope); // if null return if (beanObject == null) { return null; } // go get the property return getBeanProperty(beanObject, beanProperty); } // simple, only the javabean if (log.isDebugEnabled()) { log.debug("getBeanValue - bean: {" + beanAndPropertyName + "}"); } return pageContext.getAttribute(beanAndPropertyName, scope); }
From source file:org.hyperic.hq.ui.taglib.display.TableTag.java
/** * This functionality is borrowed from struts, but I've removed some struts * specific features so that this tag can be used both in a struts * application, and outside of one.//w w w. j a v a 2 s . c o m * * 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. * * @param pageContext * Page context to be searched * @param name * Name of the bean to be retrieved * @param scope * Scope to be searched (page, request, session, application) or * <code>null</code> to use <code>findAttribute()</code> instead * * @exception JspException * if an invalid scope name is requested */ public Object lookup(PageContext pageContext, String name, String scope) throws JspException { Object bean = null; if (scope == null) bean = pageContext.findAttribute(name); else if (scope.equalsIgnoreCase("page")) bean = pageContext.getAttribute(name, PageContext.PAGE_SCOPE); else if (scope.equalsIgnoreCase("request")) bean = pageContext.getAttribute(name, PageContext.REQUEST_SCOPE); else if (scope.equalsIgnoreCase("session")) bean = pageContext.getAttribute(name, PageContext.SESSION_SCOPE); else if (scope.equalsIgnoreCase("application")) bean = pageContext.getAttribute(name, PageContext.APPLICATION_SCOPE); else { Object[] objs = { name, scope }; if (prop.getProperty("error.msg.cant_find_bean") != null) { String msg = MessageFormat.format(prop.getProperty("error.msg.cant_find_bean"), objs); throw new JspException(msg); } else { throw new JspException("Could not find " + name + " in scope " + scope); } } return (bean); }
From source file:org.jahia.taglibs.template.include.OptionTag.java
public static void renderNodeWithViewAndTypes(JCRNodeWrapper node, String view, String commaConcatenatedNodeTypes, PageContext pageContext, Map<String, String> parameters) throws RepositoryException, IOException, RenderException { String charset = pageContext.getResponse().getCharacterEncoding(); // Todo test if module is active RenderContext renderContext = (RenderContext) pageContext.getAttribute("renderContext", PageContext.REQUEST_SCOPE);//from ww w. j av a 2 s . co m Resource currentResource = (Resource) pageContext.getAttribute("currentResource", PageContext.REQUEST_SCOPE); String[] nodeTypes = StringUtils.split(commaConcatenatedNodeTypes, ","); if (nodeTypes.length > 0) { final String primaryNodeType = nodeTypes[0]; if (node.isNodeType(primaryNodeType)) { ExtendedNodeType mixinNodeType = NodeTypeRegistry.getInstance().getNodeType(primaryNodeType); // create a resource to render the current node with the specified view Resource wrappedResource = new Resource(node, currentResource.getTemplateType(), view, Resource.CONFIGURATION_INCLUDE); wrappedResource.setResourceNodeType(mixinNodeType); // set parameters for (Map.Entry<String, String> param : parameters.entrySet()) { wrappedResource.getModuleParams().put(URLDecoder.decode(param.getKey(), charset), URLDecoder.decode(param.getValue(), charset)); } // attempt to resolve script for the newly created resource Script script = null; try { script = RenderService.getInstance().resolveScript(wrappedResource, renderContext); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } catch (TemplateNotFoundException e) { // if we didn't find a script, attempt to locate one based on secondary node type if one was specified if (nodeTypes.length > 1) { mixinNodeType = NodeTypeRegistry.getInstance().getNodeType(nodeTypes[1]); wrappedResource.setResourceNodeType(mixinNodeType); script = RenderService.getInstance().resolveScript(wrappedResource, renderContext); } } // if we have found a script, render it if (script != null) { final ServletRequest request = pageContext.getRequest(); //save environment Object currentNode = request.getAttribute("currentNode"); Resource currentOption = (Resource) request.getAttribute("optionResource"); // set attributes to render the newly created resource request.setAttribute("optionResource", currentResource); request.setAttribute("currentNode", node); request.setAttribute("currentResource", wrappedResource); try { pageContext.getOut().write(script.execute(wrappedResource, renderContext)); } finally { // restore environment as it previously was request.setAttribute("optionResource", currentOption); request.setAttribute("currentNode", currentNode); request.setAttribute("currentResource", currentResource); } } } } }