001/*
002 * Copyright 2002-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.expression.common;
018
019import org.springframework.expression.ParserContext;
020
021/**
022 * Configurable {@link ParserContext} implementation for template parsing. Expects the
023 * expression prefix and suffix as constructor arguments.
024 *
025 * @author Juergen Hoeller
026 * @since 3.0
027 */
028public class TemplateParserContext implements ParserContext {
029
030        private final String expressionPrefix;
031
032        private final String expressionSuffix;
033
034
035        /**
036         * Create a new TemplateParserContext with the default "#{" prefix and "}" suffix.
037         */
038        public TemplateParserContext() {
039                this("#{", "}");
040        }
041
042        /**
043         * Create a new TemplateParserContext for the given prefix and suffix.
044         * @param expressionPrefix the expression prefix to use
045         * @param expressionSuffix the expression suffix to use
046         */
047        public TemplateParserContext(String expressionPrefix, String expressionSuffix) {
048                this.expressionPrefix = expressionPrefix;
049                this.expressionSuffix = expressionSuffix;
050        }
051
052
053        @Override
054        public final boolean isTemplate() {
055                return true;
056        }
057
058        @Override
059        public final String getExpressionPrefix() {
060                return this.expressionPrefix;
061        }
062
063        @Override
064        public final String getExpressionSuffix() {
065                return this.expressionSuffix;
066        }
067
068}