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

📄 namebasedthememanager.java

📁 一个简单的java邮件系统源码
💻 JAVA
字号:
package com.easyjf.web.theme;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.easyjf.web.IPathMappingRuler;

/**
 * 
 * <p>
 * Title:主题接口
 * </p>
 * <p>
 * Description:具体的主题对象,一个主题对应一个主题对象;
 * </p>
 * <p>
 * Copyright: Copyright (c) 2006
 * </p>
 * <p>
 * Company: www.easyjf.com
 * </p>
 * 
 * @author stef_wu
 * @version 1.0
 */

public abstract class NameBasedThemeManager implements IThemeManager {

	/**
	 * 默认的主题请求参数名字用theme;
	 */
	private static final String DEFAULT_THEME_PARAME_NAME = "theme";

	private static final String THEME_NAME_IN_SESSION = "theme";

	/**
	 * 请求解析器; 在这里将使用这个解析器来得到请求的参数; 并检查是否含有paramName这个参数名称对应的参数; 这个参数就是要请求的主题名称;
	 */
	private IPathMappingRuler pathRuler;

	/**
	 * 请求的主题的参数名称;
	 */
	private String paramName;

	public String getParamName() {
		return paramName;
	}

	public final void setParamName(String paramName) {
		this.paramName = paramName;
	}

	public final IPathMappingRuler getPathRuler() {
		return pathRuler;
	}

	public final void setPathRuler(IPathMappingRuler pathRuler) {
		this.pathRuler = pathRuler;
	}

	/*
	 * 通过IPathMappingRuler来从请求中解析出Theme的名字;
	 * 
	 * @see com.easyjf.web.theme.IThemeManager#getTheme(javax.servlet.http.HttpServletRequest)
	 */
	public final ITheme getTheme(HttpServletRequest request)
			throws ThemeProcessException {
		// TODO Auto-generated method stub
		ITheme result = null;

		if (this.getParamName() == null || this.getParamName().equals("")) {
			this.setParamName(DEFAULT_THEME_PARAME_NAME);
		} 
		Map params = getPathRuler().getParams();
		String themeName = null;
		if (params != null) {
			java.util.Iterator it=params.keySet().iterator();
			while(it.hasNext())
			{
				String tempParamName=(String)it.next();
				if (tempParamName.toLowerCase().equals(
						getParamName().toLowerCase())) {
					themeName =(String) params.get(paramName);
					break;
				}
			} 
			/*
			for (String tempParamName : params.keySet()) {
				if (tempParamName.toLowerCase().equals(
						getParamName().toLowerCase())) {
					themeName = params.get(paramName);
					break;
				}
				
			}*/
			if ( themeName != null && !"".equals(themeName)) {
				try {
					result = getThemeByName(themeName);
					System.out.println(result);
					request.getSession().removeAttribute(megerSessionName());
					request.getSession(true).setAttribute(megerSessionName(),
							result);
				} catch (PropertiesThemeLoadException ex) {
					throw new ThemeProcessException();
				}
			}
		} 
		if (result == null) {
			result = (ITheme) request.getSession(true).getAttribute(
					megerSessionName());
		}
		return result;

	}

	private String megerSessionName() {
		return this.getClass().getName() + "." + THEME_NAME_IN_SESSION;
	}

	/**
	 * 通过给定的请求的主题的名字来寻找主题对象;
	 * 
	 * @param themeName
	 *            请求的Theme的名字;
	 * @return 匹配到的主题;
	 */
	abstract protected ITheme getThemeByName(String themeName)
			throws PropertiesThemeLoadException;

}

⌨️ 快捷键说明

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