Source Code Cross Referenced for SamplePortals.java in  » Portal » Open-Portal » com » sun » portal » fabric » 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.fabric.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2004 Sun Microsystems, Inc. All
003:         * rights reserved. Use of this product is subject
004:         * to license terms. Federal Acquisitions:
005:         * Commercial Software -- Government Users
006:         * Subject to Standard License Terms and
007:         * Conditions.
008:         *
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010:         * are trademarks or registered trademarks of Sun Microsystems,
011:         * Inc. in the United States and other countries.
012:         */package com.sun.portal.fabric.config;
013:
014:        import java.io.File;
015:        import java.io.PrintStream;
016:        import java.io.FileOutputStream;
017:        import java.lang.InterruptedException;
018:        import java.util.HashMap;
019:        import java.util.List;
020:        import java.util.Map;
021:        import java.util.Iterator;
022:        import java.util.Set;
023:        import java.util.Vector;
024:        import java.util.logging.Level;
025:        import java.util.logging.Logger;
026:
027:        import javax.management.MBeanServerConnection;
028:        import javax.management.ObjectName;
029:
030:        import com.sun.portal.admin.common.context.PSConfigContext;
031:        import com.sun.portal.admin.common.util.AdminClientUtil;
032:        import com.sun.portal.fabric.util.AntUtil;
033:        import com.sun.portal.fabric.util.FileUtil;
034:        import com.sun.portal.log.common.PortalLogger;
035:        import com.sun.portal.util.Platform;
036:
037:        import org.jdom.Attribute;
038:
039:        import org.apache.tools.ant.BuildEvent;
040:        import org.apache.tools.ant.BuildException;
041:        import org.apache.tools.ant.BuildListener;
042:        import org.apache.tools.ant.DefaultLogger;
043:        import org.apache.tools.ant.Project;
044:        import org.apache.tools.ant.ProjectHelper;
045:
046:        /*
047:         * The primary purpose of this class is to setup the Portal samples
048:         * shared data.  This data is used to configure sample Portal content 
049:         * with the JES Portal installer or manually with the Portal content
050:         * configuration ant scripts.
051:         */
052:        public class SamplePortals implements  BuildListener {
053:
054:            private PSConfigContext pscContext = null;
055:            private String sharedBaseDir = null;
056:            private String buildfile = null;
057:            private String tmpDir = null;
058:            private Logger logger = null;
059:            private AntUtil antUtil = null;
060:
061:            // vectors for sample targets
062:            Vector developerTargets = null;
063:            Vector enterpriseTargets = null;
064:            Vector communityTargets = null;
065:            Vector welcomeTargets = null;
066:            Vector portalTargets = null;
067:            Vector postTargets = null;
068:            Vector sraTargets = null;
069:            Vector uninstallTargets = null;
070:
071:            // shared properties file names
072:            private final static String INPUT_FILE = "input.properties";
073:            private final static String PASSWORD_FILE = "password.properties";
074:            private final static String COMMS_FILE = "comms.properties";
075:
076:            // top level sample portal targets 
077:            private final static String COMMUNITY_PORTAL = "community_portal";
078:            private final static String COMMUNITY_POST = "community_post";
079:            private final static String COMMUNITY_SRA = "community_sra";
080:            private final static String DEVELOPER_PORTAL = "developer_portal";
081:            private final static String DEVELOPER_POST = "developer_post";
082:            private final static String DEVELOPER_SRA = "developer_sra";
083:            private final static String ENTERPRISE_PORTAL = "enterprise_portal";
084:            private final static String ENTERPRISE_POST = "enterprise_post";
085:            private final static String ENTERPRISE_SRA = "enterprise_sra";
086:            private final static String WELCOME_PORTAL = "welcome_portal";
087:            private final static String WELCOME_POST = "welcome_post";
088:
089:            // common vars
090:            private final static String fs = Platform.fs;
091:            private final static String TEMPLATE = ".template";
092:            private final static String LOG = ".log";
093:            private final static String SHARED_BUILD_FILE = "build.xml";
094:            private final static String INSTALL_REDEPLOY = "install_redeploy";
095:            private final static String UNINSTALL_SAMPLES = "uninstall_samples";
096:            private final static String PORTALS = "portals";
097:            private final static String SAMPLES = "samples";
098:            private final static String SHARED = "shared";
099:            private final static String ANT_INSTANCE_PROP = "ps.instance.id";
100:
101:            // profiler and communications element attribute names
102:            private final static String PROFILER_EMAIL = "ProfilerFromEmailAddress";
103:            private final static String PROFILER_SMTP = "ProfilerSMTPHost";
104:            private final static String PROTOCOL = "Protocol";
105:            private final static String HOST = "Host";
106:            private final static String PORT = "Port";
107:            private final static String SMTP_HOST = "SMTPHost";
108:            private final static String SMTP_PORT = "SMTPPort";
109:            private final static String CLIENT_PROTOCOL = "ClientProtocol";
110:            private final static String CLIENT_HOST = "ClientHost";
111:            private final static String CLIENT_PORT = "ClientPort";
112:            private final static String WEBAPP_URI = "WebappURI";
113:            private final static String DOMAIN = "Domain";
114:            private final static String CODEBASE = "Codebase";
115:
116:            // logfiles
117:            private final static String CONFIG_DEVELOPER_LOGFILE = "portal.developer.sample.";
118:            private final static String CONFIG_ENTERPRISE_LOGFILE = "portal.enterprise.sample.";
119:            private final static String CONFIG_COMMUNITY_LOGFILE = "portal.community.sample.";
120:            private final static String CONFIG_WELCOME_LOGFILE = "portal.welcome.sample.";
121:            private final static String CONFIG_LOGFILE = "portal.samples.";
122:            private final static String CONFIG_SRA_LOGFILE = "portal.samples.sra";
123:            private final static String UNCONFIG_LOGFILE = "portal.samples.unconfig";
124:
125:            /* 
126:             * Default Constructor 
127:             * 
128:             * @param pcc PSConfigContext 
129:             */
130:            public SamplePortals(PSConfigContext pcc) {
131:                pscContext = pcc;
132:                logger = PortalLogger.getLogger(SamplePortals.class);
133:                String sPSDataDir = pcc.getPSDataDir();
134:                tmpDir = sPSDataDir + fs + "tmp";
135:                String samplesBaseDir = pcc.getPSBaseDir() + fs + SAMPLES + fs
136:                        + PORTALS;
137:                sharedBaseDir = samplesBaseDir + fs + SHARED;
138:                buildfile = samplesBaseDir + fs + SHARED_BUILD_FILE;
139:                antUtil = new AntUtil(sPSDataDir);
140:            }
141:
142:            /* 
143:             * Configure the Portal Samples 
144:             * 
145:             * @param configDeveloper  Configure the developer sample (true or false)
146:             * @param configEnterprise Configure the enterprise sample (true or false)
147:             * @param configCommunity  Configure the community sample (true or false)
148:             * @param portalID         Portal identifier 
149:             * @param portalAccessURL  Portal access url
150:             * @param portalWebappURI  Portal web application uri
151:             * @param amAdminPassword  AM admin password
152:             * @param amldapuserPassword  AM ldap user password
153:             * @param searchID         Search identifier
154:             * @param searchURL        Search access url
155:             * @param portalInstances  List of portal server instances
156:             * @param profiler         List of profiler settings
157:             * @param addressbook      List of address book settings
158:             * @param calendar         List of calendar settings
159:             * @param instantmessenger List of instant messenger settings
160:             * @param mail             List of mail settings
161:             * @param msc              MBean Server Connection
162:             * @param pc               Portal Configurator
163:             * @param portalServerData Portal Server Related Data in psconfig.xml
164:             */
165:            public void configure(boolean configDeveloper,
166:                    boolean configEnterprise, boolean configCommunity,
167:                    String portalID, String portalAccessURL,
168:                    String portalWebappURI, String amAdminPassword,
169:                    String amldapuserPassword, String searchID,
170:                    String searchURL, List portalInstances, List profiler,
171:                    List addressbook, List calendar, List instantmessenger,
172:                    List mail, MBeanServerConnection msc,
173:                    PortalConfigurator pc, Map portalServerData) {
174:
175:                // configure samples if selected
176:                if (configDeveloper || configEnterprise || configCommunity) {
177:
178:                    logger.log(Level.INFO, "PSFB_CSPFC0078");
179:
180:                    portalTargets = new Vector();
181:                    postTargets = new Vector();
182:                    sraTargets = new Vector();
183:
184:                    // set samples to configure
185:                    setConfigCommunity(configCommunity);
186:                    setConfigDeveloper(configDeveloper);
187:                    setConfigEnterprise(configEnterprise);
188:                    setConfigWelcome();
189:
190:                    String sDevList = "Developer";
191:                    String sEntList = "Enterprise";
192:                    String sComList = "Community";
193:                    String sWelcomeList = "Welcome";
194:                    if (developerTargets != null) {
195:
196:                        if (communityTargets != null) {
197:                            developerTargets.addAll(communityTargets);
198:                            communityTargets = null;
199:                            sDevList += ",Community";
200:                        }
201:                        if (enterpriseTargets != null) {
202:                            developerTargets.addAll(enterpriseTargets);
203:                            enterpriseTargets = null;
204:                            sDevList += ",Enterprise";
205:                        }
206:                        developerTargets.addAll(welcomeTargets);
207:                        welcomeTargets = null;
208:                        sDevList += ",Welcome";
209:                    } else if (enterpriseTargets != null) {
210:
211:                        if (communityTargets != null) {
212:                            enterpriseTargets.addAll(communityTargets);
213:                            communityTargets = null;
214:                            sEntList += ",Community";
215:                        }
216:                        enterpriseTargets.addAll(welcomeTargets);
217:                        welcomeTargets = null;
218:                        sEntList += ",Welcome";
219:                    } else if (communityTargets != null) {
220:
221:                        communityTargets.addAll(welcomeTargets);
222:                        welcomeTargets = null;
223:                        sComList += ",Welcome";
224:                    }
225:
226:                    // generate input and password properties files
227:                    generatePasswordFile(amAdminPassword, amldapuserPassword);
228:                    generateInputFile(portalID, portalAccessURL,
229:                            portalWebappURI, amAdminPassword, searchID,
230:                            searchURL, profiler);
231:                    generateCommsFile(addressbook, calendar, instantmessenger,
232:                            mail);
233:
234:                    // configure portal samples (not instance specific)
235:                    String logprefix = null;
236:
237:                    try {
238:
239:                        PortalSampleConfiguration communitySampleThread = null;
240:                        if (communityTargets != null) {
241:
242:                            logger.log(Level.FINEST, "PSFB_CSPFC0302",
243:                                    new String[] { sComList });
244:                            logprefix = CONFIG_COMMUNITY_LOGFILE + portalID;
245:                            communitySampleThread = new PortalSampleConfiguration(
246:                                    communityTargets, logprefix);
247:                            communitySampleThread.start();
248:                        }
249:
250:                        PortalSampleConfiguration welcomeSampleThread = null;
251:                        if (welcomeTargets != null) {
252:
253:                            logger.log(Level.FINEST, "PSFB_CSPFC0302",
254:                                    new String[] { sWelcomeList });
255:                            logprefix = CONFIG_WELCOME_LOGFILE + portalID;
256:                            welcomeSampleThread = new PortalSampleConfiguration(
257:                                    welcomeTargets, logprefix);
258:                            welcomeSampleThread.start();
259:                        }
260:
261:                        PortalSampleConfiguration enterpriseSampleThread = null;
262:                        if (enterpriseTargets != null) {
263:
264:                            logger.log(Level.FINEST, "PSFB_CSPFC0302",
265:                                    new String[] { sEntList });
266:                            logprefix = CONFIG_ENTERPRISE_LOGFILE + portalID;
267:                            enterpriseSampleThread = new PortalSampleConfiguration(
268:                                    enterpriseTargets, logprefix);
269:                            enterpriseSampleThread.start();
270:                        }
271:
272:                        if (developerTargets != null) {
273:
274:                            logger.log(Level.FINEST, "PSFB_CSPFC0304");
275:                            pc.configurePortletApps(portalServerData,
276:                                    pscContext, amAdminPassword, searchURL);
277:
278:                            // developer sample configuration
279:                            logger.log(Level.FINEST, "PSFB_CSPFC0302",
280:                                    new String[] { sDevList });
281:                            logprefix = CONFIG_DEVELOPER_LOGFILE + portalID;
282:                            antUtil.runant(buildfile, developerTargets,
283:                                    logprefix, null, null);
284:                            logger.log(Level.FINEST, "PSFB_CSPFC0303",
285:                                    new String[] { sDevList });
286:                        } else {
287:
288:                            logger.log(Level.FINEST, "PSFB_CSPFC0304");
289:                            pc.configurePortletApps(portalServerData,
290:                                    pscContext, amAdminPassword, searchURL);
291:                            logger.log(Level.FINEST, "PSFB_CSPFC0305");
292:                        }
293:
294:                        if (welcomeSampleThread != null) {
295:
296:                            welcomeSampleThread.join();
297:                            logger.log(Level.FINEST, "PSFB_CSPFC0303",
298:                                    new String[] { sWelcomeList });
299:                        }
300:
301:                        if (communitySampleThread != null) {
302:
303:                            communitySampleThread.join();
304:                            logger.log(Level.FINEST, "PSFB_CSPFC0303",
305:                                    new String[] { sComList });
306:                        }
307:
308:                        if (enterpriseSampleThread != null) {
309:
310:                            enterpriseSampleThread.join();
311:                            logger.log(Level.FINEST, "PSFB_CSPFC0303",
312:                                    new String[] { sEntList });
313:                        }
314:
315:                    } catch (InterruptedException e) {
316:
317:                        logger.log(Level.FINEST, "", e);
318:                    }
319:
320:                    logprefix = CONFIG_LOGFILE + portalID;
321:                    antUtil.runant(buildfile, portalTargets, logprefix, null,
322:                            null);
323:
324:                    // remove password file
325:                    removePasswordFile();
326:                    logger.log(Level.INFO, "PSFB_CSPFC0080");
327:                } else {
328:                    logger.log(Level.INFO, "PSFB_CSPFC0079");
329:
330:                    logger.log(Level.FINEST, "PSFB_CSPFC0304");
331:                    pc.configurePortletApps(portalServerData, pscContext,
332:                            amAdminPassword, searchURL);
333:                    logger.log(Level.FINEST, "PSFB_CSPFC0305");
334:
335:                }
336:            }
337:
338:            /* 
339:             * Configure SRA 
340:             * 
341:             * @param amAdminPassword  AM admin password
342:             * @param amAdminPassword  AM ldap password
343:             */
344:            public void configureSRA(String amAdminPassword,
345:                    String amldapuserPassword) {
346:                if ((sraTargets != null) && (!sraTargets.isEmpty())) {
347:                    generatePasswordFile(amAdminPassword, amldapuserPassword);
348:                    antUtil.runant(buildfile, sraTargets, CONFIG_SRA_LOGFILE,
349:                            null, null);
350:                    removePasswordFile();
351:                }
352:            }
353:
354:            /* 
355:             * Unconfigure the Portal Samples
356:             *
357:             * @param amAdminPassword  AM admin password
358:             */
359:            public void unconfigure(String amAdminPassword,
360:                    String amldapuserPassword) {
361:                logger.log(Level.INFO, "PSFB_CSPFC0082");
362:                generatePasswordFile(amAdminPassword, amldapuserPassword);
363:                uninstallTargets = new Vector();
364:                uninstallTargets.add(UNINSTALL_SAMPLES);
365:                antUtil.runant(buildfile, uninstallTargets, UNCONFIG_LOGFILE,
366:                        null, null);
367:                removePasswordFile();
368:                logger.log(Level.INFO, "PSFB_CSPFC0162");
369:            }
370:
371:            /*
372:             * Sets welcome sample configuration boolean
373:             */
374:            public void setConfigWelcome() {
375:
376:                welcomeTargets = new Vector();
377:                welcomeTargets.add(WELCOME_PORTAL);
378:                portalTargets.add(INSTALL_REDEPLOY);
379:                portalTargets.addAll(postTargets);
380:            }
381:
382:            /*
383:             * Sets developer sample configuration boolean
384:             */
385:            public void setConfigDeveloper(final boolean bConfigDeveloper) {
386:                if (bConfigDeveloper) {
387:                    developerTargets = new Vector();
388:                    developerTargets.add(DEVELOPER_PORTAL);
389:                    postTargets.add(DEVELOPER_POST);
390:                    sraTargets.add(DEVELOPER_SRA);
391:                }
392:            }
393:
394:            /*
395:             * Sets enterprise sample configuration boolean
396:             */
397:            public void setConfigEnterprise(final boolean bConfigEnterprise) {
398:                if (bConfigEnterprise) {
399:                    enterpriseTargets = new Vector();
400:                    enterpriseTargets.add(ENTERPRISE_PORTAL);
401:                    sraTargets.add(ENTERPRISE_SRA);
402:                }
403:            }
404:
405:            /*
406:             * Sets community sample configuration boolean
407:             */
408:            public void setConfigCommunity(final boolean bConfigCommunity) {
409:                if (bConfigCommunity) {
410:                    communityTargets = new Vector();
411:                    communityTargets.add(COMMUNITY_PORTAL);
412:                    sraTargets.add(COMMUNITY_SRA);
413:                }
414:            }
415:
416:            /* 
417:             * Generate the input.properties file with substituted tokens
418:             * 
419:             * @param portalID         The Portal Identifier
420:             * @param portalAccessURL  Portal access url
421:             * @param portalWebappURI  Portal web application uri
422:             * @param amAdminPassword  AM admin password
423:             * @param searchID         Search identifier
424:             * @param searchURL        Search access url
425:             * @param profiler         List of profiler settings (smtp & email)
426:             */
427:            private void generateInputFile(String portalID,
428:                    String portalAccessURL, String portalWebappURI,
429:                    String amAdminPassword, String searchID, String searchURL,
430:                    List profiler) {
431:
432:                File file = getSharedAntFile(INPUT_FILE);
433:                FileUtil.replaceTokenInFile(file, "%DEFAULT_ORG_DN%",
434:                        pscContext.getDefaultOrganization());
435:                FileUtil.replaceTokenInFile(file, "%AM.ADMIN.DN%", pscContext
436:                        .getAdminUserDN());
437:                FileUtil.replaceTokenInFile(file, "%PS_CONFIG_LOCATION%",
438:                        pscContext.getPSConfigDir());
439:                FileUtil.replaceTokenInFile(file, "%PORTAL_ID%", portalID);
440:                FileUtil.replaceTokenInFile(file, "%PORTAL_ACCESS_URL%",
441:                        portalAccessURL);
442:                FileUtil.replaceTokenInFile(file, "%PORTAL_WEBAPP_URI%",
443:                        portalWebappURI);
444:                FileUtil.replaceTokenInFile(file, "%SEARCH_ACCESS_URL%",
445:                        searchURL);
446:                FileUtil.replaceTokenInFile(file, "%SEARCH_ID%", searchID);
447:
448:                String profilerEmail = "";
449:                String profilerSMTP = "";
450:
451:                if (!profiler.isEmpty()) {
452:                    HashMap pmap = new HashMap(profiler.size());
453:                    for (Iterator it = profiler.iterator(); it.hasNext();) {
454:                        Attribute attr = (Attribute) it.next();
455:                        pmap.put(attr.getName(), attr.getValue());
456:                    }
457:
458:                    profilerEmail = (String) pmap.get(PROFILER_EMAIL);
459:                    profilerSMTP = (String) pmap.get(PROFILER_SMTP);
460:                }
461:
462:                FileUtil.replaceTokenInFile(file, "%PROFILER_EMAIL%",
463:                        profilerEmail);
464:                FileUtil.replaceTokenInFile(file, "%PROFILER_SMTP_HOST%",
465:                        profilerSMTP);
466:            }
467:
468:            /* 
469:             * Generate the comms.properties file with substituted tokens
470:             * 
471:             * @param ab       List of address book server settings
472:             * @param calendar List of calendar server settings
473:             * @param im       List of instant messenger server settings
474:             * @param mail     List of mail server settings
475:             */
476:            private void generateCommsFile(List ab, List calendar, List im,
477:                    List mail) {
478:
479:                File file = getSharedAntFile(COMMS_FILE);
480:
481:                if (!ab.isEmpty()) {
482:                    HashMap abMap = new HashMap(ab.size());
483:                    for (Iterator abIt = ab.iterator(); abIt.hasNext();) {
484:                        Attribute abAttr = (Attribute) abIt.next();
485:                        abMap.put(abAttr.getName(), abAttr.getValue());
486:                    }
487:
488:                    FileUtil.replaceTokenInFile(file, "%AB_PROTOCOL%",
489:                            (String) abMap.get(PROTOCOL));
490:                    FileUtil.replaceTokenInFile(file, "%AB_HOST%",
491:                            (String) abMap.get(HOST));
492:                    FileUtil.replaceTokenInFile(file, "%AB_PORT%",
493:                            (String) abMap.get(PORT));
494:                    FileUtil.replaceTokenInFile(file, "%AB_CLIENT_PROTOCOL%",
495:                            (String) abMap.get(CLIENT_PROTOCOL));
496:                    FileUtil.replaceTokenInFile(file, "%AB_CLIENT_HOST%",
497:                            (String) abMap.get(CLIENT_HOST));
498:                    FileUtil.replaceTokenInFile(file, "%AB_CLIENT_PORT%",
499:                            (String) abMap.get(CLIENT_PORT));
500:                    FileUtil.replaceTokenInFile(file, "%AB_WEBAPP_URI%",
501:                            (String) abMap.get(WEBAPP_URI));
502:                    FileUtil.replaceTokenInFile(file, "%AB_DOMAIN%",
503:                            (String) abMap.get(DOMAIN));
504:                }
505:
506:                if (!calendar.isEmpty()) {
507:                    HashMap calMap = new HashMap(calendar.size());
508:                    for (Iterator calIt = calendar.iterator(); calIt.hasNext();) {
509:                        Attribute calAttr = (Attribute) calIt.next();
510:                        calMap.put(calAttr.getName(), calAttr.getValue());
511:                    }
512:
513:                    FileUtil.replaceTokenInFile(file, "%CAL_PROTOCOL%",
514:                            (String) calMap.get(PROTOCOL));
515:                    FileUtil.replaceTokenInFile(file, "%CAL_HOST%",
516:                            (String) calMap.get(HOST));
517:                    FileUtil.replaceTokenInFile(file, "%CAL_PORT%",
518:                            (String) calMap.get(PORT));
519:                    FileUtil.replaceTokenInFile(file, "%CAL_CLIENT_PROTOCOL%",
520:                            (String) calMap.get(CLIENT_PROTOCOL));
521:                    FileUtil.replaceTokenInFile(file, "%CAL_CLIENT_HOST%",
522:                            (String) calMap.get(CLIENT_HOST));
523:                    FileUtil.replaceTokenInFile(file, "%CAL_CLIENT_PORT%",
524:                            (String) calMap.get(CLIENT_PORT));
525:                    FileUtil.replaceTokenInFile(file, "%CAL_WEBAPP_URI%",
526:                            (String) calMap.get(WEBAPP_URI));
527:                    FileUtil.replaceTokenInFile(file, "%CAL_DOMAIN%",
528:                            (String) calMap.get(DOMAIN));
529:                }
530:
531:                if (!mail.isEmpty()) {
532:                    HashMap mMap = new HashMap(mail.size());
533:                    for (Iterator mailIt = mail.iterator(); mailIt.hasNext();) {
534:                        Attribute mailAttr = (Attribute) mailIt.next();
535:                        mMap.put(mailAttr.getName(), mailAttr.getValue());
536:                    }
537:
538:                    FileUtil.replaceTokenInFile(file, "%MAIL_IMAP_HOST%",
539:                            (String) mMap.get(HOST));
540:                    FileUtil.replaceTokenInFile(file, "%MAIL_IMAP_PORT%",
541:                            (String) mMap.get(PORT));
542:                    FileUtil.replaceTokenInFile(file, "%MAIL_SMTP_HOST%",
543:                            (String) mMap.get(SMTP_HOST));
544:                    FileUtil.replaceTokenInFile(file, "%MAIL_SMTP_PORT%",
545:                            (String) mMap.get(SMTP_PORT));
546:                    FileUtil.replaceTokenInFile(file, "%MAIL_CLIENT_PROTOCOL%",
547:                            (String) mMap.get(CLIENT_PROTOCOL));
548:                    FileUtil.replaceTokenInFile(file, "%MAIL_CLIENT_HOST%",
549:                            (String) mMap.get(CLIENT_HOST));
550:                    FileUtil.replaceTokenInFile(file, "%MAIL_CLIENT_PORT%",
551:                            (String) mMap.get(CLIENT_PORT));
552:                    FileUtil.replaceTokenInFile(file, "%MAIL_WEBAPP_URI%",
553:                            (String) mMap.get(WEBAPP_URI));
554:                    FileUtil.replaceTokenInFile(file, "%MAIL_DOMAIN%",
555:                            (String) mMap.get(DOMAIN));
556:                }
557:
558:                if (!im.isEmpty()) {
559:                    HashMap imMap = new HashMap(im.size());
560:                    for (Iterator imIt = im.iterator(); imIt.hasNext();) {
561:                        Attribute imAttr = (Attribute) imIt.next();
562:                        imMap.put(imAttr.getName(), imAttr.getValue());
563:                    }
564:
565:                    FileUtil.replaceTokenInFile(file, "%IM_HOST%",
566:                            (String) imMap.get(HOST));
567:                    FileUtil.replaceTokenInFile(file, "%IM_PORT%",
568:                            (String) imMap.get(PORT));
569:                    FileUtil.replaceTokenInFile(file, "%IM_CODEBASE%",
570:                            (String) imMap.get(CODEBASE));
571:                }
572:            }
573:
574:            /* 
575:             * Generate the password.properties file with substituted tokens
576:             * 
577:             * @param amAdminPassword  The amadmin user password
578:             */
579:            private void generatePasswordFile(String amAdminPassword,
580:                    String amldapuser) {
581:
582:                File file = getSharedAntFile(PASSWORD_FILE);
583:                file.deleteOnExit();
584:                FileUtil.replaceTokenInFile(file, "%AMADMIN_PASSWORD%",
585:                        amAdminPassword);
586:                FileUtil.replaceTokenInFile(file, "%AMLDAPUSER_PASSWORD%",
587:                        amldapuser);
588:            }
589:
590:            /* 
591:             * Retrieves a File object based on the filename in the shared portals sample
592:             * directory.  This method will append ".template" to the filename for source file
593:             * to retrieve.  Then it copies filename.template to filename and returns this
594:             * file object.
595:             * 
596:             * @param filename  name of file to return 
597:             */
598:            private File getSharedAntFile(String filename) {
599:                StringBuffer fromFile = new StringBuffer();
600:                StringBuffer toFile = new StringBuffer();
601:
602:                fromFile.append(sharedBaseDir).append(fs).append(filename)
603:                        .append(TEMPLATE);
604:                toFile.append(tmpDir).append(fs).append(filename);
605:                FileUtil.copyFile(fromFile.toString(), toFile.toString());
606:                File file = new File(toFile.toString());
607:                return file;
608:            }
609:
610:            /*
611:             * Remove the generated shared password file
612:             * 
613:             */
614:            public void removePasswordFile() {
615:                String filename = tmpDir + fs + PASSWORD_FILE;
616:                File file = new File(filename);
617:
618:                if (file.exists()) {
619:                    file.delete();
620:                }
621:            }
622:
623:            /*
624:             * Signals that the last target has finished.
625:             */
626:            public void buildFinished(BuildEvent event) {
627:                Throwable error = event.getException();
628:
629:                if (error != null) {
630:                    String[] param = new String[1];
631:
632:                    if (error instanceof  BuildException) {
633:                        param[0] = error.toString();
634:                    } else {
635:                        param[0] = error.getMessage();
636:                    }
637:
638:                    logger.log(Level.SEVERE, "PSFB_CSPFC0084", param);
639:                }
640:            }
641:
642:            /*
643:             * Signals that a build has started.
644:             */
645:            public void buildStarted(BuildEvent event) {
646:            }
647:
648:            /*
649:             * Signals a message logging event.
650:             */
651:            public void messageLogged(BuildEvent event) {
652:            }
653:
654:            /*
655:             * Signals that a target has finished.
656:             */
657:            public void targetFinished(BuildEvent event) {
658:            }
659:
660:            /*
661:             * Signals that a target is starting.
662:             */
663:            public void targetStarted(BuildEvent event) {
664:            }
665:
666:            /*
667:             * Signals that a task has finished.
668:             */
669:            public void taskFinished(BuildEvent event) {
670:            }
671:
672:            /*
673:             * Signals that a task is starting.
674:             */
675:            public void taskStarted(BuildEvent event) {
676:            }
677:
678:            private class PortalSampleConfiguration extends Thread {
679:
680:                Vector targets = null;
681:                String logName = null;
682:
683:                /*
684:                 * Use ant API to configure the sample portals with the <code>buildfile</code>
685:                 * and the <code>targets</code>
686:                 *
687:                 * @param targets  Ant targets
688:                 * @param logfile  Ant logfile prefix
689:                 */
690:                public PortalSampleConfiguration(Vector targets, String logName) {
691:
692:                    this .targets = targets;
693:                    this .logName = logName;
694:                }
695:
696:                public void run() {
697:
698:                    antUtil.runant(buildfile, targets, logName, null, null);
699:                }
700:            }
701:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.