|
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;
}
|