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: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));
            }//from  ww  w  . ja  va  2s  . c o m
        }
    }
    request.setAttribute(getRadioName(listName), value);
    return value;
}

From source file:org.jruby.rack.mock.WebUtils.java

/**
 * Expose the specified request attribute if not already present.
 * @param request current servlet request
 * @param name the name of the attribute
 * @param value the suggested value of the attribute
 *///from   w w  w  .j av  a2s .  c o m
private static void exposeRequestAttributeIfNotPresent(ServletRequest request, String name, Object value) {
    if (request.getAttribute(name) == null) {
        request.setAttribute(name, value);
    }
}

From source file:org.opencms.jsp.util.CmsJspStandardContextBean.java

/**
 * Creates a new instance of the standard JSP context bean.<p>
 * /*from ww w .  j  a  va2  s . c  om*/
 * To prevent multiple creations of the bean during a request, the OpenCms request context 
 * attributes are used to cache the created VFS access utility bean.<p>
 * 
 * @param req the current servlet request
 * 
 * @return a new instance of the standard JSP context bean
 */
public static CmsJspStandardContextBean getInstance(ServletRequest req) {

    Object attribute = req.getAttribute(ATTRIBUTE_NAME);
    CmsJspStandardContextBean result;
    if ((attribute != null) && (attribute instanceof CmsJspStandardContextBean)) {
        result = (CmsJspStandardContextBean) attribute;
    } else {
        result = new CmsJspStandardContextBean(req);
        req.setAttribute(ATTRIBUTE_NAME, result);
    }
    return result;
}

From source file:org.jruby.rack.mock.WebUtils.java

/**
 * Expose the given Map as request attributes, using the keys as attribute names
 * and the values as corresponding attribute values. Keys need to be Strings.
 * @param request current HTTP request/*from   w w w  .  ja  va  2s.co  m*/
 * @param attributes the attributes Map
 */
public static void exposeRequestAttributes(ServletRequest request, Map<String, ?> attributes) {
    Assert.notNull(request, "Request must not be null");
    Assert.notNull(attributes, "Attributes Map must not be null");
    for (Map.Entry<String, ?> entry : attributes.entrySet()) {
        request.setAttribute(entry.getKey(), entry.getValue());
    }
}

From source file:org.surfnet.oaaas.auth.AbstractFilter.java

protected final void setAuthStateValue(ServletRequest request, String authState) {
    request.setAttribute(AUTH_STATE, authState);
}

From source file:com.ace.erp.filter.authc.CustomFormAuthenticationFilter.java

@Override
protected void setFailureAttribute(ServletRequest request, AuthenticationException ae) {
    request.setAttribute(getFailureKeyAttribute(), ae);
}

From source file:org.opencms.xml.page.CmsXmlPageFactory.java

/**
 * Factory method to unmarshal (read) a XML page instance from
 * a resource, using the request attributes as cache.<p>
 * /*from  ww  w .j  a  v a 2 s .  c  o m*/
 * @param cms the current OpenCms user context
 * @param resource the resource to unmarshal
 * @param req the current request
 * 
 * @return the unmarshaled XML page, or null if the given resource was not of type {@link CmsResourceTypeXmlPage}
 * 
 * @throws CmsException in something goes wrong
 */
public static CmsXmlPage unmarshal(CmsObject cms, CmsResource resource, ServletRequest req)
        throws CmsException {

    String rootPath = resource.getRootPath();

    if (!CmsResourceTypeXmlPage.isXmlPage(resource)) {
        // sanity check: resource must be of type XML page
        throw new CmsXmlException(Messages.get().container(Messages.ERR_XML_PAGE_FACT_NO_XMLPAGE_TYPE_1,
                cms.getSitePath(resource)));
    }

    // try to get the requested page form the current request attributes 
    CmsXmlPage page = (CmsXmlPage) req.getAttribute(rootPath);

    if (page == null) {
        // unmarshal XML structure from the file content
        page = unmarshal(cms, cms.readFile(resource));
        // store the page that was read as request attribute for future read requests
        req.setAttribute(rootPath, page);
    }

    return page;
}

From source file:com.nominanuda.solr.SpringMvcServerEmbed.java

public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
    request.setAttribute(notHandledReqAttr, true);
}

From source file:no.kantega.publishing.api.taglibs.util.GetOrgUnitTag.java

@SuppressWarnings("unchecked")
public int doStartTag() throws JspException {
    if (isBlank(orgUnitId)) {
        return SKIP_BODY;
    }/*from  w  ww  . j a  v  a2 s  .c  om*/

    try {
        for (OrganizationManager organizationManager : organizationManagers) {
            OrgUnit orgUnit = organizationManager.getUnitByExternalId(orgUnitId);
            if (orgUnit != null) {
                ServletRequest request = pageContext.getRequest();
                request.setAttribute(name, orgUnit);
                break;
            }
        }

    } catch (Exception e) {
        log.error("", e);
        throw new JspTagException(e);
    }

    return SKIP_BODY;
}

From source file:com.erudika.para.utils.filters.ErrorFilter.java

private void setErrorAttributes(ServletRequest request, int status, String message) {
    request.setAttribute(ERROR_STATUS_CODE, status);
    request.setAttribute(ERROR_MESSAGE, message);
}