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

📄 cookiemap.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
字号:
/* * Copyright 2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.myfaces.context.servlet;import java.util.Enumeration;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;/** * HttpServletRequest Cookies as Map. *  * @author Dimitry D'hondt * @author Anton Koinov * @version $Revision: 1.10 $ $Date: 2004/11/24 13:40:11 $ * $Log: CookieMap.java,v $ * Revision 1.10  2004/11/24 13:40:11  manolito * additional null cookies fixes * * Revision 1.9  2004/11/24 13:36:11  manolito * SF-Bug #1072442 fixed * * Revision 1.8  2004/11/23 12:26:45  manolito * SF-Bug #1071640 fixed * */public class CookieMap extends AbstractAttributeMap{    private static final Cookie[] EMPTY_ARRAY = new Cookie[0];    final HttpServletRequest _httpServletRequest;    CookieMap(HttpServletRequest httpServletRequest)    {        _httpServletRequest = httpServletRequest;    }    public void clear()    {        throw new UnsupportedOperationException(            "Cannot clear HttpRequest Cookies");    }    public boolean containsKey(Object key)    {        Cookie[] cookies = _httpServletRequest.getCookies();        if (cookies == null) return false;        for (int i = 0, len = cookies.length; i < len; i++)        {            if (cookies[i].getName().equals(key))            {                return true;            }        }        return false;    }    public boolean containsValue(Object findValue)    {        if (findValue == null)        {            return false;        }        Cookie[] cookies = _httpServletRequest.getCookies();        if (cookies == null) return false;        for (int i = 0, len = cookies.length; i < len; i++)        {            if (findValue.equals(cookies[i].getValue()))            {                return true;            }        }        return false;    }    public boolean isEmpty()    {        Cookie[] cookies = _httpServletRequest.getCookies();        return cookies == null || cookies.length == 0;    }    public int size()    {        Cookie[] cookies = _httpServletRequest.getCookies();        return cookies == null ? 0 : cookies.length;    }    protected Object getAttribute(String key)    {        Cookie[] cookies = _httpServletRequest.getCookies();        if (cookies == null) return null;        for (int i = 0, len = cookies.length; i < len; i++)        {            if (cookies[i].getName().equals(key))            {                return cookies[i];            }        }        return null;    }    protected void setAttribute(String key, Object value)    {        throw new UnsupportedOperationException(            "Cannot set HttpRequest Cookies");    }    protected void removeAttribute(String key)    {        throw new UnsupportedOperationException(            "Cannot remove HttpRequest Cookies");    }    protected Enumeration getAttributeNames()    {        Cookie[] cookies = _httpServletRequest.getCookies();        if (cookies == null)        {            return new CookieNameEnumeration(EMPTY_ARRAY);        }        else        {            return new CookieNameEnumeration(cookies);        }    }        private static class CookieNameEnumeration implements Enumeration    {        private final Cookie[] _cookies;        private final int _length;        private int _index;                public CookieNameEnumeration(Cookie[] cookies)        {            _cookies = cookies;            _length = cookies.length;        }        public boolean hasMoreElements()        {            return _index < _length;        }        public Object nextElement()        {            return _cookies[_index++].getName();        }    }}

⌨️ 快捷键说明

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