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:org.ff4j.web.embedded.ConsoleServlet.java

/**
 * Servlet initialization, init FF4J from "ff4jProvider" attribute Name.
 *
 * @param servletConfig// w w w.  j av a2  s.  c o m
 *            current {@link ServletConfig} context
 * @throws ServletException
 *             error during servlet initialization
 */
public void init(ServletConfig servletConfig) throws ServletException {
    LOGGER.info("  __  __ _  _   _ ");
    LOGGER.info(" / _|/ _| || | (_)");
    LOGGER.info("| |_| |_| || |_| |");
    LOGGER.info("|  _|  _|__   _| |");
    LOGGER.info("|_| |_|    |_|_/ |");
    LOGGER.info(
            "             |__/   Embedded Console - v" + getClass().getPackage().getImplementationVersion());
    LOGGER.info(" ");

    if (ff4j == null) {
        String className = servletConfig.getInitParameter(PROVIDER_PARAM_NAME);
        try {
            Class<?> c = Class.forName(className);
            Object o = c.newInstance();
            ff4jProvider = (FF4jProvider) o;
            LOGGER.info("ff4j context has been successfully initialized - {} feature(s)",
                    ff4jProvider.getFF4j().getFeatures().size());
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException("Cannot load ff4jProvider as " + ff4jProvider, e);
        } catch (InstantiationException e) {
            throw new IllegalArgumentException("Cannot instantiate  " + ff4jProvider + " as ff4jProvider", e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException(
                    "No public constructor for  " + ff4jProvider + " as ff4jProvider", e);
        } catch (ClassCastException ce) {
            throw new IllegalArgumentException("ff4jProvider expected instance of " + FF4jProvider.class, ce);
        }

        // Put the FF4J in ApplicationScope (useful for tags)
        ff4j = ff4jProvider.getFF4j();
        servletConfig.getServletContext().setAttribute(FF4J_SESSIONATTRIBUTE_NAME, ff4j);
        LOGGER.debug("Servlet has been initialized and ff4j store in session with {} ",
                ff4j.getFeatures().size());
    } else {
        LOGGER.debug("Servlet has been initialized, ff4j was injected");
    }
}

From source file:org.webguitoolkit.ui.http.PageServlet.java

/**
 * // init page-mappings (i102455/20080220)
 * requires mapping in web-xml/* w w  w .jav a  2s  .c  om*/
 * 
 * Example: <init-param> <description> page mapping to prevent long page
 * names </description> <param-name>page-mapping@NameOfPageClass</param-name>
 * <param-value> abbriviation;index;test;index.htm;whatever
 * </param-value> </init-param>
 * 
 * Description: param-name: page-mapping@ followed by the PageClassName.
 * Packages must be defined by the import init-param of this servlet
 * param-value: add short names for the PageClassName
 */
private void initPageMappings(ServletConfig sc) throws ServletException {

    // get all initParamsNames
    Enumeration initParamNames = sc.getInitParameterNames();
    if (initParamNames != null) {
        // loop through initParamsNames and check for start page-mapping@
        while (initParamNames.hasMoreElements()) {
            String initParamName = (String) initParamNames.nextElement();
            if (initParamName != null && initParamName.startsWith(PAGE_MAPPING)
                    && initParamName.indexOf("@") < initParamName.length()) {
                // get parameter
                String mapping = sc.getInitParameter(initParamName);
                if (StringUtils.isNotEmpty(mapping)) {
                    String[] mapArray = StringUtils.split(mapping, ';');
                    if (mapArray != null) {
                        for (int i = 0; i < mapArray.length; i++) {
                            if (pageMapppingMap == null)
                                pageMapppingMap = new Hashtable();
                            // add mapping -> page entry to table
                            try {
                                if (pageMapppingMap.get(StringUtils.trimToEmpty(mapArray[i])) == null) {
                                    pageMapppingMap.put(StringUtils.trimToEmpty(mapArray[i]),
                                            StringUtils.substringAfter(initParamName, "@"));
                                } else {
                                    throw new Exception("Duplicate page mapping for '"
                                            + StringUtils.trimToEmpty(mapArray[i]) + "', check web.xml");
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:org.wings.session.PortletWingServlet.java

/**
 * The following init parameters are known by wings.
 * <p/>//from w w w.java2  s  .c  om
 * <dl compact>
 * <dt>externalizer.timeout</dt><dd> - The time, externalized objects
 * are kept, before they are removed</dd>
 * <p/>
 * <dt>content.maxlength</dt><dd> - Maximum content lengt for form posts.
 * Remember to increase this, if you make use of the SFileChooser
 * component</dd>
 * <p/>
 * <dt>filechooser.uploaddir</dt><dd> - The directory, where uploaded
 * files ar stored temporarily</dd>
 * </dl>
 * <p/>
 * <dt>wings.servlet.lookupname</dt><dd> - The name the wings sessions of
 * this servlet instance are stored in the servlet session hashtable</dd>
 * </dl>
 *
 * @throws ServletException
 */
public final void init(ServletConfig config) throws ServletException {
    super.init(config);
    servletConfig = config;

    if (log.isInfoEnabled()) {
        log.info("Initializing wingS global servlet with configuration:");
        for (Enumeration en = config.getInitParameterNames(); en.hasMoreElements();) {
            String param = (String) en.nextElement();
            log.info("    " + param + " = " + config.getInitParameter(param));
        }
    }

    //        initLookupName(config);
}

From source file:com.bluedragon.platform.java.JavaFileIO.java

public JavaFileIO(ServletConfig config) throws ServletException {

    try {// w  w  w .j av  a  2  s  .c  o  m
        fsManager = VFS.getManager();
        ((StandardFileSystemManager) fsManager).addProvider("s3",
                new com.intridea.io.vfs.provider.s3.S3FileProvider());
        ((StandardFileSystemManager) fsManager).addOperationProvider("s3",
                new com.intridea.io.vfs.provider.s3.acl.AclOperationsProvider());
    } catch (Exception e1) {
        cfEngine.log("Failed to register the s3:// name space: " + e1.getMessage());
    }

    // Set the working directory
    try {
        if (!setWorkingDirectory(config.getInitParameter("BLUEDRAGON_WORKING_DIRECTORY"))) {
            throw new Exception(
                    config.getInitParameter("BLUEDRAGON_WORKING_DIRECTORY") + " could not be created");
        }
    } catch (Exception E) {
        System.out.println(cfEngine.PRODUCT_NAME + ": Init Parameter BLUEDRAGON_WORKING_DIRECTORY Error: " + E);
        throw new ServletException(
                cfEngine.PRODUCT_NAME + ": Init Parameter BLUEDRAGON_WORKING_DIRECTORY Error: " + E);
    }

    // Setup the logging
    com.nary.Debug.SystemOff();
    File logFile = new File(getWorkingDirectory(), "bluedragon.log");
    rolloverLogFile(logFile);
    com.nary.Debug.setFilename(logFile.toString());

    setTempDirectory();
    setupRuntimeLogging();

    cfEngine.log(cfEngine.PRODUCT_NAME + " WorkingDirectory=[" + getWorkingDirectory() + "]");
    cfEngine.log(cfEngine.PRODUCT_NAME + " TempDirectory=[" + getTempDirectory() + "]");
}

From source file:nl.b3p.kaartenbalie.service.servlet.GeneralServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    log = LogFactory.getLog(this.getClass());
    log.debug("Initializing GeneralServlet");

    updateUserLastLoginStatus = "true"
            .equalsIgnoreCase(config.getInitParameter(MyEMFDatabase.USER_UPDATELASTLOGINSTATUS));
}

From source file:org.jahia.services.content.files.StaticFileServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    String basePathValue = SettingsBean.getInstance().getJahiaGeneratedResourcesDiskPath();
    try {//from   ww w.ja  v a  2 s  .c  o m
        basePath = (new File(basePathValue)).getCanonicalPath();
    } catch (IOException e) {
        throw new ServletException(e);
    }
    enableGzip = Boolean.valueOf(StringUtils.defaultString(config.getInitParameter("enable-gzip"), "true"));
}

From source file:com.portfolio.data.attachment.XSLService.java

@Override
public void init(ServletConfig config) throws ServletException {
    sc = config.getServletContext();/*from w  w  w. j a  va2s.com*/
    servletDir = sc.getRealPath("/");
    int last = servletDir.lastIndexOf(File.separator);
    last = servletDir.lastIndexOf(File.separator, last - 1);
    baseDir = servletDir.substring(0, last);
    server = config.getInitParameter("redirectedServer");

    //Setting up the JAXP TransformerFactory
    this.transFactory = TransformerFactory.newInstance();

    //Setting up the FOP factory
    this.fopFactory = FopFactory.newInstance();

    try {
        String dataProviderName = config.getInitParameter("dataProviderClass");
        dataProvider = (DataProvider) Class.forName(dataProviderName).newInstance();

        InitialContext cxt = new InitialContext();

        /// Init this here, might fail depending on server hosting
        ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/portfolio-backend");
        if (ds == null) {
            throw new Exception("Data  jdbc/portfolio-backend source not found!");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:nl.strohalm.cyclos.servlets.ImageByNameServlet.java

@Override
public synchronized void init(final ServletConfig config) throws ServletException {
    super.init(config);

    context = getServletContext();/*from   w w  w .ja va2 s.  c  o m*/
    webImageHelper = SpringHelper.bean(context, WebImageHelper.class);
    responseHelper = SpringHelper.bean(context, ResponseHelper.class);

    // Whenever the image is updated, we have to invalidate the cache
    SpringHelper.bean(context, CustomizedFileHandler.class).addImageChangeListener(new ImageChangeListener() {
        @Override
        public void onImageChanged(final Image image) {
            if (nature.equals(image.getNature())) {
                removeFromCache(image.getName());
            }
        }
    });

    final String natureParameter = config.getInitParameter("nature");
    try {
        nature = Nature.valueOf(natureParameter);
    } catch (final Exception e) {
        context.log("Invalid nature for " + ClassHelper.getClassName(getClass()) + ": " + natureParameter);
    }

    imagePath = webImageHelper.imagePath(nature);
    thumbnailPath = webImageHelper.thumbnailPath(nature);
}

From source file:org.hyperic.lather.server.LatherServlet.java

private ConnManager getConnManager(ServletConfig cfg) throws ServletException {
    @SuppressWarnings("unchecked")
    final Enumeration<String> paramNames = cfg.getInitParameterNames();
    final Map<String, Semaphore> maxConnMap = new HashMap<String, Semaphore>();
    while (paramNames.hasMoreElements()) {
        final String name = paramNames.nextElement();
        if (!name.startsWith(PROP_PREFIX) || name.contains(PROP_EXECTIMEOUT)) {
            continue;
        }/*from w  ww . ja v a2  s  .c  o  m*/
        final String param = cfg.getInitParameter(name);
        try {
            final int value = Integer.parseInt(param);
            maxConnMap.put(name.replace(PROP_PREFIX, ""), new Semaphore(value));
        } catch (NumberFormatException e) {
            log.error("could not initialize max conn setting for " + name + " value=" + param);
        }
    }
    if (!maxConnMap.containsKey(PROP_MAXCONNS)) {
        throw new ServletException("init-params do not contain key=" + PROP_MAXCONNS + ")");
    }
    return new ConnManager(maxConnMap);
}

From source file:com.netscape.cms.servlet.connector.ConnectorServlet.java

public void init(ServletConfig sc) throws ServletException {
    super.init(sc);
    mConfig = sc;/*www  . jav  a 2 s . c  o  m*/
    String authority = sc.getInitParameter(PROP_AUTHORITY);

    if (authority != null)
        mAuthority = (IAuthority) CMS.getSubsystem(authority);
    mReqEncoder = CMS.getHttpRequestEncoder();

    mAuthSubsystem = (IAuthSubsystem) CMS.getSubsystem(CMS.SUBSYSTEM_AUTH);
}