Example usage for javax.servlet ServletRequest setAttribute

List of usage examples for javax.servlet ServletRequest setAttribute

Introduction

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

Prototype

public void setAttribute(String name, Object o);

Source Link

Document

Stores an attribute in this request.

Usage

From source file:org.apache.felix.webconsole.WebConsoleUtil.java

/**
 * Sets the {@link VariableResolver} as the
 * {@link WebConsoleConstants#ATTR_CONSOLE_VARIABLE_RESOLVER}
 * attribute in the given request. An attribute of that name already
 * existing is silently replaced.//  w  ww . j  a va2s . co m
 *
 * @param request The request whose attribute is set
 * @param resolver The {@link VariableResolver} to place into the request
 */
public static void setVariableResolver(final ServletRequest request, final VariableResolver resolver) {
    request.setAttribute(WebConsoleConstants.ATTR_CONSOLE_VARIABLE_RESOLVER, resolver);
}

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.//from   w  ww  .j  a  v  a2  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:com.netspective.sparx.util.HttpUtils.java

public static void includeServletResourceContent(Writer writer, HttpServletValueContext vc, String includePath,
        String valueContextAttrName) throws IOException, ServletException {
    ServletRequest request = vc.getRequest();
    ServletResponse response = vc.getResponse();

    RequestDispatcher rd = request.getRequestDispatcher(includePath);

    if (writer != response.getWriter())
        response = new AlternateOutputDestServletResponse(writer, response);

    request.setAttribute(valueContextAttrName, vc);
    rd.include(request, response);/* ww w.j  a  va  2 s  . c  om*/
    request.removeAttribute(valueContextAttrName);
}

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  ww  w  .  ja  va2 s. c o  m*/

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

From source file:com.day.cq.wcm.foundation.forms.FormResourceEdit.java

/**
 * Sets the list of resources to be handled by the "edit" resources form action.
 * @param req current request//from  w w w.  j a v  a2 s  .  c  om
 * @param resources the list of resources
 */
public static void setResources(ServletRequest req, List<Resource> resources) {
    req.setAttribute(RESOURCES_ATTRIBUTE, resources);
}

From source file:net.ontopia.topicmaps.webed.impl.utils.TagUtils.java

public static void setCurrentFormTag(ServletRequest request, FormTag tag) {
    request.setAttribute("OKS_FORM", tag);
}

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  w w w  .  java 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);
                }
            }
        }
    }
}

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

private static void addPostScript(String script, String listName, ServletRequest request) {
    String key = makePostScriptKey(listName);
    StringBuilder test = (StringBuilder) request.getAttribute(key);
    if (test == null) {
        test = new StringBuilder();
        request.setAttribute(key, test);
    }/*w  ww  . jav  a 2  s  .  com*/
    test.append(script);
}

From source file:org.opencms.flex.CmsFlexController.java

/** 
 * Stores the given controller in the given request (using a request attribute).<p>
 * //from  w w w.j  a va  2 s  .c om
 * @param req the request where to store the controller in 
 * @param controller the controller to store
 */
public static void setController(ServletRequest req, CmsFlexController controller) {

    req.setAttribute(CmsFlexController.ATTRIBUTE_NAME, controller);
}

From source file:no.sesat.search.http.filters.SiteLocatorFilter.java

static String getRequestId(final ServletRequest servletRequest) {

    if (null == servletRequest.getAttribute("UNIQUE_ID")) {
        servletRequest.setAttribute("UNIQUE_ID", UUID.randomUUID().toString());
    }//from   www  .j  av  a 2  s.com
    return (String) servletRequest.getAttribute("UNIQUE_ID");
}