attributestorage.java

来自「web版的SVN客户端」· Java 代码 · 共 43 行

JAVA
43
字号
package org.polarion.svnwebclient.web;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;

public class AttributeStorage {	
	protected static AttributeStorage handler = new AttributeStorage();
	protected static String RESTRICTED_MAP = "restrictedMap";
	
	protected AttributeStorage() {}
		 
	public void addParameter(HttpSession session, String key, Object value) {
		Map restricedMap = this.getRestrictedMap(session);
		restricedMap.put(key, value);
	}
	
	public Object getParameter(HttpSession session,String key) {
		Map restricedMap = this.getRestrictedMap(session);
		return restricedMap.get(key);
	}
	
	public static AttributeStorage getInstance() {
		return handler;
	}
	
	public void cleanSession(HttpSession session) {
		Map restricedMap = this.getRestrictedMap(session);
		restricedMap.clear();	
		session.setAttribute(SystemInitializing.ORIGINAL_URL, null);
	}
	
	protected synchronized Map getRestrictedMap(HttpSession session) {
		Map restricedMap = (Map) session.getAttribute(AttributeStorage.RESTRICTED_MAP);
		if (restricedMap == null) {
			restricedMap = Collections.synchronizedMap(new HashMap());
			session.setAttribute(AttributeStorage.RESTRICTED_MAP, restricedMap);
		}
		return restricedMap;
	}
}

⌨️ 快捷键说明

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