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

📄 confighelper.java

📁 Eclipse RCP下编写的工作管理软件代码
💻 JAVA
字号:
package net.sf.util;

import static net.sf.util.StringUtil.string2int;
import static net.sf.util.StringUtil.toArray;
import static net.sf.util.StringUtil.toMap;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;


/**
 * 一组配置的静态辅助方法
 */
public class ConfigHelper {
    //选项值
    private static Properties propList=new Properties(){
		@Override
		public String getProperty(String key) {
			return filterCipher(super.getProperty(key));
		}		
    };
	//选项中文
    private static Properties propMcList;
    //需要定制的属性
    private static List<String> configKeys;
    //配置项
    private static ConfigItems configItems;
    //初始化配置项
    static {
        configItems=new ConfigItems();
        
        configItems.addItem("work.ry", "使用人员",true,"用户");
        configItems.addItem("work.bm", "所在部门",true,"部门");
        configItems.addItem("work.headersize", "表头间隔(不可缺项)",false,"72,36,72,72,72,72,240,80,50,60");
        configItems.addItem("work.listgzfl", "工作分类",true,"程序,管理,需求,支持,会议,其他");
        configItems.addItem("work.listxmz", "项目组分类",true,"无");
        configItems.addItem("work.search3", "第三项搜索参数(不可缺项)",true,"20070101,20070201");
		//设置主目录为启动目录
		String testHome = new File("test").getAbsolutePath();
		testHome = testHome.substring(0, testHome.length() - 4);
        configItems.addItem("work.datahome", "主目录",true,testHome);
        configItems.addItem("work.datetip", "使用时间提示",false,"true");
        configItems.addItem("work.importhome", "导入时的目录",true,testHome);
        configItems.addItem("work.verticalsize", "垂直间隔",false,"240,180");
        configItems.addItem("work.horizontalsize", "水平间隔",false,"300,700");
        configItems.addItem("work.positionsave", "退出时保存位置",false,"true");
        configItems.addItem("work.windowsize", "窗口大小",false,"858,550");
        configItems.addItem("work.windowlocation", "窗口位置",false,"100,100");
        configItems.addItem("work.search1", "第一项搜索配置",true,"近一周");
        configItems.addItem("work.tjzero", "统计时保留0数据",true,"true");
        configItems.addItem("work.chinesecalendar", "使用农历日历",false,"true");
        configItems.addItem("work.gregorianholiday", "阳历节日",true,"");
        configItems.addItem("work.chineseholiday", "阴历节日",true,"12_8,腊八节;");
        configItems.addItem("work.warningminutes", "警告时间",true,"90");
        configItems.addItem("work.timer", "显示时间",false,"true");
        configItems.addItem("work.pspmaxtime", "任务进入周报最小分钟",true,"60");
        configItems.addItem("work.port", "阻止第二实例的端口",false,"8011");
        configItems.addItem("work.mail", "邮件提醒参数",true,"[server,port,username,password,app]");
        configItems.addItem("work.firstday", "每周从周几开始",false,"1");
        configItems.addItem("mail.address", "邮箱地址",true,"name<mailaddress>,[another address]");
        configItems.addItem("mail.popper", "popper设置",true,"leaveOnServer,true;offline,false;checkInterval,10;timeout,0;");
        configItems.addItem("mail.pop3", "邮箱POP3配置",true,"pop3://username:password@host,[another pop3]");
        configItems.addItem("mail.smtp", "邮箱SMTP配置",true,"smtp://username:password@host,[another smtp]");
        configItems.addItem("folderviewer.headersize", "邮件表头",false,"@,5;发件人,60;主题,200;接收时间,80;");
        configItems.addItem("mail.viewratio", "视图比例",false,"0.45");
        configItems.addItem("mail.contractfilter", "联系人过滤条件",false," , ");
        
        propMcList=configItems.getPropMcList();
        //是否需要定制
        configKeys=configItems.getConfigList();
        init();
    }
	
    public static Properties init() {
        try {
        	propList.load(new FileInputStream("work.properties"));
        	//补充缺少的属性
        	Properties prop=configItems.getInitProperties();
        		for(Iterator it=prop.keySet().iterator();it.hasNext();){
        			String key=(String) it.next();
        			if(!propList.containsKey(key))
        				propList.put(key,prop.getProperty(key));
        		}
        		store();
        }
        catch (Exception ie) {
            //加入缺省属性
            propList.putAll(configItems.getInitProperties());
            store();
        }
        return propList;
    }
    //保存配置
    public static void store(){
        try {
        	propList.store((new FileOutputStream("work.properties")), "Default");
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    public static Map getPropMcList() {
        return propMcList;
    }
    
    public static Properties getPropList(){
    	return propList;
    }
    //不允许实例化
    private ConfigHelper() {
    }

    //取人员
    public static String getRy() {
        return propList.getProperty("work.ry");
    }

    //取部门
    public static String getBm() {
        return propList.getProperty("work.bm");
    }
    //取表头间隔
    public static int[] getHeaderSize() {
    	return string2int(toArray(propList.getProperty("work.headersize")),null);
    }

    //取候选工作分类列表
    public static String[] getListGzfl() {
        return toArray(propList.getProperty("work.listgzfl"));
    }

    //取候选项目列表
    public static String[] getListXmz() {
        return toArray(propList.getProperty("work.listxmz"));
    }
    
    //取第三项搜索参数
    public static String[] getSearch3() {
        return toArray(propList.getProperty("work.search3"));
    }

    public static boolean showDateTip() {
        return "true".equalsIgnoreCase(propList.getProperty("work.datetip"));
    }

    public static String getImportHome() {
        return propList.getProperty("work.importhome");
    }

    public static String getDataHome() {
        return propList.getProperty("work.datahome");
    }
    
    //取垂直间隔
    public static int[] getVerticalSize(){
    	return string2int(toArray(propList.getProperty("work.verticalsize")),new String[]{"62","38"});
    }
    
    public static float getVerticalRatio(){
    	return 1.0f*getVerticalSize()[0]/(getVerticalSize()[0]+getVerticalSize()[1]);
    }
    //取水平间隔
    public static int[] getHorizontalSize(){
    	return string2int(toArray(propList.getProperty("work.horizontalsize")),new String[]{"30","70"});
    }
    
    public static float getHorizontalRation(){
    	return 1.0f*getHorizontalSize()[0]/(getHorizontalSize()[0]+getHorizontalSize()[1]);
    }

    public static int[] getWindowSize(){
    	return string2int(toArray(propList.getProperty("work.windowsize")),new String[]{"858","550"});
    }
    public static int[] getWindowLocation(){
    	return string2int(toArray(propList.getProperty("work.windowlocation")),new String[]{"100","100"});
    }

    
    public static boolean getPositionSave(){
    	return "true".equalsIgnoreCase(propList.getProperty("work.positionsave"));
    }
    
    public static String getSearch1(){
    	return StringUtil.convertNull(propList.getProperty("work.search1"));
    }
    
    public static boolean showTjZero() {
        return "true".equalsIgnoreCase(propList.getProperty("work.tjzero"));
    }
    
    //取阳历节日
    public static Map<String,String> getGregorianHoliday(){
    	return toMap(propList.getProperty("work.gregorianholiday"));
    }
    
    public static Map<String,String> getChineseHoliday(){
    	return toMap(propList.getProperty("work.chineseholiday"));
    }
    //显示农历
	public static boolean ShowChineseCalendar() {
		return "true".equalsIgnoreCase(propList.getProperty("work.chinesecalendar"));
	}
	//取警告时间
	public static int getWarningMinutes(){
		return StringUtil.parseInt(propList.getProperty("work.warningminutes"));
	}

	public static List<String> getConfigKeys() {
		return configKeys;
	}
	
	//取btv的headersize
	public static Map<String,String> getHeaderSize(Class clazz){
		return toMap(propList.getProperty(clazz.getSimpleName().toLowerCase()+".headersize"));
	}
    //显示时间
	public static boolean ShowTimer() {
		return "true".equalsIgnoreCase(propList.getProperty("work.timer"));
	}
	
	public static int getPspMaxTime(){
		return StringUtil.parseInt(propList.getProperty("work.pspmaxtime"));
	}
	
	public static int getPort(){
		return StringUtil.parseInt(propList.getProperty("work.port"));
	}
	
	//取邮件参数
	public static String[] getMail(){
		if(propList.getProperty("work.mail").startsWith("["))
			return new String[0];
		else
			return toArray(propList.getProperty("work.mail"));
	}
	
	//取每周从周几开始
	public static int getFirstDay(){
		return StringUtil.parseInt(propList.getProperty("work.firstday","1"));
	}
	
	//取邮箱地址
	public static String[] getAddress(){
		return toArray(propList.getProperty("mail.address"));
	}
	
	//取popper的设置
	public static Map<String,String> getPopper(){
		return toMap(propList.getProperty("mail.popper"));
	}
	
	//取pop3邮箱设置
	public static String[] getPop3(){
		return toArray(propList.getProperty("mail.pop3"));
	}
	
	//取pop3邮箱设置
	public static String[] getSmtp(){
		return toArray(propList.getProperty("mail.smtp"));
	}
	
	//透明处理加密信息,可处理多组,但不嵌套的编码
	private static String filterCipher(String cipher){
		if(cipher == null)
			return cipher;
		int start = cipher.indexOf(CipherUtil.PREFIX);
		int end = cipher.indexOf(CipherUtil.SUFIX,start);
		if(start == -1 || end == -1)
			return cipher;
		String seg=cipher.substring(start+CipherUtil.PREFIX.length(),end);
		String plain=cipher.substring(0,start)+CipherUtil.Decrypt(seg)+cipher.substring(end+CipherUtil.SUFIX.length());
		return filterCipher(plain);
	}
	
	//通用属性获取方法
	public static String[] getStringArrayProperty(String property){
		return toArray(propList.getProperty(property));
	}
}

⌨️ 快捷键说明

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