⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basebodysupporttag.java

📁 struts+spring+hibernate自创框架
💻 JAVA
字号:

package com.pegasus.framework.component.taglib.util;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.Globals;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.taglib.html.Constants;
import org.apache.struts.util.MessageResources;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import java.lang.reflect.InvocationTargetException;


public abstract class BaseBodySupportTag extends BodyTagSupport {
	// private Logger logger = LogManager.getLogger(BasePagerTag.class);
	/** The messages. */
	protected MessageResources messages = MessageResources.getMessageResources(Constants.Package
			+ ".LocalStrings");

	/**
	 * Searches all scopes for the bean.找寻formbean
	 * 
	 * @param beanName The name of the object to get the property from.
	 * @return the object
	 * @throws JspException the jsp exception
	 */
	protected Object lookupFormBean(String beanName) throws JspException {
		Object bean = TagUtils.getInstance().lookup(this.pageContext, beanName, null);
		if (bean == null) {
			throw new JspException(messages.getMessage("getter.bean", beanName));
		}
		return bean;
	}

	/**
	 * Searches all scopes for the bean and calls BeanUtils.getProperty() with the given arguments and
	 * converts any exceptions into JspException.
	 * 
	 * @param beanName The name of the object to get the property from.
	 * @param property The name of the property to get.
	 * @return The value of the property.
	 * @throws JspException the jsp exception
	 * @since Struts 1.1
	 */
	protected String lookupProperty(String beanName, String property) throws JspException {

		Object bean = lookupFormBean(beanName);

		try {
			return BeanUtils.getProperty(bean, property);

		}
		catch (IllegalAccessException e) {
			throw new JspException(messages.getMessage("getter.access", property, beanName));

		}
		catch (InvocationTargetException e) {
			Throwable t = e.getTargetException();
			throw new JspException(messages.getMessage("getter.result", property, t.toString()));

		}
		catch (NoSuchMethodException e) {
			throw new JspException(messages.getMessage("getter.method", property, beanName));
		}
	}

	/**
	 * Gets the message.根据配置得到key对应的资源文件中的内容
	 * 
	 * @param key the key
	 * @param useResource the use resource是否使用资源文件
	 * @param bundle the bundle资源文件邦定
	 * @return the message
	 */
	protected String getMessage(String key, boolean useResource, String bundle) {
		// logger.info(" getMessage useResource : " + useResource);
		if (useResource) {
			String message = null;
			// logger.info(" getMessage bundle : " + bundle);
			try {
				message = TagUtils.getInstance().message(this.pageContext, bundle, Globals.LOCALE_KEY, key,
						null);
			}
			catch (JspException e) {
				// e.printStackTrace();
				return key;
			}

			if (message == null) {
				return key;
			}
			return message;
		}
		else {
			return key;
		}

	}

	/**
	 * 
	 */
	public void release() {
		super.release();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -