001: package com.sun.portal.config;
002:
003: import java.util.Properties;
004: import com.sun.addressbook.*;
005: import com.sun.addressbook.wabp.*;
006:
007: /*
008: * address book required inputs:
009: *
010: * protocol
011: * host
012: * port
013: * contexturi
014: * domain
015: *
016: */
017: public class PopulateWabpAddressBook {
018:
019: protected static String serviceClass = "com.sun.addressbook.wabp.WabpABStore";
020: protected String protocol = null;
021: protected String host = null;
022: protected String port = null;
023: protected String contexturi = null;
024: protected String domain = null;
025:
026: protected final static String CHRIS = "chris";
027: protected final static String CHRIS_FN = "Chris";
028: protected final static String CHRIS_LN = "Content-Editor";
029: protected final static String CHRIS_CN = CHRIS_FN + " " + CHRIS_LN;
030:
031: protected final static String ED = "ed";
032: protected final static String ED_FN = "Ed";
033: protected final static String ED_LN = "Employee";
034: protected final static String ED_CN = ED_FN + " " + ED_LN;
035:
036: protected final static String MARY = "mary";
037: protected final static String MARY_FN = "Mary";
038: protected final static String MARY_LN = "Manager";
039: protected final static String MARY_CN = MARY_FN + " " + MARY_LN;
040:
041: /*
042: * Constructor
043: */
044: public PopulateWabpAddressBook(String args[]) {
045: protocol = args[0];
046: host = args[1];
047: port = args[2];
048: contexturi = args[3];
049: domain = args[4];
050:
051: }
052:
053: /*
054: * Retrieves Address Book store.
055: *
056: * @param user User Id
057: * @param password User Password
058: * @return store connection
059: */
060: public ABStore getABStore(String user, String password)
061: throws Exception {
062:
063: ABSession abSession = null;
064: Properties props = new Properties();
065: props.put("ab.protocol", protocol);
066: props.put("ab.host", host);
067: props.put("ab.port", port);
068: props.put("ab.contextURI", contexturi);
069: props.put("ab.userName", user + "@" + domain);
070: props.put("ab.userPassword", user);
071:
072: abSession = abSession.getInstance(props);
073: ABStore abStore = abSession.getABStore(serviceClass);
074: abStore.connect();
075:
076: return abStore;
077: }
078:
079: /*
080: * Populate user data.
081: *
082: * @param user User Id
083: * @param password User Password
084: */
085: public void generate(String user, String password) {
086: ABStore store = null;
087: AddressBook ab = null;
088:
089: try {
090: store = getABStore(user, password);
091: ab = store.openAddressBook();
092:
093: if (user.equals(CHRIS)) {
094: setPabForChris(ab);
095: } else if (user.equals(ED)) {
096: setPabForEd(ab);
097: } else if (user.equals(MARY)) {
098: setPabForMary(ab);
099: }
100:
101: store.disconnect();
102: } catch (Exception e) {
103: e.printStackTrace();
104: }
105: }
106:
107: /*
108: * Chris' Address Book
109: *
110: */
111: public void setPabForChris(AddressBook ab) throws Exception {
112:
113: Entry entry = new Entry();
114: entry.setCn(MARY_CN);
115: entry.setFn(MARY_FN);
116: entry.setLn(MARY_LN);
117: entry.setEm(MARY + "@" + domain);
118: ab.add((Element) entry);
119:
120: entry = new Entry();
121: entry.setCn(ED_CN);
122: entry.setFn(ED_FN);
123: entry.setLn(ED_LN);
124: entry.setEm(ED + "@" + domain);
125: ab.add((Element) entry);
126: }
127:
128: /*
129: * Ed's Address Book
130: *
131: */
132: public void setPabForEd(AddressBook ab) throws Exception {
133:
134: Entry entry = new Entry();
135: entry.setCn(CHRIS_CN);
136: entry.setFn(CHRIS_FN);
137: entry.setLn(CHRIS_LN);
138: entry.setEm(CHRIS + "@" + domain);
139: ab.add((Element) entry);
140:
141: entry = new Entry();
142: entry.setCn(MARY_CN);
143: entry.setFn(MARY_FN);
144: entry.setLn(MARY_LN);
145: entry.setEm(MARY + "@" + domain);
146: ab.add((Element) entry);
147:
148: }
149:
150: /*
151: * Mary's Address Book
152: *
153: */
154: public void setPabForMary(AddressBook ab) throws Exception {
155:
156: Entry entry = new Entry();
157: entry.setCn(CHRIS_CN);
158: entry.setFn(CHRIS_FN);
159: entry.setLn(CHRIS_LN);
160: entry.setEm(CHRIS + "@" + domain);
161: ab.add((Element) entry);
162:
163: entry = new Entry();
164: entry.setCn(ED_CN);
165: entry.setFn(ED_FN);
166: entry.setLn(ED_LN);
167: entry.setEm(ED + "@" + domain);
168: ab.add((Element) entry);
169: }
170:
171: /*
172: *
173: *
174: */
175: private static void usage() {
176: System.out
177: .println("usage: java PopulateWabpAddressBook <protocol> <host> <port> "
178: + "<contexturi> <domain>");
179: }
180:
181: /*
182: *
183: *
184: */
185: public static void main(String args[]) {
186:
187: if (args.length > 5) {
188: PopulateWabpAddressBook seed = new PopulateWabpAddressBook(
189: args);
190: seed.generate(seed.ED, seed.ED);
191: seed.generate(seed.CHRIS, seed.CHRIS);
192: seed.generate(seed.MARY, seed.MARY);
193: } else {
194: usage();
195: }
196: }
197:
198: }
|