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 PageFieldExpression extends AbstractValueExpression {
045: private final String _field;
046:
047: PageFieldExpression(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 PageContextImpl.PageELContext)) {
059: ELResolver elResolver = env.getELResolver();
060:
061: Object scope = elResolver.getValue(env, null, "pageScope");
062:
063: return elResolver.getValue(env, scope, _field);
064: }
065:
066: PageContextImpl pageContext = ((PageContextImpl.PageELContext) env)
067: .getPageContext();
068:
069: return pageContext.getAttribute(_field);
070: }
071:
072: /**
073: * Evaluate the expr as an object.
074: *
075: * @param env the page context
076: */
077: @Override
078: public boolean isReadOnly(ELContext env) throws ELException {
079: return false;
080: }
081:
082: /**
083: * Evaluate the expr as an object.
084: *
085: * @param env the page context
086: */
087: @Override
088: public void setValue(ELContext env, Object value)
089: throws ELException {
090: if (!(env instanceof PageContextImpl.PageELContext)) {
091: ELResolver elResolver = env.getELResolver();
092:
093: Object scope = elResolver.getValue(env, null,
094: "pageContextScope");
095:
096: elResolver.setValue(env, scope, _field, value);
097:
098: return;
099: }
100:
101: PageContextImpl pageContext = ((PageContextImpl.PageELContext) env)
102: .getPageContext();
103:
104: pageContext.setAttribute(_field, value);
105: }
106:
107: public String getExpressionString() {
108: return "pageScope['" + _field + "']";
109: }
110: }
|