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.seam;
018
019import javax.el.ArrayELResolver;
020import javax.el.BeanELResolver;
021import javax.el.CompositeELResolver;
022import javax.el.ELContext;
023import javax.el.ELResolver;
024import javax.el.ExpressionFactory;
025import javax.el.ListELResolver;
026import javax.el.MapELResolver;
027import javax.el.ResourceBundleELResolver;
028
029import org.jboss.el.ExpressionFactoryImpl;
030import org.jboss.el.lang.FunctionMapperImpl;
031import org.jboss.seam.el.EL;
032import org.jboss.seam.el.SeamELResolver;
033import org.nuxeo.ecm.platform.actions.ELActionContext;
034import org.nuxeo.ecm.platform.el.DocumentModelResolver;
035
036/**
037 * Sample Seam action context, resolving components in Seam context (but not relying on faces context to do so)
038 * <p>
039 * Adds the {@link DocumentModelResolver} at the top of the list of default Seam resolvers.
040 *
041 * @since 5.7.3
042 */
043public class SeamActionContext extends ELActionContext {
044
045    private static final long serialVersionUID = 1L;
046
047    public static final ELResolver EL_RESOLVER = createELResolver();
048
049    public static ELResolver createELResolver() {
050        CompositeELResolver resolver = new CompositeELResolver();
051        resolver.add(new DocumentModelResolver());
052        resolver.add(new SeamELResolver());
053        resolver.add(new MapELResolver());
054        resolver.add(new ListELResolver());
055        resolver.add(new ArrayELResolver());
056        resolver.add(new ResourceBundleELResolver());
057        resolver.add(new BeanELResolver());
058        return resolver;
059    }
060
061    public static final ExpressionFactory EXPRESSION_FACTORY = new ExpressionFactoryImpl();
062
063    public SeamActionContext() {
064        super(EL.createELContext(EL_RESOLVER, new FunctionMapperImpl()), EXPRESSION_FACTORY);
065    }
066
067    public SeamActionContext(ELContext originalContext, ExpressionFactory expressionFactory) {
068        super(originalContext, expressionFactory);
069    }
070
071}