Example usage for javax.servlet ServletContext getInitParameter

List of usage examples for javax.servlet ServletContext getInitParameter

Introduction

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

Prototype

public String getInitParameter(String name);

Source Link

Document

Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.

Usage

From source file:net.ontopia.topicmaps.webed.impl.utils.TagUtils.java

public static Map getSchemaRegistry(ServletContext servletContext) {
    Map schemas = (Map) servletContext.getAttribute(Constants.AA_SCHEMAS);
    if (schemas != null)
        return schemas;

    // Read in schemas for the topicmaps and provide them to the app context
    String schemasRootDir = servletContext.getInitParameter(Constants.SCTXT_SCHEMAS_ROOTDIR);
    if (schemasRootDir != null)
        schemasRootDir = servletContext.getRealPath(schemasRootDir);

    schemas = new HashMap();
    if (schemasRootDir == null) {
        servletContext.setAttribute(Constants.AA_SCHEMAS, schemas);
        log.debug("No schema directory configured; registry empty");
        return schemas;
    }//w  w  w .  j  a va  2s. c o  m

    log.debug("Reading schemas from " + schemasRootDir);
    TopicMapRepositoryIF repository = NavigatorUtils.getTopicMapRepository(servletContext);
    Collection refkeys = repository.getReferenceKeys();
    Iterator iter = refkeys.iterator();
    while (iter.hasNext()) {
        String refkey = (String) iter.next();
        TopicMapReferenceIF reference = repository.getReferenceByKey(refkey);
        String tmid = reference.getId();
        try {
            OSLSchemaReader reader = new OSLSchemaReader(new File(schemasRootDir, tmid + ".osl"));
            OSLSchema schema = (OSLSchema) reader.read();
            schemas.put(tmid, schema);
            log.info("Loaded schema for " + tmid);
        } catch (java.io.IOException e) {
            log.info("Warning: " + e.getMessage());
        } catch (SchemaSyntaxException e) {
            log.error("Schema syntax error: " + e.getMessage());
            Locator loc = e.getErrorLocation();
            log.error("Location: " + loc.getSystemId() + ":" + loc.getLineNumber() + ":" + loc.getColumnNumber()
                    + ".");
        }
    }

    servletContext.setAttribute(Constants.AA_SCHEMAS, schemas);
    return schemas;
}

From source file:org.apache.myfaces.shared.util.StateUtils.java

private static String findAlgorithm(ServletContext ctx) {

    String algorithm = ctx.getInitParameter(INIT_ALGORITHM);

    if (algorithm == null) {
        algorithm = ctx.getInitParameter(INIT_ALGORITHM.toLowerCase());
    }/* w  ww.j  a  va  2  s  .c  om*/

    return findAlgorithm(algorithm);
}

From source file:org.apache.myfaces.shared.util.StateUtils.java

private static String findMacAlgorithm(ServletContext ctx) {

    String algorithm = ctx.getInitParameter(INIT_MAC_ALGORITHM);

    if (algorithm == null) {
        algorithm = ctx.getInitParameter(INIT_MAC_ALGORITHM.toLowerCase());
    }//w  w w . jav a  2 s.  com

    return findMacAlgorithm(algorithm);

}

From source file:org.apache.myfaces.shared.util.StateUtils.java

private static byte[] findSecret(ServletContext ctx, String algorithm) {
    String secret = ctx.getInitParameter(INIT_SECRET);

    if (secret == null) {
        secret = ctx.getInitParameter(INIT_SECRET.toLowerCase());
    }//from w w w .j ava2s .c o m

    return findSecret(secret, algorithm);
}

From source file:org.apache.myfaces.shared.util.StateUtils.java

private static byte[] findMacSecret(ServletContext ctx, String algorithm) {
    String secret = ctx.getInitParameter(INIT_MAC_SECRET);

    if (secret == null) {
        secret = ctx.getInitParameter(INIT_MAC_SECRET.toLowerCase());
    }/*from www.j  a v  a  2 s .  c o  m*/

    return findMacSecret(secret, algorithm);
}

From source file:net.community.chest.gitcloud.facade.ServletUtils.java

public static final NamedExtendedPlaceholderResolver toPlaceholderResolver(final ServletContext context) {
    if (context == null) {
        return ExtendedPlaceholderResolverUtils.EMPTY_RESOLVER;
    } else {//w  w w. j a v  a 2  s  .co  m
        return new NamedExtendedPlaceholderResolver() {

            @Override
            public String resolvePlaceholder(String placeholderName, String defaultValue) {
                String value = resolvePlaceholder(placeholderName);
                if (value == null) {
                    return defaultValue;
                } else {
                    return value;
                }
            }

            @Override
            public String resolvePlaceholder(String placeholderName) {
                return context.getInitParameter(placeholderName);
            }

            @Override
            public Collection<String> getPlaceholderNames() {
                return Collections.list(context.getInitParameterNames());
            }
        };
    }
}

From source file:org.springframework.web.util.WebUtils.java

/**
 * Return whether response encoding should be used when HTML escaping characters,
 * thus only escaping XML markup significant characters with UTF-* encodings.
 * This option is enabled for the web application with a ServletContext param,
 * i.e. the value of the "responseEncodedHtmlEscape" context-param in {@code web.xml}
 * (if any)./*from   ww w .  j  av  a2 s. c  o m*/
 * <p>This method differentiates between no param specified at all and
 * an actual boolean value specified, allowing to have a context-specific
 * default in case of no setting at the global level.
 * @param servletContext the servlet context of the web application
 * @return whether response encoding is used for HTML escaping (null = no explicit default)
 * @since 4.1.2
 */
public static Boolean getResponseEncodedHtmlEscape(ServletContext servletContext) {
    if (servletContext == null) {
        return null;
    }
    String param = servletContext.getInitParameter(RESPONSE_ENCODED_HTML_ESCAPE_CONTEXT_PARAM);
    return (StringUtils.hasText(param) ? Boolean.valueOf(param) : null);
}

From source file:org.springframework.web.util.WebUtils.java

/**
 * Return whether default HTML escaping is enabled for the web application,
 * i.e. the value of the "defaultHtmlEscape" context-param in {@code web.xml}
 * (if any). Falls back to {@code false} in case of no explicit default given.
 * @param servletContext the servlet context of the web application
 * @return whether default HTML escaping is enabled (default is false)
 * @deprecated as of Spring 4.1, in favor of {@link #getDefaultHtmlEscape}
 *//*from w  w w.java2  s. com*/
@Deprecated
public static boolean isDefaultHtmlEscape(ServletContext servletContext) {
    if (servletContext == null) {
        return false;
    }
    String param = servletContext.getInitParameter(HTML_ESCAPE_CONTEXT_PARAM);
    return Boolean.valueOf(param);
}

From source file:net.ontopia.topicmaps.webed.impl.utils.TagUtils.java

public static ActionRegistryIF getActionRegistry(ServletRequest request) throws JspTagException {
    ServletContext servletContext = ((HttpServletRequest) request).getSession().getServletContext();
    ActionRegistryIF registry = (ActionRegistryIF) servletContext.getAttribute(Constants.AA_REGISTRY);
    if (registry != null)
        return registry;

    // Read in Action Configuration and set it to application context
    String cfgpath = servletContext.getInitParameter(Constants.SCTXT_CONFIG_PATH);
    if (cfgpath == null)
        cfgpath = "classpath:actions.xml";

    log.debug("Start reading action configuration from " + cfgpath);

    String str_delay = servletContext.getInitParameter(Constants.SCTXT_RELOAD_DELAY);
    long delay = 6000; // every 6 seconds by default
    if (str_delay != null) {
        try {//from  w w w  . ja v  a2 s. c o  m
            delay = Long.parseLong(str_delay) * 1000; // value in milliseconds
        } catch (NumberFormatException e) {
            delay = -1;
            log.warn("Warning: Falling back to no config re-reading, " + e);
        }
    }
    String ctxtPath = ((HttpServletRequest) request).getContextPath();
    String realpath = servletContext.getRealPath("");
    ActionConfigurator aconf = new ActionConfigurator(ctxtPath, realpath, cfgpath, delay);
    ActionConfigRegistrator registrator = new ActionConfigRegistrator(servletContext);

    //!aconf.addObserver(registrator);
    //!aconf.readAndWatchRegistry();

    // HACK to make loading config files from classpath work
    aconf.readRegistryConfiguration();
    registry = aconf.getRegistry();
    registrator.configurationChanged(registry);

    log.debug("Setup action configuration for the web editor and assigned it to application context.");

    return registry;
}

From source file:net.ontopia.topicmaps.webed.impl.utils.TagUtils.java

protected static VelocityEngine getVelocityEngine(ServletContext scontext) {
    VelocityEngine vengine = (VelocityEngine) scontext.getAttribute(Constants.SCTXT_VELOCITY_ENGINE);

    if (vengine == null) {

        // create a new velocity engine
        vengine = new VelocityEngine();

        // --- try to get properties from an own file
        String relPath = scontext.getInitParameter(Constants.SCTXT_VELOPROPS_PATH);
        if (relPath != null) {
            String velocityPropPath = scontext.getRealPath(relPath);
            log.info("Initialising velocity from property file: " + velocityPropPath);
            // load in properties
            Properties props = new Properties();
            try {
                props.load(new java.io.FileInputStream(velocityPropPath));
            } catch (java.io.IOException ioe) {
                throw new OntopiaRuntimeException(ioe);
            }/*w w w  . ja va2s .co  m*/
            // pre-cat the real directory
            String path = props.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH, null);
            if (path != null) {
                path = scontext.getRealPath(path);
                props.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
            } else {
                // no directory set, use default loader (classpath) for default templates
                props.setProperty("resource.loader", "class");
                props.setProperty("class.resource.loader.class",
                        "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
                props.setProperty("class.resource.loader.cache", "true");
            }
            try {
                vengine.init(props);
            } catch (Exception e) {
                throw new OntopiaRuntimeException(e);
            }
        } else {
            log.info("Initializing velocity with default properties.");
            // use class resource loaders
            Properties props = new Properties();
            props.setProperty("resource.loader", "class");
            props.setProperty("class.resource.loader.class",
                    "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
            props.setProperty("class.resource.loader.cache", "true");
            // use log4j logging system
            props.setProperty("runtime.log.system", "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
            props.setProperty("runtime.log.logsystem.log4j.category", "net.ontopia.velocity");
            props.setProperty("runtime.log", "velocity.log");
            try {
                vengine.init(props);
            } catch (Exception e) {
                throw new OntopiaRuntimeException(e);
            }
        }

        // add velocity engine to servlet context
        scontext.setAttribute(Constants.SCTXT_VELOCITY_ENGINE, vengine);
    }
    return vengine;
}