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

📄 implicitobjectelresolver.java

📁 梅花雪树的经典制作
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements.  See the NOTICE file distributed with* this work for additional information regarding copyright ownership.* The ASF licenses this file to You 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 javax.servlet.jsp.el;import java.beans.FeatureDescriptor;import java.util.AbstractMap;import java.util.ArrayList;import java.util.Arrays;import java.util.Enumeration;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.Vector;import javax.el.ELContext;import javax.el.ELException;import javax.el.ELResolver;import javax.el.PropertyNotFoundException;import javax.el.PropertyNotWritableException;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpSession;import javax.servlet.jsp.JspContext;import javax.servlet.jsp.PageContext;/** * * @since 2.1 */public class ImplicitObjectELResolver extends ELResolver {    private final static String[] SCOPE_NAMES = new String[] {            "applicationScope", "cookie", "header", "headerValues",            "initParam", "pageContext", "pageScope", "param", "paramValues",            "requestScope", "sessionScope" };    private final static int APPLICATIONSCOPE = 0;    private final static int COOKIE = 1;    private final static int HEADER = 2;    private final static int HEADERVALUES = 3;    private final static int INITPARAM = 4;    private final static int PAGECONTEXT = 5;    private final static int PAGESCOPE = 6;    private final static int PARAM = 7;    private final static int PARAM_VALUES = 8;    private final static int REQUEST_SCOPE = 9;    private final static int SESSION_SCOPE = 10;    public ImplicitObjectELResolver() {        super();    }    public Object getValue(ELContext context, Object base, Object property)            throws NullPointerException, PropertyNotFoundException, ELException {        if (context == null) {            throw new NullPointerException();        }        if (base == null && property != null) {            int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());            if (idx >= 0) {                PageContext page = (PageContext) context                        .getContext(JspContext.class);                context.setPropertyResolved(true);                switch (idx) {                case APPLICATIONSCOPE:                    return ScopeManager.get(page).getApplicationScope();                case COOKIE:                    return ScopeManager.get(page).getCookie();                case HEADER:                    return ScopeManager.get(page).getHeader();                case HEADERVALUES:                    return ScopeManager.get(page).getHeaderValues();                case INITPARAM:                    return ScopeManager.get(page).getInitParam();                case PAGECONTEXT:                    return ScopeManager.get(page).getPageContext();                case PAGESCOPE:                    return ScopeManager.get(page).getPageScope();                case PARAM:                    return ScopeManager.get(page).getParam();                case PARAM_VALUES:                    return ScopeManager.get(page).getParamValues();                case REQUEST_SCOPE:                    return ScopeManager.get(page).getRequestScope();                case SESSION_SCOPE:                    return ScopeManager.get(page).getSessionScope();                }            }        }        return null;    }    public Class getType(ELContext context, Object base, Object property)            throws NullPointerException, PropertyNotFoundException, ELException {        if (context == null) {            throw new NullPointerException();        }        if (base == null && property != null) {            int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());            if (idx >= 0) {                context.setPropertyResolved(true);            }        }        return null;    }    public void setValue(ELContext context, Object base, Object property,            Object value) throws NullPointerException,            PropertyNotFoundException, PropertyNotWritableException,            ELException {        if (context == null) {            throw new NullPointerException();        }        if (base == null && property != null) {            int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());            if (idx >= 0) {                context.setPropertyResolved(true);                throw new PropertyNotWritableException();            }        }    }    public boolean isReadOnly(ELContext context, Object base, Object property)            throws NullPointerException, PropertyNotFoundException, ELException {        if (context == null) {            throw new NullPointerException();        }        if (base == null && property != null) {            int idx = Arrays.binarySearch(SCOPE_NAMES, property.toString());            if (idx >= 0) {                context.setPropertyResolved(true);                return true;            }        }        return false;    }    public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {        List<FeatureDescriptor> feats = new ArrayList<FeatureDescriptor>(                SCOPE_NAMES.length);        FeatureDescriptor feat;        for (int i = 0; i < SCOPE_NAMES.length; i++) {            feat = new FeatureDescriptor();            feat.setDisplayName(SCOPE_NAMES[i]);            feat.setExpert(false);            feat.setHidden(false);            feat.setName(SCOPE_NAMES[i]);            feat.setPreferred(true);            feat.setValue(RESOLVABLE_AT_DESIGN_TIME, Boolean.TRUE);            feat.setValue(TYPE, String.class);            feats.add(feat);        }        return feats.iterator();    }    public Class<String> getCommonPropertyType(ELContext context, Object base) {        if (base == null) {            return String.class;        }        return null;    }    private static class ScopeManager {        private final static String MNGR_KEY = ScopeManager.class.getName();        private final PageContext page;        private Map applicationScope;        private Map cookie;        private Map header;        private Map headerValues;        private Map initParam;        private Map pageScope;        private Map param;        private Map paramValues;        private Map requestScope;        private Map sessionScope;        public ScopeManager(PageContext page) {            this.page = page;        }        public static ScopeManager get(PageContext page) {            ScopeManager mngr = (ScopeManager) page.getAttribute(MNGR_KEY);            if (mngr == null) {                mngr = new ScopeManager(page);                page.setAttribute(MNGR_KEY, mngr);            }            return mngr;        }        public Map getApplicationScope() {            if (this.applicationScope == null) {                this.applicationScope = new ScopeMap() {                    protected void setAttribute(String name, Object value) {                        page.getServletContext().setAttribute(name, value);                    }                    protected void removeAttribute(String name) {                        page.getServletContext().removeAttribute(name);                    }                    protected Enumeration getAttributeNames() {                        return page.getServletContext().getAttributeNames();                    }                    protected Object getAttribute(String name) {                        return page.getServletContext().getAttribute(name);                    }                };            }            return this.applicationScope;        }        public Map getCookie() {            if (this.cookie == null) {                this.cookie = new ScopeMap() {                    protected Enumeration getAttributeNames() {                        Cookie[] c = ((HttpServletRequest) page.getRequest())                                .getCookies();                        if (c != null) {                            Vector v = new Vector();                            for (int i = 0; i < c.length; i++) {                                v.add(c[i].getName());                            }                            return v.elements();                        }                        return null;                    }                    protected Object getAttribute(String name) {                        Cookie[] c = ((HttpServletRequest) page.getRequest())                                .getCookies();                        if (c != null) {                            for (int i = 0; i < c.length; i++) {                                if (name.equals(c[i].getName())) {                                    return c[i];

⌨️ 快捷键说明

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