Example usage for javax.servlet ServletContext getAttribute

List of usage examples for javax.servlet ServletContext getAttribute

Introduction

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

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the servlet container attribute with the given name, or null if there is no attribute by that name.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration.java

/**
 * Get the bean from the context. If there no bean, create one on the fly
 * and store it in the context.//w  w w.j  a v a2  s.  c o  m
 * 
 * Never returns null.
 */
public static SelfEditingConfiguration getBean(ServletContext ctx) {
    Object attr = ctx.getAttribute(BEAN_ATTRIBUTE);
    if (attr instanceof SelfEditingConfiguration) {
        log.debug("Found a bean: " + attr);
        return (SelfEditingConfiguration) attr;
    }

    SelfEditingConfiguration bean = buildBean(ctx);
    log.debug("Created a bean: " + bean);
    ctx.setAttribute(BEAN_ATTRIBUTE, bean);
    return bean;
}

From source file:com.mtgi.analytics.servlet.BehaviorTrackingFilter.java

public static boolean isFiltered(ServletContext context) {
    Integer count = (Integer) context.getAttribute(ATT_FILTER_REGISTERED);
    return count != null && count > 0;
}

From source file:edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.java

public static RDFServiceFactory getRDFServiceFactory(ServletContext context, WhichService which) {
    String attribute = RDFSERVICEFACTORY_ATTR + "." + which.name();
    Object o = context.getAttribute(attribute);
    if (o instanceof RDFServiceFactory) {
        RDFServiceFactory factory = (RDFServiceFactory) o;
        return new LoggingRDFServiceFactory(factory);
    } else {//from   www  .j  ava 2 s . c  o m
        throw new IllegalStateException(
                "Expecting an RDFServiceFactory on the context at '" + attribute + "', but found " + o);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.auth.policy.ServletPolicyList.java

/**
 * Get the current PolicyList from the context, or create one if there is
 * none. This method may return an empty list, but it never returns null.
 *///from  ww  w  .j  a va2s.c  o  m
private static PolicyList getPolicyList(ServletContext ctx) {
    if (ctx == null) {
        throw new NullPointerException("ctx may not be null.");
    }

    Object obj = ctx.getAttribute(ATTRIBUTE_POLICY_LIST);
    if (obj == null) {
        obj = new PolicyList();
        ctx.setAttribute(ATTRIBUTE_POLICY_LIST, obj);
    }

    if (!(obj instanceof PolicyList)) {
        throw new IllegalStateException("Expected to find an instance of " + PolicyList.class.getName()
                + " in the context, but found an instance of " + obj.getClass().getName() + " instead.");
    }

    return (PolicyList) obj;
}

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup.java

public static RecomputeMode getRecomputeRequired(ServletContext ctx) {
    return (RecomputeMode) ctx.getAttribute(RECOMPUTE_REQUIRED_ATTR);
}

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup.java

public static SimpleReasoner getSimpleReasonerFromServletContext(ServletContext ctx) {
    Object simpleReasoner = ctx.getAttribute(SimpleReasoner.class.getName());

    if (simpleReasoner instanceof SimpleReasoner) {
        return (SimpleReasoner) simpleReasoner;
    } else {//from   w w  w.  jav  a2 s  .co  m
        return null;
    }
}

From source file:org.eclipse.rwt.widgets.upload.servlet.FileUploadServlet.java

public static File getUploadTempDir(final HttpSession session) {
    ServletContext context = session.getServletContext();
    StringBuffer path = new StringBuffer();
    File tempDir = (File) context.getAttribute(CONTEXT_TEMP_DIR);
    path.append(tempDir.getAbsolutePath());
    path.append(File.separatorChar);
    path.append(session.getId());// ww w  .j ava2 s.c o m
    File result = new File(path.toString());
    if (!result.exists()) {
        result.mkdir();
    }
    return result;
}

From source file:org.apache.qpid.server.management.plugin.HttpManagementUtil.java

public static Broker<?> getBroker(ServletContext servletContext) {
    return (Broker<?>) servletContext.getAttribute(ATTR_BROKER);
}

From source file:edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup.java

public static SimpleReasonerTBoxListener getSimpleReasonerTBoxListenerFromContext(ServletContext ctx) {
    Object simpleReasonerTBoxListener = ctx.getAttribute(SimpleReasonerTBoxListener.class.getName());

    if (simpleReasonerTBoxListener instanceof SimpleReasonerTBoxListener) {
        return (SimpleReasonerTBoxListener) simpleReasonerTBoxListener;
    } else {//from  w w w . java2 s  .  c  om
        return null;
    }
}

From source file:com.sonicle.webtop.core.app.ContextLoader.java

public static String getWabappName(ServletContext servletContext) {
    return (String) servletContext.getAttribute(WEBAPPNAME_ATTRIBUTE_KEY);
}