Source Code Cross Referenced for PopulateAddressBook.java in  » Portal » Open-Portal » com » sun » portal » config » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.config;
002:
003:        import java.util.Properties;
004:        import com.sun.addressbook.*;
005:
006:        /*
007:         * address book required inputs:
008:         *
009:         *   host
010:         *   port
011:         *   user
012:         *   aid
013:         *   aidPassword
014:         *   dirSearchBase
015:         *   pabSearchBase
016:         *   mail default domain
017:         *
018:         */
019:        public class PopulateAddressBook {
020:
021:            protected static String serviceClass = "com.sun.addressbook.ldap.LdapABStore";
022:            protected String host = null;
023:            protected String port = null;
024:            protected String user = null;
025:            protected String aid = null;
026:            protected String aidPassword = null;
027:            protected String dirSearchBase = null;
028:            protected String pabSearchBase = null;
029:            protected String cn = null;
030:            protected String fn = null;
031:            protected String ln = null;
032:            protected String mailDomain = null;
033:
034:            // known users
035:            protected final static String CHRIS = "chris";
036:            protected final static String CHRIS_FN = "Chris";
037:            protected final static String CHRIS_LN = "Content-Editor";
038:            protected final static String CHRIS_CN = CHRIS_FN + " " + CHRIS_LN;
039:
040:            protected final static String ED = "ed";
041:            protected final static String ED_FN = "Ed";
042:            protected final static String ED_LN = "Employee";
043:            protected final static String ED_CN = ED_FN + " " + ED_LN;
044:
045:            protected final static String MARY = "mary";
046:            protected final static String MARY_FN = "Mary";
047:            protected final static String MARY_LN = "Manager";
048:            protected final static String MARY_CN = MARY_FN + " " + MARY_LN;
049:
050:            /*
051:             * Constructor
052:             */
053:            public PopulateAddressBook(String args[]) {
054:                host = args[0];
055:                port = args[1];
056:                user = args[2];
057:                aid = args[3];
058:                aidPassword = args[4];
059:                dirSearchBase = args[5];
060:                pabSearchBase = args[6];
061:                mailDomain = args[7];
062:            }
063:
064:            /**
065:             * Returns a connected Ldap ABStore object.
066:             */
067:            public ABStore getABStore() throws Exception {
068:
069:                ABSession abSession = getABSession();
070:                ABStore abStore = abSession.getABStore(serviceClass);
071:                abStore.connect();
072:
073:                return abStore;
074:            }
075:
076:            /**
077:             * Returns a JABAPI ABSession object.
078:             */
079:            public ABSession getABSession() throws Exception {
080:
081:                ABSession abSession = null;
082:                Properties props = new Properties();
083:
084:                props.put("ab.host", host);
085:                props.put("ab.port", port);
086:                props.put("ab.userName", user);
087:                props.put("ab.ldap.authId", aid);
088:                props.put("ab.ldap.authPw", aidPassword);
089:                props.put("ab.ldap.dirSearchBase", dirSearchBase);
090:                props.put("ab.ldap.pabSearchBase", pabSearchBase);
091:                props.put("ab.ldap.lang", "en");
092:                props.put("ab.ldap.connPoolMin", "5");
093:                props.put("ab.ldap.connPoolMax", "20");
094:                props.put("ab.ldap.timeout", "10000");
095:
096:                abSession = abSession.getInstance(props);
097:
098:                return abSession;
099:            }
100:
101:            /*
102:             *
103:             *
104:             */
105:            public void generate() {
106:                ABStore store = null;
107:                AddressBook ab = null;
108:
109:                try {
110:                    store = getABStore();
111:                    ab = store.openAddressBook();
112:                } catch (NullPointerException npe) {
113:                    // the jabapi complains that the paburi attribute is not 
114:                    // found and throws a NPE then creates it.  just ignore.
115:                } catch (Exception e) {
116:                    e.printStackTrace();
117:                }
118:
119:                try {
120:
121:                    if (user.equals(CHRIS)) {
122:                        setPabForChris(ab);
123:                    } else if (user.equals(ED)) {
124:                        setPabForEd(ab);
125:                    } else if (user.equals(MARY)) {
126:                        setPabForMary(ab);
127:                    }
128:
129:                } catch (Exception e) {
130:                    e.printStackTrace();
131:                    System.exit(-1);
132:                }
133:
134:                try {
135:                    store.disconnect();
136:                } catch (Exception e) {
137:                    e.printStackTrace();
138:                    System.exit(-1);
139:                }
140:            }
141:
142:            /*
143:             * Chris' Address Book
144:             *
145:             */
146:            public void setPabForChris(AddressBook ab) throws Exception {
147:
148:                Entry entry = new Entry();
149:                entry.setCn(MARY_CN);
150:                entry.setFn(MARY_FN);
151:                entry.setLn(MARY_LN);
152:                entry.setEm(MARY + "@" + mailDomain);
153:                ab.add((Element) entry);
154:
155:                entry = new Entry();
156:                entry.setCn(ED_CN);
157:                entry.setFn(ED_FN);
158:                entry.setLn(ED_LN);
159:                entry.setEm(ED + "@" + mailDomain);
160:                ab.add((Element) entry);
161:            }
162:
163:            /*
164:             * Ed's Address Book
165:             *
166:             */
167:            public void setPabForEd(AddressBook ab) throws Exception {
168:
169:                Entry entry = new Entry();
170:                entry.setCn(CHRIS_CN);
171:                entry.setFn(CHRIS_FN);
172:                entry.setLn(CHRIS_LN);
173:                entry.setEm(CHRIS + "@" + mailDomain);
174:                ab.add((Element) entry);
175:
176:                entry = new Entry();
177:                entry.setCn(MARY_CN);
178:                entry.setFn(MARY_FN);
179:                entry.setLn(MARY_LN);
180:                entry.setEm(MARY + "@" + mailDomain);
181:                ab.add((Element) entry);
182:
183:            }
184:
185:            /*
186:             * Mary's Address Book
187:             *
188:             */
189:            public void setPabForMary(AddressBook ab) throws Exception {
190:
191:                Entry entry = new Entry();
192:                entry.setCn(CHRIS_CN);
193:                entry.setFn(CHRIS_FN);
194:                entry.setLn(CHRIS_LN);
195:                entry.setEm(CHRIS + "@" + mailDomain);
196:                ab.add((Element) entry);
197:
198:                entry = new Entry();
199:                entry.setCn(ED_CN);
200:                entry.setFn(ED_FN);
201:                entry.setLn(ED_LN);
202:                entry.setEm(ED + "@" + mailDomain);
203:                ab.add((Element) entry);
204:            }
205:
206:            /*
207:             *
208:             *
209:             */
210:            private static void usage() {
211:                System.out
212:                        .println("usage: java PopulateAddressBook <host> <port> <user> <aid> "
213:                                + "<aid password> <directory search base> <pab search base>"
214:                                + "<mail domain>");
215:            }
216:
217:            /*
218:             *
219:             *
220:             */
221:            public static void main(String args[]) {
222:
223:                if (args.length < 8) {
224:                    usage();
225:                    System.exit(-1);
226:                }
227:
228:                PopulateAddressBook seed = new PopulateAddressBook(args);
229:                seed.generate();
230:                System.exit(1);
231:            }
232:
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.