Package org.thymeleaf.spring3.expression

Source Code of org.thymeleaf.spring3.expression.ThymeleafEvaluationContext

/*
* =============================================================================
*
*   Copyright (c) 2011-2014, The THYMELEAF team (http://www.thymeleaf.org)
*
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
*
* =============================================================================
*/
package org.thymeleaf.spring3.expression;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.expression.BeanFactoryResolver;
import org.springframework.context.expression.MapAccessor;
import org.springframework.core.convert.ConversionService;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.expression.spel.support.StandardTypeConverter;
import org.thymeleaf.util.Validate;

/**
* <p>
*   Thymeleaf's basic implementation of Spring's {@link org.springframework.expression.EvaluationContext}
*   interface.
* </p>
* <p>
*   This implementation adds Thymeleaf's own property accessors
*   (see {@link org.springframework.expression.PropertyAccessor}) for accessing
*   the {@link org.thymeleaf.context.VariablesMap} object in which variables are stored at the
*   context.
* </p>
* <p>
*   Also, this evaluation context (which is usually instanced at the
*   {@link org.thymeleaf.spring3.view.ThymeleafView} initialization) links the execution of expressions
*   with the available {@link BeanFactory} and {@link ConversionService} instances, used during evaluation.
* </p>
* <p>
*   Before executing a Spring EL expression using this evaluation context, it should be enriched with the
*   variables to be made accessible (like <tt>#variableName</tt>), using a
*   {@link ThymeleafEvaluationContextWrapper} object.
* </p>
*
* @author Daniel Fern&aacute;ndez
*
* @since 2.1.0
*
*/
public final class ThymeleafEvaluationContext extends StandardEvaluationContext {

    public static final String THYMELEAF_EVALUATION_CONTEXT_CONTEXT_VARIABLE_NAME = "thymeleafEvaluationContext";

    public static final MapAccessor MAP_ACCESSOR_INSTANCE = new MapAccessor();

    public ThymeleafEvaluationContext(final BeanFactory beanFactory, final ConversionService conversionService) {
       
        super();

        Validate.notNull(beanFactory, "Bean factory cannot be null");
        // ConversionService CAN be null

        this.setBeanResolver(new BeanFactoryResolver(beanFactory));
        if (conversionService != null) {
            this.setTypeConverter(new StandardTypeConverter(conversionService));
        }

        this.addPropertyAccessor(VariablesMapPropertyAccessor.INSTANCE);
        this.addPropertyAccessor(BeansPropertyAccessor.INSTANCE);
        this.addPropertyAccessor(MAP_ACCESSOR_INSTANCE);

    }

}
TOP

Related Classes of org.thymeleaf.spring3.expression.ThymeleafEvaluationContext

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.