001/*
002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017package org.nuxeo.ecm.platform.actions.jsf;
018
019import java.util.Locale;
020
021import javax.el.ELContext;
022import javax.el.ELResolver;
023import javax.el.FunctionMapper;
024import javax.el.VariableMapper;
025
026import com.sun.faces.facelets.el.VariableMapperWrapper;
027
028/**
029 * Wrapper around another EL context to allow override of the variable mapper for some values in context.
030 *
031 * @since 5.7.3
032 */
033public class JSFELContext extends ELContext {
034
035    protected final ELContext originalContext;
036
037    protected final VariableMapper variableMapper;
038
039    public JSFELContext(ELContext originalContext) {
040        super();
041        this.originalContext = originalContext;
042        this.variableMapper = new VariableMapperWrapper(originalContext.getVariableMapper());
043    }
044
045    @Override
046    public ELResolver getELResolver() {
047        return originalContext.getELResolver();
048    }
049
050    @Override
051    public FunctionMapper getFunctionMapper() {
052        return originalContext.getFunctionMapper();
053    }
054
055    @Override
056    public VariableMapper getVariableMapper() {
057        return variableMapper;
058    }
059
060    @Override
061    @SuppressWarnings("rawtypes")
062    public Object getContext(Class key) {
063        return originalContext.getContext(key);
064    }
065
066    @Override
067    public Locale getLocale() {
068        return originalContext.getLocale();
069    }
070
071    @Override
072    public boolean isPropertyResolved() {
073        return originalContext.isPropertyResolved();
074    }
075
076    @Override
077    @SuppressWarnings("rawtypes")
078    public void putContext(Class key, Object contextObject) {
079        originalContext.putContext(key, contextObject);
080    }
081
082    @Override
083    public void setLocale(Locale locale) {
084        originalContext.setLocale(locale);
085    }
086
087    @Override
088    public void setPropertyResolved(boolean resolved) {
089        originalContext.setPropertyResolved(resolved);
090    }
091
092}