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