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 com.caucho.jsp.el;
031:
032: import com.caucho.el.Expr;
033: import com.caucho.jsp.PageContextImpl;
034: import com.caucho.vfs.WriteStream;
035:
036: import javax.el.*;
037: import javax.servlet.ServletContext;
038: import javax.servlet.http.Cookie;
039: import javax.servlet.http.HttpServletRequest;
040: import javax.servlet.jsp.PageContext;
041: import java.io.IOException;
042: import java.util.*;
043:
044: public class RequestFieldExpression extends AbstractValueExpression {
045: private final String _field;
046:
047: RequestFieldExpression(String field) {
048: _field = field;
049: }
050:
051: /**
052: * Evaluate the expr as an object.
053: *
054: * @param env the page context
055: */
056: @Override
057: public Object getValue(ELContext env) throws ELException {
058: if (!(env instanceof ServletELContext)) {
059: ELResolver elResolver = env.getELResolver();
060:
061: Object scope = elResolver.getValue(env, null,
062: "requestScope");
063:
064: return elResolver.getValue(env, scope, _field);
065: }
066:
067: env.setPropertyResolved(true);
068:
069: ServletELContext servletEnv = (ServletELContext) env;
070:
071: HttpServletRequest request = servletEnv.getRequest();
072:
073: return request.getAttribute(_field);
074: }
075:
076: /**
077: * Evaluate the expr as an object.
078: *
079: * @param env the page context
080: */
081: @Override
082: public boolean isReadOnly(ELContext env) throws ELException {
083: env.setPropertyResolved(true);
084:
085: return false;
086: }
087:
088: /**
089: * Evaluate the expr as an object.
090: *
091: * @param env the page context
092: */
093: @Override
094: public void setValue(ELContext env, Object value)
095: throws ELException {
096: if (!(env instanceof ServletELContext)) {
097: ELResolver elResolver = env.getELResolver();
098:
099: Object scope = elResolver.getValue(env, null,
100: "requestScope");
101:
102: elResolver.setValue(env, scope, _field, value);
103:
104: return;
105: }
106:
107: env.setPropertyResolved(true);
108:
109: ServletELContext servletEnv = (ServletELContext) env;
110:
111: HttpServletRequest request = servletEnv.getRequest();
112:
113: request.setAttribute(_field, value);
114: }
115:
116: public String getExpressionString() {
117: return "requestScope['" + _field + "']";
118: }
119: }
|