001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package javax.servlet.jsp.el;
031:
032: import javax.el.ELContext;
033: import javax.el.ELResolver;
034: import javax.servlet.jsp.JspContext;
035: import javax.servlet.jsp.PageContext;
036: import java.beans.FeatureDescriptor;
037: import java.util.ArrayList;
038: import java.util.Enumeration;
039: import java.util.Iterator;
040:
041: /**
042: * Variable resolution for JSP variables
043: */
044: public class ScopedAttributeELResolver extends ELResolver {
045: @Override
046: public Class<String> getCommonPropertyType(ELContext context,
047: Object base) {
048: if (base == null)
049: return String.class;
050: else
051: return null;
052: }
053:
054: @Override
055: public Iterator<FeatureDescriptor> getFeatureDescriptors(
056: ELContext context, Object base) {
057: if (base != null)
058: return null;
059:
060: PageContext pageContext = (PageContext) context
061: .getContext(JspContext.class);
062:
063: context.setPropertyResolved(true);
064:
065: ArrayList<FeatureDescriptor> keys = new ArrayList<FeatureDescriptor>();
066:
067: Enumeration e = pageContext.getAttributeNames();
068: while (e.hasMoreElements()) {
069: Object key = e.nextElement();
070: String name = (String) key;
071:
072: FeatureDescriptor desc = new FeatureDescriptor();
073: desc.setName(name);
074: desc.setDisplayName(name);
075: desc.setShortDescription("");
076: desc.setExpert(false);
077: desc.setHidden(false);
078: desc.setPreferred(true);
079:
080: if (key == null)
081: desc.setValue(ELResolver.TYPE, null);
082: else
083: desc.setValue(ELResolver.TYPE, key.getClass());
084:
085: desc.setValue(ELResolver.RESOLVABLE_AT_DESIGN_TIME,
086: Boolean.TRUE);
087:
088: keys.add(desc);
089: }
090:
091: return keys.iterator();
092: }
093:
094: @Override
095: public Class getType(ELContext context, Object base, Object property) {
096: if (base != null)
097: return null;
098:
099: context.setPropertyResolved(true);
100: return Object.class;
101: }
102:
103: @Override
104: public Object getValue(ELContext context, Object base,
105: Object property) {
106: if (base != null)
107: return null;
108:
109: context.setPropertyResolved(true);
110: PageContext pageContext = (PageContext) context
111: .getContext(JspContext.class);
112:
113: return pageContext.getAttribute(String.valueOf(property));
114: }
115:
116: @Override
117: public boolean isReadOnly(ELContext context, Object base,
118: Object property) {
119: if (base != null)
120: return true;
121:
122: context.setPropertyResolved(true);
123:
124: return false;
125: }
126:
127: @Override
128: public void setValue(ELContext context, Object base,
129: Object property, Object value) {
130: if (base != null)
131: return;
132:
133: context.setPropertyResolved(true);
134:
135: context.setPropertyResolved(true);
136: PageContext pageContext = (PageContext) context
137: .getContext(JspContext.class);
138:
139: pageContext.setAttribute(String.valueOf(property), value);
140: }
141: }
|