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

📄 appsettings.java

📁 一个用struts tiles的在线影院web系统
💻 JAVA
字号:
package com.blue.web.common.util;


import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.HashMap;

/**
 * 用户配置文件类
 * @author Lucifer
 *
 */

public class AppSettings {

	private static AppSettings _instance = null;
	private HashMap _properties = null;

	/**
	 * 获取实例
	 * @return
	 */
	synchronized public static AppSettings getInstance()
	{
	    if (_instance == null)
	    	_instance = new AppSettings();
	
	    return _instance;
	}
	/**
	 * 构造函数
	 *
	 */
	public AppSettings() {
		_properties = new HashMap();
	}

	/**
	 * 读取配置信息
	 * @param root	配置信息的XML 根节点
	 */
	public void loadValuesFromConfigurationXml(Element root) {

		Node configSectionNode = root.getElementsByTagName(AppKeys.CONFIG_SECTION).item(0);
		NodeList list = configSectionNode.getChildNodes();
		
		for (int i = 0; i < list.getLength(); i++) {
			Node node = list.item(i);
			if (node != null) {
                // get url attributes
                // need to be a element to get attributes
				if (node instanceof Element) {
					Element element = (Element) node;
					String key = element.getNodeName();
					
					// Prosses for classInstance.
					if (key.equalsIgnoreCase(AppKeys.CLASS_INSTANCE)) {
						// TODO: 添加代码处理classInstance
					} else {
						try {
							this.setProperty(key, element.getFirstChild().getNodeValue());
						} catch (Exception e) {
							System.err.println("AppSettings.loadValuesFromConfigurationXml() : parse element value error...ignored!");
						}
					}
				}
			}
		}
	}
	/**
	 * 获取配置属性
	 * @param key
	 * @return
	 */
	public synchronized String getProperty(String key) {
		return (String)_properties.get(key);
	}
	/**
	 * 设置配置属性
	 * @param key
	 * @param value
	 */
	public synchronized void setProperty(String key, String value) {
		_properties.put(key, value);
	}
}

⌨️ 快捷键说明

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