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


001:        /**
002:         * $Id: Portal.java,v 1.33 2007/01/26 03:48:32 portalbld Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.fabric.tasks;
014:
015:        import java.io.File;
016:        import java.io.FileInputStream;
017:        import java.io.FileNotFoundException;
018:        import java.io.IOException;
019:        import java.io.FileWriter;
020:
021:        import java.util.Set;
022:        import java.util.HashSet;
023:        import java.util.List;
024:        import java.util.ArrayList;
025:        import java.util.Iterator;
026:        import java.util.Properties;
027:        import java.util.HashMap;
028:        import java.util.Map;
029:        import java.util.Vector;
030:
031:        import java.util.logging.Level;
032:        import java.util.logging.Logger;
033:
034:        import java.util.Random;
035:
036:        import com.sun.portal.util.LDAPUtil;
037:        import com.sun.portal.admin.common.Tags;
038:        import com.sun.portal.admin.common.PSConfigConstants;
039:        import com.sun.portal.admin.common.context.PSConfigContext;
040:        import com.sun.portal.admin.common.util.AdminUtil;
041:        import com.sun.portal.log.common.PortalLogger;
042:
043:        import com.sun.portal.fabric.util.AntUtil;
044:        import com.sun.portal.fabric.util.FileUtil;
045:        import com.sun.portal.fabric.util.ExecuteUtil;
046:        import com.sun.portal.fabric.util.AMUtil;
047:        import com.sun.portal.fabric.util.AMTaskUtil;
048:        import com.sun.portal.fabric.util.LogConfigUtil;
049:        import com.sun.portal.fabric.util.ClasspathGenUtil;
050:        import com.sun.portal.util.Platform;
051:
052:        import com.iplanet.sso.SSOToken;
053:
054:        import netscape.ldap.LDAPConnection;
055:        import netscape.ldap.LDAPException;
056:
057:        /**
058:         * Provides the functionality needed for configuring
059:         * a Portal on a host.
060:         *
061:         */
062:        public class Portal {
063:
064:            /**
065:             * Identity Server SDK installation directory path
066:             */
067:            private String isBaseDir;
068:
069:            /**
070:             * Portal Server product installation directory path
071:             */
072:            private String psBaseDir;
073:
074:            /**
075:             * Portal Server software date directory path
076:             */
077:            private String psDataDir;
078:
079:            /**
080:             * Portal Server config directory path
081:             */
082:            private String psConfigDir;
083:
084:            /**
085:             * The directory where the original ldif/service/request files are located 
086:             * under their own dirs
087:             */
088:            private String psExportLocation;
089:
090:            /**
091:             * The directory where the Portal Server libraries files are located 
092:             */
093:            private String psLibLocation;
094:
095:            /**
096:             * The directory where the tagswapped service and request xmls are located
097:             */
098:            private String psTmpDir;
099:
100:            /**
101:             * Logger instance
102:             */
103:            private static Logger logger = PortalLogger.getLogger(Portal.class);
104:
105:            /**
106:             *  File separator
107:             */
108:            private final static String fs = Platform.fs;
109:            private final static String cps = Platform.pathSep;
110:
111:            /**
112:             * Ant Utility
113:             */
114:            private AntUtil antUtil;
115:
116:            private static Set PROTECTED_FILES = new HashSet();
117:
118:            static {
119:                PROTECTED_FILES.add("00community.sql");
120:                PROTECTED_FILES.add("community.datasource");
121:                PROTECTED_FILES.add("communitymgmnt.properties");
122:                PROTECTED_FILES.add("portal.dbadmin");
123:            }
124:
125:            /**
126:             * Constructor
127:             *
128:             * @param psDataDir Location of the data directory for Portal Server as
129:                      String
130:             * @param psBaseDir Portal Server installation directory path
131:             * @param psConfigDir Portal Server config directory path
132:             * @param isBaseDir Identity Server SDK installation directory path
133:             */
134:            public Portal(PSConfigContext cc) {
135:
136:                this .psBaseDir = cc.getPSBaseDir();
137:                this .psDataDir = cc.getPSDataDir();
138:                this .psConfigDir = cc.getPSConfigDir();
139:                this .isBaseDir = cc.getISBaseDir();
140:
141:                psExportLocation = psBaseDir + fs + "export";
142:                psLibLocation = psBaseDir + fs + "lib";
143:                psTmpDir = psDataDir + fs + "tmp";
144:                antUtil = new AntUtil(psDataDir);
145:                Platform.psConfDir = psConfigDir;
146:            }
147:
148:            /**
149:             * Does all the tasks that are needed to make a portal
150:             * available on this host
151:             *
152:             * @param portalID The new Portal Identifier as a String
153:             * @param amAdminDN The Identity Server super user DN as a String
154:             * @param amAdminPassword The Identity Server super user password as String
155:             */
156:            public void configurePortal(String portalID, SSOToken ssoToken,
157:                    String dsHost, String dsPort, String userDataStoreMgr,
158:                    String userDataStoreMgrCredentials, boolean dsSecure)
159:                    throws ConfigurationException {
160:
161:                // Tokens to be replaced in the files
162:                String[] tokens = { Tags.PORTAL_ID };
163:
164:                // Values to be replaced for the token %PORTAL_ID%
165:                // is empty in case of a upgraded portal
166:                // for the purpose of the svc names and attrs.
167:                // For example, the desktop service name for upgraded portal
168:                // is SunPortalDesktopService. But the portal still has an ID
169:                // which is defined by AdminUtil.UPGRADED_PORTAL
170:                String tValue = AdminUtil.UPGRADED_PORTAL.equals(portalID) ? ""
171:                        : portalID;
172:
173:                String[] values = { tValue };
174:
175:                // Locations for tagswapped files
176:                String randomDir = FileUtil.getRandomDirName();
177:                String cPortalTmpDirLoc = psTmpDir + fs + randomDir;
178:                logger.log(Level.FINEST, "PSFB_CSPFT0254", new Object[] {
179:                        cPortalTmpDirLoc, portalID });
180:
181:                // Create the tmp dir
182:                File cPortalTmpDir = new File(cPortalTmpDirLoc);
183:                if (!cPortalTmpDir.mkdirs()) {
184:                    throw new ConfigurationException(
185:                            "Could not create directory " + cPortalTmpDirLoc);
186:                }
187:
188:                // Create connection to the Directory Server hosting Portals
189:                LDAPConnection conn = LDAPUtil.getLDAPConnection(dsHost,
190:                        dsPort, userDataStoreMgr, userDataStoreMgrCredentials,
191:                        dsSecure);
192:
193:                try {
194:
195:                    // Get the list of portal services
196:                    Set portalSvcs = getPortalServices();
197:                    Iterator svcsItr = portalSvcs.iterator();
198:
199:                    logger.log(Level.FINEST, "PSFB_CSPFT0255");
200:                    String svcLDIFMapperLocation = psLibLocation + fs
201:                            + PSConfigConstants.PS_SVC_LDIF_MAP_FILE;
202:                    Properties svcToLDIFFileMap = new Properties();
203:                    // Load the property file that maps service names to LDIF files
204:                    // that are associated with a services
205:                    svcToLDIFFileMap.load(new FileInputStream(
206:                            svcLDIFMapperLocation));
207:
208:                    logger.log(Level.FINEST, "PSFB_CSPFT0256");
209:
210:                    String svcXMLMapperLocation = psLibLocation + fs
211:                            + PSConfigConstants.PS_SVC_SCHEMA_MAP_FILE;
212:
213:                    Properties svcToXmlFileMap = new Properties();
214:                    // Load the property file that maps service names to Schema XML
215:                    // file associated with that service
216:                    svcToXmlFileMap.load(new FileInputStream(
217:                            svcXMLMapperLocation));
218:
219:                    // Define a Set which will contain the paths of service schema
220:                    // xml files
221:                    Set svcXmlFilePaths = new HashSet();
222:
223:                    // For each service in the portalSvcs Set
224:                    // 1. Pickup the LDIF files associated with that service and
225:                    //    add them to the array of LDIFs to be loaded
226:                    // 2. Pickup the Service Schema XML file associated with that
227:                    //    service and add it to the svcXmlFiles array.
228:                    while (svcsItr.hasNext()) {
229:
230:                        // Get Service Name from the Set of Portal Service Names
231:                        String svcName = (String) svcsItr.next();
232:
233:                        // From the svcToLDIFFileMap pickup the value associated
234:                        // with the current service name
235:                        String svcLDIFFile = svcToLDIFFileMap.getProperty(
236:                                svcName, "");
237:
238:                        // A single service may be associated with multiple LDIF
239:                        // files. In that case the value is a space separated list
240:                        // of LDIF files. Always tokenize the value that there in
241:                        // the map that is defined in the property file.
242:                        svcLDIFFile.trim();
243:                        String[] ldifFileNames = null;
244:                        if (svcLDIFFile.length() > 0) {
245:                            ldifFileNames = svcLDIFFile.split("[\\s]+");
246:                        }
247:                        int iSize0 = (ldifFileNames != null) ? ldifFileNames.length
248:                                : 0;
249:
250:                        // Load each of these LDIF files. Usually a service is only
251:                        // associated with one LDIF file except for WSRP service
252:                        for (int i = 0; i < iSize0; i++) {
253:
254:                            // Get the LDIF File name from tokenizer
255:                            String svcLDIFFileName = ldifFileNames[i];
256:                            // Prepare a String that represents the fullpath for the
257:                            // LDIF file on the filesytem
258:                            String svcLDIFPath = psExportLocation + fs + "ldif"
259:                                    + fs + svcLDIFFileName;
260:                            // Prepare a String that represents the full path of the
261:                            // tagswapped LDIF file on the filesystem
262:                            String copyToPath = cPortalTmpDirLoc + fs
263:                                    + svcLDIFFileName;
264:
265:                            File svcLDIF = new File(svcLDIFPath);
266:                            File copiedLDIFFile = new File(copyToPath);
267:                            // Copy this service LDIF file to the random directory
268:                            FileUtil.copyFile(svcLDIF, copiedLDIFFile);
269:                            // Tag swap the portal ID into the LDIF file
270:                            FileUtil.replaceTokensInFile(copiedLDIFFile,
271:                                    tokens, values);
272:
273:                            // Load the Portal Specific Service Related Objectclasse
274:                            // into the Directory Server using the LDAPUtils
275:                            logger.log(Level.FINEST, "PSFB_CSPFT0257",
276:                                    copiedLDIFFile);
277:
278:                            try {
279:                                LDAPUtil.loadLDIF(copyToPath, conn);
280:                            } catch (LDAPException ldape) {
281:                                throw new ConfigurationException(
282:                                        "Failed to load objectclasses", ldape);
283:                            }
284:                        }
285:
286:                        // From the svcToXmlFileMap pickup the value associated
287:                        // with the current service name
288:                        String svcSchemaXMLFile = svcToXmlFileMap.getProperty(
289:                                svcName, "");
290:
291:                        // Check if the schema XML file mapping exists for this svc
292:                        if (!svcSchemaXMLFile.equals("")) {
293:
294:                            // Prepare a String that represents the full path of the
295:                            // original service XML on the filesystem
296:                            String svcXMLFilePath = psExportLocation + fs
297:                                    + "service" + fs + svcSchemaXMLFile;
298:
299:                            File svcXMLFile = new File(svcXMLFilePath);
300:                            // If the service schema file is existing
301:                            // add its path to the set of services schemas to load
302:                            if (svcXMLFile.exists()) {
303:                                // Prepare a String that represents the full path of
304:                                // tagswapped Service XML of this service
305:                                String copyToPath = cPortalTmpDirLoc + fs
306:                                        + svcSchemaXMLFile;
307:                                File copiedSvcXMLFile = new File(copyToPath);
308:                                // Copy this service XML file to the random dir
309:                                logger.log(Level.FINEST, "PSFB_CSPFT0228",
310:                                        new Object[] { svcXMLFile,
311:                                                copiedSvcXMLFile });
312:                                FileUtil.copyFile(svcXMLFile, copiedSvcXMLFile);
313:
314:                                // Tag swap the portal ID into the copied XML file
315:                                logger.log(Level.FINEST, "PSFB_CSPFT0258",
316:                                        copiedSvcXMLFile);
317:                                FileUtil.replaceTokensInFile(copiedSvcXMLFile,
318:                                        tokens, values);
319:                                // Add the file object representing the tagswapped
320:                                // service XML file into the svcXmlFiles array
321:                                logger.log(Level.FINEST, "PSFB_CSPFT0259",
322:                                        copiedSvcXMLFile);
323:                                svcXmlFilePaths.add(copyToPath);
324:                            } else {
325:                                logger.log(Level.INFO, "PSFB_CSPFT0260",
326:                                        svcName);
327:                            }
328:
329:                        } else {
330:                            logger.log(Level.SEVERE, "PSFB_CSPFT0261", svcName);
331:                        }
332:                    }
333:
334:                    // Load Service Schemas using the AMTaskUtil                
335:                    logger.log(Level.FINEST, "PSFB_CSPFT0262", portalID);
336:                    AMUtil.loadServiceSchema(svcXmlFilePaths, ssoToken);
337:
338:                    // Load ResouceBundles for Domain Services                
339:                    logger.log(Level.FINEST, "PSFB_CSPFT0263", portalID);
340:                    File rbLoc = new File(psExportLocation + fs + "locale");
341:                    File[] localeFileList = rbLoc.listFiles();
342:                    for (int i = 0; i < localeFileList.length; i++) {
343:                        try {
344:                            // Get the full path and the file name                        
345:                            String fname = localeFileList[i].getName();
346:                            String fPath = localeFileList[i].getAbsolutePath();
347:                            String fileLocale = null;
348:                            // If file is a properties file and its name contains
349:                            // the word psPortalServices then load it
350:                            if (fname.startsWith("psPortalServices")
351:                                    && fname.endsWith(".properties")) {
352:                                // Prepare a properties object from the file
353:                                Properties props = new Properties();
354:                                FileInputStream fis = new FileInputStream(fPath);
355:                                props.load(fis);
356:                                // Now replace portalId token in property values
357:                                Set keys = props.keySet();
358:                                Iterator itr = keys.iterator();
359:                                while (itr.hasNext()) {
360:                                    String key = (String) itr.next();
361:                                    String value = props.getProperty(key);
362:                                    value = value.replaceAll("%PORTAL_ID%",
363:                                            portalID);
364:                                    props.setProperty(key, value);
365:                                }
366:                                // Get the locale from the file name                            
367:                                int beginFileLocale = fname.indexOf('_') + 1;
368:                                int endFileLocale = fname
369:                                        .indexOf(".properties");
370:                                if (beginFileLocale > 0) {
371:                                    fileLocale = fname.substring(
372:                                            beginFileLocale, endFileLocale);
373:                                }
374:                                // The resourceBundle name should have the portalId
375:                                // mangled into it
376:                                String resBndleName = "ps" + portalID
377:                                        + "Services";
378:                                AMUtil.addResourceBundle(resBndleName,
379:                                        fileLocale, props, ssoToken);
380:                            }
381:                        } catch (Exception e) {
382:                            logger.log(Level.SEVERE, "PSFB_CSPFT0264", e);
383:                        }
384:                    }
385:
386:                    logger.log(Level.FINEST, "PSFB_CSPFT0265", new Object[] {
387:                            cPortalTmpDirLoc, portalID });
388:                    // Delete the random tmp dir that was created for tagswapping
389:                    if (!FileUtil.deleteDir(cPortalTmpDirLoc)) {
390:                        logger.log(Level.SEVERE, "PSFB_CSPFT0266",
391:                                cPortalTmpDirLoc);
392:                    }
393:
394:                    // Create the portal webapps directory 
395:                    String portalDir = psDataDir + fs + "portals" + fs
396:                            + portalID;
397:                    String portalWARDir = portalDir + fs + "war";
398:                    File warDir = new File(portalWARDir);
399:                    warDir.mkdirs();
400:
401:                    //copy psconsole war to webapps directory
402:                    String consoleWar = "psconsole.war";
403:                    String consoleWarSrc = psBaseDir + fs + "admin" + fs
404:                            + consoleWar;
405:                    if ((new File(consoleWarSrc)).exists()) {
406:                        FileUtil.copyFile(consoleWarSrc, portalWARDir + fs
407:                                + consoleWar);
408:                    }
409:
410:                    // Set up the portal specific configuration files from the
411:                    // property file tempalates
412:                    setupPortalConfigFiles(portalID);
413:
414:                    // Configures the sql framework
415:                    String configDataDir = portalDir + fs + "config";
416:                    configureBackend(configDataDir);
417:
418:                } catch (FileNotFoundException fnfe) {
419:                    logger.log(Level.SEVERE, "PSFB_CSPFT0267", fnfe);
420:                    throw new ConfigurationException(
421:                            "Configuration Files are missing", fnfe);
422:                } catch (IOException ioe) {
423:                    logger.log(Level.SEVERE, "PSFB_CSPFT0268", ioe);
424:                    throw new ConfigurationException(
425:                            "Failed to read configuration", ioe);
426:                }
427:            }
428:
429:            private void setupPortalConfigFiles(String portalID)
430:                    throws IOException {
431:
432:                // Path of PSConfig.properties file
433:                String psConfigPath = psConfigDir + fs
434:                        + PSConfigConstants.PS_CONFIG_FILE;
435:                // Home of the portal specific data
436:                String portalDir = psDataDir + fs + "portals" + fs + portalID;
437:                // Path of the portal specific data directory
438:                String portalConfigDir = portalDir + fs + "config";
439:                // Path to the template portal specific config templates property files
440:                String portalTemplateDir = psBaseDir + fs + "template" + fs
441:                        + "portal";
442:                // Path to the derby.properties file
443:                String derbyPropPath = psDataDir + fs + "derby" + fs
444:                        + PSConfigConstants.PS_DERBY_CONFIG_FILE;
445:
446:                // Create config directory for the portal
447:                File pcDir = new File(portalConfigDir);
448:                pcDir.mkdirs();
449:                // Copy the portal config templates into portal specific config dir
450:                FileUtil.copyDir(portalTemplateDir, portalConfigDir);
451:
452:                // Load the pre-existing derby.properties file as a properties object        
453:                Properties derbyProps = new Properties();
454:                derbyProps.load(new FileInputStream(derbyPropPath));
455:                // Load the PSConfig.properties file to get the derby lib
456:                Properties psConfig = new Properties();
457:                psConfig.load(new FileInputStream(psConfigPath));
458:
459:                // Get the derby host and port form derby.properties
460:                String derbyHostName = derbyProps.getProperty(
461:                        "derby.drda.host", "localhost");
462:                String derbyPort = derbyProps.getProperty(
463:                        "derby.drda.portNumber", "1527");
464:                // Get the Derby lib directory from the PSConfig properties file
465:                String derbyDriverLoc = psConfig.getProperty(
466:                        "derby.lib.location", "");
467:
468:                String[] tmpTokens = new String[] { "%PORTAL_ID%",
469:                        "%PS_CONFIG_DIR%", "%DERBY_HOST%", "%DERBY_PORT%",
470:                        "%DERBY_LIB_DIR%", "%DB_PASSWORD%" };
471:                String[] tmpValues = new String[] { portalID, psConfigDir,
472:                        derbyHostName, derbyPort, derbyDriverLoc,
473:                        FileUtil.getRandomString() };
474:
475:                // First step is to replace the tokens in the tokens.properties file
476:                // The contents of this files will be a map of tokens and values  that
477:                // will be tagswapped in the rest of the files
478:                File tokensPropFile = new File(portalConfigDir + fs
479:                        + "tokens.properties");
480:                FileUtil.replaceTokensInFile(tokensPropFile, tmpTokens,
481:                        tmpValues);
482:
483:                Map tokenMap = new HashMap();
484:                tokenMap.put(Tags.PS_DIR, psBaseDir);
485:                tokenMap.put(Tags.PS_VAR_DIR, psDataDir);
486:                tokenMap.put(Tags.PORTAL_DIR, portalDir);
487:                tokenMap.put(Tags.PORTAL_CONFIG_DIR, portalConfigDir);
488:                tokenMap.put(Tags.PORTAL_ID, portalID);
489:
490:                if (tokensPropFile.exists()) {
491:                    Properties tokenProp = new Properties();
492:                    tokenProp.load(new FileInputStream(tokensPropFile));
493:                    tokenMap.putAll(tokenProp);
494:                    // Once we have the properties object delete the file from config
495:                    // directory. Its no more needed
496:                    tokensPropFile.delete();
497:                }
498:
499:                logger.log(Level.FINEST, "PSFB_CSPFT0269", tokenMap);
500:
501:                String[] tokens = new String[tokenMap.size()];
502:                String[] values = new String[tokenMap.size()];
503:                Iterator itr = tokenMap.entrySet().iterator();
504:                int ctr = 0;
505:                while (itr.hasNext()) {
506:                    Map.Entry entry = (Map.Entry) itr.next();
507:                    tokens[ctr] = (String) entry.getKey();
508:                    values[ctr] = (String) entry.getValue();
509:                    ctr++;
510:                }
511:
512:                List files = new ArrayList();
513:                if (FileUtil.getFiles(pcDir, files)) {
514:                    for (int i = 0; i < files.size(); i++) {
515:                        File configFile = (File) files.get(i);
516:                        boolean replaced = FileUtil.replaceTokensInFile(
517:                                configFile, tokens, values);
518:                        if (!replaced) {
519:                            logger.log(Level.SEVERE, "PSFB_CSPFT0270",
520:                                    configFile.getAbsolutePath());
521:                            throw new IOException(
522:                                    "Failed to replace tokens in "
523:                                            + configFile.getAbsolutePath());
524:                        }
525:
526:                        if (PROTECTED_FILES.contains(configFile.getName())) {
527:                            FileUtil.changeFilePermissions(configFile, "600");
528:                        }
529:                    }
530:                } else {
531:                    logger.log(Level.SEVERE, "PSFB_CSPFT0271");
532:                    throw new IOException(
533:                            "Failed to copy portal configuration templates");
534:                }
535:
536:                // Tagswap jspCompilerWARClassPath in desktopconfig properties
537:                String desktopConfigDest = portalConfigDir + fs
538:                        + PSConfigConstants.PS_DESKTOP_CONFIG_FILE;
539:
540:                File desktopConfig = new File(desktopConfigDest);
541:                String templateDir = portalDir + fs + "desktop";
542:
543:                String cpath = ClasspathGenUtil.getClasspath(
544:                        "jspcompiler.classpath", true);
545:
546:                // TODO workaround code. Remove it the line below for beta
547:                cpath = templateDir + fs + "default" + fs + "tld" + cps + cpath;
548:
549:                FileUtil.replaceTokenInFile(desktopConfig,
550:                        "jspCompilerWARClassPath=", "jspCompilerWARClassPath="
551:                                + cpath);
552:
553:                logger.log(Level.FINEST, "PSFB_CSPFT0272", desktopConfig);
554:
555:                // Tagswap the pslogconfig properties and place it in the
556:                // configuration directory of the new portal
557:                LogConfigUtil.createPortalLogConfigFile(psBaseDir, psDataDir,
558:                        portalID);
559:                logger.log(Level.FINEST, "PSFB_CSPFT0273",
560:                        PSConfigConstants.PS_LOG_CONFIG_FILE);
561:            }
562:
563:            /**
564:             * This method fetches the set of portal specific services from the 
565:             * Service configuration property file and returns the 
566:             * services names in a String array
567:             */
568:            private Set getPortalServices() throws IOException {
569:
570:                // Load the property file that defines the set portal Services
571:                logger.log(Level.FINEST, "PSFB_CSPFT0274");
572:                String svcConfLocation = psLibLocation + fs
573:                        + PSConfigConstants.PS_SERVICE_CONFIG_FILE;
574:                Properties svcConf = new Properties();
575:                // Load the property file
576:                svcConf.load(new FileInputStream(svcConfLocation));
577:                // Get the value of the property that defines the list of
578:                // services that are portal specific
579:                String portalSvcList = svcConf
580:                        .getProperty("PortalServices", "");
581:                portalSvcList.trim();
582:                // The value of the portal services property is a space
583:                // separated string of service names. Create a tokenizer to
584:                // tokenize the string into individual service names
585:                String[] portalSvc = null;
586:                if (portalSvcList.length() > 0) {
587:                    portalSvc = portalSvcList.split("[\\s]+");
588:                }
589:                int iSize0 = (portalSvc != null) ? portalSvc.length : 0;
590:
591:                // Initialize a Set that will contain the portal specific service names 
592:                Set portalSvcs = new HashSet();
593:                for (int i = 0; i < iSize0; i++) {
594:                    portalSvcs.add(portalSvc[i]);
595:                }
596:
597:                return portalSvcs;
598:            }
599:
600:            /**
601:             * Creates a PAR file out of the ps.product.location/par-src/default-par
602:             * directory structure. 
603:             * 
604:             */
605:            public String createDesktopPar() throws ConfigurationException {
606:
607:                String createPar = null;
608:                createPar = Platform.getCommand("psadmin");
609:                String desktopParSrc = psBaseDir + fs + "par-src" + fs
610:                        + "default-portal";
611:                String desktopParLoc = psTmpDir + fs + "desktop.par";
612:                File desktopParFile = new File(desktopParLoc);
613:                if (desktopParFile.exists()) {
614:                    desktopParFile.delete();
615:                }
616:
617:                ExecuteUtil execUtil = new ExecuteUtil();
618:                execUtil.storeOutput(true);
619:
620:                String[] args = { "create-par", "--dir", desktopParSrc,
621:                        desktopParLoc };
622:                execUtil.exec(createPar, args);
623:
624:                if (desktopParFile.exists()) {
625:                    return desktopParFile.getPath();
626:                } else {
627:                    logger.log(Level.SEVERE, "PSFB_CSPFT0275");
628:                    throw new ConfigurationException("Errors Creating PAR file");
629:                }
630:            }
631:
632:            /**
633:             *  Configures the sql framework
634:             *
635:             * @param configDataDir Location where the sql framework files resides
636:             * after token replacement
637:             */
638:            public void configureBackend(String configDataDir) {
639:                try {
640:                    File sqlFile = new File(configDataDir + fs
641:                            + "00community.sql");
642:                    File dbadminFile = new File(configDataDir + fs
643:                            + "portal.dbadmin");
644:
645:                    if (sqlFile.exists() && dbadminFile.exists()) {
646:                        File file = File.createTempFile("backend", ".xml");
647:                        FileWriter fw = new FileWriter(file);
648:                        fw
649:                                .write("<project name=\"sqlframework\" default=\"init\" basedir=\".\">\n");
650:                        fw.write("  <target name=\"init\">\n");
651:                        fw.write("      <property name=\"build.dir\" value=\""
652:                                + configDataDir + "\"/>\n");
653:                        fw
654:                                .write("      <available file=\"${build.dir}/config.xml\" property=\"xml.present\"/>\n");
655:                        fw.write("  </target>\n");
656:                        fw
657:                                .write("  <target name=\"execute_sql\" depends=\"init\">\n");
658:                        fw
659:                                .write("      <property file=\"${build.dir}/portal.dbadmin\"/>\n");
660:                        fw.write("      <sql\n");
661:                        fw.write("          driver=\"${db.driver}\"\n");
662:                        fw.write("          url=\"${community.db.url}\"\n");
663:                        fw.write("          userid=\"${community.db.user}\"\n");
664:                        fw
665:                                .write("          password=\"${community.db.password}\"\n");
666:                        fw
667:                                .write("          classpath=\"${db.driver.classpath}\">\n");
668:                        fw.write("          <fileset dir=\"${build.dir}\">\n");
669:                        fw.write("              <include name=\"*.sql\"/>\n");
670:                        fw.write("          </fileset>\n");
671:                        fw.write("      </sql>\n");
672:                        fw.write("  </target>\n");
673:                        fw
674:                                .write("  <target name=\"config_backend\" if=\"xml.present\" depends=\"execute_sql\">\n");
675:                        fw
676:                                .write("      <ant antfile=\"${build.dir}/config.xml\" target=\"configure\"/>\n");
677:                        fw.write("  </target>\n");
678:                        fw.write("</project>\n");
679:                        fw.close();
680:
681:                        if (file.exists()) {
682:                            Vector targets = new Vector();
683:                            targets.add("config_backend");
684:                            antUtil.runant(file.getAbsolutePath(), targets,
685:                                    "config.backend", null, null);
686:                            //file.delete();
687:                        }
688:                    } else {
689:                        logger.log(Level.INFO, configDataDir + fs
690:                                + "00community.sql" + " & " + configDataDir
691:                                + fs + "portal.dbadmin" + " does not exists.");
692:                    }
693:                } catch (Exception e) {
694:                    logger.log(Level.SEVERE, "PSFB_CSPFT0276", e);
695:                }
696:            }
697:
698:            /**
699:             * Unconfigures an existing portal
700:             *
701:             * @param portalID The Portal Identifier as a String
702:             * @param ssoToken The Identity Server super user ssoToken as a String
703:             * @param amAdminPassword The Identity Server super user password as String
704:             */
705:            public void unconfigurePortal(String portalID, SSOToken ssoToken)
706:                    throws ConfigurationException {
707:
708:                try {
709:
710:                    // Get the list of Portal Specific services
711:                    Set portalSvcs = getPortalServices();
712:                    // For each service name String in the array modify the String to
713:                    // insert the portalID to generate the portal specific service name
714:                    Set toDelete = new HashSet();
715:                    Iterator iter = portalSvcs.iterator();
716:                    while (iter.hasNext()) {
717:                        String svcName = (String) iter.next();
718:                        svcName = svcName.replaceAll(Tags.PORTAL_ID, portalID);
719:                        toDelete.add(svcName);
720:                    }
721:
722:                    logger.log(Level.FINEST, "PSFB_CSPFT0277", portalID);
723:                    // Remove services using the AMTaskUtils
724:                    AMUtil.deleteServiceSchema(toDelete, ssoToken);
725:                    // Remove the resource bundles loaded for this portal into AM
726:                    String portalRBName = "ps" + portalID + "Services";
727:                    AMUtil.removeResourceBundle(portalRBName, null, ssoToken);
728:
729:                    logger.log(Level.FINEST, "PSFB_CSPFT0278", portalID);
730:                    // Construct the portal directory location
731:                    String portalDir = psDataDir + fs + "portals" + fs
732:                            + portalID;
733:                    // Remove the filesystem data that was created for this portal
734:                    FileUtil.deleteDir(portalDir);
735:                } catch (FileNotFoundException fnfe) {
736:                    logger.log(Level.SEVERE, "PSFB_CSPFT0279", fnfe);
737:                    throw new ConfigurationException(
738:                            "Configuration Files are missing", fnfe);
739:                } catch (IOException ioe) {
740:                    logger.log(Level.SEVERE, "PSFB_CSPFT0280", ioe);
741:                    throw new ConfigurationException(
742:                            "Failed to read configuration", ioe);
743:                }
744:            }
745:
746:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.