1 /** 2 * Licensed under the Artistic License; you may not use this file 3 * except in compliance with the License. 4 * You may obtain a copy of the License at 5 * 6 * http://displaytag.sourceforge.net/license.html 7 * 8 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR 9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 10 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 package org.displaytag.tags; 13 14 import javax.servlet.jsp.PageContext; 15 import javax.servlet.jsp.tagext.BodyTagSupport; 16 17 import org.displaytag.exception.ObjectLookupException; 18 import org.displaytag.util.LookupUtil; 19 20 21 /** 22 * Base template class. 23 * @author bgsmith 24 * @author Fabrizio Giustina 25 * @version $Revision: 1081 $ ($Author: fgiust $) 26 */ 27 public abstract class TemplateTag extends BodyTagSupport 28 { 29 30 /** 31 * <p> 32 * evaluate an expression in a way similar to LE in jstl. 33 * </p> 34 * <p> 35 * the first token is supposed to be an object in the page scope (default scope) or one of the following: 36 * </p> 37 * <ul> 38 * <li>pageScope</li> 39 * <li>requestScope</li> 40 * <li>sessionScope</li> 41 * <li>applicationScope</li> 42 * </ul> 43 * <p> 44 * Tokens after the object name are interpreted as javabean properties (accessed through getters), mapped or indexed 45 * properties, using the jakarta common-beans library 46 * </p> 47 * @param expression expression to evaluate 48 * @return Object result 49 * @throws ObjectLookupException if unable to get a bean using the given expression 50 */ 51 protected Object evaluateExpression(String expression) throws ObjectLookupException 52 { 53 54 String expressionWithoutScope = expression; 55 56 // default scope = request 57 // this is for compatibility with the previous version, probably default should be PAGE 58 int scope = PageContext.REQUEST_SCOPE; 59 60 if (expression.startsWith("pageScope.")) //$NON-NLS-1$ 61 { 62 scope = PageContext.PAGE_SCOPE; 63 expressionWithoutScope = expressionWithoutScope.substring(expressionWithoutScope.indexOf('.') + 1); 64 } 65 else if (expression.startsWith("requestScope.")) //$NON-NLS-1$ 66 { 67 scope = PageContext.REQUEST_SCOPE; 68 expressionWithoutScope = expressionWithoutScope.substring(expressionWithoutScope.indexOf('.') + 1); 69 70 } 71 else if (expression.startsWith("sessionScope.")) //$NON-NLS-1$ 72 { 73 scope = PageContext.SESSION_SCOPE; 74 expressionWithoutScope = expressionWithoutScope.substring(expressionWithoutScope.indexOf('.') + 1); 75 76 } 77 else if (expression.startsWith("applicationScope.")) //$NON-NLS-1$ 78 { 79 scope = PageContext.APPLICATION_SCOPE; 80 expressionWithoutScope = expressionWithoutScope.substring(expressionWithoutScope.indexOf('.') + 1); 81 82 } 83 84 return LookupUtil.getBeanValue(this.pageContext, expressionWithoutScope, scope); 85 86 } 87 88 }