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; 018 019/** 020 * Input provided to an expression parser that can influence an expression 021 * parsing/compilation routine. 022 * 023 * @author Keith Donald 024 * @author Andy Clement 025 * @since 3.0 026 */ 027public interface ParserContext { 028 029 /** 030 * Whether or not the expression being parsed is a template. A template expression 031 * consists of literal text that can be mixed with evaluatable blocks. Some examples: 032 * <pre class="code"> 033 * Some literal text 034 * Hello #{name.firstName}! 035 * #{3 + 4} 036 * </pre> 037 * @return true if the expression is a template, false otherwise 038 */ 039 boolean isTemplate(); 040 041 /** 042 * For template expressions, returns the prefix that identifies the start of an 043 * expression block within a string. For example: "${" 044 * @return the prefix that identifies the start of an expression 045 */ 046 String getExpressionPrefix(); 047 048 /** 049 * For template expressions, return the prefix that identifies the end of an 050 * expression block within a string. For example: "}" 051 * @return the suffix that identifies the end of an expression 052 */ 053 String getExpressionSuffix(); 054 055 056 /** 057 * The default ParserContext implementation that enables template expression parsing 058 * mode. The expression prefix is #{ and the expression suffix is }. 059 * @see #isTemplate() 060 */ 061 public static final ParserContext TEMPLATE_EXPRESSION = new ParserContext() { 062 063 @Override 064 public String getExpressionPrefix() { 065 return "#{"; 066 } 067 068 @Override 069 public String getExpressionSuffix() { 070 return "}"; 071 } 072 073 @Override 074 public boolean isTemplate() { 075 return true; 076 } 077 078 }; 079 080}