Example usage for javax.servlet ServletConfig getInitParameter

List of usage examples for javax.servlet ServletConfig getInitParameter

Introduction

In this page you can find the example usage for javax.servlet ServletConfig getInitParameter.

Prototype

public String getInitParameter(String name);

Source Link

Document

Gets the value of the initialization parameter with the given name.

Usage

From source file:com.meltmedia.cadmium.servlets.FileServletTest.java

@BeforeClass
public static void beforeClass() throws ServletException, NoSuchMethodException, IllegalAccessException,
        InvocationTargetException, FileNotFoundException, IOException {
    MimeTypeConfigProcessor mimeTypes = mock(MimeTypeConfigProcessor.class);
    when(mimeTypes.getContentType(anyString())).thenReturn("text/html");

    ServletConfig config = mock(ServletConfig.class);
    when(config.getInitParameter("basePath")).thenReturn(CONTENT_ROOT.getAbsolutePath());

    fileServlet = new FileServlet();
    fileServlet.setMimeTypeConfigProcessor(mimeTypes);
    fileServlet.setLastModifiedForTesting(CURRENT_LAST_MODIFIED);
    fileServlet.init(config);//from  ww w. j a v a2 s. c om

}

From source file:nl.b3p.kaartenbalie.core.server.persistence.MyEMFDatabase.java

private static String getConfigValue(ServletConfig config, String parameter, String defaultValue) {
    String tmpval = config.getInitParameter(parameter);
    if (tmpval == null || tmpval.trim().length() == 0) {
        tmpval = defaultValue;/* w w  w.  j a  v  a2s  . co m*/
    }
    log.debug("ManagedPersistence.getConfigValue(config, " + parameter + ", " + tmpval + ")");
    return tmpval.trim();
}

From source file:org.exist.security.realm.openid.AuthenticatorOpenIdServlet.java

private static ProxyProperties getProxyProperties(ServletConfig config) {
    ProxyProperties proxyProps;// ww  w.  j  ava 2s  . c o  m
    String host = config.getInitParameter("proxy.host");
    LOG.debug("proxy.host: " + host);
    if (host == null) {
        proxyProps = null;
    } else {
        proxyProps = new ProxyProperties();
        String port = config.getInitParameter("proxy.port");
        String username = config.getInitParameter("proxy.username");
        String password = config.getInitParameter("proxy.password");
        String domain = config.getInitParameter("proxy.domain");
        proxyProps.setProxyHostName(host);
        proxyProps.setProxyPort(Integer.parseInt(port));
        proxyProps.setUserName(username);
        proxyProps.setPassword(password);
        proxyProps.setDomain(domain);
    }
    return proxyProps;
}

From source file:com.acciente.induction.init.ConfigLoaderInitializer.java

/**
 * Loads the configuration parameters used to configure every module in this dispatcher servlet.
 *
 * @param oServletConfig provides access to the dispatcher's servlet config
 *
 * @return a container with configuration values
 *
 * @throws ClassNotFoundException propagated exception
 * @throws ConstructorNotFoundException propagated exception
 * @throws IllegalAccessException propagated exception
 * @throws InstantiationException propagated exception
 * @throws InvocationTargetException propagated exception
 *
 * Log/*from w w  w  .j  a v  a 2  s.com*/
 * Mar 15, 2008 APR  -  created
 */
public static ConfigLoader getConfigLoader(ServletConfig oServletConfig)
        throws ClassNotFoundException, InvocationTargetException, ConstructorNotFoundException,
        ParameterProviderException, IllegalAccessException, InstantiationException {
    ConfigLoader oConfigLoader;
    String sConfigLoaderClassName;
    Log oLog;

    oLog = LogFactory.getLog(ConfigLoaderInitializer.class);

    sConfigLoaderClassName = oServletConfig.getInitParameter(
            oServletConfig.getServletName() + "." + ConfigLoaderInitializer.CONFIG_LOADER_CLASS);

    // first check if there is custom config loader defined
    if (sConfigLoaderClassName == null) {
        // no custom loader defined, use the default XML loader (this is the typical case)
        oConfigLoader = new XMLConfigLoader("induction-" + oServletConfig.getServletName() + ".xml",
                oServletConfig);

        oLog.info("using default XML config loader");
    } else {
        oLog.info("loading user-defined config loader class: " + sConfigLoaderClassName);

        // note that to load this class we use the default class loader since any of our
        // custom classloaders have to wait until we load in the configuration
        Class oConfigLoaderClass = Class.forName(sConfigLoaderClassName);

        // attempt to find and call the single public constructor
        oConfigLoader = (ConfigLoader) ObjectFactory.createObject(oConfigLoaderClass,
                new Object[] { oServletConfig }, null);
    }

    return oConfigLoader;
}

From source file:info.magnolia.cms.util.ServletUtil.java

/**
 * Returns the init parameters for a {@link javax.servlet.ServletConfig} object as a Map, preserving the order in which they are exposed
 * by the {@link javax.servlet.ServletConfig} object.
 *//*from   w w  w .  ja v  a 2  s.co  m*/
public static LinkedHashMap<String, String> initParametersToMap(ServletConfig config) {
    LinkedHashMap<String, String> initParameters = new LinkedHashMap<String, String>();
    Enumeration parameterNames = config.getInitParameterNames();
    while (parameterNames.hasMoreElements()) {
        String parameterName = (String) parameterNames.nextElement();
        initParameters.put(parameterName, config.getInitParameter(parameterName));
    }
    return initParameters;
}

From source file:mondrian.xmla.impl.Olap4jXmlaServlet.java

/**
 * Obtains connection properties from the
 * ServletConfig init parameters and from System properties.
 *
 * <p>The properties found in the System properties override the ones in
 * the ServletConfig.//from   www  .j  av  a2  s. c  om
 *
 * <p>copies the values of init parameters / properties which
 * start with the given prefix to a target Map object stripping out the
 * configured prefix from the property name.
 *
 * <p>The following example uses prefix "olapConn.":
 *
 * <code><pre>
 *  &lt;init-param&gt;
 *      &lt;param-name&gt;olapConn.User&lt;/param-name&gt;
 *      &lt;param-value&gt;mrossi&lt;/param-value&gt;
 *  &lt;/init-param&gt;
 *  &lt;init-param&gt;
 *      &lt;param-name&gt;olapConn.Password&lt;/param-name&gt;
 *      &lt;param-value&gt;manhattan&lt;/param-value&gt;
 *  &lt;/init-param&gt;
 *
 * </pre></code>
 *
 * <p>This will result in a connection properties object with entries
 * <code>{("User", "mrossi"), ("Password", "manhattan")}</code>.
 *
 * @param prefix Prefix to property name
 * @param servletConfig Servlet config
 * @return Map containing property names and values
 */
private static Map<String, String> getOlap4jConnectionProperties(final ServletConfig servletConfig,
        final String prefix) {
    Map<String, String> options = new LinkedHashMap<String, String>();

    // Get properties from servlet config.
    @SuppressWarnings({ "unchecked" })
    java.util.Enumeration<String> en = servletConfig.getInitParameterNames();
    while (en.hasMoreElements()) {
        String paramName = en.nextElement();
        if (paramName.startsWith(prefix)) {
            String paramValue = servletConfig.getInitParameter(paramName);
            String prefixRemovedParamName = paramName.substring(prefix.length());
            options.put(prefixRemovedParamName, paramValue);
        }
    }

    // Get system properties.
    final Map<String, String> systemProps = Util.toMap(System.getProperties());
    for (Map.Entry<String, String> entry : systemProps.entrySet()) {
        String sk = entry.getKey();
        if (sk.startsWith(prefix)) {
            String value = entry.getValue();
            String prefixRemovedKey = sk.substring(prefix.length());
            options.put(prefixRemovedKey, value);
        }
    }

    return options;
}

From source file:org.mycore.common.content.util.MCRServletContentHelper.java

public static Config buildConfig(ServletConfig servletConfig) {
    Config config = new Config();

    if (servletConfig.getInitParameter("inputBufferSize") != null) {
        config.inputBufferSize = Integer.parseInt(servletConfig.getInitParameter("inputBufferSize"));
    }/*w  w  w.j  a  va  2s .  com*/

    if (servletConfig.getInitParameter("outputBufferSize") != null) {
        config.outputBufferSize = Integer.parseInt(servletConfig.getInitParameter("outputBufferSize"));
    }

    if (servletConfig.getInitParameter("useAcceptRanges") != null) {
        config.useAcceptRanges = Boolean.parseBoolean(servletConfig.getInitParameter("useAcceptRanges"));
    }

    if (config.inputBufferSize < MIN_BUFFER_SIZE) {
        config.inputBufferSize = MIN_BUFFER_SIZE;
    }
    if (config.outputBufferSize < MIN_BUFFER_SIZE) {
        config.outputBufferSize = MIN_BUFFER_SIZE;
    }
    return config;
}

From source file:com.predic8.membrane.servlet.embedded.MembraneServlet.java

private String getProxiesXmlLocation(ServletConfig config) {
    return config.getInitParameter("proxiesXml");
}

From source file:org.nanoframework.core.plugins.defaults.plugin.Log4jPlugin.java

@Override
public void config(ServletConfig config) throws Throwable {
    log4j = config.getInitParameter(DEFAULT_LOG4J_PARAMETER_NAME);
}

From source file:org.opensubsystems.core.util.servlet.WebUtils.java

/**
 * Get names and values for all the init parameters from the specified 
 * servlet config.//from w ww. jav  a 2  s.  c  o  m
 * 
 * @param  scConfig - config from where to retrieve the init parameters
 * @return Properties - names and values of the init parameters or empty
 *                      properties if no init parameters are specified
 */
public static Properties getInitParameters(ServletConfig scConfig) {
    Properties prpSettings = new Properties();
    String strName;
    String strValue;

    for (Enumeration paramNames = scConfig.getInitParameterNames(); paramNames.hasMoreElements();) {
        strName = (String) paramNames.nextElement();
        strValue = scConfig.getInitParameter(strName);
        prpSettings.put(strName, strValue);
    }

    return prpSettings;
}