1 /* 2 * Copyright 2002-2013 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.expression; 18 19 /** 20 * Input provided to an expression parser that can influence an expression 21 * parsing/compilation routine. 22 * 23 * @author Keith Donald 24 * @author Andy Clement 25 * @since 3.0 26 */ 27 public interface ParserContext { 28 29 /** 30 * Whether or not the expression being parsed is a template. A template expression 31 * consists of literal text that can be mixed with evaluatable blocks. Some examples: 32 * <pre class="code"> 33 * Some literal text 34 * Hello #{name.firstName}! 35 * #{3 + 4} 36 * </pre> 37 * @return true if the expression is a template, false otherwise 38 */ 39 boolean isTemplate(); 40 41 /** 42 * For template expressions, returns the prefix that identifies the start of an 43 * expression block within a string. For example: "${" 44 * @return the prefix that identifies the start of an expression 45 */ 46 String getExpressionPrefix(); 47 48 /** 49 * For template expressions, return the prefix that identifies the end of an 50 * expression block within a string. For example: "}" 51 * @return the suffix that identifies the end of an expression 52 */ 53 String getExpressionSuffix(); 54 55 56 /** 57 * The default ParserContext implementation that enables template expression parsing 58 * mode. The expression prefix is #{ and the expression suffix is }. 59 * @see #isTemplate() 60 */ 61 public static final ParserContext TEMPLATE_EXPRESSION = new ParserContext() { 62 63 @Override 64 public String getExpressionPrefix() { 65 return "#{"; 66 } 67 68 @Override 69 public String getExpressionSuffix() { 70 return "}"; 71 } 72 73 @Override 74 public boolean isTemplate() { 75 return true; 76 } 77 78 }; 79 80 }