Example usage for javax.servlet ServletConfig getServletContext

List of usage examples for javax.servlet ServletConfig getServletContext

Introduction

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

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns a reference to the ServletContext in which the caller is executing.

Usage

From source file:org.getobjects.servlets.WOServletAdaptor.java

protected String valueFromServletConfig(final ServletConfig _cfg, final String _key) {
    String an = _cfg.getInitParameter(_key);
    if (an != null)
        return an;

    final ServletContext sctx = _cfg.getServletContext();
    if (sctx == null)
        return null;

    /*/* w ww .j  a v  a2 s  .com*/
     * This is specified in web.xml like:
     *   <context-param>
     *     <param-name>WOAppName</param-name>
     *     <param-value>com.zideone.HelloWorld.HelloWorld</param-value>
     *   </context-param>
     */
    if ((an = sctx.getInitParameter(_key)) != null)
        return an;
    if ((an = (String) sctx.getAttribute(_key)) != null)
        return an;

    return an;
}

From source file:org.jbpm.designer.server.EditorHandler.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    DroolsFactoryImpl.init();//from  w ww . j ava 2s.  c  o m
    BpsimFactoryImpl.init();
    _profileService.init(config.getServletContext());
    _pluginService = PluginServiceImpl.getInstance(config.getServletContext());
    _preProcessingService = PreprocessingServiceImpl.INSTANCE;
    _preProcessingService.init(config.getServletContext(), vfsServices);

    _devMode = Boolean.parseBoolean(
            System.getProperty(DEV) == null ? config.getInitParameter(DEV) : System.getProperty(DEV));
    _useOldDataAssignments = Boolean.parseBoolean(
            System.getProperty(USEOLDDATAASSIGNMENTS) == null ? config.getInitParameter(USEOLDDATAASSIGNMENTS)
                    : System.getProperty(USEOLDDATAASSIGNMENTS));
    _preProcess = Boolean
            .parseBoolean(System.getProperty(PREPROCESS) == null ? config.getInitParameter(PREPROCESS)
                    : System.getProperty(PREPROCESS));
    _skin = System.getProperty(SKIN) == null ? config.getInitParameter(SKIN) : System.getProperty(SKIN);
    _designerVersion = readDesignerVersion(config.getServletContext());
    showPDFDoc = doShowPDFDoc(config);

    String editor_file = config.getServletContext().getRealPath(designer_path + "editor.st");
    try {
        _doc = readFile(editor_file);
    } catch (Exception e) {
        throw new ServletException("Error while parsing editor.st", e);
    }
    if (_doc == null) {
        _logger.error("Invalid editor.st, " + "could not be read as a document.");
        throw new ServletException("Invalid editor.st, " + "could not be read as a document.");
    }
}

From source file:common.web.servlets.StaticFilesServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    if (config != null) {
        String prop_file = config.getInitParameter(PROPERTIES_PATH_NAME);
        if (prop_file == null || prop_file.equals(""))
            throw new ServletException("properties_file not specified");
        //loadFromPropertiesFile( config.getServletContext().getRealPath(prop_file) );
        loadFromPropertiesFile(prop_file);

        config.getServletContext().setAttribute("NewIO", newStat);
        config.getServletContext().setAttribute("OldIO", oldStat);
    }/*from ww w.j av  a2  s  . c o m*/
    if (realPath == null)
        throw new ServletException("path to directory not found");
}

From source file:org.apache.jasper.servlet.JspServletWrapper.java

JspServletWrapper(ServletConfig config, Options options, String jspUri, boolean isErrorPage,
        JspRuntimeContext rctxt) throws JasperException {

    this.isTagFile = false;
    this.config = config;
    this.options = options;
    this.jspUri = jspUri;
    ctxt = new JspCompilationContext(jspUri, isErrorPage, options, config.getServletContext(), this, rctxt);
}

From source file:es.juntadeandalucia.mapea.proxy.ProxyRedirect.java

/***************************************************************************
 * Initialize variables called when context is initialized
 ****************************************************************************/
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    context_ = config.getServletContext();
    log.info("proxysig.ProxyRedirect: context initialized to: " + context_.getServletContextName());
}

From source file:m.c.m.proxyma.ProxymaServlet.java

/**
 * Initialize the servlet and the proxyma environment.
 *///w  w w. j  av a 2 s.co  m
@Override
public void init() {
    try {
        //Obtain configuration parameters..
        ServletConfig config = this.getServletConfig();
        String proxymaConfigFile = this.getInitParameter("ProxymaConfigurationFile");
        String proxymaContextName = this.getInitParameter("ProxymaContextName");
        String proxymaLogsDirectory = this.getInitParameter("ProxymaLogsDir");

        //if the config file init-parameter is notspecified use the default configuration
        if (proxymaConfigFile == null)
            proxymaConfigFile = config.getServletContext().getRealPath("/WEB-INF/proxyma-config.xml");

        //Hack to get the servlet path reading it directly from the deployment descriptor.
        //Valid until apache will put a getServletMappings() method into the ServletConfig class.
        XMLConfiguration deploymentDescriptor = null;
        try {
            deploymentDescriptor = new XMLConfiguration();
            deploymentDescriptor.setFile(new File(config.getServletContext().getRealPath("/WEB-INF/web.xml")));
            deploymentDescriptor.setValidating(false);
            deploymentDescriptor.load();
        } catch (ConfigurationException ex) {
            Logger.getLogger("").log(Level.SEVERE, "Unable to load web.xml", ex);
        }
        deploymentDescriptor.setExpressionEngine(new XPathExpressionEngine());
        String servletPath = deploymentDescriptor
                .getString("servlet-mapping[servlet-name='" + config.getServletName() + "']/url-pattern");
        String proxymaServletContext = config.getServletContext().getContextPath()
                + servletPath.replaceFirst("/\\*$", GlobalConstants.EMPTY_STRING);

        //Check if the logs directory init-parameter ends with "/"
        if (!proxymaLogsDirectory.endsWith("/")) {
            proxymaLogsDirectory = proxymaLogsDirectory + "/";
        }

        //Create a new proxyma facade
        this.proxyma = new ProxymaFacade();

        //Create a new proxyma context
        this.proxymaContext = proxyma.createNewContext(proxymaContextName, proxymaServletContext,
                proxymaConfigFile, proxymaLogsDirectory);

        //Create a reverse proxy engine for this servlet thread
        this.proxymaEngine = proxyma.createNewProxyEngine(proxymaContext);
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    }
}

From source file:cn.vlabs.duckling.vwb.ui.servlet.AbstractLoginServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    String file = config.getInitParameter("configFile");
    if (file == null) {
        throw new ServletException("Init parameter configFile  which contains sso configuration is required.");
    }//from   w w  w .j  a  va 2 s  .  c  o  m
    principalKey = config.getInitParameter("principalKey");
    if (principalKey == null) {
        principalKey = "umt.principal";
    }
    String prefix = config.getInitParameter("prefix");
    String realPath = config.getServletContext().getRealPath(file);
    Config config1 = loadConfig(realPath);
    copyToLocal(prefix, config1);
}

From source file:com.hphoto.server.ApiServlet.java

public void init(ServletConfig config) throws ServletException {
    if (server != null) {
        return;//from  ww w  . j  av a2  s . c  o  m
    }
    try {
        ServletContext context = config.getServletContext();
        this.server = (TableServer) context.getAttribute("hphoto.tableServer");
        this.conf = (Configuration) context.getAttribute("hphoto.conf");
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:org.appcelerator.transport.AjaxServiceTransportServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    String validate = config.getInitParameter("validate");
    if (validate != null && !validate.equals("")) {
        performValidation = Boolean.parseBoolean(validate);
    }//from w  w w.j  a v a 2  s .  c o  m

    if (this.embeddedMode) {
        AnnotationHelper.initializeAnnotationDBFromClasspath();
    } else {
        AnnotationHelper.initializeAnnotationDBFromServlet(config.getServletContext());
    }

    ServiceRegistry.intialize(config.getServletContext());
}

From source file:org.opencms.main.OpenCmsServlet.java

/**
 * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
 *//*from  w  w  w.  jav  a2s. c  o  m*/
@Override
public synchronized void init(ServletConfig config) throws ServletException {

    super.init(config);
    try {
        // upgrade the runlevel 
        // usually this should have already been done by the context listener
        // however, after a fresh install / setup this will be done from here
        OpenCmsCore.getInstance().upgradeRunlevel(config.getServletContext());
        // finalize OpenCms initialization
        OpenCmsCore.getInstance().initServlet(this);
    } catch (CmsInitException e) {
        if (Messages.ERR_CRITICAL_INIT_WIZARD_0.equals(e.getMessageContainer().getKey())) {
            // if wizard is still enabled - allow retry of initialization (required for setup wizard)
            // this means the servlet init() call must be terminated by an exception
            if (CmsServletContainerSettings.isServletThrowsException()) {
                throw new ServletException(e.getMessage());
            } else {
                // this is needed since some servlet containers does not like the servlet to throw exceptions, 
                // like BEA WLS 9.x and Resin
                LOG.error(Messages.get().getBundle().key(Messages.LOG_ERROR_GENERIC_0), e);
            }
        }
    } catch (Throwable t) {
        LOG.error(Messages.get().getBundle().key(Messages.LOG_ERROR_GENERIC_0), t);
    }
}