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

📄 contexthandler.java

📁 jetty SERVER連接資料庫用的軟體
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * </p>     * @author gregw     *     */    public class SContext implements ServletContext    {        /* ------------------------------------------------------------ */        protected SContext()        {        }        /* ------------------------------------------------------------ */        public ContextHandler getContextHandler()        {            // TODO reduce visibility of this method            return ContextHandler.this;        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getContext(java.lang.String)         */        public ServletContext getContext(String uripath)        {            // TODO this is a very poor implementation!            // TODO move this to Server            ContextHandler context=null;            Handler[] handlers = getServer().getChildHandlersByClass(ContextHandler.class);            for (int i=0;i<handlers.length;i++)            {                if (handlers[i]==null || !handlers[i].isStarted())                    continue;                ContextHandler ch = (ContextHandler)handlers[i];                String context_path=ch.getContextPath();                if (uripath.equals(context_path) || (uripath.startsWith(context_path)&&uripath.charAt(context_path.length())=='/'))                {                    if (context==null || context_path.length()>context.getContextPath().length())                        context=ch;                }            }                        if (context!=null)                return context._scontext;            return null;        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getMajorVersion()         */        public int getMajorVersion()        {            return 2;        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getMimeType(java.lang.String)         */        public String getMimeType(String file)        {            if (_mimeTypes==null)                return null;            Buffer mime = _mimeTypes.getMimeByExtension(file);            if (mime!=null)                return mime.toString();            return null;        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getMinorVersion()         */        public int getMinorVersion()        {            return 5;        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)         */        public RequestDispatcher getNamedDispatcher(String name)        {            return null;        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getRealPath(java.lang.String)         */        public String getRealPath(String path)        {            if(path==null)                return null;            if(path.length()==0)                path = URIUtil.SLASH;            else if(path.charAt(0)!='/')                path = URIUtil.SLASH + path;                            try            {                Resource resource=ContextHandler.this.getResource(path);                if(resource!=null)                {                    File file = resource.getFile();                    if (file!=null)                        return file.getCanonicalPath();                }            }            catch (Exception e)            {                Log.ignore(e);            }                        return null;        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)         */        public RequestDispatcher getRequestDispatcher(String uriInContext)        {            return null;        }        /* ------------------------------------------------------------ */        /*          */        public URL getResource(String path) throws MalformedURLException        {            Resource resource=ContextHandler.this.getResource(path);            if (resource!=null && resource.exists())                return resource.getURL();            return null;        }                /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)         */        public InputStream getResourceAsStream(String path)        {            try            {                URL url=getResource(path);                if (url==null)                    return null;                return url.openStream();            }            catch(Exception e)            {                Log.ignore(e);                return null;            }        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)         */        public Set getResourcePaths(String path)        {                        return ContextHandler.this.getResourcePaths(path);        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getServerInfo()         */        public String getServerInfo()        {            return "jetty/"+Server.getVersion();        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getServlet(java.lang.String)         */        public Servlet getServlet(String name) throws ServletException        {            return null;        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getServletNames()         */        public Enumeration getServletNames()        {            return Collections.enumeration(Collections.EMPTY_LIST);        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getServlets()         */        public Enumeration getServlets()        {            return Collections.enumeration(Collections.EMPTY_LIST);        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#log(java.lang.Exception, java.lang.String)         */        public void log(Exception exception, String msg)        {            _logger.warn(msg,exception);        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#log(java.lang.String)         */        public void log(String msg)        {            _logger.info(msg, null, null);        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#log(java.lang.String, java.lang.Throwable)         */        public void log(String message, Throwable throwable)        {            _logger.warn(message,throwable);        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)         */        public String getInitParameter(String name)        {            return ContextHandler.this.getInitParameter(name);        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getInitParameterNames()         */        public Enumeration getInitParameterNames()        {            return ContextHandler.this.getInitParameterNames();        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getAttribute(java.lang.String)         */        public synchronized Object getAttribute(String name)        {            Object o = ContextHandler.this.getAttribute(name);            if (o==null && _contextAttributes!=null)                o=_contextAttributes.getAttribute(name);            return o;        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getAttributeNames()         */        public synchronized Enumeration getAttributeNames()        {            HashSet set = new HashSet();            if (_contextAttributes!=null)            {            	Enumeration e = _contextAttributes.getAttributeNames();            	while(e.hasMoreElements())            		set.add(e.nextElement());            }            Enumeration e = _attributes.getAttributeNames();            while(e.hasMoreElements())                set.add(e.nextElement());                        return Collections.enumeration(set);        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object)         */        public synchronized void setAttribute(String name, Object value)        {                        if (_contextAttributes==null)            {            	// Set it on the handler            	ContextHandler.this.setAttribute(name, value);                return;            }            setManagedAttribute(name,value);            Object old_value=_contextAttributes==null?null:_contextAttributes.getAttribute(name);                        if (value==null)                _contextAttributes.removeAttribute(name);            else                _contextAttributes.setAttribute(name,value);                        if (_contextAttributeListeners!=null)            {                ServletContextAttributeEvent event =                    new ServletContextAttributeEvent(_scontext,name, old_value==null?value:old_value);                for(int i=0;i<LazyList.size(_contextAttributeListeners);i++)                {                    ServletContextAttributeListener l = (ServletContextAttributeListener)LazyList.get(_contextAttributeListeners,i);                                        if (old_value==null)                        l.attributeAdded(event);                    else if (value==null)                        l.attributeRemoved(event);                    else                        l.attributeReplaced(event);                }            }        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)         */        public synchronized void removeAttribute(String name)        {            setManagedAttribute(name,null);                        if (_contextAttributes==null)            {            	// Set it on the handler            	_attributes.removeAttribute(name);                return;            }                        Object old_value=_contextAttributes.getAttribute(name);            _contextAttributes.removeAttribute(name);            if (old_value!=null)            {                if (_contextAttributeListeners!=null)                {                    ServletContextAttributeEvent event =                        new ServletContextAttributeEvent(_scontext,name, old_value);                    for(int i=0;i<LazyList.size(_contextAttributeListeners);i++)                        ((ServletContextAttributeListener)LazyList.get(_contextAttributeListeners,i)).attributeRemoved(event);                }            }        }        /* ------------------------------------------------------------ */        /*          * @see javax.servlet.ServletContext#getServletContextName()         */        public String getServletContextName()        {            String name = ContextHandler.this.getDisplayName();            if (name==null)                name=ContextHandler.this.getContextPath();            return name;        }        /* ------------------------------------------------------------ */        /**         * @return Returns the _contextPath.         */        public String getContextPath()        {            if ((_contextPath != null) && _contextPath.equals(URIUtil.SLASH))                return "";                        return _contextPath;        }        /* ------------------------------------------------------------ */        public String toString()        {            return "ServletContext@"+Integer.toHexString(hashCode())+"{"+(getContextPath().equals("")?URIUtil.SLASH:getContextPath())+","+getBaseResource()+"}";        }    }    /* ------------------------------------------------------------ */    private String normalizeHostname( String host )    {        if ( host == null )            return null;                if ( host.endsWith( "." ) )            return host.substring( 0, host.length() -1);                  return host;    }}

⌨️ 快捷键说明

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