⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webappcontext.java

📁 jetty SERVER連接資料庫用的軟體
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                    setAttribute(ServletHandler.__J_S_CONTEXT_TEMPDIR,_tmpDir);                    return _tmpDir;                }            }            catch(Exception e)            {                Log.warn(Log.EXCEPTION,e);            }        }        // No tempdir so look for a work directory to use as tempDir base        File work=null;        try        {            File w=new File(System.getProperty("jetty.home"),"work");            if (w.exists() && w.canWrite() && w.isDirectory())                work=w;            else if (getBaseResource()!=null)            {                Resource web_inf = getWebInf();                if (web_inf !=null && web_inf.exists())                {                    w=new File(web_inf.getFile(),"work");                    if (w.exists() && w.canWrite() && w.isDirectory())                        work=w;                }            }        }        catch(Exception e)        {            Log.ignore(e);        }        // No tempdir set so make one!        try        {                      String temp = getCanonicalNameForWebAppTmpDir();                        if (work!=null)                _tmpDir=new File(work,temp);            else            {                _tmpDir=new File(System.getProperty("java.io.tmpdir"),temp);                                if (_tmpDir.exists())                {                    if(Log.isDebugEnabled())Log.debug("Delete existing temp dir "+_tmpDir+" for "+this);                    if (!IO.delete(_tmpDir))                    {                        if(Log.isDebugEnabled())Log.debug("Failed to delete temp dir "+_tmpDir);                    }                                    if (_tmpDir.exists())                    {                        String old=_tmpDir.toString();                        _tmpDir=File.createTempFile(temp+"_","");                        if (_tmpDir.exists())                            _tmpDir.delete();                        Log.warn("Can't reuse "+old+", using "+_tmpDir);                    }                }            }            if (!_tmpDir.exists())                _tmpDir.mkdir();                        //if not in a dir called "work" then we want to delete it on jvm exit            if (!isTempWorkDirectory())                _tmpDir.deleteOnExit();            if(Log.isDebugEnabled())Log.debug("Created temp dir "+_tmpDir+" for "+this);        }        catch(Exception e)        {            _tmpDir=null;            Log.ignore(e);        }        if (_tmpDir==null)        {            try{                // that didn't work, so try something simpler (ish)                _tmpDir=File.createTempFile("JettyContext","");                if (_tmpDir.exists())                    _tmpDir.delete();                _tmpDir.mkdir();                _tmpDir.deleteOnExit();                if(Log.isDebugEnabled())Log.debug("Created temp dir "+_tmpDir+" for "+this);            }            catch(IOException e)            {                Log.warn("tmpdir",e); System.exit(1);            }        }        setAttribute(ServletHandler.__J_S_CONTEXT_TEMPDIR,_tmpDir);        return _tmpDir;    }        /**     * Check if the _tmpDir itself is called "work", or if the _tmpDir     * is in a directory called "work".     * @return     */    public boolean isTempWorkDirectory ()    {        if (_tmpDir == null)            return false;        if (_tmpDir.getName().equalsIgnoreCase("work"))            return true;        File t = _tmpDir.getParentFile();        if (t == null)            return false;        return (t.getName().equalsIgnoreCase("work"));    }        /* ------------------------------------------------------------ */    /**     * @return Returns the war as a file or URL string (Resource)     */    public String getWar()    {        if (_war==null)            _war=getResourceBase();        return _war;    }    /* ------------------------------------------------------------ */    public Resource getWebInf() throws IOException    {        resolveWebApp();        // Iw there a WEB-INF directory?        Resource web_inf= super.getBaseResource().addPath("WEB-INF/");        if (!web_inf.exists() || !web_inf.isDirectory())            return null;                return web_inf;    }        /* ------------------------------------------------------------ */    /**     * @return Returns the distributable.     */    public boolean isDistributable()    {        return _distributable;    }    /* ------------------------------------------------------------ */    /**     * @return Returns the extractWAR.     */    public boolean isExtractWAR()    {        return _extractWAR;    }    /* ------------------------------------------------------------ */    /**     * @return True if the webdir is copied (to allow hot replacement of jars)     */    public boolean isCopyWebDir()    {        return _copyDir;    }        /* ------------------------------------------------------------ */    /**     * @return Returns the java2compliant.     */    public boolean isParentLoaderPriority()    {        return _parentLoaderPriority;    }        /* ------------------------------------------------------------ */    protected void loadConfigurations()     	throws Exception    {        if (_configurations!=null)            return;        if (_configurationClasses==null)            _configurationClasses=__dftConfigurationClasses;                _configurations = new Configuration[_configurationClasses.length];        for (int i=0;i<_configurations.length;i++)        {            _configurations[i]=(Configuration)Loader.loadClass(this.getClass(), _configurationClasses[i]).newInstance();        }    }        /* ------------------------------------------------------------ */    protected boolean isProtectedTarget(String target)    {        while (target.startsWith("//"))            target=URIUtil.compactPath(target);                 return StringUtil.startsWithIgnoreCase(target, "/web-inf") || StringUtil.startsWithIgnoreCase(target, "/meta-inf");    }        /* ------------------------------------------------------------ */    public String toString()    {        return this.getClass().getName()+"@"+Integer.toHexString(hashCode())+"{"+getContextPath()+","+(_war==null?getResourceBase():_war)+"}";    }        /* ------------------------------------------------------------ */    /** Resolve Web App directory     * If the BaseResource has not been set, use the war resource to     * derive a webapp resource (expanding WAR if required).     */    protected void resolveWebApp() throws IOException    {        Resource web_app = super.getBaseResource();        if (web_app == null)        {            if (_war==null || _war.length()==0)                _war=getResourceBase();                        // Set dir or WAR            web_app= Resource.newResource(_war);            // Accept aliases for WAR files            if (web_app.getAlias() != null)            {                Log.debug(web_app + " anti-aliased to " + web_app.getAlias());                web_app= Resource.newResource(web_app.getAlias());            }            if (Log.isDebugEnabled())                Log.debug("Try webapp=" + web_app + ", exists=" + web_app.exists() + ", directory=" + web_app.isDirectory());            // Is the WAR usable directly?            if (web_app.exists() && !web_app.isDirectory() && !web_app.toString().startsWith("jar:"))            {                // No - then lets see if it can be turned into a jar URL.                Resource jarWebApp= Resource.newResource("jar:" + web_app + "!/");                if (jarWebApp.exists() && jarWebApp.isDirectory())                {                    web_app= jarWebApp;                }            }            // If we should extract or the URL is still not usable            if (web_app.exists()  && (               (_copyDir && web_app.getFile()!= null && web_app.getFile().isDirectory())                ||               (_extractWAR && web_app.getFile()!= null && !web_app.getFile().isDirectory())               ||               (_extractWAR && web_app.getFile() == null)               ||               !web_app.isDirectory()               ))            {                // Then extract it if necessary.                File extractedWebAppDir= new File(getTempDirectory(), "webapp");                                if (web_app.getFile()!=null && web_app.getFile().isDirectory())                {                    // Copy directory                    Log.info("Copy " + web_app.getFile() + " to " + extractedWebAppDir);                    IO.copyDir(web_app.getFile(),extractedWebAppDir);                }                else                {                    if (!extractedWebAppDir.exists())                    {                        //it hasn't been extracted before so extract it                        extractedWebAppDir.mkdir();                        Log.info("Extract " + _war + " to " + extractedWebAppDir);                        JarResource.extract(web_app, extractedWebAppDir, false);                    }                    else                    {                        //only extract if the war file is newer                        if (web_app.lastModified() > extractedWebAppDir.lastModified())                        {                            extractedWebAppDir.delete();                            extractedWebAppDir.mkdir();                            Log.info("Extract " + _war + " to " + extractedWebAppDir);                            JarResource.extract(web_app, extractedWebAppDir, false);                        }                    }                }                                web_app= Resource.newResource(extractedWebAppDir.getCanonicalPath());            }            // Now do we have something usable?            if (!web_app.exists() || !web_app.isDirectory())            {                Log.warn("Web application not found " + _war);                throw new java.io.FileNotFoundException(_war);            }            if (Log.isDebugEnabled())                Log.debug("webapp=" + web_app);            // ResourcePath            super.setBaseResource(web_app);        }    }        /* ------------------------------------------------------------ */    /**     * @param configurations The configuration class names.  If setConfigurations is not called     * these classes are used to create a configurations array.     */    public void setConfigurationClasses(String[] configurations)    {        _configurationClasses = configurations==null?null:(String[])configurations.clone();    }        /* ------------------------------------------------------------ */    /**     * @param configurations The configurations to set.     */    public void setConfigurations(Configuration[] configurations)    {        _configurations = configurations==null?null:(Configuration[])configurations.clone();    }    /* ------------------------------------------------------------ */    /**      * The default descriptor is a web.xml format file that is applied to the context before the standard WEB-INF/web.xml     * @param defaultsDescriptor The defaultsDescriptor to set.     */    public void setDefaultsDescriptor(String defaultsDescriptor)    {        _defaultsDescriptor = defaultsDescriptor;

⌨️ 快捷键说明

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