LifeRay: 获取id Print E-mail
User Rating: / 1
PoorBest 
Portal门户 - Liferay相关
Wednesday, 02 April 2008 05:50
package com.liferay.portal.util;

import java.util.Hashtable;
import java.util.Random;

/**
* <a href="/ImageKey.java.html" mce_href="/ImageKey.java.html"><b><i>View Source</i></b></a>
*
* @author  Brian Wing Shun Chan
* @version $Revision: 1.4 $
*
*/

public class ImageKey {

public static String generateNewKey(String id) {
ImageKey imageKey = _getInstance();

Random random = new Random();
int i = random.nextInt(1000000);

String key = Integer.toString(i);

imageKey._put(id, key);

return key;
}

public static String get(String id) {
ImageKey imageKey = _getInstance();

String key = imageKey._get(id);

if (key == null) {
key = generateNewKey(id);
}

return key;
}

private static ImageKey _getInstance() {
if (_instance == null) {
synchronized (ImageKey.class) {
if (_instance == null) {
_instance = new ImageKey();
}
}
}

return _instance;
}

private ImageKey() {
_imageKey = new Hashtable();
}

private String _get(String id) {
return (String)_imageKey.get(id);
}

private void _put(String id, String key) {
_imageKey.put(id, key);
}

private static ImageKey _instance;

private Hashtable _imageKey;

}
 
Banner

本站文章均来自网络为方便大家阅读之用,如有侵权,请联系我们,我们收到后立即删除,谢谢!另文章言论不代表本站观点。

 
上海定制公寓:瑞虹新城3期
瑞安房地产推出上海内环住宅瑞虹新城3期,该楼盘首推“定制公寓”概念,大胆借鉴国际前沿的设计理念,在上海北外滩打造精致优雅的国际现代化上海虹口高品质住宅小区。

娱乐竞拍:噢耶竞拍网
噢耶竞拍网提供低价竞拍、抢拍、竞猜,为您提供低价购物、娱乐购物以及娱乐竞猜,噢耶团队为您提供竭诚服务,开心又刺激的娱乐购物新体验就在噢耶竞拍网

zhishi123.com.cn广告