All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.thymeleaf.context.AbstractContext Maven / Gradle / Ivy

Go to download

Modern server-side Java template engine for both web and standalone environments

There is a newer version: 3.1.2.RELEASE
Show newest version
/*
 * =============================================================================
 *
 *   Copyright (c) 2011-2018, 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.context;

import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import org.thymeleaf.util.Validate;

/**
 * 

* Abstract base class for most {@link IContext} implementations. *

*

* Note a class with this name existed since 1.0, but it was completely reimplemented * in Thymeleaf 3.0 *

* * @author Daniel Fernández * * @since 3.0.0 * */ public abstract class AbstractContext implements IContext { private final Map variables; private Locale locale; protected AbstractContext() { this(null, null); } protected AbstractContext(final Locale locale) { this(locale, null); } protected AbstractContext(final Locale locale, final Map variables) { super(); this.locale = (locale == null? Locale.getDefault() : locale); this.variables = (variables == null? new LinkedHashMap(10) : new LinkedHashMap(variables)); } public final Locale getLocale() { return this.locale; } public final boolean containsVariable(final String name) { return this.variables.containsKey(name); } public final Set getVariableNames() { return this.variables.keySet(); } public final Object getVariable(final String name) { return this.variables.get(name); } /** *

* Sets the locale to be used. *

* * @param locale the locale. */ public void setLocale(final Locale locale) { Validate.notNull(locale, "Locale cannot be null"); this.locale = locale; } /** *

* Sets a new variable into the context. *

* * @param name the name of the variable. * @param value the value of the variable. */ public void setVariable(final String name, final Object value) { this.variables.put(name, value); } /** *

* Sets several variables at a time into the context. *

* * @param variables the variables to be set. */ public void setVariables(final Map variables) { if (variables == null) { return; } this.variables.putAll(variables); } /** *

* Removes a variable from the context. *

* * @param name the name of the variable to be removed. */ public void removeVariable(final String name) { this.variables.remove(name); } /** *

* Removes all the variables from the context. *

*/ public void clearVariables() { this.variables.clear(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy