webapp.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 2,683 行 · 第 1/5 页

JAVA
2,683
字号
    _accessLogLocal.set(log);  }  /**   * Adds a mime-mapping   */  public void addMimeMapping(MimeMapping mimeMapping)  {    _mimeMapping.put(mimeMapping.getExtension(),                     mimeMapping.getMimeType());  }  /**   * Adds a locale-mapping   */  public void putLocaleEncoding(String locale, String encoding)  {    _localeMapping.put(locale.toLowerCase(), encoding);  }  /**   * Returns the locale encoding.   */  public String getLocaleEncoding(Locale locale)  {    String encoding;    String key = locale.toString();    encoding = _localeMapping.get(key.toLowerCase());    if (encoding != null)      return encoding;    if (locale.getVariant() != null) {      key = locale.getLanguage() + '_' + locale.getCountry();      encoding = _localeMapping.get(key.toLowerCase());      if (encoding != null)        return encoding;    }    if (locale.getCountry() != null) {      key = locale.getLanguage();      encoding = _localeMapping.get(key.toLowerCase());      if (encoding != null)        return encoding;    }    return Encoding.getMimeName(locale);  }  /**   * Sets the login   */  public void setLoginConfig(LoginConfig loginConfig)    throws Throwable  {    _loginManager = loginConfig.getLogin();  }  /**   * Sets the login   */  public void setLogin(Login login)  {    _loginFactory = login;  }  /**   * Adds rewrite-dispatch.   */  public RewriteDispatch createRewriteDispatch()  {    return new RewriteDispatch(this);  }  /**   * Adds rewrite-dispatch.   */  public void addRewriteDispatch(RewriteDispatch dispatch)  {    if (dispatch.isRequest())      _requestRewriteDispatch = dispatch;        if (dispatch.isInclude())      _includeRewriteDispatch = dispatch;        if (dispatch.isForward())      _forwardRewriteDispatch = dispatch;  }  /**   * Adds rewrite-real-path.   */  public RewriteRealPath createRewriteRealPath()  {    if (_rewriteRealPath == null)      _rewriteRealPath = new RewriteRealPath(getAppDir());    return _rewriteRealPath;  }  /**   * Adds a path-mapping   */  public void addPathMapping(PathMapping pathMapping)    throws Exception  {    String urlPattern = pathMapping.getUrlPattern();    String urlRegexp = pathMapping.getUrlRegexp();    String realPath = pathMapping.getRealPath();    if (urlPattern != null)      createRewriteRealPath().addPathPattern(urlPattern, realPath);    else if (urlRegexp != null)      createRewriteRealPath().addPathRegexp(urlRegexp, realPath);    else      throw new NullPointerException();  }  /**   * Adds a security constraint   */  public void addSecurityConstraint(SecurityConstraint constraint)  {    _constraintManager.addConstraint(constraint);  }  /**   * Adds a security role   */  public void addSecurityRole(SecurityRole role)  {  }  /**   * Sets the secure requirement.   */  public void setSecure(boolean isSecure)  {    _isSecure = isSecure;    if (isSecure) {      TransportConstraint transConstraint = new TransportConstraint("secure");      SecurityConstraint constraint = new SecurityConstraint();      constraint.setURLPattern("/*");      constraint.addConstraint(transConstraint);      _constraintManager.addConstraint(constraint);    }  }  public void addListener(Listener listener)    throws Exception  {    if (! hasListener(listener.getListenerClass())) {      _listeners.add(listener);      if (_lifecycle.isStarting() || _lifecycle.isActive()) {        addListenerObject(listener.createListenerObject(), true);      }    }  }  /**   * Returns true if a listener with the given type exists.   */  public boolean hasListener(Class listenerClass)  {    for (int i = 0; i < _listeners.size(); i++) {      Listener listener = _listeners.get(i);      if (listenerClass.equals(listener.getListenerClass()))        return true;    }    return false;  }  /**   * Adds the listener object.   */  private void addListenerObject(Object listenerObj, boolean start)  {    if (listenerObj instanceof ServletContextListener) {      ServletContextListener scListener = (ServletContextListener) listenerObj;      _webAppListeners.add(scListener);      if (start) {        ServletContextEvent event = new ServletContextEvent(this);        try {          scListener.contextInitialized(event);        } catch (Exception e) {          log.log(Level.FINE, e.toString(), e);        }      }    }    if (listenerObj instanceof ServletContextAttributeListener)      addAttributeListener((ServletContextAttributeListener) listenerObj);    if (listenerObj instanceof ServletRequestListener) {      _requestListeners.add((ServletRequestListener) listenerObj);      _requestListenerArray = new ServletRequestListener[_requestListeners.size()];      _requestListeners.toArray(_requestListenerArray);    }    if (listenerObj instanceof ServletRequestAttributeListener) {      _requestAttributeListeners.add((ServletRequestAttributeListener) listenerObj);      _requestAttributeListenerArray = new ServletRequestAttributeListener[_requestAttributeListeners.size()];      _requestAttributeListeners.toArray(_requestAttributeListenerArray);    }    if (listenerObj instanceof HttpSessionListener)      getSessionManager().addListener((HttpSessionListener) listenerObj);    if (listenerObj instanceof HttpSessionAttributeListener)      getSessionManager().addAttributeListener((HttpSessionAttributeListener) listenerObj);    if (listenerObj instanceof HttpSessionActivationListener)      getSessionManager().addActivationListener((HttpSessionActivationListener) listenerObj);  }  /**   * Returns the request listeners.   */  public ServletRequestListener []getRequestListeners()  {    return _requestListenerArray;  }  /**   * Returns the request attribute listeners.   */  public ServletRequestAttributeListener []getRequestAttributeListeners()  {    return _requestAttributeListenerArray;  }  /**   * Adds a ResourceRef validator.   */  public void addResourceRef(ResourceRef ref)  {    _resourceValidators.add(ref);  }  // special config  /**   * Multipart form config.   */  public MultipartForm createMultipartForm()  {    if (_multipartForm == null)      _multipartForm = new MultipartForm();    return _multipartForm;  }  /**   * Returns true if multipart forms are enabled.   */  public boolean doMultipartForm()  {    return _multipartForm != null && _multipartForm.isEnable();  }  /**   * Returns the form upload max.   */  public long getFormUploadMax()  {    if (_multipartForm != null)      return _multipartForm.getUploadMax();    else      return -1;  }  /**   * Returns the access log   */  public AbstractAccessLog getAccessLog()  {    return _accessLog;  }  /**   * Sets the temporary directory   */  public void setTempDir(Path path)  {    _tempDir = path;  }  /**   * jsp configuration   */  public JspPropertyGroup createJsp()  {    if (_jsp == null) {      _jsp = new JspPropertyGroup();    }    return _jsp;  }  /**   * Returns the JSP configuration.   */  public JspPropertyGroup getJsp()  {    return _jsp;  }  /**   * jsf configuration   */  public JsfPropertyGroup createJsf()  {    if (_jsf == null)      _jsf = new JsfPropertyGroup();    return _jsf;  }  /**   * Returns the JSF configuration   */  public JsfPropertyGroup getJsf() {    return _jsf;  }  /**   * Returns the JspApplicationContext for EL evaluation.   */  public JspApplicationContextImpl getJspApplicationContext()  {    return _jspApplicationContext;  }  /**   * Returns true for JSP 1.x   */  public boolean has23Config()  {    return _jspState == JSP_1;  }  /**   * taglib configuration   */  public void addTaglib(JspTaglib taglib)  {    if (_taglibList == null) {      _taglibList = new ArrayList<JspTaglib>();    }    _taglibList.add(taglib);  }  /**   * Returns the taglib configuration.   */  public ArrayList<JspTaglib> getTaglibList()  {    return _taglibList;  }  public JspConfig createJspConfig()  {    return new JspConfig(this);  }  /**   * jsp-config configuration   */  public void addJspConfig(JspConfig config)  {    _extensions.put("jsp-config", config);  }  /**   * Returns an extension.   */  public Object getExtension(String key)  {    return _extensions.get(key);  }  /**   * ejb-ref configuration   */  public EjbRef createEjbRef()  {    if (_controller != null && _controller.getArchivePath() != null)      return new EjbRef(_controller.getArchivePath());    else      return new EjbRef();  }  /**   * ejb-local-ref configuration   */  public EjbLocalRef createEjbLocalRef()  {    if (_controller != null && _controller.getArchivePath() != null)      return new EjbLocalRef(_controller.getArchivePath());    else      return new EjbLocalRef();  }  /**   * Sets the war-expansion   */  public WebAppExpandDeployGenerator createWebAppDeploy()  {    return _parent.createWebAppDeploy();  }  /**   * Adds a war generator   */  public void addWebAppDeploy(WebAppExpandDeployGenerator deploy)    throws Exception  {    String contextPath = getContextPath();    String prefix = deploy.getURLPrefix();    deploy.setURLPrefix(contextPath + prefix);    deploy.setParent(_controller);    // _parent.addWebAppDeploy(gen);    deploy.setParentClassLoader(getClassLoader());    // deploy.deploy();    // XXX: The parent is added in the init()    // server/10t3    // _parent.addWebAppDeploy(deploy);    for (WebAppConfig configDefault : _webAppDefaultList)      deploy.addWebAppDefault(configDefault);    Environment.addEnvironmentListener(deploy, getClassLoader());    _appGenerators.add(deploy);  }  /**   * Adds a web-app default   */  public void addWebAppDefault(WebAppConfig config)  {    _webAppDefaultList.add(config);  }  /**   * Adds a web-app default   */  public ArrayList<WebAppConfig> getWebAppDefaultList()  {    return _webAppDefaultList;  }  /**   * Adds a sub web-app   */  public void addWebApp(WebAppConfig config)    throws Exception  {    String contextPath = getContextPath();    String prefix = config.getId();    if (prefix == null || prefix.equals("") || prefix.equals("/"))      throw new ConfigException(L.l("'{0}' is an illegal sub web-app id.",                                    prefix));    WebAppContainer container = _parent;    DeployContainer<WebAppController> appGenerator;    appGenerator = _parent.getWebAppGenerator();    WebAppSingleDeployGenerator deploy;    deploy = new WebAppSingleDeployGenerator(appGenerator,                                             container, config);    deploy.setURLPrefix(contextPath + prefix);    // deploy.setParent(_controller);    // XXX: The parent is added in the init()    // _parent.addWebAppDeploy(gen);    deploy.setParentWebApp(_controller);    deploy.setParentClassLoader(getClassLoader());    deploy.setContainer(container);    for (WebAppConfig configDefault : _webAppDefaultList)      deploy.addWebAppDefault(configDefault);    String appDir = config.getDocumentDirectory();    if (appDir == null)      appDir = "./" + prefix;    Path root = PathBuilder.lookupPath(appDir, null, getAppDir());    deploy.setRootDirectory(root);    deploy.init();    _parent.addDeploy(deploy);    //_appGenerators.add(deploy);    //deploy.deploy();  }  /**   * Sets the config exception.   */  public void setConfigException(Throwable e)  {    if (e != null) {      Throwable e1 = e;      for (;           e1 != null	     && ! (e1 instanceof ConfigException)             && e1.getCause() != null             && e1.getCause() != e1;           e1 = e1.getCause()) {      }            if (e1 != null) {	if (e1 instanceof ConfigException) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?