01: /**
02: * $Id: FileUserMapping.java,v 1.4 2005/10/19 12:38:54 pg133018 Exp $
03: * Copyright 2004 Sun Microsystems, Inc. All
04: * rights reserved. Use of this product is subject
05: * to license terms. Federal Acquisitions:
06: * Commercial Software -- Government Users
07: * Subject to Standard License Terms and
08: * Conditions.
09: *
10: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
11: * are trademarks or registered trademarks of Sun Microsystems,
12: * Inc. in the United States and other countries.
13: */package com.sun.portal.psftportlet.common;
14:
15: import com.sun.portal.log.common.PortalLogger;
16:
17: import java.util.ResourceBundle;
18: import java.util.Map;
19: import java.util.HashMap;
20: import java.util.Enumeration;
21: import java.util.Collections;
22: import java.util.logging.Logger;
23:
24: /**
25: * This is the file implementaion of UserMapping interface
26: * Keys are treated case-insensitive here
27: * @author Pradeep Gond
28: */
29:
30: public class FileUserMapping implements IUserMapping {
31: private static Logger logger = PortalLogger
32: .getLogger(FileUserMapping.class);
33:
34: private ResourceBundle fileResource;
35: private Map userMap;
36:
37: public FileUserMapping(String fileName) {
38: try {
39: fileResource = ResourceBundle.getBundle(fileName);
40: } catch (Exception ex) {
41: ex.printStackTrace();
42: }
43: userMap = initializeUserMap();
44: }
45:
46: private Map initializeUserMap() {
47: HashMap map = new HashMap();
48: Enumeration keys = fileResource.getKeys();
49:
50: while (keys.hasMoreElements()) {
51: String key = keys.nextElement().toString();
52: String value = fileResource.getString(key);
53: map.put(key.toUpperCase(), value);
54: }
55:
56: return Collections.unmodifiableMap(map);
57: }
58:
59: public String getERPUser(String portalUser) {
60: String result = NO_MAPPING_AVAILABLE;
61:
62: if (portalUser != null) {
63: String key = portalUser.toUpperCase();
64: if (userMap.containsKey(key)) {
65: result = (String) userMap.get(key);
66: }
67: }
68: logger.info("(" + portalUser + ") => " + result);
69:
70: return result;
71: }
72: }
|