Example usage for javax.servlet.jsp PageContext APPLICATION_SCOPE

List of usage examples for javax.servlet.jsp PageContext APPLICATION_SCOPE

Introduction

In this page you can find the example usage for javax.servlet.jsp PageContext APPLICATION_SCOPE.

Prototype

int APPLICATION_SCOPE

To view the source code for javax.servlet.jsp PageContext APPLICATION_SCOPE.

Click Source Link

Document

Application scope: named reference remains available in the ServletContext until it is reclaimed.

Usage

From source file:ar.com.zauber.commons.web.uri.assets.AbstractSpringTag.java

/**
 *  @return the {@link AssetRepository} 
 *  Search path:// w  ww.j  a va 2s. c o  m
 *     - If there is one configured  in the context we use that
 *     - if not we create one and put it in the PageContext.
 */
@SuppressWarnings("unchecked")
protected final <T> T resolve(final Class<T> clazz, final String beanName, final String requestBean,
        final String requestWarn, final ServiceFactory<T> factory, final int scope) {
    final WebApplicationContext appCtx = getApplicationContext();
    T service = null;

    service = (T) pageContext.getAttribute(requestBean, scope);
    if (service == null) {
        try {
            service = appCtx.getBean(beanName, clazz);
        } catch (final NoSuchBeanDefinitionException e) {
            service = factory.create(appCtx);
            pageContext.setAttribute(requestBean, service, scope);

            final Boolean warned = (Boolean) pageContext.getAttribute(requestWarn,
                    PageContext.APPLICATION_SCOPE);
            if (warned == null) {
                LoggerFactory.getLogger(getClass()).warn("Bean  " + beanName + " wasn't found. "
                        + "We will use " + service.getClass().getName());
                pageContext.setAttribute(requestWarn, true, PageContext.APPLICATION_SCOPE);
            }
        }
    }
    return service;
}

From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java

@Override
public int getAttributesScope(String key) {
    if (pageAttributes.containsKey(key) == true)
        return PageContext.PAGE_SCOPE;
    if (contains(request.getAttributeNames(), key) == true)
        return PageContext.REQUEST_SCOPE;
    if (session != null) {
        if (contains(session.getAttributeNames(), key) == true) {
            return PageContext.SESSION_SCOPE;
        }//www . j a  v  a2  s  .co  m
    }
    if (contains(servletCtx.getAttributeNames(), key) == true)
        return PageContext.APPLICATION_SCOPE;
    return 0;
}

From source file:eionet.cr.util.Util.java

/**
 *
 * @param pageContext/*  www  .ja v  a  2 s.  c  om*/
 * @param objectClass
 * @return
 */
public static Object findInAnyScope(PageContext pageContext, Class objectClass) {

    if (pageContext == null || objectClass == null) {
        return null;
    }

    int[] scopes = { PageContext.APPLICATION_SCOPE, PageContext.PAGE_SCOPE, PageContext.REQUEST_SCOPE,
            PageContext.SESSION_SCOPE };
    for (int i = 0; i < scopes.length; i++) {
        Enumeration attrs = pageContext.getAttributeNamesInScope(scopes[i]);
        while (attrs != null && attrs.hasMoreElements()) {
            String name = (String) attrs.nextElement();
            Object o = pageContext.getAttribute(name, scopes[i]);
            if (o != null && objectClass.isInstance(o)) {
                return o;
            }
        }
    }

    return null;
}

From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java

@Override
public void setAttribute(String key, Object value, int scope) {
    if (value == null) {
        removeAttribute(key, scope);/*from w  w  w.j a  v a 2s .  c om*/
        return;
    }
    switch (scope) {
    case PageContext.PAGE_SCOPE:
        pageAttributes.put(key, value);
        break;
    case PageContext.REQUEST_SCOPE:
        request.setAttribute(key, value);
        break;
    case PageContext.SESSION_SCOPE:
        if (session != null) {
            session.setAttribute(key, value);
        }
        break;
    case PageContext.APPLICATION_SCOPE:
        servletCtx.setAttribute(key, value);
        break;
    default:

        break;
    }
}

From source file:de.micromata.genome.gwiki.page.gspt.StandAlonePageContext.java

@Override
public void removeAttribute(String key) {
    for (int i = 0; i < PageContext.APPLICATION_SCOPE - 1; ++i) {
        scopes.get(i).remove(key);/*from ww  w.j  ava 2 s.  co m*/
    }
}

From source file:de.micromata.genome.gwiki.page.gspt.ServletStandalonePageContext.java

@Override
public void removeAttribute(String key, int scope) {
    switch (scope) {
    case PageContext.PAGE_SCOPE:
        pageAttributes.remove(key);//from  w  w w.j a  va  2  s .  com
        break;
    case PageContext.REQUEST_SCOPE:
        request.removeAttribute(key);
        break;
    case PageContext.SESSION_SCOPE:
        if (session != null) {
            session.removeAttribute(key);
        }
        break;
    case PageContext.APPLICATION_SCOPE:
        servletCtx.removeAttribute(key);
        break;
    default:
        break;
    }
}

From source file:com.glaf.core.tag.TagUtils.java

/**
 * Returns the appropriate MessageResources object for the current module
 * and the given bundle.//from   w  w  w .  j av  a2 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 = conf.get("i18n.messages_key");
    }

    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) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.APPLICATION_SCOPE);
    }

    if (resources == null) {
        resources = (MessageResources) pageContext.getAttribute(Globals.DEFAULT_RESOURCE_NAME,
                PageContext.APPLICATION_SCOPE);
        if (resources == null) {
            resources = PropertyMessageResourcesFactory.createFactory()
                    .createResources(Globals.DEFAULT_RESOURCE_NAME);
            pageContext.setAttribute(Globals.DEFAULT_RESOURCE_NAME, resources, 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:de.innovationgate.wgpublisher.WGACore.java

public static WGACore retrieve(PageContext pageContext) {
    return (WGACore) pageContext.getAttribute(ATTRIB_CORE, PageContext.APPLICATION_SCOPE);
}

From source file:nl.strohalm.cyclos.taglibs.AbstractEscapeTag.java

public void setScope(String scope) {
    scope = StringUtils.trimToNull(scope);
    if ("application".equalsIgnoreCase(scope)) {
        this.scope = PageContext.APPLICATION_SCOPE;
    } else if ("session".equalsIgnoreCase(scope)) {
        this.scope = PageContext.SESSION_SCOPE;
    } else if ("request".equalsIgnoreCase(scope)) {
        this.scope = PageContext.REQUEST_SCOPE;
    } else {//from   w w  w.  j  ava2s . c  om
        this.scope = PageContext.PAGE_SCOPE;
    }
}

From source file:org.apache.cactus.extension.jsp.JspTagLifecycle.java

/**
 * Adds a special expectation that verifies that a specific scoped variable
 * is exposed in the body of the tag.//  w  w w.j a v a 2s.c  o  m
 * 
 * @param theName The name of the variable
 * @param theExpectedValues An ordered list containing the expected values 
 *        values of the scoped variable, one for each expected iteration
 *        step
 * @param theScope The scope under which the variable is stored
 */
public void expectScopedVariableExposed(String theName, Object[] theExpectedValues, int theScope) {
    if ((theName == null) || (theExpectedValues == null)) {
        throw new NullPointerException();
    }
    if (theExpectedValues.length == 0) {
        throw new IllegalArgumentException();
    }
    if ((theScope != PageContext.PAGE_SCOPE) && (theScope != PageContext.REQUEST_SCOPE)
            && (theScope != PageContext.SESSION_SCOPE) && (theScope != PageContext.APPLICATION_SCOPE)) {
        throw new IllegalArgumentException();
    }
    addInterceptor(new ExpectScopedVariableExposedInterceptor(theName, theExpectedValues, theScope));
}