Example usage for javax.servlet ServletRequest getAttribute

List of usage examples for javax.servlet ServletRequest getAttribute

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Usage

From source file:org.opencms.file.history.CmsHistoryResourceHandler.java

/**
 * Returns <code>true</code> if the given request is displaying an historical version.<p> 
 * /*  w ww .j  a v a2s.c o m*/
 * @param req the request to check
 * 
 * @return <code>true</code> if the given request is displaying a historical version
 */
public static boolean isHistoryRequest(ServletRequest req) {

    return (null != req.getAttribute(ATTRIBUTE_NAME));
}

From source file:com.cognifide.slice.api.tag.SliceTagUtils.java

private static SlingScriptHelper getSlingScriptHelper(final PageContext pageContext) {
    ServletRequest request = pageContext.getRequest();
    SlingBindings bindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
    return bindings.getSling();
}

From source file:org.opencms.file.history.CmsHistoryResourceHandler.java

/**
 * Returns the historical version of a resource, 
 * if the given request is displaying a history version.<p> 
 * //from   w ww .  j  a  v a  2s  . c  o  m
 * @param req the request to check
 * 
 * @return the historical resource if the given request is displaying an historical version
 */
public static I_CmsHistoryResource getHistoryResource(ServletRequest req) {

    return (I_CmsHistoryResource) req.getAttribute(ATTRIBUTE_NAME);
}

From source file:be.iminds.aiolos.ui.CommonServlet.java

@SuppressWarnings("unchecked")
public static Map<Object, Object> getProperties(final ServletRequest request) {
    final Object resolverObj = request.getAttribute("felix.webconsole.variable.resolver");
    if (resolverObj instanceof Map<?, ?>) {
        return (Map<Object, Object>) resolverObj;
    }//from   w w  w . ja  v  a  2 s  .  co m

    final Map<Object, Object> resolver = new HashMap<Object, Object>();
    request.setAttribute("felix.webconsole.variable.resolver", resolver);
    return resolver;
}

From source file:com.redhat.rhn.frontend.taglibs.list.RadioColumnTag.java

static String getRadioValue(ServletRequest request, String listName) {
    String value = (String) request.getAttribute(getRadioName(listName));
    if (StringUtils.isBlank(value)) {
        value = request.getParameter(getRadioName(listName));
        if (StringUtils.isBlank(value)) {
            value = request.getParameter(getRadioHidden(listName));
            if (StringUtils.isBlank(value)) {
                value = (String) request.getAttribute(getDefaultValueName(listName));
            }/*w  w  w .  j  ava 2  s  . c  om*/
        }
    }
    request.setAttribute(getRadioName(listName), value);
    return value;
}

From source file:ru.org.linux.site.Template.java

public static Template getTemplate(ServletRequest request) {
    return (Template) request.getAttribute("template");
}

From source file:org.apache.tiles.servlet.context.ServletUtil.java

/**
 * Returns the current container that has been set, or the default one.
 *
 * @param request The request to use./*  w  w  w  .ja v a 2 s.c o m*/
 * @param context The servlet context to use.
 * @return The current Tiles container to use in web pages.
 * @since 2.1.0
 */
public static TilesContainer getCurrentContainer(ServletRequest request, ServletContext context) {
    TilesContainer container = (TilesContainer) request.getAttribute(CURRENT_CONTAINER_ATTRIBUTE_NAME);
    if (container == null) {
        container = getContainer(context);
        request.setAttribute(CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
    }

    return container;
}

From source file:org.apache.struts.tiles.DefinitionsUtil.java

/**
 * Get Definition stored in jsp context by an action.
 * @return ComponentDefinition or null if not found.
 */// w w w. jav a  2  s  .c  om
public static ComponentDefinition getActionDefinition(ServletRequest request) {
    return (ComponentDefinition) request.getAttribute(ACTION_DEFINITION);
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagHelper.java

/**
 * Returns a set declaration associated to this list
 * if it was previously bound./*from w w w . j  a  v a 2 s.  c  o  m*/
 * @param listName the name of the list to who holds the set.
 *                  Note: this must be a Unique Name ..
 *                  See bindSetDeclTo method for more info.
 * @param request the servlet request object
 * @return returns the set declaration label associated to the list.
 */
public static String lookupSetDeclFor(String listName, ServletRequest request) {
    String selectedName = makeSetDeclAttributeName(listName);
    return (String) request.getAttribute(selectedName);
}

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  a  v  a2s.c  o  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);
                }
            }
        }
    }
}