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

📄 propertiesnamebasedthememanager.java

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

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import com.easyjf.web.Globals;
import com.easyjf.web.IPathMappingRuler;
import com.easyjf.web.theme.ITheme;
import com.easyjf.web.theme.NameBasedThemeManager;
import com.easyjf.web.theme.PropertiesThemeLoadException;

/**
 * 
 * <p>
 * Title:实现的一个默认的主题管理器, 会在一个指定的路径下根据传入的主题的名字寻找一个指定的.properties文件, 并装配成一个ITheme对象;
 * </p>
 * <p>
 * Description:具体的主题对象,一个主题对应一个主题对象;
 * </p>
 * <p>
 * Copyright: Copyright (c) 2006
 * </p>
 * <p>
 * Company: www.easyjf.com
 * </p>
 * 
 * @author stef_wu
 * @version 1.0
 */

public class PropertiesNameBasedThemeManager extends NameBasedThemeManager {

	/**
	 * 默认的.properties文件的前缀;
	 */
	private static final String DEFAULT_PERFIX_NAME = "theme_";

	/**
	 * 默认的寻找properties文件的位置;
	 */
	private static final String DEFAULT_DOC_BASE = Globals.APP_BASE_DIR+Globals.DEFAULT_TEMPLATE_PATH.substring(1)
			+ File.separator+"theme";

	/**
	 * .properties文件的前缀;
	 */
	private String perfixName = DEFAULT_PERFIX_NAME;

	/**
	 * 寻找properties文件的位置;
	 */
	private String docBase = DEFAULT_DOC_BASE;

	private Map themeCache = new HashMap();

	/**
	 * 默认的ITheme对象; 当根据名字找不到一个theme对象的时候,就会使用该对象合成ITheme; 如果没有配置该对象, 则getThemeByName方法返回null;
	 */
	private Properties defaultProperties;

	public PropertiesNameBasedThemeManager() {

	}

	public PropertiesNameBasedThemeManager(IPathMappingRuler pathRuler) {
		this.setPathRuler(pathRuler);
	}

	public Properties getDefaultTheme() {
		return defaultProperties;
	}

	public void setDefaultTheme(Properties defaultProperties) {
		this.defaultProperties = defaultProperties;
	}

	public String getDocBase() {
		return docBase;
	}

	public void setDocBase(String docBase) {
		this.docBase = docBase;
	}

	public String getPerfixName() {
		return perfixName;
	}

	public void setPerfixName(String perfixName) {
		this.perfixName = perfixName;
	}


	protected ITheme getThemeByName(String themeName)
			throws PropertiesThemeLoadException {
		// TODO Auto-generated method stub
		String fileName = this.mergeThemePropertiesName(themeName);
		ITheme result = (ITheme)this.themeCache.get(fileName);
		if (result == null) {
			Properties targetProperties = this.getDefaultTheme();
			File file = new File(fileName);
			if (file.exists()) {
				targetProperties = new Properties();
				try {
					targetProperties.load(new FileInputStream(file));
				} catch (FileNotFoundException ex) {

				} catch (IOException ex) {
					throw new PropertiesThemeLoadException(fileName);
				}
			}
			if (targetProperties != null) {
				result = new PropertiesDefinedTheme(targetProperties);
				this.themeCache.put(fileName, result);
			}
		}
		return result;
	}

	/**
	 * 合成.properties文件的名字;
	 */
	private String mergeThemePropertiesName(String themeName) {
		String fullName =this.getDocBase()+File.separator+getPerfixName()  + themeName + ".properties";
		return fullName;
	}

}

⌨️ 快捷键说明

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