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

com.rt.core.util.ELUtil Maven / Gradle / Ivy

There is a newer version: 1.1.17
Show newest version
package com.rt.core.util;

import ognl.Ognl;
import ognl.OgnlContext;
import ognl.OgnlRuntime;

import java.util.Map;

/**
 * OGNL助手
 * 
 */
class ELUtil {

	private ELUtil() {
	}

	/**
	 * 执行普通表达式,表达式中不能包含未放入堆栈的对象.
	 * 
	 * @param expression
	 * @param elContext
	 * @return Object
	 * @throws Exception
	 */
	public static Object findValue(String expression, Object elContext)
			throws Exception {
		findValueBefore();
		return findValue(expression, null, elContext);
	}

	/**
	 * 执行ognl表达式
	 * 
	 * @param expression
	 * @param elContext
	 * @return String
	 * @throws Exception
	 */
	public static String findString(String expression, Object elContext)
			throws Exception {
		findValueBefore();
		Object o = findValue(expression, null, elContext);
		return o == null ? null : o.toString();
	}

	/**
	 * 执行ognl表达式
	 * 
	 * @param expression
	 * @param props
	 * @param elContext
	 * @return Object
	 * @throws Exception
	 */
	public static Object findValue(String expression, Map props,
			Object elContext) throws Exception {
		if (elContext == null) {
			elContext = getElContext();
		}
		findValueBefore();
		return Ognl.getValue(RTUtil.replaceVariable(expression, props),
				elContext);

	}

	/**
	 * 查找值之前执行代码
	 */
	private static void findValueBefore() {
		// just use in gae runtime
		OgnlRuntime.setSecurityManager(null);
	}

	/**
	 * 取得ELContext
	 * 
	 * @return ELContext
	 */
	public static Map getElContext() {
		return new OgnlContext();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy