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


0001:        package com.sun.portal.fabric.upgrade;
0002:
0003:        import com.sun.portal.fabric.util.FileUtil;
0004:        import com.sun.portal.fabric.util.ExecuteUtil;
0005:        import com.sun.portal.admin.common.InstanceAttributes;
0006:        import com.sun.portal.fabric.tasks.WebContainer;
0007:        import com.sun.portal.fabric.tasks.WebContainerFactory;
0008:        import com.sun.portal.fabric.tasks.JESAS81Impl;
0009:        import com.sun.portal.fabric.tasks.JESWS6Impl;
0010:        import com.sun.portal.fabric.tasks.JESWS7Impl;
0011:        import com.sun.portal.fabric.tasks.BEAWL8Impl;
0012:        import com.sun.portal.fabric.tasks.IBMWAS5Impl;
0013:
0014:        import java.io.*;
0015:        import java.lang.*;
0016:        import java.util.*;
0017:        import java.util.logging.*;
0018:        import java.util.regex.Pattern;
0019:
0020:        import java.util.logging.Level;
0021:        import java.util.logging.Logger;
0022:        import java.util.logging.LogRecord;
0023:        import java.util.logging.FileHandler;
0024:        import java.util.logging.Handler;
0025:        import java.util.logging.SimpleFormatter;
0026:
0027:        import java.net.InetAddress;
0028:        import java.net.UnknownHostException;
0029:        import javax.xml.xpath.XPathExpressionException;
0030:        import netscape.ldap.LDAPConnection;
0031:        import netscape.ldap.LDAPException;
0032:        import netscape.ldap.factory.JSSESocketFactory;
0033:        import org.jdom.Document;
0034:        import org.jdom.Element;
0035:        import org.jdom.JDOMException;
0036:        import org.jdom.output.XMLOutputter;
0037:        import org.jdom.input.SAXBuilder;
0038:        import org.w3c.dom.NodeList;
0039:        import org.w3c.dom.DocumentFragment;
0040:        import org.xml.sax.InputSource;
0041:        import org.xml.sax.SAXException;
0042:        import org.xml.sax.SAXParseException;
0043:
0044:        import javax.xml.parsers.DocumentBuilderFactory;
0045:        import javax.xml.parsers.ParserConfigurationException;
0046:
0047:        import com.sun.portal.log.common.PortalLogger;
0048:        import com.sun.portal.fabric.upgrade.UpgradeUtilException;
0049:
0050:        public class UpgradeUtils {
0051:            private static Logger logger = null;
0052:            private static ExecuteUtil execUtil = null;
0053:            private static LDAPConnection connection = new LDAPConnection();
0054:            private static FileHandler fh = null;
0055:            private static EraserThread masker = null;
0056:            private static int currentFile = 0;
0057:            private static int upgradeUtilExitCode = -1;
0058:
0059:            public static String getWebContainerType(Properties WCType) {
0060:                String type = null;
0061:                String version = WCType.getProperty("version");
0062:                String ps_deploy_type = WCType.getProperty("deployType");
0063:                if (version.equals("6.3.1") || version.equals("6.3")) {
0064:                    /*If Type is AppServer 8.0 or 8.1 do it for 8.1.
0065:                    Note that JES5 has AS 8.2. But for PS purposes 8.2 is same as 8.1*/
0066:                    if (ps_deploy_type.equals("SUNONE")
0067:                            || ps_deploy_type.equals("SUNONE8")
0068:                            || ps_deploy_type
0069:                                    .equals(UpgradeConstants.WC_TYPE_S1AS8))
0070:                        type = UpgradeConstants.WC_TYPE_S1AS8;
0071:                    else /* If Type is WS 6.x do it for 7.0. JES5 has only WS7.0*/
0072:                    if (ps_deploy_type.equals("IWS")
0073:                            || ps_deploy_type
0074:                                    .equals(UpgradeConstants.WC_TYPE_S1WS6)) {
0075:                        if (WCType.getProperty("upgradeOnWS70")
0076:                                .equalsIgnoreCase("true"))
0077:                            type = UpgradeConstants.WC_TYPE_S1WS7;
0078:                        else
0079:                            type = UpgradeConstants.WC_TYPE_S1WS6;
0080:                    } else if (ps_deploy_type
0081:                            .equals(UpgradeConstants.WC_TYPE_WEBSPHERE)
0082:                            || ps_deploy_type
0083:                                    .equals(UpgradeConstants.WC_TYPE_IBMWAS5))
0084:                        type = UpgradeConstants.WC_TYPE_IBMWAS5;
0085:                    else if (ps_deploy_type
0086:                            .equals(UpgradeConstants.WC_TYPE_WEBLOGIC)
0087:                            || ps_deploy_type
0088:                                    .equals(UpgradeConstants.WC_TYPE_BEAWL8))
0089:                        type = UpgradeConstants.WC_TYPE_BEAWL8;
0090:                }
0091:                return type;
0092:            }
0093:
0094:            /*
0095:             * Execute the Content Configuration Framework or ant script
0096:             *
0097:             * @param filesuffix  Ant build file suffix
0098:             * @param targets     Ant targets
0099:             * @param logfile     Ant logfile prefix
0100:             * @param prop        Ant property
0101:             */
0102:            public static void execAnt(String buildfile, Vector targets,
0103:                    String logfile, String propfile) throws UpgradeException {
0104:                logger.log(Level.INFO, "PSFB_CSPFUP0087", targets.toString());
0105:                logfile = new File(logfile).getPath() + "_ant_"
0106:                        + targets.get(0) + ".log";
0107:                File file = new File(buildfile);
0108:
0109:                int exitVal = 0;
0110:
0111:                if (file.exists()) {
0112:                    Vector vargs = new Vector();
0113:                    vargs.add("-buildfile");
0114:                    vargs.add(buildfile);
0115:                    vargs.add("-logfile");
0116:                    vargs.add(logfile);
0117:
0118:                    if (propfile != null) {
0119:                        //Check the porperty file indeed exist
0120:                        file = new File(propfile);
0121:                        if (!file.exists()) {
0122:                            logger.log(Level.SEVERE, "PSFB_CSPFUP0088",
0123:                                    propfile);
0124:                            throw new UpgradeException("Property file:"
0125:                                    + propfile + "does not exist");
0126:                        }
0127:                        vargs.add("-propertyfile");
0128:                        vargs.add(propfile);
0129:                    }
0130:
0131:                    targets.addAll(vargs);
0132:                    //TODO: ant command. Make it anthome based.
0133:                    String command = System.getProperty("ANT_HOME")
0134:                            + File.separator + "bin" + File.separator + "ant";
0135:                    execUtil.storeOutput(false);
0136:                    execUtil.exec(command, (String[]) targets
0137:                            .toArray(new String[0]));
0138:                    //UpgradeUtils.log("Ant Output: "+execUtil.getOutput());
0139:                    /* if(exitVal!=0){
0140:                    throw new UpgradeException("Error executing ant target. See log file for  details:");
0141:                    }*/
0142:                } else {
0143:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0089", file);
0144:                    throw new UpgradeException("Ant build file:" + buildfile
0145:                            + "does not exist");
0146:                }
0147:
0148:            }
0149:
0150:            /*
0151:             * CR 6373066 - New method added to pass on env variables.
0152:             * Execute the Content Configuration Framework or ant script
0153:             *
0154:             * @param filesuffix  Ant build file suffix
0155:             * @param targets     Ant targets
0156:             * @param logfile     Ant logfile prefix
0157:             * @param prop        Ant property
0158:             * @param env         env variables
0159:             */
0160:            public static void execAnt(String buildfile, Vector targets,
0161:                    String logfile, String propfile, Vector env)
0162:                    throws UpgradeException {
0163:                logger.log(Level.INFO, "PSFB_CSPFUP0087", targets.toString());
0164:                logfile = new File(logfile).getPath() + "_ant_"
0165:                        + targets.get(0) + ".log";
0166:                File file = new File(buildfile);
0167:
0168:                int exitVal = 0;
0169:
0170:                if (file.exists()) {
0171:                    Vector vargs = new Vector();
0172:                    vargs.add("-buildfile");
0173:                    vargs.add(buildfile);
0174:                    vargs.add("-logfile");
0175:                    vargs.add(logfile);
0176:
0177:                    if (propfile != null) {
0178:                        //Check the porperty file indeed exist
0179:                        file = new File(propfile);
0180:                        if (!file.exists()) {
0181:                            logger.log(Level.SEVERE, "PSFB_CSPFUP0088",
0182:                                    propfile);
0183:                            throw new UpgradeException("Property file:"
0184:                                    + propfile + "does not exist");
0185:                        }
0186:                        vargs.add("-propertyfile");
0187:                        vargs.add(propfile);
0188:                    }
0189:
0190:                    targets.addAll(vargs);
0191:                    //TODO: ant command. Make it anthome based.
0192:                    String command = System.getProperty("ANT_HOME")
0193:                            + File.separator + "bin" + File.separator + "ant";
0194:                    execUtil.storeOutput(false);
0195:                    execUtil.exec(command, (String[]) targets
0196:                            .toArray(new String[0]), (String[]) env
0197:                            .toArray(new String[0]));
0198:                    //UpgradeUtils.log("Ant Output: "+execUtil.getOutput());
0199:                    /* if(exitVal!=0){
0200:                    throw new UpgradeException("Error executing ant target. See log file for  details:");
0201:                    }*/
0202:                } else {
0203:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0089", file);
0204:                    throw new UpgradeException("Ant build file:" + buildfile
0205:                            + "does not exist");
0206:                }
0207:
0208:            }
0209:
0210:            public static void execAMRequest(final Properties prop,
0211:                    String compName, int totalFiles) throws UpgradeException {
0212:                currentFile++;
0213:                logger.log(Level.INFO, "PSFB_CSPFUP0090", new Object[] {
0214:                        compName, String.valueOf(currentFile),
0215:                        String.valueOf(totalFiles),
0216:                        (totalFiles == 1 ? " " : "s") });
0217:                String command = prop.getProperty("AM_BASEDIR")
0218:                        + File.separator + prop.getProperty("AM_PRODUCT_DIR")
0219:                        + File.separator + "bin" + File.separator + "amadmin";
0220:                String[] args = new String[7];
0221:                args[0] = "-u";
0222:                args[1] = prop.getProperty("ADMIN_DN");
0223:                args[2] = "-w";
0224:                args[3] = prop.getProperty("IDSAME_ADMIN_PASSWORD");
0225:                args[4] = "-v";
0226:                args[5] = "-t";
0227:                args[6] = prop.getProperty("requestFile");
0228:
0229:                execUtil.storeOutput(true);
0230:                try {
0231:                    int exitVal = execUtil.exec(command, args);
0232:                } catch (Exception e) {
0233:                    if (logger.isLoggable(Level.SEVERE)) {
0234:                        LogRecord rec = new LogRecord(Level.SEVERE,
0235:                                "PSFB_CSPFUP0091");
0236:                        rec.setLoggerName(logger.getName());
0237:                        rec.setParameters(new Object[] { prop
0238:                                .getProperty("requestFile") });
0239:                        rec.setThrown(e);
0240:                        logger.log(rec);
0241:                    }
0242:                    throw new UpgradeException("AM request failed for file "
0243:                            + prop.getProperty("requestFile"), e);
0244:                }
0245:                logger.log(Level.INFO, "PSFB_CSPFUP0092", execUtil.getOutput());
0246:
0247:            }
0248:
0249:            public static void execAMResourceBundleRequest(Properties prop,
0250:                    String compName) throws UpgradeException {
0251:                System.out
0252:                        .println("Executing Access Manager command line resource bundle sub command for "
0253:                                + compName + " upgrade ");
0254:                String command = prop.getProperty("AM_BASEDIR")
0255:                        + File.separator + prop.getProperty("AM_PRODUCT_DIR")
0256:                        + File.separator + "bin" + File.separator + "amadmin";
0257:                String[] args = new String[9];
0258:                args[0] = "-u";
0259:                args[1] = prop.getProperty("ADMIN_DN");
0260:                args[2] = "-w";
0261:                args[3] = prop.getProperty("IDSAME_ADMIN_PASSWORD");
0262:                args[4] = "-v";
0263:                args[5] = "--addresourcebundle";
0264:                args[6] = prop.getProperty("requestFile");
0265:                args[7] = "--resourceName";
0266:                args[8] = prop.getProperty("resourceBundleFile");
0267:
0268:                execUtil.storeOutput(true);
0269:                try {
0270:                    execUtil.exec(command, args);
0271:                } catch (Exception e) {
0272:                    if (logger.isLoggable(Level.SEVERE)) {
0273:                        LogRecord rec = new LogRecord(Level.SEVERE,
0274:                                "PSFB_CSPFUP0093");
0275:                        rec.setLoggerName(logger.getName());
0276:                        rec.setParameters(new Object[] { prop
0277:                                .getProperty("resourceBundleFile") });
0278:                        rec.setThrown(e);
0279:                        logger.log(rec);
0280:
0281:                    }
0282:                    throw new UpgradeException(
0283:                            "Access Manager request failed for file "
0284:                                    + prop.getProperty("resourceBundleFile"), e);
0285:                }
0286:                logger.log(Level.INFO, "PSFB_CSPFUP0094", execUtil.getOutput());
0287:
0288:            }
0289:
0290:            public static void execLDAPModify(Properties prop, String compName)
0291:                    throws UpgradeException {
0292:                System.out.println("Executing LDAP Modify command for "
0293:                        + compName + " upgrade ");
0294:                String command = prop.getProperty("AM_BASEDIR")
0295:                        + File.separator + prop.getProperty("AM_PRODUCT_DIR")
0296:                        + File.separator + "bin" + File.separator
0297:                        + "ldapmodify";
0298:                String orgLibPath = System.getProperty("LD_LIBRARY_PATH", "");
0299:                String modifiedLibPath = prop.getProperty("AM_BASEDIR")
0300:                        + File.separator + prop.getProperty("AM_PRODUCT_DIR")
0301:                        + File.separator + "ldaplib" + File.separator
0302:                        + "ldapsdk" + ":" + orgLibPath;
0303:                System.setProperty("LD_LIBRARY_PATH", modifiedLibPath);
0304:                String[] args = new String[10];
0305:                args[0] = "-h";
0306:                args[1] = prop.getProperty("DS_HOST");
0307:                args[2] = "-p";
0308:                args[3] = prop.getProperty("DS_PORT");
0309:                args[4] = "-D";
0310:                args[5] = prop.getProperty("DS_DIRMGR_DN");
0311:                args[6] = "-w";
0312:                args[7] = prop.getProperty("DS_DIRMGR_PASSWORD");
0313:                args[8] = "-f";
0314:                args[9] = prop.getProperty("ldifFile");
0315:
0316:                execUtil.storeOutput(true);
0317:                try {
0318:                    execUtil.exec(command, args);
0319:                } catch (Exception e) {
0320:                    if (logger.isLoggable(Level.SEVERE)) {
0321:                        LogRecord rec = new LogRecord(Level.SEVERE,
0322:                                "PSFB_CSPFUP0095");
0323:                        rec.setLoggerName(logger.getName());
0324:                        rec.setParameters(new Object[] { prop
0325:                                .getProperty("ldifFile") });
0326:                        rec.setThrown(e);
0327:                        logger.log(rec);
0328:
0329:                    }
0330:                    throw new UpgradeException("LDAP Modify failed for file "
0331:                            + prop.getProperty("ldifFile"), e);
0332:                }
0333:                logger.log(Level.INFO, "PSFB_CSPFUP0096", execUtil.getOutput());
0334:                System.setProperty("LD_LIBRARY_PATH", orgLibPath);
0335:            }
0336:
0337:            public static void executeDesktopProfileUpdates(
0338:                    Properties psInstallationProps, String[] resDirs)
0339:                    throws UpgradeException {
0340:                File DPChanges = null, globalDP = null, orgDP = null;
0341:                String fileSep = File.separator;
0342:                try {
0343:                    System.out.println("Performing desktop profile updates...");
0344:                    globalDP = new File(fileSep + "var" + fileSep + "tmp"
0345:                            + fileSep + "PSUpgradeDPGlobal.xml");
0346:                    FileUtil.deleteLineInFile(globalDP,
0347:                            "<!DOCTYPE DisplayProfile SYSTEM",
0348:                            FileUtil.DELETE_FIRST_OCCURANCE);
0349:                    orgDP = new File(fileSep + "var" + fileSep + "tmp"
0350:                            + fileSep + "PSUpgradeDPOrg.xml");
0351:                    FileUtil.deleteLineInFile(orgDP,
0352:                            "<!DOCTYPE DisplayProfile SYSTEM",
0353:                            FileUtil.DELETE_FIRST_OCCURANCE);
0354:                    FileUtil.replaceTokenInFile(orgDP,
0355:                            "/etc/opt/SUNWps/desktop",
0356:                            "/var/opt/SUNWportal/portals/Upgraded/desktop");
0357:
0358:                    //Process Global DP
0359:                    try { //Even if one release DP updates fails, the entire DP XML becomes unloadable
0360:                        for (int i = 0; i < resDirs.length; i++) {
0361:                            //make the directories if not existent.
0362:                            DPChanges = FileUtil.extractFileFromJar(resDirs[i]
0363:                                    + "/" + UpgradeConstants.RESOURCE_JAR,
0364:                                    "DPChanges.txt", false);
0365:                            UpgradeUtils.processDPUpdates(globalDP, DPChanges,
0366:                                    "GLOBAL");
0367:                            //Workarounds for bug in jaxp cache?
0368:                            File tmpGlobal = new File(globalDP
0369:                                    .getAbsolutePath()
0370:                                    + "with"
0371:                                    + resDirs[i].substring(resDirs[i]
0372:                                            .lastIndexOf("/") + 1) + "Changes");
0373:                            copy(globalDP, tmpGlobal);
0374:                            globalDP = tmpGlobal;
0375:                        }
0376:
0377:                        //Start - L10N Code change
0378:
0379:                        //Proces Global DP for L10n DP changes if L10n install detected
0380:                        if (UpgradeConstants.PORTAL_L10N_INSTALLED == true) {
0381:                            try {
0382:                                for (int i = 0; i < resDirs.length; i++) {
0383:                                    //make the directories if not existent.                                                        
0384:                                    DPChanges = FileUtil
0385:                                            .extractFileFromJar(
0386:                                                    resDirs[i]
0387:                                                            + "/"
0388:                                                            + UpgradeConstants.RESOURCE_JAR,
0389:                                                    "DPChanges-l10n.txt", false);
0390:                                    copy(DPChanges, new File(DPChanges
0391:                                            .getAbsolutePath()
0392:                                            + "-" + "test"));
0393:                                    UpgradeUtils.processDPUpdates(globalDP,
0394:                                            DPChanges, "GLOBAL");
0395:                                    //Workarounds for bug in jaxp cache?
0396:                                    File tmpGlobal = new File(globalDP
0397:                                            .getAbsolutePath()
0398:                                            + "with"
0399:                                            + resDirs[i].substring(resDirs[i]
0400:                                                    .lastIndexOf("/") + 1)
0401:                                            + "Changes-l10n");
0402:                                    copy(globalDP, tmpGlobal);
0403:                                    globalDP = tmpGlobal;
0404:                                }
0405:                            } catch (FileNotFoundException fex) {
0406:                                System.out.println("No DPChanges for L10n");
0407:                            }
0408:                        }
0409:
0410:                        //End - L10N Code change
0411:
0412:                        FileUtil
0413:                                .appendLineInFile(
0414:                                        globalDP,
0415:                                        "<?xml",
0416:                                        "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE DisplayProfile SYSTEM \"jar://resources/psdp.dtd\">\n<DisplayProfile version=\"1.0\" priority=\"0\">",
0417:                                        FileUtil.APPEND_FIRST_OCCURANCE);
0418:                        FileUtil.deleteLineInFile(globalDP, "<?xml",
0419:                                FileUtil.DELETE_FIRST_OCCURANCE);
0420:                        //Display profile element appears twice. Bug?? . Remedy is in the next three lines.
0421:                        FileUtil
0422:                                .deleteLineInFile(
0423:                                        globalDP,
0424:                                        "<DisplayProfile advanced=\"false\" lock=\"false\"",
0425:                                        FileUtil.DELETE_FIRST_OCCURANCE);
0426:                        FileUtil.deleteLineInFile(globalDP,
0427:                                "<DisplayProfile xmlns:DisplayProfile=",
0428:                                FileUtil.DELETE_FIRST_OCCURANCE);
0429:                        FileUtil.deleteLineInFile(globalDP,
0430:                                "<DisplayProfile priority=\"0\"",
0431:                                FileUtil.DELETE_FIRST_OCCURANCE);
0432:                        //Workaround for jaxp bug.
0433:                        copy(globalDP, new File(fileSep + "var" + fileSep
0434:                                + "tmp" + fileSep + "UpdatedDPGlobal.xml"));
0435:                    } catch (UpgradeUtilException e) {
0436:                        logger.log(Level.SEVERE, e.getMessage());
0437:                        setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
0438:                    }
0439:
0440:                    //Process ORG DP
0441:                    try {
0442:                        for (int i = 0; i < resDirs.length; i++) {
0443:                            //make the directories if not existent.
0444:                            DPChanges = FileUtil.extractFileFromJar(resDirs[i]
0445:                                    + "/" + UpgradeConstants.RESOURCE_JAR,
0446:                                    "DPChanges.txt", false);
0447:                            UpgradeUtils.processDPUpdates(orgDP, DPChanges,
0448:                                    "ORG");
0449:                            //Workarounds for bug in jaxp cache?
0450:                            File tmpOrg = new File(orgDP.getAbsolutePath()
0451:                                    + "with"
0452:                                    + resDirs[i].substring(resDirs[i]
0453:                                            .lastIndexOf("/") + 1) + "Changes");
0454:                            copy(orgDP, tmpOrg);
0455:                            orgDP = tmpOrg;
0456:                        }
0457:                        //Start - L10N Code change
0458:
0459:                        //Proces Org DP for L10n DP changes if L10n install detected
0460:                        if (UpgradeConstants.PORTAL_L10N_INSTALLED == true) {
0461:                            try {
0462:                                for (int i = 0; i < resDirs.length; i++) {
0463:                                    //make the directories if not existent.
0464:                                    DPChanges = FileUtil
0465:                                            .extractFileFromJar(
0466:                                                    resDirs[i]
0467:                                                            + "/"
0468:                                                            + UpgradeConstants.RESOURCE_JAR,
0469:                                                    "DPChanges-l10n.txt", false);
0470:                                    UpgradeUtils.processDPUpdates(orgDP,
0471:                                            DPChanges, "ORG");
0472:                                    //Workarounds for bug in jaxp cache?
0473:                                    File tmpOrg = new File(orgDP
0474:                                            .getAbsolutePath()
0475:                                            + "with"
0476:                                            + resDirs[i].substring(resDirs[i]
0477:                                                    .lastIndexOf("/") + 1)
0478:                                            + "Changes-l10n");
0479:                                    copy(orgDP, tmpOrg);
0480:                                    orgDP = tmpOrg;
0481:                                }
0482:                            } catch (FileNotFoundException fex) {
0483:                                System.out.println("No DPChanges for L10n");
0484:                            }
0485:                        }
0486:
0487:                        //End - L10N Code change                              
0488:                        FileUtil
0489:                                .appendLineInFile(
0490:                                        orgDP,
0491:                                        "<?xml",
0492:                                        "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE DisplayProfile SYSTEM \"jar://resources/psdp.dtd\">\n<DisplayProfile version=\"1.0\" priority=\"10\">",
0493:                                        FileUtil.APPEND_FIRST_OCCURANCE);
0494:                        FileUtil.deleteLineInFile(orgDP, "<?xml",
0495:                                FileUtil.DELETE_FIRST_OCCURANCE);
0496:                        //Display profile element appears twice. Bug?? . Remedy is in the next three lines.
0497:                        FileUtil
0498:                                .deleteLineInFile(
0499:                                        orgDP,
0500:                                        "<DisplayProfile advanced=\"false\" lock=\"false\"",
0501:                                        FileUtil.DELETE_FIRST_OCCURANCE);
0502:
0503:                        //Start - L10N Code Change
0504:
0505:                        //In above comment , it is mentioned that three lines required same as Global , but only one line found to delete
0506:                        // when checkout this file but without following two lines L10n upgrade so added them
0507:                        if (UpgradeConstants.PORTAL_L10N_INSTALLED == true) {
0508:                            FileUtil.deleteLineInFile(orgDP,
0509:                                    "<DisplayProfile xmlns:DisplayProfile=",
0510:                                    FileUtil.DELETE_FIRST_OCCURANCE);
0511:                            FileUtil.deleteLineInFile(orgDP,
0512:                                    "<DisplayProfile priority=\"10\"",
0513:                                    FileUtil.DELETE_FIRST_OCCURANCE);
0514:                        }
0515:
0516:                        //End - L10N Code Change
0517:
0518:                        //Workaround for jaxp bug.
0519:                        copy(orgDP, new File(fileSep + "var" + fileSep + "tmp"
0520:                                + fileSep + "UpdatedDPOrg.xml"));
0521:                    } catch (UpgradeUtilException e) {
0522:                        logger.log(Level.SEVERE, e.getMessage());
0523:                        setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
0524:                    }
0525:
0526:                } catch (IOException e) {
0527:                    if (logger.isLoggable(Level.SEVERE)) {
0528:                        LogRecord rec = new LogRecord(Level.SEVERE,
0529:                                "PSFB_CSPFUP0097");
0530:                        rec.setLoggerName(logger.getName());
0531:                        rec.setParameters(new Object[] { DPChanges
0532:                                .getAbsolutePath() });
0533:                        rec.setThrown(e);
0534:                        logger.log(rec);
0535:                    }
0536:                } catch (Exception e) {
0537:                    if (logger.isLoggable(Level.SEVERE)) {
0538:                        LogRecord rec = new LogRecord(Level.SEVERE,
0539:                                "PSFB_CSPFUP0097");
0540:                        rec.setLoggerName(logger.getName());
0541:                        rec.setParameters(new Object[] { DPChanges
0542:                                .getAbsolutePath() });
0543:                        rec.setThrown(e);
0544:                        logger.log(rec);
0545:                    }
0546:                }
0547:            }
0548:
0549:            public static void executeClassPathUpdates(File cpChangesFile,
0550:                    String configFilePath, Properties wcAttributes,
0551:                    boolean validate) {
0552:
0553:                //TODO: Classpath update related code
0554:                String type = (String) wcAttributes
0555:                        .get(InstanceAttributes.WEB_CONTAINER_TYPE);
0556:                Map attributes = new HashMap(wcAttributes);
0557:                try {
0558:                    WebContainer wc = WebContainerFactory.getWebContainer(
0559:                            attributes, validate);
0560:                    String cpUpdatesLine = null;
0561:                    String[] cpEntriesArray = null;
0562:
0563:                    BufferedReader br = new BufferedReader(
0564:                            new InputStreamReader(new FileInputStream(
0565:                                    cpChangesFile)));
0566:                    if (type.equalsIgnoreCase("SJSAS81")) {
0567:                        //Perform actions related to AS 8.1
0568:                        JESAS81Impl jesAS81Instance = (JESAS81Impl) wc;
0569:
0570:                        while ((cpUpdatesLine = br.readLine()) != null) {
0571:
0572:                            if (cpUpdatesLine.startsWith("ADD_SJSAS81")) {
0573:                                cpEntriesArray = cpUpdatesLine.split("=");
0574:                                if (cpEntriesArray != null
0575:                                        && cpEntriesArray.length > 1) {
0576:
0577:                                    String cpAllEntries = cpEntriesArray[1];
0578:
0579:                                    String[] cpEntries = cpAllEntries
0580:                                            .split(",");
0581:                                    if (cpEntries != null
0582:                                            && cpEntries.length > 0) {
0583:                                        int i = 0;
0584:                                        while (i < cpEntries.length) {
0585:                                            String cpEntry = cpEntries[i];
0586:                                            String subEntry = getSubstitutedCPEntry(
0587:                                                    cpEntry.trim(),
0588:                                                    configFilePath);
0589:                                            boolean added = jesAS81Instance
0590:                                                    .appendClasspath(subEntry
0591:                                                            .trim());
0592:                                            i++;
0593:                                        }
0594:                                    }
0595:                                }
0596:                            } else if (cpUpdatesLine
0597:                                    .startsWith("REMOVE_SJSAS81")) {
0598:                                cpEntriesArray = cpUpdatesLine.split("=");
0599:                                if (cpEntriesArray != null
0600:                                        && cpEntriesArray.length > 1) {
0601:
0602:                                    String cpAllEntries = cpEntriesArray[1];
0603:
0604:                                    String[] cpEntries = cpAllEntries
0605:                                            .split(",");
0606:                                    if (cpEntries != null
0607:                                            && cpEntries.length > 0) {
0608:                                        int i = 0;
0609:                                        while (i < cpEntries.length) {
0610:                                            String cpEntry = cpEntries[i];
0611:                                            String subEntry = getSubstitutedCPEntry(
0612:                                                    cpEntry.trim(),
0613:                                                    configFilePath);
0614:                                            boolean removed = jesAS81Instance
0615:                                                    .removeClasspath(subEntry
0616:                                                            .trim());
0617:                                            i++;
0618:                                        }
0619:                                    }
0620:                                }
0621:                            }
0622:                        }
0623:
0624:                    }
0625:                    if (type.equalsIgnoreCase("SJSWS6")) {
0626:                        //Perform actions related to WS 6.1
0627:                        JESWS6Impl jesWS6Instance = (JESWS6Impl) wc;
0628:
0629:                        while ((cpUpdatesLine = br.readLine()) != null) {
0630:
0631:                            if (cpUpdatesLine.startsWith("ADD_SJSWS6")) {
0632:                                cpEntriesArray = cpUpdatesLine.split("=");
0633:                                if (cpEntriesArray != null
0634:                                        && cpEntriesArray.length > 1) {
0635:
0636:                                    String cpAllEntries = cpEntriesArray[1];
0637:
0638:                                    String[] cpEntries = cpAllEntries
0639:                                            .split(",");
0640:                                    if (cpEntries != null
0641:                                            && cpEntries.length > 0) {
0642:                                        int i = 0;
0643:                                        while (i < cpEntries.length) {
0644:                                            String cpEntry = cpEntries[i];
0645:                                            String subEntry = getSubstitutedCPEntry(
0646:                                                    cpEntry.trim(),
0647:                                                    configFilePath);
0648:                                            boolean added = jesWS6Instance
0649:                                                    .appendClasspath(subEntry
0650:                                                            .trim());
0651:                                            i++;
0652:                                        }
0653:                                    }
0654:                                }
0655:                            } else if (cpUpdatesLine
0656:                                    .startsWith("REMOVE_SJSWS6")) {
0657:                                cpEntriesArray = cpUpdatesLine.split("=");
0658:                                if (cpEntriesArray != null
0659:                                        && cpEntriesArray.length > 1) {
0660:
0661:                                    String cpAllEntries = cpEntriesArray[1];
0662:
0663:                                    String[] cpEntries = cpAllEntries
0664:                                            .split(",");
0665:                                    if (cpEntries != null
0666:                                            && cpEntries.length > 0) {
0667:                                        int i = 0;
0668:                                        while (i < cpEntries.length) {
0669:                                            String cpEntry = cpEntries[i];
0670:                                            String subEntry = getSubstitutedCPEntry(
0671:                                                    cpEntry.trim(),
0672:                                                    configFilePath);
0673:                                            boolean removed = jesWS6Instance
0674:                                                    .removeClasspath(subEntry
0675:                                                            .trim());
0676:                                            i++;
0677:                                        }
0678:                                    }
0679:                                }
0680:                            }
0681:                        }
0682:                    }
0683:                    if (type.equalsIgnoreCase("SJSAS82")) {
0684:                        //Perform actions related to AS 8.2
0685:                        JESAS81Impl jesAS81Instance = (JESAS81Impl) wc;
0686:
0687:                        while ((cpUpdatesLine = br.readLine()) != null) {
0688:
0689:                            if (cpUpdatesLine.startsWith("ADD_SJSAS82")) {
0690:                                cpEntriesArray = cpUpdatesLine.split("=");
0691:                                if (cpEntriesArray != null
0692:                                        && cpEntriesArray.length > 1) {
0693:
0694:                                    String cpAllEntries = cpEntriesArray[1];
0695:
0696:                                    String[] cpEntries = cpAllEntries
0697:                                            .split(",");
0698:                                    if (cpEntries != null
0699:                                            && cpEntries.length > 0) {
0700:                                        int i = 0;
0701:                                        while (i < cpEntries.length) {
0702:                                            String cpEntry = cpEntries[i];
0703:                                            String subEntry = getSubstitutedCPEntry(
0704:                                                    cpEntry.trim(),
0705:                                                    configFilePath);
0706:                                            boolean added = jesAS81Instance
0707:                                                    .appendClasspath(subEntry
0708:                                                            .trim());
0709:                                            i++;
0710:                                        }
0711:                                    }
0712:                                }
0713:                            } else if (cpUpdatesLine
0714:                                    .startsWith("REMOVE_SJSAS82")) {
0715:                                cpEntriesArray = cpUpdatesLine.split("=");
0716:                                if (cpEntriesArray != null
0717:                                        && cpEntriesArray.length > 1) {
0718:
0719:                                    String cpAllEntries = cpEntriesArray[1];
0720:
0721:                                    String[] cpEntries = cpAllEntries
0722:                                            .split(",");
0723:                                    if (cpEntries != null
0724:                                            && cpEntries.length > 0) {
0725:                                        int i = 0;
0726:                                        while (i < cpEntries.length) {
0727:                                            String cpEntry = cpEntries[i];
0728:                                            String subEntry = getSubstitutedCPEntry(
0729:                                                    cpEntry.trim(),
0730:                                                    configFilePath);
0731:                                            boolean removed = jesAS81Instance
0732:                                                    .removeClasspath(subEntry
0733:                                                            .trim());
0734:                                            i++;
0735:                                        }
0736:                                    }
0737:                                }
0738:                            }
0739:                        }
0740:
0741:                    }
0742:                    if (type.equalsIgnoreCase("SJSWS7")) {
0743:                        //Perform actions related to WS 7
0744:                        JESWS7Impl jesWS7Instance = (JESWS7Impl) wc;
0745:
0746:                        while ((cpUpdatesLine = br.readLine()) != null) {
0747:
0748:                            if (cpUpdatesLine.startsWith("ADD_SJSWS7")) {
0749:                                cpEntriesArray = cpUpdatesLine.split("=");
0750:                                if (cpEntriesArray != null
0751:                                        && cpEntriesArray.length > 1) {
0752:
0753:                                    String cpAllEntries = cpEntriesArray[1];
0754:
0755:                                    String[] cpEntries = cpAllEntries
0756:                                            .split(",");
0757:                                    if (cpEntries != null
0758:                                            && cpEntries.length > 0) {
0759:                                        int i = 0;
0760:                                        while (i < cpEntries.length) {
0761:                                            String cpEntry = cpEntries[i];
0762:                                            String subEntry = getSubstitutedCPEntry(
0763:                                                    cpEntry.trim(),
0764:                                                    configFilePath);
0765:                                            boolean added = jesWS7Instance
0766:                                                    .appendClasspath(subEntry
0767:                                                            .trim());
0768:                                            i++;
0769:                                        }
0770:                                        jesWS7Instance.DeployConfigforUpgrade();
0771:                                    }
0772:                                }
0773:                            } else if (cpUpdatesLine
0774:                                    .startsWith("REMOVE_SJSWS7")) {
0775:                                cpEntriesArray = cpUpdatesLine.split("=");
0776:                                if (cpEntriesArray != null
0777:                                        && cpEntriesArray.length > 1) {
0778:
0779:                                    String cpAllEntries = cpEntriesArray[1];
0780:
0781:                                    String[] cpEntries = cpAllEntries
0782:                                            .split(",");
0783:                                    if (cpEntries != null
0784:                                            && cpEntries.length > 0) {
0785:                                        int i = 0;
0786:                                        while (i < cpEntries.length) {
0787:                                            String cpEntry = cpEntries[i];
0788:                                            String subEntry = getSubstitutedCPEntry(
0789:                                                    cpEntry.trim(),
0790:                                                    configFilePath);
0791:                                            boolean removed = jesWS7Instance
0792:                                                    .removeClasspath(subEntry
0793:                                                            .trim());
0794:                                            i++;
0795:                                        }
0796:                                    }
0797:                                }
0798:                            }
0799:                        }
0800:                    }
0801:
0802:                    if (type.equalsIgnoreCase("IBMWAS5")) {
0803:                        //Perform actions related to WS 7
0804:                        IBMWAS5Impl IBMWAS5Instance = (IBMWAS5Impl) wc;
0805:
0806:                        while ((cpUpdatesLine = br.readLine()) != null) {
0807:
0808:                            if (cpUpdatesLine.startsWith("ADD_IBMWAS5")) {
0809:                                cpEntriesArray = cpUpdatesLine.split("=");
0810:                                if (cpEntriesArray != null
0811:                                        && cpEntriesArray.length > 1) {
0812:
0813:                                    String cpAllEntries = cpEntriesArray[1];
0814:
0815:                                    String[] cpEntries = cpAllEntries
0816:                                            .split(",");
0817:                                    if (cpEntries != null
0818:                                            && cpEntries.length > 0) {
0819:                                        int i = 0;
0820:                                        while (i < cpEntries.length) {
0821:                                            String cpEntry = cpEntries[i];
0822:                                            String subEntry = getSubstitutedCPEntry(
0823:                                                    cpEntry.trim(),
0824:                                                    configFilePath);
0825:                                            boolean added = IBMWAS5Instance
0826:                                                    .appendClasspath(subEntry
0827:                                                            .trim());
0828:                                            i++;
0829:                                        }
0830:                                    }
0831:                                }
0832:                            } else if (cpUpdatesLine
0833:                                    .startsWith("REMOVE_IBMWAS5")) {
0834:                                cpEntriesArray = cpUpdatesLine.split("=");
0835:                                if (cpEntriesArray != null
0836:                                        && cpEntriesArray.length > 1) {
0837:
0838:                                    String cpAllEntries = cpEntriesArray[1];
0839:
0840:                                    String[] cpEntries = cpAllEntries
0841:                                            .split(",");
0842:                                    if (cpEntries != null
0843:                                            && cpEntries.length > 0) {
0844:                                        int i = 0;
0845:                                        while (i < cpEntries.length) {
0846:                                            String cpEntry = cpEntries[i];
0847:                                            String subEntry = getSubstitutedCPEntry(
0848:                                                    cpEntry.trim(),
0849:                                                    configFilePath);
0850:                                            boolean removed = IBMWAS5Instance
0851:                                                    .removeClasspath(subEntry
0852:                                                            .trim());
0853:                                            i++;
0854:                                        }
0855:                                    }
0856:                                }
0857:                            }
0858:                        }
0859:                    }
0860:                    if (type.equalsIgnoreCase("BEAWL8")) {
0861:                        //Perform actions related to AS 8.1
0862:                        BEAWL8Impl BEAWL8Instance = (BEAWL8Impl) wc;
0863:
0864:                        while ((cpUpdatesLine = br.readLine()) != null) {
0865:
0866:                            if (cpUpdatesLine.startsWith("ADD_BEAWL8")) {
0867:                                cpEntriesArray = cpUpdatesLine.split("=");
0868:                                if (cpEntriesArray != null
0869:                                        && cpEntriesArray.length > 1) {
0870:
0871:                                    String cpAllEntries = cpEntriesArray[1];
0872:
0873:                                    String[] cpEntries = cpAllEntries
0874:                                            .split(",");
0875:                                    if (cpEntries != null
0876:                                            && cpEntries.length > 0) {
0877:                                        int i = 0;
0878:                                        while (i < cpEntries.length) {
0879:                                            String cpEntry = cpEntries[i];
0880:                                            String subEntry = getSubstitutedCPEntry(
0881:                                                    cpEntry.trim(),
0882:                                                    configFilePath);
0883:                                            boolean added = BEAWL8Instance
0884:                                                    .appendClasspath(subEntry
0885:                                                            .trim());
0886:                                            i++;
0887:                                        }
0888:                                    }
0889:                                }
0890:                            } else if (cpUpdatesLine
0891:                                    .startsWith("REMOVE_BEAWL8")) {
0892:                                cpEntriesArray = cpUpdatesLine.split("=");
0893:                                if (cpEntriesArray != null
0894:                                        && cpEntriesArray.length > 1) {
0895:
0896:                                    String cpAllEntries = cpEntriesArray[1];
0897:
0898:                                    String[] cpEntries = cpAllEntries
0899:                                            .split(",");
0900:                                    if (cpEntries != null
0901:                                            && cpEntries.length > 0) {
0902:                                        int i = 0;
0903:                                        while (i < cpEntries.length) {
0904:                                            String cpEntry = cpEntries[i];
0905:                                            String subEntry = getSubstitutedCPEntry(
0906:                                                    cpEntry.trim(),
0907:                                                    configFilePath);
0908:                                            boolean removed = BEAWL8Instance
0909:                                                    .removeClasspath(subEntry
0910:                                                            .trim());
0911:                                            i++;
0912:                                        }
0913:                                    }
0914:                                }
0915:                            }
0916:                        }
0917:
0918:                    }
0919:                } catch (Exception ex) {
0920:                    System.out
0921:                            .println("Exception while performing classpath updates -- "
0922:                                    + ex);
0923:                }
0924:            }
0925:
0926:            public static void executeJVMOptionUpdates(File jvmOCFile,
0927:                    Properties wcAttributes, boolean validate) {
0928:
0929:                String type = (String) wcAttributes
0930:                        .get(InstanceAttributes.WEB_CONTAINER_TYPE);
0931:                Map attributes = new HashMap(wcAttributes);
0932:                try {
0933:                    WebContainer wc = WebContainerFactory.getWebContainer(
0934:                            attributes, validate);
0935:                    String jvmOptionLine = null;
0936:                    String[] splitJVMOption = null;
0937:
0938:                    BufferedReader br = new BufferedReader(
0939:                            new InputStreamReader(
0940:                                    new FileInputStream(jvmOCFile)));
0941:                    if (type.equalsIgnoreCase("SJSAS81")) {
0942:                        //Perform actions related to AS 8.1
0943:                        JESAS81Impl jesAS81Instance = (JESAS81Impl) wc;
0944:
0945:                        while ((jvmOptionLine = br.readLine()) != null) {
0946:
0947:                            if (jvmOptionLine.startsWith("ADD_SJSAS81")) {
0948:                                splitJVMOption = jvmOptionLine.split("=");
0949:                                if (splitJVMOption != null
0950:                                        && splitJVMOption.length > 1) {
0951:
0952:                                    String jvmOption = splitJVMOption[1];
0953:
0954:                                    String[] splitJVMKeyValue = jvmOption
0955:                                            .split(",");
0956:                                    String jvmKey = splitJVMKeyValue[0];
0957:                                    String jvmValue = splitJVMKeyValue[1];
0958:
0959:                                    boolean added = jesAS81Instance
0960:                                            .addJVMOption(jvmKey, jvmValue);
0961:                                }
0962:                            } else if (jvmOptionLine
0963:                                    .startsWith("REMOVE_SJSAS81")) {
0964:                                splitJVMOption = jvmOptionLine.split("=");
0965:                                if (splitJVMOption != null
0966:                                        && splitJVMOption.length > 1) {
0967:
0968:                                    String jvmOption = splitJVMOption[1];
0969:
0970:                                    String[] splitJVMKeyValue = jvmOption
0971:                                            .split(",");
0972:                                    String jvmKey = splitJVMKeyValue[0];
0973:                                    String jvmValue = splitJVMKeyValue[1];
0974:
0975:                                    boolean removed = jesAS81Instance
0976:                                            .removeJVMOption(jvmKey, jvmValue);
0977:                                }
0978:                            }
0979:                        }
0980:
0981:                    }
0982:                    if (type.equalsIgnoreCase("SJSWS6")) {
0983:                        //Perform actions related to WS 6.1
0984:                        JESWS6Impl jesWS6Instance = (JESWS6Impl) wc;
0985:
0986:                        while ((jvmOptionLine = br.readLine()) != null) {
0987:
0988:                            if (jvmOptionLine.startsWith("ADD_SJSWS6")) {
0989:                                splitJVMOption = jvmOptionLine.split("=");
0990:                                if (splitJVMOption != null
0991:                                        && splitJVMOption.length > 1) {
0992:
0993:                                    String jvmOption = splitJVMOption[1];
0994:
0995:                                    String[] splitJVMKeyValue = jvmOption
0996:                                            .split(",");
0997:                                    String jvmKey = splitJVMKeyValue[0];
0998:                                    String jvmValue = splitJVMKeyValue[1];
0999:
1000:                                    boolean added = jesWS6Instance
1001:                                            .addJVMOption(jvmKey, jvmValue);
1002:                                }
1003:                            } else if (jvmOptionLine
1004:                                    .startsWith("REMOVE_SJSWS6")) {
1005:                                splitJVMOption = jvmOptionLine.split("=");
1006:                                if (splitJVMOption != null
1007:                                        && splitJVMOption.length > 1) {
1008:
1009:                                    String jvmOption = splitJVMOption[1];
1010:
1011:                                    String[] splitJVMKeyValue = jvmOption
1012:                                            .split(",");
1013:                                    String jvmKey = splitJVMKeyValue[0];
1014:                                    String jvmValue = splitJVMKeyValue[1];
1015:
1016:                                    boolean removed = jesWS6Instance
1017:                                            .removeJVMOption(jvmKey, jvmValue);
1018:                                }
1019:                            }
1020:                        }
1021:
1022:                    }
1023:                    if (type.equalsIgnoreCase("SJSAS82")) {
1024:                        //Perform actions related to AS 8.2
1025:                        JESAS81Impl jesAS81Instance = (JESAS81Impl) wc;
1026:
1027:                        while ((jvmOptionLine = br.readLine()) != null) {
1028:
1029:                            if (jvmOptionLine.startsWith("ADD_SJSAS82")) {
1030:                                splitJVMOption = jvmOptionLine.split("=");
1031:                                if (splitJVMOption != null
1032:                                        && splitJVMOption.length > 1) {
1033:
1034:                                    String jvmOption = splitJVMOption[1];
1035:
1036:                                    String[] splitJVMKeyValue = jvmOption
1037:                                            .split(",");
1038:                                    String jvmKey = splitJVMKeyValue[0];
1039:                                    String jvmValue = splitJVMKeyValue[1];
1040:
1041:                                    boolean added = jesAS81Instance
1042:                                            .addJVMOption(jvmKey, jvmValue);
1043:                                }
1044:                            } else if (jvmOptionLine
1045:                                    .startsWith("REMOVE_SJSAS82")) {
1046:                                splitJVMOption = jvmOptionLine.split("=");
1047:                                if (splitJVMOption != null
1048:                                        && splitJVMOption.length > 1) {
1049:
1050:                                    String jvmOption = splitJVMOption[1];
1051:
1052:                                    String[] splitJVMKeyValue = jvmOption
1053:                                            .split(",");
1054:                                    String jvmKey = splitJVMKeyValue[0];
1055:                                    String jvmValue = splitJVMKeyValue[1];
1056:
1057:                                    boolean removed = jesAS81Instance
1058:                                            .removeJVMOption(jvmKey, jvmValue);
1059:                                }
1060:                            }
1061:                        }
1062:
1063:                    }
1064:                    if (type.equalsIgnoreCase("SJSWS7")) {
1065:                        //Perform actions related to WS 7
1066:                        JESWS7Impl jesWS7Instance = (JESWS7Impl) wc;
1067:
1068:                        while ((jvmOptionLine = br.readLine()) != null) {
1069:
1070:                            if (jvmOptionLine.startsWith("ADD_SJSWS7")) {
1071:                                splitJVMOption = jvmOptionLine.split("=");
1072:                                if (splitJVMOption != null
1073:                                        && splitJVMOption.length > 1) {
1074:
1075:                                    String jvmOption = splitJVMOption[1];
1076:
1077:                                    String[] splitJVMKeyValue = jvmOption
1078:                                            .split(",");
1079:                                    String jvmKey = splitJVMKeyValue[0];
1080:                                    String jvmValue = splitJVMKeyValue[1];
1081:
1082:                                    boolean added = jesWS7Instance
1083:                                            .addJVMOption(jvmKey, jvmValue);
1084:                                }
1085:                            } else if (jvmOptionLine
1086:                                    .startsWith("REMOVE_SJSWS7")) {
1087:                                splitJVMOption = jvmOptionLine.split("=");
1088:                                if (splitJVMOption != null
1089:                                        && splitJVMOption.length > 1) {
1090:
1091:                                    String jvmOption = splitJVMOption[1];
1092:
1093:                                    String[] splitJVMKeyValue = jvmOption
1094:                                            .split(",");
1095:                                    String jvmKey = splitJVMKeyValue[0];
1096:                                    String jvmValue = splitJVMKeyValue[1];
1097:
1098:                                    boolean removed = jesWS7Instance
1099:                                            .removeJVMOption(jvmKey, jvmValue);
1100:                                }
1101:                            }
1102:                        }
1103:
1104:                    }
1105:                } catch (Exception ex) {
1106:                    System.out
1107:                            .println("Exception while performing JVM Option updates -- "
1108:                                    + ex);
1109:                }
1110:            }
1111:
1112:            public static void executeServerPolicyUpdates(File spChangesFile,
1113:                    Properties wcAttributes, Logger log, boolean validate) {
1114:
1115:                //TODO: Server Policy update related code
1116:            }
1117:
1118:            public static void executeAccessManagerUpdates(
1119:                    Properties psInstallationProps, String[] resDirs)
1120:                    throws UpgradeException {
1121:
1122:                boolean portalInstalled = psInstallationProps.getProperty(
1123:                        "PORTAL_INSTALLED").equalsIgnoreCase("true");
1124:                boolean sraInstalled = false;
1125:                if (portalInstalled == true) {
1126:                    sraInstalled = true;
1127:                }
1128:
1129:                for (int j = 0; j < resDirs.length; j++) {
1130:                    //make the directories if not existent.
1131:                    String portalUpgradeTmpDir = UpgradeConstants.SOLARIS_TMP_DIR
1132:                            + File.separator
1133:                            + "portal"
1134:                            + File.separator
1135:                            + resDirs[j].substring(resDirs[j]
1136:                                    .lastIndexOf(File.separator) + 1,
1137:                                    resDirs[j].length());
1138:
1139:                    String[] amrequestfiles = null;
1140:                    String fileNamePattern = null;
1141:                    int fileCount = 0;
1142:                    if (portalInstalled == true) {
1143:                        fileNamePattern = "PSrequest[\\d]{1,3}.xml$";// Files of the form "request<number>.xml"
1144:                        amrequestfiles = UpgradeUtils
1145:                                .returnFileListHavingPattern(
1146:                                        portalUpgradeTmpDir, fileNamePattern);
1147:                        fileCount = amrequestfiles.length;
1148:                        for (int i = 0; i < fileCount; i++) {
1149:                            psInstallationProps.setProperty("requestFile",
1150:                                    amrequestfiles[i]);
1151:                            FileUtil.replaceTokenInFile(new File(
1152:                                    amrequestfiles[i]), "ORG_DN",
1153:                                    psInstallationProps.getProperty("ORG_DN"));
1154:                            UpgradeUtils.execAMRequest(psInstallationProps,
1155:                                    "Portal Server", fileCount);
1156:                        }
1157:                    }
1158:                    if (sraInstalled == true) {
1159:                        fileNamePattern = "SRArequest[\\d]{1,3}.xml$";// Files of the form "request<number>.xml"
1160:                        amrequestfiles = UpgradeUtils
1161:                                .returnFileListHavingPattern(
1162:                                        portalUpgradeTmpDir, fileNamePattern);
1163:
1164:                        File f = new File(portalUpgradeTmpDir);
1165:                        File[] allAMFile = f.listFiles();
1166:                        for (int i = 0; i < fileCount; i++) {
1167:                            FileUtil.replaceTokenInFile(allAMFile[i], "ORG_DN",
1168:                                    psInstallationProps.getProperty("ORG_DN"));
1169:                            FileUtil.replaceTokenInFile(allAMFile[i],
1170:                                    "LOAD_BALANCER_URL", psInstallationProps
1171:                                            .getProperty("LOAD_BALANCER_URL"));
1172:                            FileUtil.replaceTokenInFile(allAMFile[i],
1173:                                    "SERVER_DOMAIN", psInstallationProps
1174:                                            .getProperty("SERVER_DOMAIN"));
1175:                        }
1176:
1177:                        fileCount = amrequestfiles.length;
1178:                        for (int i = 0; i < fileCount; i++) {
1179:                            psInstallationProps.setProperty("requestFile",
1180:                                    amrequestfiles[i]);
1181:                            UpgradeUtils.execAMRequest(psInstallationProps,
1182:                                    "SRA", fileCount);
1183:                        }
1184:                    }
1185:
1186:                    //Perform the am resource now.
1187:                    String[] amResourceBundleFiles = null;
1188:                    if (portalInstalled == true) {
1189:                        fileNamePattern = "\\w*PortalServer.res$";// Files of the form "*.res"
1190:                        amResourceBundleFiles = UpgradeUtils
1191:                                .returnFileListHavingPattern(
1192:                                        portalUpgradeTmpDir, fileNamePattern);
1193:                        fileCount = amResourceBundleFiles.length;
1194:                        for (int i = 0; i < fileCount; i++) {
1195:                            psInstallationProps.setProperty("resourceName",
1196:                                    amResourceBundleFiles[i].substring(0,
1197:                                            amResourceBundleFiles[i]
1198:                                                    .indexOf(".")));
1199:                            psInstallationProps.setProperty(
1200:                                    "resourceBundleFile",
1201:                                    amResourceBundleFiles[i]);
1202:                            UpgradeUtils.execAMResourceBundleRequest(
1203:                                    psInstallationProps, "Portal Server");
1204:                        }
1205:                    }
1206:                    if (sraInstalled == true) {
1207:                        fileNamePattern = "\\w*SRA.res$";// Files of the form "*.res"
1208:                        amResourceBundleFiles = UpgradeUtils
1209:                                .returnFileListHavingPattern(
1210:                                        portalUpgradeTmpDir, fileNamePattern);
1211:                        fileCount = amResourceBundleFiles.length;
1212:                        for (int i = 0; i < fileCount; i++) {
1213:                            psInstallationProps.setProperty("resourceName",
1214:                                    amResourceBundleFiles[i].substring(0,
1215:                                            amResourceBundleFiles[i]
1216:                                                    .indexOf(".")));
1217:                            psInstallationProps.setProperty(
1218:                                    "resourceBundleFile",
1219:                                    amResourceBundleFiles[i]);
1220:                            UpgradeUtils.execAMResourceBundleRequest(
1221:                                    psInstallationProps, "Portal Server");
1222:                        }
1223:                        fileNamePattern = "\\w*srapGateway.res$";// Files of the form "*.res"
1224:                        amResourceBundleFiles = UpgradeUtils
1225:                                .returnFileListHavingPattern(
1226:                                        portalUpgradeTmpDir, fileNamePattern);
1227:                        fileCount = amResourceBundleFiles.length;
1228:                        for (int i = 0; i < fileCount; i++) {
1229:                            psInstallationProps.setProperty("resourceName",
1230:                                    amResourceBundleFiles[i].substring(0,
1231:                                            amResourceBundleFiles[i]
1232:                                                    .indexOf(".")));
1233:                            psInstallationProps.setProperty(
1234:                                    "resourceBundleFile",
1235:                                    amResourceBundleFiles[i]);
1236:                            UpgradeUtils.execAMResourceBundleRequest(
1237:                                    psInstallationProps, "Portal Server");
1238:                        }
1239:
1240:                        fileNamePattern = "\\w*srapNetlet.res$";// Files of the form "*.res"
1241:                        amResourceBundleFiles = UpgradeUtils
1242:                                .returnFileListHavingPattern(
1243:                                        portalUpgradeTmpDir, fileNamePattern);
1244:                        fileCount = amResourceBundleFiles.length;
1245:                        for (int i = 0; i < fileCount; i++) {
1246:                            psInstallationProps.setProperty("resourceName",
1247:                                    amResourceBundleFiles[i].substring(0,
1248:                                            amResourceBundleFiles[i]
1249:                                                    .indexOf(".")));
1250:                            psInstallationProps.setProperty(
1251:                                    "resourceBundleFile",
1252:                                    amResourceBundleFiles[i]);
1253:                            UpgradeUtils.execAMResourceBundleRequest(
1254:                                    psInstallationProps, "Portal Server");
1255:                        }
1256:
1257:                        fileNamePattern = "\\w*srapRewriter.res$";// Files of the form "*.res"
1258:                        amResourceBundleFiles = UpgradeUtils
1259:                                .returnFileListHavingPattern(
1260:                                        portalUpgradeTmpDir, fileNamePattern);
1261:                        fileCount = amResourceBundleFiles.length;
1262:                        for (int i = 0; i < fileCount; i++) {
1263:                            psInstallationProps.setProperty("resourceName",
1264:                                    amResourceBundleFiles[i].substring(0,
1265:                                            amResourceBundleFiles[i]
1266:                                                    .indexOf(".")));
1267:                            psInstallationProps.setProperty(
1268:                                    "resourceBundleFile",
1269:                                    amResourceBundleFiles[i]);
1270:                            UpgradeUtils.execAMResourceBundleRequest(
1271:                                    psInstallationProps, "Portal Server");
1272:                        }
1273:                    }
1274:
1275:                    //Perform the ldapmodify requests now.
1276:                    String[] ldapModifyLdifFiles = null;
1277:                    if (portalInstalled == true) {
1278:                        fileNamePattern = "^ldapmodify\\w*PortalServer.ldif$";// Files of the form "*.res"
1279:                        ldapModifyLdifFiles = UpgradeUtils
1280:                                .returnFileListHavingPattern(
1281:                                        portalUpgradeTmpDir, fileNamePattern);
1282:                        fileCount = ldapModifyLdifFiles.length;
1283:                        for (int i = 0; i < fileCount; i++) {
1284:                            psInstallationProps.setProperty("ldifFile",
1285:                                    ldapModifyLdifFiles[i]);
1286:                            UpgradeUtils.execLDAPModify(psInstallationProps,
1287:                                    "Portal Server");
1288:                        }
1289:                    }
1290:                    if (sraInstalled == true) {
1291:                        fileNamePattern = "^ldapmodify\\w*SRA.ldif$";// Files of the form "*.res"
1292:                        ldapModifyLdifFiles = UpgradeUtils
1293:                                .returnFileListHavingPattern(
1294:                                        portalUpgradeTmpDir, fileNamePattern);
1295:                        fileCount = ldapModifyLdifFiles.length;
1296:                        for (int i = 0; i < fileCount; i++) {
1297:                            psInstallationProps.setProperty("ldifFile",
1298:                                    ldapModifyLdifFiles[i]);
1299:                            UpgradeUtils.execLDAPModify(psInstallationProps,
1300:                                    "SRA");
1301:                        }
1302:
1303:                        fileNamePattern = "^ldapmodify\\w*Gateway.ldif$";// Files of the form "*.res"
1304:                        ldapModifyLdifFiles = UpgradeUtils
1305:                                .returnFileListHavingPattern(
1306:                                        portalUpgradeTmpDir, fileNamePattern);
1307:                        fileCount = ldapModifyLdifFiles.length;
1308:                        for (int i = 0; i < fileCount; i++) {
1309:                            psInstallationProps.setProperty("ldifFile",
1310:                                    ldapModifyLdifFiles[i]);
1311:                            UpgradeUtils.execLDAPModify(psInstallationProps,
1312:                                    "Gateway");
1313:                        }
1314:
1315:                        fileNamePattern = "^ldapmodify\\w*Netlet.ldif$";// Files of the form "*.res"
1316:                        ldapModifyLdifFiles = UpgradeUtils
1317:                                .returnFileListHavingPattern(
1318:                                        portalUpgradeTmpDir, fileNamePattern);
1319:                        fileCount = ldapModifyLdifFiles.length;
1320:                        for (int i = 0; i < fileCount; i++) {
1321:                            psInstallationProps.setProperty("ldifFile",
1322:                                    ldapModifyLdifFiles[i]);
1323:                            UpgradeUtils.execLDAPModify(psInstallationProps,
1324:                                    "Netlet");
1325:                        }
1326:
1327:                        fileNamePattern = "^ldapmodify\\w*Rewriter.ldif$";// Files of the form "*.res"
1328:                        ldapModifyLdifFiles = UpgradeUtils
1329:                                .returnFileListHavingPattern(
1330:                                        portalUpgradeTmpDir, fileNamePattern);
1331:                        fileCount = ldapModifyLdifFiles.length;
1332:                        for (int i = 0; i < fileCount; i++) {
1333:                            psInstallationProps.setProperty("ldifFile",
1334:                                    ldapModifyLdifFiles[i]);
1335:                            UpgradeUtils.execLDAPModify(psInstallationProps,
1336:                                    "Rewriter");
1337:                        }
1338:                    }
1339:
1340:                    //Perform the service removal requests now.
1341:
1342:                    String[] service = null;
1343:                    String services = null;
1344:                    File amServicesRemovalFile = null;
1345:                    boolean serviceRemoved = false;
1346:                    Properties servicesProp = new Properties();
1347:                    try {
1348:                        amServicesRemovalFile = FileUtil
1349:                                .extractFileFromJar(
1350:                                        resDirs[j] + File.separator
1351:                                                + UpgradeConstants.RESOURCE_JAR,
1352:                                        UpgradeConstants.AM_SERVICES_REMOVE_FILE,
1353:                                        false);
1354:                        servicesProp.load(new FileInputStream(
1355:                                amServicesRemovalFile));
1356:                    } catch (IOException e) {
1357:                        logger.log(Level.SEVERE, "PSFB_CSPFUP0098",
1358:                                amServicesRemovalFile);
1359:                    }
1360:                    if (sraInstalled == true) {
1361:                        services = servicesProp
1362:                                .getProperty("SRA.services.remove");
1363:                        logger.log(Level.INFO, "PSFB_CSPFUP0099", services);
1364:
1365:                        if (services != null) {
1366:                            service = services.split(",");
1367:                            //For each patch
1368:                            for (int i = 0; i < service.length; i++) {
1369:                                serviceRemoved = UpgradeUtils.removeService(
1370:                                        psInstallationProps, service[i]);
1371:                                if (serviceRemoved == false) {
1372:                                    System.out
1373:                                            .println("One or more Service Removal failed. See log for details");
1374:                                    logger.log(Level.INFO, "PSFB_CSPFUP0100",
1375:                                            service[i]);
1376:                                } else {
1377:                                    logger.log(Level.INFO, "PSFB_CSPFUP0101",
1378:                                            service[i]);
1379:                                }
1380:                            }
1381:                        } else {
1382:                            serviceRemoved = true;
1383:                        }
1384:                    }
1385:                }
1386:            }
1387:
1388:            public static void preparePSAMBackupScript(Properties prop,
1389:                    File backUpScript) {
1390:                System.out
1391:                        .println("Executing PortalServer Directory server backup..");
1392:                FileUtil.replaceTokenInFile(backUpScript, "AM_BASEDIR", prop
1393:                        .getProperty("AM_BASEDIR"));
1394:                FileUtil.replaceTokenInFile(backUpScript, "AM_PRODUCT_DIR",
1395:                        prop.getProperty("AM_PRODUCT_DIR"));
1396:                FileUtil.replaceTokenInFile(backUpScript, "DS_HOST", prop
1397:                        .getProperty("DS_HOST"));
1398:                FileUtil.replaceTokenInFile(backUpScript, "DS_PORT", prop
1399:                        .getProperty("DS_PORT"));
1400:                FileUtil.replaceTokenInFile(backUpScript, "DS_DIRMGR_DN", prop
1401:                        .getProperty("DS_DIRMGR_DN"));
1402:                FileUtil.replaceTokenInFile(backUpScript, "DS_DIRMGR_PASSWORD",
1403:                        prop.getProperty("DS_DIRMGR_PASSWORD"));
1404:                FileUtil.replaceTokenInFile(backUpScript, "ORG_DN", prop
1405:                        .getProperty("ORG_DN"));
1406:            }
1407:
1408:            public static void execPSInstall(Properties prop)
1409:                    throws UpgradeException {
1410:                System.out.println("Executing psinstall command for upgrade ");
1411:                String command = prop.getProperty("psinstallShFile");
1412:                String[] args = new String[2];
1413:                args[0] = "-s";
1414:                args[1] = prop.getProperty("psinstallFile");
1415:
1416:                execUtil.storeOutput(true);
1417:                try {
1418:                    execUtil.exec(command, args);
1419:                } catch (Exception e) {
1420:                    if (logger.isLoggable(Level.SEVERE)) {
1421:                        LogRecord rec = new LogRecord(Level.SEVERE,
1422:                                "PSFB_CSPFUP0102");
1423:                        rec.setLoggerName(logger.getName());
1424:                        rec.setParameters(new Object[] { prop
1425:                                .getProperty("ldifFile") });
1426:                        rec.setThrown(e);
1427:                        logger.log(rec);
1428:
1429:                    }
1430:                    throw new UpgradeException("psinstall failed", e);
1431:                }
1432:                logger.log(Level.INFO, "PSFB_CSPFUP0103", execUtil.getOutput());
1433:            }
1434:
1435:            static String parseCertInfo(String certStr, String info) {
1436:                String infoValue = "";
1437:                String[] tokens = certStr.split(",");
1438:
1439:                for (int i = 0; i < tokens.length; i++)
1440:                    if (tokens[i].startsWith(info + "=")) {
1441:                        //Country C is not encoded as "". So we need the next line fix.
1442:                        int add = 1;
1443:                        if (info.equals("C"))
1444:                            add = 0;
1445:                        infoValue = tokens[i].substring(tokens[i].indexOf("=")
1446:                                + (add + 1), tokens[i].length() - add);
1447:                    }
1448:
1449:                return infoValue;
1450:
1451:            }
1452:
1453:            static String getLocalSystemIPAddress() {
1454:                String ipAddrStr = "";
1455:                try {
1456:                    InetAddress addr = InetAddress.getLocalHost();
1457:
1458:                    // Get IP Address
1459:                    byte[] ipAddr = addr.getAddress();
1460:
1461:                    for (int i = 0; i < ipAddr.length; i++) {
1462:                        if (i > 0) {
1463:                            ipAddrStr += ".";
1464:                        }
1465:                        ipAddrStr += ipAddr[i] & 0xFF;
1466:                    }
1467:                    logger.log(Level.INFO, "PSFB_CSPFUP0104", ipAddrStr);
1468:
1469:                } catch (UnknownHostException e) {
1470:
1471:                }
1472:
1473:                return ipAddrStr;
1474:            }
1475:
1476:            static String getStartInstanceStatus(String stat) {
1477:
1478:                if (stat.equals("Y"))
1479:                    return "true";
1480:                else
1481:                    return "false";
1482:
1483:            }
1484:
1485:            static String[] returnFileListEndingWith(String dirStr,
1486:                    final String startpat, final String[] endpatterns) {
1487:                String[] consolidatedFileNamesList = null;
1488:                ArrayList consolidatedFileNamesArrayList = new ArrayList();
1489:                //Place holder for returned files.
1490:                String[] fileslist = null;
1491:
1492:                int totalFileCount = 0;
1493:                for (int i = 0; i < endpatterns.length; i++) {
1494:                    //Fetch all the files for this particular pattern.
1495:                    fileslist = returnFileListEndingWith(dirStr, startpat,
1496:                            endpatterns[i]);
1497:                    if (fileslist == null)
1498:                        continue;
1499:                    //Ele continue afdding the files.
1500:                    totalFileCount = totalFileCount + fileslist.length;
1501:                    //Add the individual files in the larger consolidated Array
1502:                    for (int j = 0; j < fileslist.length; j++) {
1503:                        consolidatedFileNamesArrayList.add(fileslist[j]);
1504:                    }
1505:                }
1506:
1507:                if (totalFileCount > 0) {
1508:                    consolidatedFileNamesList = new String[totalFileCount];
1509:                    consolidatedFileNamesArrayList
1510:                            .toArray(consolidatedFileNamesList);
1511:                }
1512:                return consolidatedFileNamesList;
1513:            }
1514:
1515:            static String[] returnFileListHavingPattern(String dirStr,
1516:                    final String regexpat) {
1517:                File dir = new File(dirStr);
1518:
1519:                FilenameFilter filter = new FilenameFilter() {
1520:                    public boolean accept(File dir, String name) {
1521:                        if (regexpat != null)
1522:                            return Pattern.matches(regexpat, name);
1523:                        else
1524:                            return false;
1525:                    }
1526:                };
1527:                File[] children = dir.listFiles(filter);
1528:                TreeSet fileNames = new TreeSet();
1529:                if (children == null) {
1530:                    // Either dir does not exist or is not a directory
1531:                } else {
1532:                    for (int i = 0; i < children.length; i++) {
1533:                        // Get filename of file or directory
1534:                        fileNames.add(children[i].getAbsolutePath());
1535:                    }
1536:                }
1537:                return (String[]) fileNames.toArray(new String[0]);
1538:            }
1539:
1540:            public static String[] returnFileListEndingWith(String dirStr,
1541:                    final String startpat, final String endpattern) {
1542:                File dir = new File(dirStr);
1543:
1544:                FilenameFilter filter = new FilenameFilter() {
1545:                    public boolean accept(File dir, String name) {
1546:                        if (startpat != null && endpattern != null)
1547:                            return (name.startsWith(startpat) && name
1548:                                    .endsWith(endpattern));
1549:                        else if (endpattern != null)
1550:                            return name.endsWith(endpattern);
1551:                        else if (startpat != null)
1552:                            return name.startsWith(startpat);
1553:                        else
1554:                            return false;
1555:                    }
1556:                };
1557:                File[] children = dir.listFiles(filter);
1558:                String filenames[] = null;
1559:
1560:                if (children == null) {
1561:                    return null;
1562:                } else {
1563:                    if (children.length > 0) {
1564:                        filenames = new String[children.length];
1565:                        for (int i = 0; i < children.length; i++) {
1566:                            // Get filename of file or directory
1567:                            filenames[i] = children[i].getAbsolutePath();
1568:                        }
1569:                    }
1570:                }
1571:
1572:                return filenames;
1573:            }
1574:
1575:            static String[] returnFileList(String dirStr, String pat,
1576:                    int matchmode) {
1577:                //Call the specialised return file list methods.
1578:                return null;
1579:            }
1580:
1581:            public static void log(String msg) {
1582:
1583:                log(UpgradeConstants.LOG_MESSAGE, msg);
1584:            }
1585:
1586:            public static void log(int severity, String msg) {
1587:                if (severity == UpgradeConstants.LOG_WARNING)
1588:                    logger.warning(msg);
1589:                if (severity == UpgradeConstants.LOG_FATAL)
1590:                    logger.severe(msg);
1591:                if (severity == UpgradeConstants.LOG_MESSAGE)
1592:                    logger.info(msg);
1593:                if (severity == UpgradeConstants.LOG_DEBUG)
1594:                    logger.finest(msg);
1595:            }
1596:
1597:            public static boolean removeService(Properties prop,
1598:                    String serviceName) {
1599:                boolean success = false;
1600:
1601:                String command = prop.getProperty("AM_BASEDIR")
1602:                        + File.separator + prop.getProperty("AM_PRODUCT_DIR")
1603:                        + File.separator + "bin" + File.separator + "amadmin";
1604:                String[] args = new String[6];
1605:                args[0] = "-u";
1606:                args[1] = prop.getProperty("ADMIN_DN");
1607:                args[2] = "-w";
1608:                args[3] = prop.getProperty("IDSAME_ADMIN_PASSWORD");
1609:                args[4] = "-r";
1610:                args[5] = serviceName;
1611:
1612:                execUtil.storeOutput(true);
1613:                try {
1614:                    execUtil.exec(command, args);
1615:                } catch (Exception e) {
1616:                    if (logger.isLoggable(Level.SEVERE)) {
1617:                        LogRecord rec = new LogRecord(Level.SEVERE,
1618:                                "PSFB_CSPFUP0105");
1619:                        rec.setLoggerName(logger.getName());
1620:                        rec.setParameters(new Object[] { serviceName });
1621:                        rec.setThrown(e);
1622:                        logger.log(rec);
1623:
1624:                    }
1625:                    // throw new UpgradeException("AM service remove request failed for  "+ serviceName,e);
1626:                }
1627:                String output = execUtil.getOutput();
1628:                logger.log(Level.INFO, "PSFB_CSPFUP0106", output);
1629:                if (output.indexOf("Success") != -1)
1630:                    success = true;
1631:
1632:                return success;
1633:            }
1634:
1635:            public static boolean isRPMInstalled(String rpm) {
1636:                boolean success = false;
1637:                String command = "rpm";
1638:                String[] args = new String[2];
1639:                args[0] = "-q";
1640:                args[1] = rpm;
1641:                execUtil.storeOutput(true);
1642:                execUtil.exec(command, args);
1643:                String result = execUtil.getOutput();
1644:                logger.log(Level.INFO, "PSFB_CSPFUP0107", new Object[] { rpm,
1645:                        result });
1646:                if (result != null && result.startsWith(rpm))
1647:                    success = true;
1648:                else
1649:                    success = false;
1650:
1651:                return success;
1652:            }
1653:
1654:            public static String getRPMFullName(String rpm) {
1655:                boolean success = false;
1656:                String fullRPMName = "-1";
1657:                String command = "rpm";
1658:                String[] args = new String[2];
1659:                args[0] = "-q";
1660:                args[1] = rpm;
1661:                execUtil.storeOutput(true);
1662:                execUtil.exec(command, args);
1663:                String result = execUtil.getOutput();
1664:
1665:                logger.log(Level.INFO, "PSFB_CSPFUP0107", new Object[] { rpm,
1666:                        result });
1667:                if (result != null && result.startsWith(rpm))
1668:                    success = true;
1669:                else
1670:                    success = false;
1671:                if (success == true)
1672:                    fullRPMName = result;
1673:                else
1674:                    fullRPMName = "-1";
1675:                return fullRPMName;
1676:
1677:            }
1678:
1679:            public static boolean isSunOSPatchApplied(String patchID) {
1680:                boolean success = false;
1681:
1682:                String command = "patchadd";
1683:                String[] args = new String[1];
1684:                args[0] = "-p";
1685:
1686:                execUtil.storeOutput(true);
1687:                execUtil.exec(command, args);
1688:                String result = execUtil.getOutput();
1689:                String[] tokens = result.split("\n");
1690:                int len = tokens.length;
1691:                for (int i = 0; i < len; i++) {
1692:                    if (tokens[i].indexOf("Patch: " + patchID) != -1) {
1693:                        success = true;
1694:                        break;
1695:                    }
1696:                }
1697:
1698:                logger.log(Level.INFO, "PSFB_CSPFUP0108", new Object[] {
1699:                        patchID, String.valueOf(success) });
1700:                return success;
1701:            }
1702:
1703:            public static boolean isLinuxPatchApplied(String patchID) {
1704:                boolean success = false;
1705:
1706:                //Linux patchID here comes in the format ID:rpm1:rpm2:....
1707:                String[] tokens = patchID.split(":");
1708:                String ID = tokens[0];
1709:                for (int i = 1; i < tokens.length; i++) {
1710:                    success = isRPMInstalled(tokens[0], true);
1711:                    if (success == false)
1712:                        break;
1713:                }
1714:                logger.log(Level.INFO, "PSFB_CSPFUP0109", new Object[] {
1715:                        patchID, String.valueOf(success) });
1716:                return success;
1717:            }
1718:
1719:            public static boolean isRPMInstalled(String rpm,
1720:                    boolean checkVersion) {
1721:                boolean success = false;
1722:
1723:                //rpm argument is of the form name-name2-name3-version-release.
1724:                String[] tokens = rpm.split("-");
1725:                //Now construct the rpm name only.
1726:                String rpmName = "";
1727:                for (int i = 0; i < tokens.length - 2; i++)
1728:                    rpmName = rpmName + tokens[i] + "-";
1729:                rpmName = rpmName.substring(0, rpmName.length() - 1);
1730:
1731:                //First check if the rpm is installed.
1732:                boolean rpmInstalled = isRPMInstalled(rpmName);
1733:
1734:                if (rpmInstalled == true) {
1735:                    String command = "rpm";
1736:                    String[] args = new String[4];
1737:                    args[0] = "-q";
1738:                    args[1] = "--queryformat";
1739:                    args[2] = "RELEASE=%{RELEASE}";
1740:                    args[3] = rpmName;
1741:                    execUtil.storeOutput(true);
1742:                    execUtil.exec(command, args);
1743:                    String release = execUtil.getOutput();
1744:                    args[2] = "VERSION=%{VERSION}";
1745:                    execUtil.storeOutput(true);
1746:                    execUtil.exec(command, args);
1747:                    String version = execUtil.getOutput();
1748:
1749:                    if (version != null && version.startsWith("VERSION="))
1750:                        version = version.trim().substring(8);
1751:                    else
1752:                        version = "";
1753:
1754:                    int releaseInt = 0;
1755:                    if (release != null && release.startsWith("RELEASE=")) {
1756:                        release = release.trim().substring(8, 10);
1757:                        releaseInt = new Integer(release).intValue();
1758:                    }
1759:
1760:                    //Version is assumed to be only of type x.y or x.y.z
1761:                    //Example sun-ant-1.5.4-26. sun-cacao-1.0-25.3
1762:                    //release is of the form x or x.y
1763:                    String[] givenVersionConstituents = tokens[tokens.length - 2]
1764:                            .split("\\.");
1765:                    String[] givenReleaseConstituents = tokens[tokens.length - 1]
1766:                            .split("\\.");
1767:                    String[] installedVersionConstituents = version
1768:                            .split("\\.");
1769:                    String[] installedReleaseConstituents = release
1770:                            .split("\\.");
1771:
1772:                    success = true;
1773:                    for (int i = 0; i < givenVersionConstituents.length; i++) {
1774:                        if (installedVersionConstituents[i] != null
1775:                                && (!(Integer
1776:                                        .parseInt(installedVersionConstituents[i]) >= Integer
1777:                                        .parseInt(givenVersionConstituents[i])))) {
1778:                            success = false;
1779:                            break;
1780:                        }
1781:                    }
1782:                    if (success == true) {
1783:                        for (int i = 0; i < givenReleaseConstituents.length; i++) {
1784:                            if (installedVersionConstituents[i] != null
1785:                                    && (!(Integer
1786:                                            .parseInt(installedReleaseConstituents[i]) >= Integer
1787:                                            .parseInt(givenReleaseConstituents[i])))) {
1788:                                success = false;
1789:                                break;
1790:                            }
1791:                        }
1792:                    }
1793:                }
1794:                logger.log(Level.INFO, "PSFB_CSPFUP0110", new Object[] { rpm,
1795:                        String.valueOf(success) });
1796:                return success;
1797:
1798:            }
1799:
1800:            public static boolean isPackageInstalled(String pkg) {
1801:
1802:                String command = "/bin/pkginfo";
1803:                execUtil.storeOutput(true);
1804:                execUtil.exec(command, null);
1805:                String result = execUtil.getOutput();
1806:
1807:                logger.log(Level.INFO, "PSFB_CSPFUP0111", pkg);
1808:
1809:                String[] tokens = result.split("\n");
1810:                int len = tokens.length;
1811:                for (int i = 0; i < len; i++) {
1812:                    if (tokens[i].indexOf(pkg) != -1) {
1813:                        String pkginfoFilePath = "/var/sadm/pkg/" + pkg
1814:                                + "/pkginfo";
1815:                        File pkginfoFile = new File(pkginfoFilePath);
1816:                        if (pkginfoFile.exists()) {
1817:                            logger.log(Level.INFO, "PSFB_CSPFUP0112", pkg);
1818:                            return true;
1819:                        }
1820:                    }
1821:                }
1822:                return false;
1823:            }
1824:
1825:            public static boolean removeSunOSPackage(String pkg) {
1826:                boolean success = false;
1827:                if (isPackageInstalled(pkg)) {
1828:
1829:                    String command = "/usr/sbin/pkgrm";
1830:                    String args[] = new String[2];
1831:                    args[0] = "-n";
1832:                    args[1] = pkg;
1833:                    execUtil.storeOutput(true);
1834:                    int exitVal = execUtil.exec(command, args);
1835:                    String result = execUtil.getOutput();
1836:                    switch (exitVal) {
1837:                    case 0:
1838:                        logger.log(Level.INFO, "PSFB_CSPFUP0139",
1839:                                "Successfully Removed" + pkg);
1840:                        success = true;
1841:                        break;
1842:                    case 1:
1843:                    case 2:
1844:                    case 3:
1845:                    default:
1846:                        //System.out.println("Setting success to false" + exitVal);
1847:                        logger.log(Level.INFO, "PSFB_CSPFUP0139",
1848:                                "Could not Remove" + pkg);
1849:                        success = false;
1850:                        break;
1851:                    }
1852:
1853:                } else {
1854:                    logger.log(Level.INFO, "PSFB_CSPFUP0139", pkg
1855:                            + "Already Installed");
1856:                    //System.out.println("Package is not installed");
1857:                    success = true;
1858:                }
1859:
1860:                return success;
1861:
1862:            }
1863:
1864:            public static boolean removeLinuxOSPackage(String pkg) {
1865:                boolean success = false;
1866:
1867:                //System.out.println(getRPMFullName(pkg));
1868:
1869:                String fullRPMName = "";
1870:
1871:                if (isRPMInstalled(pkg)) {
1872:                    fullRPMName = getRPMFullName(pkg);
1873:                    if (fullRPMName.equals("-1")) {
1874:                        logger.log(Level.INFO, "PSFB_CSPFUP0139",
1875:                                "Could not get FULL RPM NAME" + pkg);
1876:                        success = false;
1877:                        return success;
1878:                    }
1879:                    logger.log(Level.INFO, "PSFB_CSPFUP0139",
1880:                            "FULL RPM NAME IS:" + fullRPMName);
1881:                    String command = "/bin/rpm";
1882:                    String args[] = new String[2];
1883:                    args[0] = "-e";
1884:                    args[1] = pkg;
1885:                    int exitVal = -1;
1886:                    execUtil.storeOutput(true);
1887:                    exitVal = execUtil.exec(command, args);
1888:                    String result = execUtil.getOutput();
1889:                    switch (exitVal) {
1890:                    case 0:
1891:
1892:                        logger.log(Level.INFO, "PSFB_CSPFUP0139",
1893:                                "Successfully Removed" + pkg);
1894:                        success = true;
1895:                        String psBaseDir;
1896:                        String psProductDir;
1897:                        String version;
1898:                        psBaseDir = UpgradeUtils.getPSBaseDirOnLinux();
1899:                        removeDir(psBaseDir);
1900:                        break;
1901:                    case 1:
1902:                    case 2:
1903:                    case 3:
1904:                    default:
1905:
1906:                        logger.log(Level.INFO, "PSFB_CSPFUP0139",
1907:                                "Could not Remove" + pkg);
1908:                        success = false;
1909:                        break;
1910:                    }
1911:                } else {
1912:
1913:                    logger.log(Level.INFO, "PSFB_CSPFUP0139", pkg
1914:                            + "Already UnInstalled");
1915:                    success = true;
1916:                }
1917:                return success;
1918:
1919:            }
1920:
1921:            public static boolean removeDir(String psBaseDir) {
1922:                boolean success = true;
1923:                try {
1924:                    String rpmDir = "webnfs";
1925:                    String absolutePath = psBaseDir + "/" + rpmDir;
1926:                    String command = "/bin/rm";
1927:                    String args[] = new String[2];
1928:                    args[0] = "-rf";
1929:                    args[1] = absolutePath;
1930:                    int exitVal = -1;
1931:                    execUtil.storeOutput(true);
1932:                    exitVal = execUtil.exec(command, args);
1933:
1934:                } catch (Exception e) {
1935:                    return success;
1936:                }
1937:                return success;
1938:
1939:            }
1940:
1941:            static void removeLogHandler() {
1942:                if (fh != null)
1943:                    fh.close();
1944:            }
1945:
1946:            public static boolean hasCommandOption(String[] args, String opt) {
1947:                boolean ret = false;
1948:                if (args != null) {
1949:                    for (int i = 1; i < args.length; i++) {
1950:                        if (args[i].equalsIgnoreCase(opt)) {
1951:                            ret = true;
1952:                            break;
1953:                        }
1954:                    }
1955:                }
1956:
1957:                return ret;
1958:            }
1959:
1960:            public static String getCommandOptionValue(String[] args, String opt) {
1961:                String ret = null;
1962:                if (args != null) {
1963:                    for (int i = 1; i < args.length; i++) {
1964:                        if (args[i].equalsIgnoreCase(opt)) {
1965:                            ret = args[i + 1];
1966:                            break;
1967:                        }
1968:                    }
1969:                }
1970:
1971:                return ret;
1972:            }
1973:
1974:            public static void setLogger(Logger log) {
1975:                logger = log;
1976:            }
1977:
1978:            public static void setExecUtil(ExecuteUtil exec) {
1979:                execUtil = exec;
1980:            }
1981:
1982:            boolean isWebContainerServerRunning() {
1983:                return false;
1984:            }
1985:
1986:            static boolean isDirectoryServerRunning(String host, int port) {
1987:                try {
1988:
1989:                    // Check if the Directory Server is running by making a connection to DS.
1990:                    connection.connect(host, port);
1991:                    connection.disconnect();
1992:
1993:                } catch (LDAPException e) {
1994:                    return false;
1995:                }
1996:                return true;
1997:            }
1998:
1999:            static boolean isDirectoryManagerCredentialValid(String host,
2000:                    int port, String DN, String password) {
2001:                //Validate DirectoryManager Credentials
2002:                return validateCredentials(host, port, DN, password);
2003:            }
2004:
2005:            static boolean isAccessManagerAdminCredentialValid(String host,
2006:                    int port, String DN, String password) {
2007:                return validateCredentials(host, port, DN, password);
2008:
2009:            }
2010:
2011:            static boolean isSRACredentialsValid(String host, int port,
2012:                    String sraAgentName, String password) {
2013:
2014:                return validateCredentials(host, port, sraAgentName, password);
2015:
2016:            }
2017:
2018:            static boolean isAccessManagerLDAPUserCredentialValid(String host,
2019:                    int port, String DN, String password) {
2020:                return validateCredentials(host, port, DN, password);
2021:            }
2022:
2023:            static boolean validateCredentials(String host, int port,
2024:                    String userName, String credentials) {
2025:
2026:                try {
2027:                    connection.connect(host, port);
2028:                    connection.authenticate(userName, credentials);
2029:                    connection.disconnect();
2030:                } catch (Exception e) {
2031:                    return false;
2032:                }
2033:                return true;
2034:            }
2035:
2036:            static String promptUser(String s) {
2037:                String[] args = new String[1];
2038:                args[0] = s;
2039:                String command = "/bin/echo";
2040:                execUtil.exec(command, args);
2041:                String resp = readUserResponse();
2042:                if (resp == null)
2043:                    resp = "";
2044:                return resp;
2045:            }
2046:
2047:            static String readUserResponse() {
2048:                BufferedReader myIn = new BufferedReader(new InputStreamReader(
2049:                        System.in));
2050:                String s = null;
2051:                try {
2052:                    s = myIn.readLine();
2053:                } catch (IOException e) {
2054:                    System.err.println("Error reading input from user ");
2055:                }
2056:                return s;
2057:            }
2058:
2059:            public static String getPatchKey() {
2060:                if (System.getProperty("os.name").indexOf("SunOS") != -1
2061:                        && System.getProperty("os.arch").indexOf("sparc") != -1)
2062:                    return UpgradeConstants.SOLARIS_SPARC_PATCH_KEY;
2063:                else if (System.getProperty("os.name").indexOf("Linux") != -1)
2064:                    return UpgradeConstants.LINUX_x86_PATCH_KEY;
2065:                else
2066:                    return UpgradeConstants.SOLARIS_x86_PATCH_KEY;
2067:
2068:            }
2069:
2070:            public static String readInput(String prompt) {
2071:                if (prompt != null)
2072:                    System.out.print(prompt);
2073:                BufferedReader in = new BufferedReader(new InputStreamReader(
2074:                        System.in));
2075:                String input = "";
2076:
2077:                try {
2078:                    input = in.readLine();
2079:                } catch (IOException ioe) {
2080:                    ioe.printStackTrace();
2081:                }
2082:                return input;
2083:            }
2084:
2085:            /*This function works only for Solaris(sparc and x86) and linux.
2086:             For Windows and Hpux write a function which disables/enables echo on console*/
2087:            public static void echo(boolean on) {
2088:                try {
2089:                    String[] cmd = {
2090:                            "/bin/sh",
2091:                            "-c",
2092:                            "/bin/stty " + (on ? "echo" : "-echo")
2093:                                    + " < /dev/tty" };
2094:                    Process p = Runtime.getRuntime().exec(cmd);
2095:                    p.waitFor();
2096:                } catch (IOException e) {
2097:                    e.printStackTrace();
2098:                } catch (InterruptedException e) {
2099:                    e.printStackTrace();
2100:                }
2101:            }
2102:
2103:            public static String readPassword(String prompt) {
2104:                masker = new EraserThread(prompt);
2105:                Thread mask = new Thread(masker);
2106:                mask.setPriority(Thread.MAX_PRIORITY);
2107:                mask.start();
2108:
2109:                BufferedReader in = new BufferedReader(new InputStreamReader(
2110:                        System.in));
2111:                String password = "";
2112:
2113:                try {
2114:                    echo(false);
2115:                    password = in.readLine();
2116:                } catch (IOException ioe) {
2117:                    ioe.printStackTrace();
2118:                } finally {
2119:                    echo(true);
2120:                    System.out.println(" ");
2121:                }
2122:                // stop masking
2123:                masker.stopMasking();
2124:                masker = null;
2125:                // return the password entered by the user
2126:                return password;
2127:            }
2128:
2129:            public static void getAMSpecialUsersDN() {
2130:            }
2131:
2132:            /*
2133:             * Return the PS base dir on Linux.
2134:             * Returns null if Portal Server or its consituents is not installed.
2135:             */
2136:            public static String getPSBaseDirOnLinux() {
2137:                //rpm -q --queryformat 'PRODUCT_DIR=%{INSTALLPREFIX}' sun-portal-configurator.
2138:                //The result will be of the form BASEDIR=/opt/sun if PortalServer is installed.
2139:                //Otherwise it will a message something else.
2140:                String command = "rpm";
2141:                String[] args = new String[4];
2142:                args[0] = "-q";
2143:                args[1] = "--queryformat";
2144:                args[2] = "BASEDIR=%{INSTALLPREFIX}";
2145:                args[3] = "sun-portal-configurator";
2146:                execUtil.storeOutput(true);
2147:                execUtil.exec(command, args);
2148:                String result = execUtil.getOutput();
2149:                logger.log(Level.INFO, "PSFB_CSPFUP0113", result);
2150:                if (result != null && result.startsWith("BASEDIR="))
2151:                    result = result.trim().substring(8);
2152:                else {
2153:                    //Check for the case where PS7 is installed and being upgraded to PS7.1
2154:                    args[3] = "sun-portal-base";
2155:                    execUtil.storeOutput(true);
2156:                    execUtil.exec(command, args);
2157:                    result = execUtil.getOutput();
2158:                    logger.log(Level.INFO, "PSFB_CSPFUP0113", result);
2159:                    if (result != null && result.startsWith("BASEDIR="))
2160:                        result = result.trim().substring(8);
2161:                    else
2162:                        result = null;
2163:                }
2164:                logger.log(Level.INFO, "PSFB_CSPFUP0114", result);
2165:                return result;
2166:            }
2167:
2168:            /*
2169:             * Return the PS7 base dir on Linux.
2170:             * Returns null if Portal Server or its consituents is not installed.
2171:             */
2172:            public static String getPS7BaseDirOnLinux() {
2173:                //rpm -q --queryformat 'PRODUCT_DIR=%{INSTALLPREFIX}' sun-portal-admin
2174:                //The result will be of the form BASEDIR=/opt/sun if PortalServer is installed.
2175:                //Otherwise this command would return something else
2176:                String command = "rpm";
2177:                String[] args = new String[4];
2178:                args[0] = "-q";
2179:                args[1] = "--queryformat";
2180:                args[2] = "BASEDIR=%{INSTALLPREFIX}";
2181:                args[3] = "sun-portal-admin";
2182:                execUtil.storeOutput(true);
2183:                execUtil.exec(command, args);
2184:                String result = execUtil.getOutput();
2185:                log("RPM query results PS Base directory=" + result);
2186:                if (result != null && result.startsWith("BASEDIR="))
2187:                    result = result.trim().substring(8);
2188:                else
2189:                    result = null;
2190:
2191:                log("PS BASEDIR is " + result);
2192:                return result;
2193:            }
2194:
2195:            /*
2196:             * Return the AM base dir on Linux.
2197:             * Returns null if Portal Server or its consituents is not installed.
2198:             */
2199:            public static String getAMBaseDirOnLinux() {
2200:                //rpm -q --queryformat 'PRODUCT_DIR=%{INSTALLPREFIX}' sun-portal-configurator.
2201:                //The result will be of the form BASEDIR=/opt/sun if PortalServer is installed.
2202:                //Otherwise it will a message something else.
2203:                String command = "rpm";
2204:                String[] args = new String[4];
2205:                args[0] = "-q";
2206:                args[1] = "--queryformat";
2207:                args[2] = "BASEDIR=%{INSTALLPREFIX}";
2208:                args[3] = "sun-identity-sdk";
2209:                execUtil.storeOutput(true);
2210:                execUtil.exec(command, args);
2211:                String result = execUtil.getOutput();
2212:                logger.log(Level.INFO, "PSFB_CSPFUP0115", result);
2213:                if (result != null && result.startsWith("BASEDIR="))
2214:                    result = result.trim().substring(8);
2215:                else
2216:                    result = null;
2217:
2218:                logger.log(Level.INFO, "PSFB_CSPFUP0116", result);
2219:                return result;
2220:            }
2221:
2222:            static String getPSVersion(String psProdDir, boolean psInstalled) {
2223:                String version = null;
2224:                String propFile = (psInstalled == true) ? "PSversion.properties"
2225:                        : "SRAversion.properties";
2226:                String versionProperty = (psInstalled == true) ? "productversion"
2227:                        : "version";
2228:                Properties versionProp = new Properties();
2229:                try {
2230:                    File versionPropFile = null;
2231:                    versionPropFile = new File(psProdDir + File.separator
2232:                            + "lib" + File.separator + propFile);
2233:                    if (versionPropFile.exists()) {
2234:                        versionProp.load(new FileInputStream(new File(psProdDir
2235:                                + File.separator + "lib" + File.separator
2236:                                + propFile)));
2237:                        version = versionProp.getProperty(versionProperty);
2238:                        logger.log(Level.INFO, "PSFB_CSPFUP0117", version);
2239:                    }
2240:                } catch (Exception e) {
2241:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0118", e);
2242:                    return version;
2243:                }
2244:                return version;
2245:            }
2246:
2247:            static String getPSVersionOnLinux() {
2248:
2249:                String command = "rpm";
2250:                String[] args = new String[4];
2251:                args[0] = "-q";
2252:                args[1] = "--queryformat";
2253:                args[2] = "RELEASE=%{RELEASE}";
2254:                args[3] = "sun-portal-configurator";
2255:                execUtil.storeOutput(true);
2256:                execUtil.exec(command, args);
2257:                String release = execUtil.getOutput();
2258:                logger.log(Level.INFO, "PSFB_CSPFUP0119", release);
2259:                args[2] = "VERSION=%{VERSION}";
2260:                execUtil.storeOutput(true);
2261:                execUtil.exec(command, args);
2262:                String version = execUtil.getOutput();
2263:                logger.log(Level.INFO, "PSFB_CSPFUP0120", version);
2264:                if (version != null && version.startsWith("VERSION="))
2265:                    version = version.trim().substring(8);
2266:                else
2267:                    version = "";
2268:
2269:                logger.log(Level.INFO, "PSFB_CSPFUP0121", version);
2270:                int releaseInt = 0;
2271:                if (release != null && release.startsWith("RELEASE=")) {
2272:                    release = release.trim().substring(8, 10);
2273:                    releaseInt = new Integer(release).intValue();
2274:                }
2275:
2276:                logger.log(Level.INFO, "PSFB_CSPFUP0122", String
2277:                        .valueOf(releaseInt));
2278:
2279:                if (version.startsWith("6.3") && releaseInt <= 25)
2280:                    return "6.3.1";
2281:                else
2282:                    return "JES4";
2283:
2284:            }
2285:
2286:            public static String getGatewayJDKDir(String gwConfigPropFileDir)
2287:                    throws IOException {
2288:                Properties prop = null;
2289:                String jdkdir = null;
2290:                String[] platformConfs = UpgradeUtils
2291:                        .returnFileListHavingPattern(gwConfigPropFileDir,
2292:                                "^platform.conf.\\w*$");
2293:                for (int i = 0; i < platformConfs.length; i++) {
2294:                    prop = new Properties();
2295:                    prop.load(new FileInputStream(platformConfs[i]));
2296:                    jdkdir = prop.getProperty("gateway.jdk.dir");
2297:                    if (jdkdir != null && checkDirectoryExists(jdkdir))
2298:                        break;
2299:                }
2300:                return jdkdir;
2301:            }
2302:
2303:            public static boolean checkDirectoryExists(String dir) {
2304:                File directory;
2305:                directory = new File(dir);
2306:                if (directory.exists())
2307:                    return true;
2308:                else
2309:                    return false;
2310:            }
2311:
2312:            public static void addSRAElementNodes(File sXMLFile, String xpath,
2313:                    String elementNodeName, String[] platformConfs,
2314:                    String sraLogPassword, String startInstanceStatus)
2315:                    throws IOException, JDOMException {
2316:
2317:                String[] childElements = xpath.split("/");
2318:                Document doc = null;
2319:
2320:                SAXBuilder builder = new SAXBuilder();
2321:                doc = builder.build(sXMLFile);
2322:                Element rootElement = doc.getRootElement();
2323:                Element rootElementCopy = rootElement;
2324:
2325:                for (int i = 0; i < childElements.length; i++)
2326:                    rootElementCopy = rootElementCopy
2327:                            .getChild(childElements[i]);
2328:
2329:                Properties prop = null;
2330:                String profile = "portal.server.instance";
2331:                String protocol = "gateway.protocol";
2332:                String host = "gateway.host";
2333:                String port = "gateway.port";
2334:                String ipaddress = "gateway.bindipaddress";
2335:                if (elementNodeName.equals("NetletProxy")) {
2336:                    port = "netletproxy.port";
2337:                } else if (elementNodeName.equals("RewriterProxy")) {
2338:                    port = "rewriterproxy.port";
2339:                }
2340:
2341:                Element[] SRAComponentNode = new Element[platformConfs.length];
2342:                Element[] SRAInstance = new Element[platformConfs.length];
2343:                for (int i = 0; i < platformConfs.length; i++) {
2344:                    logger.log(Level.INFO, "PSFB_CSPFUP0123", new Object[] {
2345:                            String.valueOf(i), platformConfs[i] });
2346:                    //Load the properties every time.
2347:                    prop = new Properties();
2348:                    prop.load(new FileInputStream(platformConfs[i]));
2349:                    SRAComponentNode[i] = new Element(elementNodeName);
2350:                    String profileName = prop.getProperty(profile);
2351:                    if (profileName == null)
2352:                        continue;//Any file that does not have a profile name is not a profile.
2353:
2354:                    //--------------------
2355:
2356:                    if (prop.getProperty(port) == null) {
2357:                        return;
2358:                    }
2359:
2360:                    String str = platformConfs[i];
2361:                    StringTokenizer stk = new StringTokenizer(str, ".");
2362:                    String pname = null;
2363:                    while (stk.hasMoreElements()) {
2364:                        pname = stk.nextToken();
2365:                    }
2366:                    profileName = pname;
2367:                    //---------------------
2368:
2369:                    SRAComponentNode[i].setAttribute("Profile", profileName);
2370:                    SRAInstance[i] = new Element("SRAInstance");
2371:                    SRAInstance[i].setAttribute("Protocol", prop
2372:                            .getProperty(protocol));
2373:                    SRAInstance[i].setAttribute("Host", prop.getProperty(host));
2374:                    SRAInstance[i].setAttribute("Port", prop.getProperty(port));
2375:
2376:                    SRAInstance[i].setAttribute("IPAddress", prop
2377:                            .getProperty(ipaddress));
2378:                    SRAInstance[i].setAttribute("LogUserPassword",
2379:                            sraLogPassword);
2380:                    SRAInstance[i].setAttribute("StartInstance",
2381:                            startInstanceStatus);
2382:
2383:                    SRAComponentNode[i].addContent("\n  ");
2384:                    SRAComponentNode[i].addContent("    ");
2385:                    SRAComponentNode[i].addContent(SRAInstance[i]);
2386:                    SRAComponentNode[i].addContent("\n  ");
2387:
2388:                    rootElementCopy.addContent(SRAComponentNode[i]);
2389:                    rootElementCopy.addContent("\n  ");
2390:                }
2391:                XMLOutputter serializer = new XMLOutputter();
2392:                serializer.output(doc, new FileWriter(sXMLFile));
2393:            }
2394:
2395:            static void addSRACertificateInfoElement(File sXMLFile,
2396:                    String xpath, String CERT_INFO, String CERT_DB_PASSWORD)
2397:                    throws IOException, JDOMException {
2398:                String[] childElements = xpath.split("/");
2399:                Document doc = null;
2400:
2401:                SAXBuilder builder = new SAXBuilder();
2402:                doc = builder.build(sXMLFile);
2403:                Element rootElement = doc.getRootElement();
2404:                Element SRACertificateInfoParentElement = rootElement;
2405:
2406:                for (int i = 0; i < childElements.length; i++)
2407:                    SRACertificateInfoParentElement = SRACertificateInfoParentElement
2408:                            .getChild(childElements[i]);
2409:
2410:                Element SRACert = new Element("CertificateInformation");
2411:                SRACert.setAttribute("Organization", UpgradeUtils
2412:                        .parseCertInfo(CERT_INFO, "OU"));
2413:                SRACert.setAttribute("Division", UpgradeUtils.parseCertInfo(
2414:                        CERT_INFO, "O"));
2415:                SRACert.setAttribute("CityOrLocality", UpgradeUtils
2416:                        .parseCertInfo(CERT_INFO, "L"));
2417:                SRACert.setAttribute("StateProvince", UpgradeUtils
2418:                        .parseCertInfo(CERT_INFO, "ST"));
2419:                SRACert.setAttribute("CountryCode", UpgradeUtils.parseCertInfo(
2420:                        CERT_INFO, "C"));
2421:                SRACert.setAttribute("CertificateDatabasePassword",
2422:                        CERT_DB_PASSWORD);
2423:
2424:                SRACertificateInfoParentElement.addContent("\n  ");
2425:                SRACertificateInfoParentElement.addContent(SRACert);
2426:                SRACertificateInfoParentElement.addContent("\n  ");
2427:                XMLOutputter serializer = new XMLOutputter();
2428:                serializer.output(doc, new FileWriter(sXMLFile));
2429:            }
2430:
2431:            static void processDPUpdates(File dp, File dpChanges, String type)
2432:                    throws UpgradeUtilException {
2433:                //Open the file and read a line.
2434:                //String split.
2435:                //If the first token is Add or Modify Attribute then add to Modify Attribute Vector.
2436:                //If the first token is Add Element then add toAdd Element Vector.
2437:                //If the first token is Delete Element then add to Delete Element Vector.
2438:                //call Modifydelete operation.
2439:                String dpInstruction = null;
2440:                String[] dpInstructionParsed = null;
2441:                BufferedReader in = null;
2442:
2443:                try {
2444:                    javax.xml.parsers.DocumentBuilderFactory dbfactory = javax.xml.parsers.DocumentBuilderFactory
2445:                            .newInstance();
2446:                    javax.xml.parsers.DocumentBuilder builder = dbfactory
2447:                            .newDocumentBuilder();
2448:                    //Fix for 6442244. XML parser calls it fatal error, but for us we can recover
2449:                    //even if DP updates fail. So set a default error handler and catch
2450:                    //the exception for logging only.
2451:                    builder
2452:                            .setErrorHandler(new org.xml.sax.helpers.DefaultHandler());
2453:                    org.w3c.dom.Document document = builder.parse(dp);
2454:                    javax.xml.xpath.XPath xpath = javax.xml.xpath.XPathFactory
2455:                            .newInstance().newXPath();
2456:                    //String xp1      = "/DisplayProfile/Providers/Provider/Properties/String[@name=\"productName\"]";
2457:                    //xp1=xp;
2458:
2459:                    int i = 0;
2460:                    //in = new BufferedReader(new InputStreamReader(new FileInputStream(dpChanges)));            
2461:                    in = FileUtil.getUTF8BufferedReader(dpChanges);
2462:
2463:                    while ((dpInstruction = in.readLine()) != null) {
2464:
2465:                        dpInstructionParsed = dpInstruction.split("::");
2466:                        if (dpInstructionParsed != null
2467:                                && dpInstructionParsed.length > 1) {
2468:                            String xp = dpInstructionParsed[0];
2469:
2470:                            if (dpInstructionParsed[0].equalsIgnoreCase(type
2471:                                    + "_DP_MODIFYNODE")) {
2472:                                String attrValue = "";
2473:                                //Check whether the attribute value is nuul, inwhich case lenght will be 3.
2474:                                if (dpInstructionParsed.length == 4)
2475:                                    attrValue = dpInstructionParsed[3];
2476:
2477:                                modifyNode(document, dpInstructionParsed[1],
2478:                                        dpInstructionParsed[2], attrValue, dp
2479:                                                .getAbsolutePath());
2480:                            } else if (dpInstructionParsed[0]
2481:                                    .equalsIgnoreCase(type + "_DP_ADDNODE")) {
2482:                                addNode(document, dpInstructionParsed[1],
2483:                                        dpInstructionParsed[2], dp
2484:                                                .getAbsolutePath());
2485:                            } else if (dpInstructionParsed[0]
2486:                                    .equalsIgnoreCase(type + "_DP_DELETENODE")) {
2487:                                deleteNode(document, dpInstructionParsed[1], dp
2488:                                        .getAbsolutePath());
2489:                            }
2490:                        }
2491:                    }
2492:                    if (in != null)
2493:                        in.close();
2494:
2495:                } catch (org.xml.sax.SAXParseException e) {
2496:                    // A parsing error occurred; the DP xml input is not valid.
2497:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0142", new Object[] {
2498:                            dp.getAbsolutePath(), "" + e.getLineNumber(),
2499:                            "" + e.getColumnNumber() });
2500:                    throw new com.sun.portal.fabric.upgrade.UpgradeUtilException(
2501:                            "DP XML appears corrupted.");
2502:                } catch (Exception e) {
2503:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0124", e);
2504:                    throw new com.sun.portal.fabric.upgrade.UpgradeUtilException(
2505:                            "DP XML appears corrupted.");
2506:                }
2507:            }
2508:
2509:            private static void modifyNode(org.w3c.dom.Document document,
2510:                    String xp, String attr, String val, String outputFile) {
2511:                try {
2512:                    javax.xml.xpath.XPath xpath = javax.xml.xpath.XPathFactory
2513:                            .newInstance().newXPath();
2514:                    org.w3c.dom.Element dummyNode = (org.w3c.dom.Element) xpath
2515:                            .evaluate(xp, document,
2516:                                    javax.xml.xpath.XPathConstants.NODE);
2517:                    NodeList matchedNodes = (NodeList) xpath.evaluate(xp,
2518:                            document, javax.xml.xpath.XPathConstants.NODESET);
2519:
2520:                    int no_of_matched_nodes = 0;
2521:                    if (matchedNodes != null)
2522:                        no_of_matched_nodes = matchedNodes.getLength();
2523:
2524:                    //System.out.println("No of matched nodes: "+no_of_matched_nodes);
2525:                    org.w3c.dom.Element[] selectedNode = new org.w3c.dom.Element[no_of_matched_nodes];
2526:                    if (no_of_matched_nodes > 0) {
2527:                        dummyNode.setAttribute(attr, val);// Bug with JAXP.
2528:                        for (int i = 0; i < no_of_matched_nodes; i++) {
2529:                            selectedNode[i] = (org.w3c.dom.Element) matchedNodes
2530:                                    .item(i);
2531:                            selectedNode[i].setAttribute(attr, val);
2532:
2533:                            //System.out.println("Modified Value of Node "+selectedNode[i].getAttribute(attr));
2534:                        }
2535:                    }
2536:
2537:                    javax.xml.transform.TransformerFactory xformFactory = javax.xml.transform.TransformerFactory
2538:                            .newInstance();
2539:                    javax.xml.transform.Transformer idTransform = xformFactory
2540:                            .newTransformer();
2541:                    javax.xml.transform.Source input = new javax.xml.transform.dom.DOMSource(
2542:                            document);
2543:                    FileOutputStream fs = new FileOutputStream(outputFile);
2544:                    javax.xml.transform.Result output = new javax.xml.transform.stream.StreamResult(
2545:                            fs);
2546:                    idTransform.transform(input, output);
2547:                    fs.flush();
2548:                    fs.close();
2549:                } catch (XPathExpressionException e) {
2550:                    logger.log(Level.WARNING, "PSFB_CSPFUP0145", new Object[] {
2551:                            e.getMessage(), "XPATH=" + xp });
2552:                    setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
2553:                } catch (Exception e) {
2554:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0125", e);
2555:                }
2556:            }
2557:
2558:            private static void addNode(org.w3c.dom.Document document,
2559:                    String xp, String element, String outputFile) {
2560:                org.w3c.dom.DocumentFragment frag = getXmlNode(document,
2561:                        element);
2562:
2563:                // Append the new fragment to the end of the root element
2564:                //org.w3c.dom.Element docElement = doc.getDocumentElement();
2565:                //docElement.appendChild(frag);
2566:
2567:                try {
2568:                    javax.xml.xpath.XPath xpath = javax.xml.xpath.XPathFactory
2569:                            .newInstance().newXPath();
2570:                    org.w3c.dom.Element dummyNode = (org.w3c.dom.Element) xpath
2571:                            .evaluate(xp, document,
2572:                                    javax.xml.xpath.XPathConstants.NODE);
2573:                    NodeList matchedNodes = (NodeList) xpath.evaluate(xp,
2574:                            document, javax.xml.xpath.XPathConstants.NODESET);
2575:
2576:                    int no_of_matched_nodes = 0;
2577:                    if (matchedNodes != null)
2578:                        no_of_matched_nodes = matchedNodes.getLength();
2579:                    //System.out.println("No of matched nodes: "+no_of_matched_nodes);
2580:                    org.w3c.dom.Element[] selectedNode = new org.w3c.dom.Element[no_of_matched_nodes];
2581:                    if (no_of_matched_nodes > 0) {
2582:                        dummyNode.appendChild(frag);
2583:                        ;// Bug with JAXP.
2584:                        for (int i = 0; i < no_of_matched_nodes; i++) {
2585:                            selectedNode[i] = (org.w3c.dom.Element) matchedNodes
2586:                                    .item(i);
2587:                            selectedNode[i].appendChild(frag);
2588:                            //System.out.println(frag.getNodeName());
2589:                            //System.out.println(selectedNode[i]);
2590:                        }
2591:                    }
2592:
2593:                    javax.xml.transform.TransformerFactory xformFactory = javax.xml.transform.TransformerFactory
2594:                            .newInstance();
2595:                    javax.xml.transform.Transformer idTransform = xformFactory
2596:                            .newTransformer();
2597:                    javax.xml.transform.Source input = new javax.xml.transform.dom.DOMSource(
2598:                            document);
2599:                    FileOutputStream fs = new FileOutputStream(outputFile);
2600:                    javax.xml.transform.Result output = new javax.xml.transform.stream.StreamResult(
2601:                            fs);
2602:                    idTransform.setOutputProperty(
2603:                            javax.xml.transform.OutputKeys.INDENT, "yes");
2604:                    idTransform.transform(input, output);
2605:                    fs.flush();
2606:                    fs.close();
2607:                } catch (XPathExpressionException e) {
2608:                    logger.log(Level.WARNING, "PSFB_CSPFUP0145", new Object[] {
2609:                            e.getMessage(), "XPATH=" + xp });
2610:                    setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
2611:                } catch (Exception e) {
2612:                    System.out.println(e);
2613:                }
2614:            }
2615:
2616:            private static void deleteNode(org.w3c.dom.Document document,
2617:                    String xp, String outputFile) {
2618:                try {
2619:                    javax.xml.xpath.XPath xpath = javax.xml.xpath.XPathFactory
2620:                            .newInstance().newXPath();
2621:                    org.w3c.dom.Element dummyNode = (org.w3c.dom.Element) xpath
2622:                            .evaluate(xp, document,
2623:                                    javax.xml.xpath.XPathConstants.NODE);
2624:                    NodeList matchedNodes = (NodeList) xpath.evaluate(xp,
2625:                            document, javax.xml.xpath.XPathConstants.NODESET);
2626:
2627:                    int no_of_matched_nodes = 0;
2628:                    if (matchedNodes != null)
2629:                        no_of_matched_nodes = matchedNodes.getLength();
2630:
2631:                    //System.out.println("No of matched nodes: "+no_of_matched_nodes);
2632:                    org.w3c.dom.Element[] selectedNode = new org.w3c.dom.Element[no_of_matched_nodes];
2633:                    if (no_of_matched_nodes > 0) {
2634:
2635:                        for (int i = 0; i < no_of_matched_nodes; i++) {
2636:                            selectedNode[i] = (org.w3c.dom.Element) matchedNodes
2637:                                    .item(i);
2638:                            selectedNode[i].getParentNode().removeChild(
2639:                                    selectedNode[i]);
2640:                            document.normalize();
2641:                        }
2642:                    }
2643:
2644:                    javax.xml.transform.TransformerFactory xformFactory = javax.xml.transform.TransformerFactory
2645:                            .newInstance();
2646:                    javax.xml.transform.Transformer idTransform = xformFactory
2647:                            .newTransformer();
2648:                    javax.xml.transform.Source input = new javax.xml.transform.dom.DOMSource(
2649:                            document);
2650:                    FileOutputStream fs = new FileOutputStream(outputFile);
2651:                    javax.xml.transform.Result output = new javax.xml.transform.stream.StreamResult(
2652:                            fs);
2653:                    idTransform.transform(input, output);
2654:                    fs.flush();
2655:                    fs.close();
2656:                } catch (XPathExpressionException e) {
2657:                    logger.log(Level.WARNING, "PSFB_CSPFUP0145", new Object[] {
2658:                            e.getMessage(), "XPATH=" + xp });
2659:                    setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
2660:                } catch (Exception e) {
2661:                    if (logger.isLoggable(Level.SEVERE)) {
2662:                        LogRecord rec = new LogRecord(Level.SEVERE,
2663:                                "PSFB_CSPFUP0126");
2664:                        rec.setLoggerName(logger.getName());
2665:                        rec.setParameters(new Object[] { xp });
2666:                        rec.setThrown(e);
2667:                        logger.log(rec);
2668:                    }
2669:                }
2670:
2671:            }
2672:
2673:            // Parses a string containing XML and returns a DocumentFragment
2674:            // containing the nodes of the parsed XML.
2675:            public static DocumentFragment getXmlNode(org.w3c.dom.Document doc,
2676:                    String fragment) {
2677:                try {
2678:                    // Create a DOM builder and parse the fragment
2679:                    DocumentBuilderFactory factory = DocumentBuilderFactory
2680:                            .newInstance();
2681:                    //Fix for 6442244. XML parser calls it fatal error, but for us we can recover
2682:                    //even if DP updates fail. So set a default error handler and catch
2683:                    //the exception for logging only.
2684:                    javax.xml.parsers.DocumentBuilder db = factory
2685:                            .newDocumentBuilder();
2686:                    db
2687:                            .setErrorHandler(new org.xml.sax.helpers.DefaultHandler());
2688:                    org.w3c.dom.Document d = db.parse(new InputSource(
2689:                            new StringReader(fragment)));
2690:
2691:                    // Import the nodes of the new document into doc so that they
2692:                    // will be compatible with doc
2693:                    org.w3c.dom.Node node = doc.importNode(d
2694:                            .getDocumentElement(), false);
2695:                    // Create the document fragment node to hold the new nodes
2696:                    org.w3c.dom.DocumentFragment docfrag = doc
2697:                            .createDocumentFragment();
2698:                    docfrag.appendChild(node);
2699:                    // Return the fragment
2700:                    return docfrag;
2701:                } catch (org.xml.sax.SAXParseException e) {
2702:                    // A parsing error occurred; the xml input fragment  is not valid
2703:                    logger.log(Level.WARNING, "PSFB_CSPFUP0142", new Object[] {
2704:                            "" + e.getLineNumber(), "" + e.getColumnNumber(),
2705:                            fragment });
2706:                } catch (SAXException e) {
2707:                    // A parsing error occurred; the xml input is not valid
2708:                    logger.log(Level.WARNING, "PSFB_CSPFUP0143", new Object[] {
2709:                            e.getMessage(), fragment });
2710:                } catch (ParserConfigurationException e) {
2711:                    // A parsing error occurred; the xml input is not valid
2712:                    logger.log(Level.WARNING, "PSFB_CSPFUP0143", new Object[] {
2713:                            e.getMessage(), fragment });
2714:                } catch (IOException e) {
2715:                    // A parsing error occurred; the xml input is not valid
2716:                    logger.log(Level.WARNING, "PSFB_CSPFUP0143", new Object[] {
2717:                            e.getMessage(), fragment });
2718:                }
2719:                return null;
2720:            }
2721:
2722:            public static String getJESInstallerWizardID(File psinstallShFile) {
2723:                String installerID = "";
2724:                String command = psinstallShFile.getAbsolutePath();
2725:                String[] args = new String[2];
2726:                args[0] = "-nodisplay";
2727:                args[1] = "-id";
2728:
2729:                execUtil.storeOutput(true);
2730:                try {
2731:                    execUtil.exec(command, args);
2732:                    installerID = execUtil.getOutput().trim();
2733:                    logger.log(Level.INFO, "PSFB_CSPFUP0127", installerID);
2734:                } catch (Exception e) {
2735:                    if (logger.isLoggable(Level.SEVERE)) {
2736:                        LogRecord rec = new LogRecord(Level.SEVERE,
2737:                                "PSFB_CSPFUP0128");
2738:                        rec.setLoggerName(logger.getName());
2739:                        rec.setParameters(new Object[] { installerID });
2740:                        rec.setThrown(e);
2741:                        logger.log(rec);
2742:
2743:                    }
2744:
2745:                }
2746:                return installerID;
2747:            }
2748:
2749:            public static void setSSLLDAPConnection(boolean sslEnabled) {
2750:                if (sslEnabled == true)
2751:                    connection = new LDAPConnection(new JSSESocketFactory(null));
2752:            }
2753:
2754:            public static void copyAllAMFilesToVarTmp(String resourceDir,
2755:                    String varTmpPSVersionDir) throws IOException {
2756:                int fileCount = 0;
2757:                String[] filesEndingWith = { ".xml", ".res", ".ldif" };
2758:                String[] amfiles = UpgradeUtils.returnFileListEndingWith(
2759:                        resourceDir, null, filesEndingWith);
2760:                if (amfiles == null)
2761:                    return;
2762:
2763:                fileCount = amfiles.length;
2764:
2765:                //These files should be deleted in cleanup.
2766:                File file[] = new File[fileCount];
2767:                File dest = new File(varTmpPSVersionDir);
2768:                // Move file to new directory
2769:                for (int i = 0; i < fileCount; i++) {
2770:                    file[i] = new File(amfiles[i]);
2771:                    copy(file[i], new File(dest, file[i].getName()));
2772:
2773:                }
2774:            }
2775:
2776:            // Copies src file to dst file.
2777:            // If the dst file does not exist, it is created
2778:            //TODO: Move this method to FileUtil
2779:            static void copy(File src, File dst) throws IOException {
2780:                InputStream in = new FileInputStream(src);
2781:                OutputStream out = new FileOutputStream(dst);
2782:
2783:                // Transfer bytes from in to out
2784:                byte[] buf = new byte[1024];
2785:                int len;
2786:                while ((len = in.read(buf)) > 0) {
2787:                    out.write(buf, 0, len);
2788:                }
2789:                in.close();
2790:                out.close();
2791:            }
2792:
2793:            // Make directory.
2794:            static void mkdir(String root, String child) throws Exception {
2795:                File d = new File(root, child);
2796:                if (d.isDirectory()) {
2797:                    return;
2798:                }
2799:                if (!d.mkdir()) {
2800:                    throw new Exception("Cannot create directory: " + root
2801:                            + File.separator + child);
2802:                }
2803:            }
2804:
2805:            // Remove directory.
2806:            static public boolean rmdir(File path) {
2807:                if (path.isDirectory()) {
2808:                    File[] files = path.listFiles();
2809:                    for (int i = 0; i < files.length; i++) {
2810:                        if (files[i].isDirectory()) {
2811:                            rmdir(files[i]);
2812:                        } else {
2813:                            files[i].delete();
2814:                        }
2815:                    }
2816:                }
2817:                return (path.delete());
2818:            }
2819:
2820:            public static String getPortalServerVersion() {
2821:                String version = null;
2822:                String psBaseDir = null;
2823:                String psProductDir = null;
2824:
2825:                String OSStr = System.getProperty("os.name");
2826:                boolean linuxOS = (OSStr.indexOf("Linux") != -1) ? true : false;
2827:                boolean sunOS = (OSStr.indexOf("SunOS") != -1) ? true : false;
2828:                //Try to see if it is PS6.3 or PS6.3.1 version.
2829:                try {
2830:                    if (sunOS == true) {
2831:                        Properties pkgInfo = new Properties();
2832:                        File pkgInfoFile = null;
2833:                        pkgInfoFile = new File(
2834:                                UpgradeConstants.PS_PKG_INFO_FILE);
2835:                        if (pkgInfoFile.exists()) {
2836:                            pkgInfo.load(new FileInputStream(
2837:                                    UpgradeConstants.PS_PKG_INFO_FILE));
2838:                            psBaseDir = pkgInfo.getProperty("BASEDIR");
2839:                            psProductDir = pkgInfo.getProperty("PRODUCT_DIR");
2840:                            version = getPSVersion(psBaseDir + File.separator
2841:                                    + psProductDir,
2842:                                    isPackageInstalled("SUNWps"));
2843:                        }
2844:                    } else if (linuxOS == true) {
2845:                        psBaseDir = UpgradeUtils.getPSBaseDirOnLinux();
2846:                        psProductDir = "portal";
2847:                        version = getPSVersion(psBaseDir + File.separator
2848:                                + psProductDir,
2849:                                isRPMInstalled("sun-portal-core"));
2850:                        if (version == null) {
2851:                            //corresponding to PS 7 to 7.1 upgrade
2852:                            version = getPSVersion(psBaseDir + File.separator
2853:                                    + psProductDir,
2854:                                    isRPMInstalled("sun-portal-base"));
2855:                        }
2856:                    }
2857:                } catch (IOException e) {
2858:                    //To change body of catch statement use File | Settings | File Templates.
2859:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0129", e);
2860:                }
2861:                if (version == null) {
2862:                    // To determine if it is PS7.0 version
2863:                    try {
2864:                        if (sunOS == true) {
2865:                            Properties pkgInfo = new Properties();
2866:                            pkgInfo.load(new FileInputStream(
2867:                                    UpgradeConstants.PS7_PKG_INFO_FILE));
2868:                            //psBaseDir = pkgInfo.getProperty("BASEDIR");
2869:                            //psProductDir=pkgInfo.getProperty("PRODUCT_DIR");
2870:                            //version=getPSVersion(psBaseDir+File.separator+psProductDir,isPackageInstalled("SUNWps"));
2871:                            version = pkgInfo.getProperty("SUNW_PRODVERS");
2872:                        } else if (linuxOS == true) {
2873:                            psBaseDir = UpgradeUtils.getPS7BaseDirOnLinux();
2874:                            psProductDir = "portal";
2875:                            version = getPSVersion(psBaseDir + File.separator
2876:                                    + psProductDir,
2877:                                    isRPMInstalled("sun-portal-base"));
2878:                        }
2879:                    } catch (IOException e) {
2880:                        log("Could not determine PS Version!" + e);//To change body of catch statement use File | Settings | File Templates.
2881:                    }
2882:                }
2883:                return version;
2884:
2885:            }
2886:
2887:            public static String getResourceDir(String version) {
2888:                String resDir = null;
2889:                if (version.equalsIgnoreCase("6.3.1")) {
2890:                    resDir = UpgradeConstants.RESOURCE_DIR_PS631;
2891:                } else if (version.equalsIgnoreCase("6.3")) {
2892:                    resDir = UpgradeConstants.RESOURCE_DIR_PS63;
2893:                } else if (version.equalsIgnoreCase("7.0")) {
2894:                    resDir = UpgradeConstants.RESOURCE_DIR_PS70;
2895:                } else if (version.equalsIgnoreCase("7.1")) {
2896:                    resDir = UpgradeConstants.RESOURCE_DIR_PS70;
2897:                }
2898:                return resDir;
2899:
2900:            }
2901:
2902:            public static String[] getResourceDirs(String version) {
2903:                String[] resDirs = null;
2904:
2905:                if (version.equalsIgnoreCase("6.3.1")) {
2906:                    resDirs = UpgradeConstants.RESOURCE_DIRS_PS631;
2907:                } else if (version.equalsIgnoreCase("6.3")) {
2908:                    resDirs = UpgradeConstants.RESOURCE_DIRS_PS63;
2909:                } else if (version.equalsIgnoreCase("7.0")) {
2910:                    resDirs = UpgradeConstants.RESOURCE_DIRS_PS70;
2911:                } else if (version.equalsIgnoreCase("7.1")) {
2912:                    resDirs = UpgradeConstants.RESOURCE_DIRS_PS70;
2913:                }
2914:                return resDirs;
2915:
2916:            }
2917:
2918:            public static void copyAllAMFilesToVarTmpPortal(String[] resDirs)
2919:                    throws IOException {
2920:
2921:                //Fetch all the resource dirs.
2922:                for (int i = 0; i < resDirs.length; i++) {
2923:                    //make the directories if not existent.
2924:                    String portalUpgradeTmpDir = UpgradeConstants.SOLARIS_TMP_DIR
2925:                            + File.separator
2926:                            + "portal"
2927:                            + File.separator
2928:                            + resDirs[i].substring(resDirs[i]
2929:                                    .lastIndexOf(File.separator) + 1,
2930:                                    resDirs[i].length());
2931:                    File f = new File(portalUpgradeTmpDir);
2932:                    f.mkdirs();
2933:
2934:                    /*System.out.println("Dir Name is"+  f.getAbsolutePath());
2935:                    System.out.println("RES Dir Name is"+  resDirs[i]);
2936:                    System.out.println("Current Dir"+new File(".").getAbsolutePath());*/
2937:
2938:                    copyAllAMFilesToVarTmp(resDirs[i], portalUpgradeTmpDir);
2939:                }
2940:
2941:            }
2942:
2943:            public static boolean isWebServer70Installed() {
2944:                //TODO:For Linux.
2945:
2946:                boolean ws7installed = false;
2947:                String OSStr = System.getProperty("os.name");
2948:                boolean linuxOS = (OSStr.indexOf("Linux") != -1) ? true : false;
2949:                boolean sunOS = (OSStr.indexOf("SunOS") != -1) ? true : false;
2950:
2951:                if (sunOS) {
2952:                    ws7installed = isPackageInstalled("SUNWwbsvr7");
2953:                } else if (linuxOS) {
2954:                    ws7installed = isRPMInstalled("sun-webserver7");
2955:                }
2956:                return ws7installed;
2957:            }
2958:
2959:            private static class EraserThread implements  Runnable {
2960:                private boolean stop;
2961:
2962:                public EraserThread(String prompt) {
2963:                    System.out.print(prompt);
2964:                }
2965:
2966:                /**
2967:                 * Begin masking...display asterisks (*)
2968:                 */
2969:                public void run() {
2970:                    stop = true;
2971:                    char c = ' ';
2972:                    boolean star = false;
2973:                    while (stop) {
2974:                        System.out.print("\010" + c);
2975:                        try {
2976:                            Thread.currentThread().sleep(1);
2977:                        } catch (InterruptedException ie) {
2978:                            logger.log(Level.SEVERE, "PSFB_CSPFUP0130", ie);
2979:                        }
2980:                    }
2981:                }
2982:
2983:                /**
2984:                 * Instruct the thread to stop masking
2985:                 */
2986:                public void stopMasking() {
2987:                    this .stop = false;
2988:                }
2989:            }
2990:
2991:            /* PJ - Code to get AM version */
2992:            public static String getAccessManagerVersion() {
2993:                String version = null;
2994:
2995:                String OSStr = System.getProperty("os.name");
2996:                boolean linuxOS = (OSStr.indexOf("Linux") != -1) ? true : false;
2997:                boolean sunOS = (OSStr.indexOf("SunOS") != -1) ? true : false;
2998:                try {
2999:                    if (sunOS == true) {
3000:                        Properties pkgInfo = new Properties();
3001:                        pkgInfo.load(new FileInputStream(
3002:                                UpgradeConstants.AMSDK_PKG_INFO_FILE));
3003:                        version = pkgInfo.getProperty("VERSION");
3004:                        version = version.substring(0, version.indexOf(","));
3005:                    } else if (linuxOS == true) {
3006:                        version = getProductVersionOnLinux("sun-identity-sdk");
3007:                    }
3008:
3009:                } catch (IOException e) {
3010:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0131", e);
3011:                }
3012:                if (version == null) {
3013:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0131");
3014:                }
3015:                return version;
3016:
3017:            }
3018:
3019:            /* PJ - Code to get WS version */
3020:            public static String getWebServerVersion() {
3021:                String version = null;
3022:
3023:                String OSStr = System.getProperty("os.name");
3024:                boolean linuxOS = (OSStr.indexOf("Linux") != -1) ? true : false;
3025:                boolean sunOS = (OSStr.indexOf("SunOS") != -1) ? true : false;
3026:                try {
3027:                    if (sunOS == true) {
3028:                        Properties pkgInfo = new Properties();
3029:                        pkgInfo.load(new FileInputStream(
3030:                                UpgradeConstants.WS_PKG_INFO_FILE));
3031:                        version = pkgInfo.getProperty("VERSION");
3032:                        version = version.substring(0, version.indexOf(","));
3033:                    } else if (linuxOS == true) {
3034:                        version = getProductVersionOnLinux("sun-webserver");
3035:                    }
3036:                } catch (IOException e) {
3037:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0132", e);
3038:                }
3039:                if (version == null) {
3040:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0132");
3041:                }
3042:                return version;
3043:
3044:            }
3045:
3046:            /* PJ - Code to get AS version */
3047:            public static String getAppServerVersion() {
3048:                String version = null;
3049:
3050:                String OSStr = System.getProperty("os.name");
3051:                boolean linuxOS = (OSStr.indexOf("Linux") != -1) ? true : false;
3052:                boolean sunOS = (OSStr.indexOf("SunOS") != -1) ? true : false;
3053:                try {
3054:                    if (sunOS == true) {
3055:                        Properties pkgInfo = new Properties();
3056:                        pkgInfo.load(new FileInputStream(
3057:                                UpgradeConstants.AS_PKG_INFO_FILE));
3058:                        version = pkgInfo.getProperty("VERSION");
3059:                        version = version.substring(0, version.indexOf(","));
3060:                    } else if (linuxOS == true) {
3061:                        version = getProductVersionOnLinux("sun-ascmn");
3062:                    }
3063:                } catch (IOException e) {
3064:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0133", e);
3065:                }
3066:                if (version == null) {
3067:                    logger.log(Level.SEVERE, "PSFB_CSPFUP0133");
3068:                }
3069:                return version;
3070:
3071:            }
3072:
3073:            /* PJ -Private method to get version of a RPM on Linux. */
3074:            private static String getProductVersionOnLinux(String rpm) {
3075:                /*Ex: rpm -q --queryformat 'VERSION=%{VERSION}' sun-ascmn.
3076:                The result will be of the form VERSION=7.0 if appserver is installed.
3077:                 */
3078:                String version = null;
3079:                String command = "rpm";
3080:                String[] args = new String[4];
3081:                args[0] = "-q";
3082:                args[1] = "--queryformat";
3083:                args[2] = "VERSION=%{VERSION}";
3084:                args[3] = rpm;
3085:                execUtil.storeOutput(true);
3086:                execUtil.exec(command, args);
3087:                version = execUtil.getOutput();
3088:                logger.log(Level.INFO, "PSFB_CSPFUP0134", new Object[] { rpm,
3089:                        version });
3090:                if (version != null && version.startsWith("VERSION="))
3091:                    version = version.trim().substring(8);
3092:                else
3093:                    version = null;
3094:                logger.log(Level.INFO, "PSFB_CSPFUP0135", version);
3095:                return version;
3096:            }
3097:
3098:            /* PJ - This method checks if the current stack installed is JES4 */
3099:            public static boolean isJES4Stack(String psVersion,
3100:                    String deployType) {
3101:                boolean jes4stack = false;
3102:
3103:                // Check the version of PS - as 6.3.1 and 7.0 can be present in JES4.
3104:                // If AM 7.0 and WS 6.0 OR AM 7.0 and AS 8.1 - the current stack is JES4
3105:                if (psVersion.startsWith("6.3.1")
3106:                        || psVersion.startsWith("7.0")) {
3107:                    System.out.println("Inside if ");
3108:                    // Check if portal is installed on WS or AS.
3109:                    if (deployType.equalsIgnoreCase("IWS")) {
3110:                        if ((UpgradeUtils.getAccessManagerVersion()
3111:                                .equalsIgnoreCase("7.0"))
3112:                                && (UpgradeUtils.getWebServerVersion()
3113:                                        .startsWith("6."))) {
3114:                            jes4stack = true;
3115:                        }
3116:
3117:                    } else if (deployType.equalsIgnoreCase("SunOne8")) {
3118:                        if ((UpgradeUtils.getAccessManagerVersion()
3119:                                .equalsIgnoreCase("7.0"))
3120:                                && (UpgradeUtils.getAppServerVersion()
3121:                                        .startsWith("8.1"))) {
3122:                            jes4stack = true;
3123:                        }
3124:                    }
3125:                }
3126:                return jes4stack;
3127:            }
3128:
3129:            /* PJ - This method checks if the current stack installed is JES5 */
3130:            public static boolean isJES5Stack(String psVersion,
3131:                    String deployType) {
3132:                // Get the version of PS.
3133:                // If AM 7.1 and WS 7.0 OR AM 7.1 and AS 8.2 - the current stack is JES5
3134:                boolean jes5stack = false;
3135:
3136:                if (psVersion.startsWith("7.")) {
3137:                    // Check if portal is installed on WS or AS.
3138:                    if (deployType.equalsIgnoreCase("IWS")) {
3139:                        if ((UpgradeUtils.getAccessManagerVersion()
3140:                                .equalsIgnoreCase("7.1"))
3141:                                && (UpgradeUtils.getWebServerVersion()
3142:                                        .startsWith("7."))) {
3143:                            jes5stack = true;
3144:                        }
3145:
3146:                    } else if (deployType.equalsIgnoreCase("SunOne8")) {
3147:                        if ((UpgradeUtils.getAccessManagerVersion()
3148:                                .equalsIgnoreCase("7.1"))
3149:                                && (UpgradeUtils.getAppServerVersion()
3150:                                        .startsWith("8.2"))) {
3151:                            jes5stack = true;
3152:                        }
3153:                    }
3154:                }
3155:                return jes5stack;
3156:            }
3157:
3158:            private static String getSubstitutedCPEntry(String cpEntry,
3159:                    String configFilePath) throws FileNotFoundException,
3160:                    IOException {
3161:
3162:                Properties psConfigProps = new Properties();
3163:                psConfigProps.load(new FileInputStream(configFilePath));
3164:
3165:                String directoryToken = cpEntry.substring(0, cpEntry
3166:                        .indexOf('/'));
3167:                String remainingPath = cpEntry.substring(cpEntry.indexOf('/'),
3168:                        cpEntry.length());
3169:
3170:                String directoryValue = psConfigProps
3171:                        .getProperty(directoryToken);
3172:
3173:                return (directoryValue + remainingPath);
3174:            }
3175:
3176:            public static boolean isSunOS() {
3177:                boolean sunOS = false;
3178:                if (System.getProperty("os.name").indexOf("SunOS") != -1)
3179:                    sunOS = true;
3180:                return sunOS;
3181:            }
3182:
3183:            public static boolean isLinuxOS() {
3184:                boolean linuxOS = false;
3185:                if (System.getProperty("os.name").indexOf("Linux") != -1)
3186:                    linuxOS = true;
3187:                return linuxOS;
3188:            }
3189:
3190:            static boolean checkJESInstallerSuccess() {
3191:                //Take a PS 7.x representative package and see if its installed.
3192:                boolean installedAdminPkg = false;
3193:                if (isSunOS() == true) {
3194:                    installedAdminPkg = isPackageInstalled("SUNWportal-admin");
3195:                } else if (isLinuxOS() == true) {
3196:                    installedAdminPkg = isRPMInstalled("sun-portal-admin");
3197:                }
3198:                return installedAdminPkg;
3199:            }
3200:
3201:            static int getExitCode() {
3202:                return upgradeUtilExitCode;
3203:            }
3204:
3205:            static void setExitCode(int ec) {
3206:                upgradeUtilExitCode = ec;
3207:            }
3208:
3209:            public static void executePS7To71DPUpdates(
3210:                    Properties psInstallationProps, String resDir)
3211:                    throws UpgradeException {
3212:                File DPChanges = null;
3213:                String fileSep = File.separator;
3214:                try {
3215:                    System.out
3216:                            .println("Updating the fetched desktop profile ...");
3217:                    DPChanges = FileUtil.extractFileFromJar(resDir + "/"
3218:                            + UpgradeConstants.RESOURCE_JAR, "DPChanges.txt",
3219:                            false);
3220:
3221:                    File globalDP = new File(fileSep + "var" + fileSep + "tmp"
3222:                            + fileSep + "PSUpgradeDPGlobal.xml");
3223:                    if (globalDP.exists() && globalDP.length() > 0) {
3224:                        try {
3225:                            FileUtil.deleteLineInFile(globalDP,
3226:                                    "<!DOCTYPE DisplayProfile SYSTEM",
3227:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3228:                            UpgradeUtils.processDPUpdates(globalDP, DPChanges,
3229:                                    "GLOBAL");
3230:                            //Workarounds for bug in jaxp cache?
3231:                            File tmpGlobal = new File(
3232:                                    globalDP.getAbsolutePath()
3233:                                            + "with"
3234:                                            + resDir.substring(resDir
3235:                                                    .lastIndexOf("/") + 1)
3236:                                            + "Changes");
3237:                            copy(globalDP, tmpGlobal);
3238:                            globalDP = tmpGlobal;
3239:
3240:                            FileUtil
3241:                                    .appendLineInFile(
3242:                                            globalDP,
3243:                                            "<?xml",
3244:                                            "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE DisplayProfile SYSTEM \"jar://resources/psdp.dtd\">\n<DisplayProfile version=\"1.0\" priority=\"0\">",
3245:                                            FileUtil.APPEND_FIRST_OCCURANCE);
3246:
3247:                            FileUtil.deleteLineInFile(globalDP, "<?xml",
3248:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3249:                            //Display profile element appears twice. Bug?? . Remedy is in the next three lines.
3250:                            FileUtil
3251:                                    .deleteLineInFile(
3252:                                            globalDP,
3253:                                            "<DisplayProfile advanced=\"false\" lock=\"false\"",
3254:                                            FileUtil.DELETE_FIRST_OCCURANCE);
3255:                            FileUtil.deleteLineInFile(globalDP,
3256:                                    "<DisplayProfile xmlns:DisplayProfile=",
3257:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3258:                            FileUtil.deleteLineInFile(globalDP,
3259:                                    "<DisplayProfile priority=\"0\"",
3260:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3261:                            copy(globalDP, new File(fileSep + "var" + fileSep
3262:                                    + "tmp" + fileSep + "UpdatedDPGlobal.xml"));
3263:                        } catch (UpgradeUtilException e) {
3264:                            logger.log(Level.SEVERE, e.getMessage());
3265:                            setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
3266:                        }
3267:                    }
3268:
3269:                    File devSampleDP = new File(fileSep + "var" + fileSep
3270:                            + "tmp" + fileSep + "PSUpgradeDPDevSample.xml");
3271:                    if (devSampleDP.exists() && devSampleDP.length() > 0) {
3272:                        try {
3273:                            FileUtil.deleteLineInFile(devSampleDP,
3274:                                    "<!DOCTYPE DisplayProfile SYSTEM",
3275:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3276:                            UpgradeUtils.processDPUpdates(devSampleDP,
3277:                                    DPChanges, "DEVELOPER_SAMPLE_ORG");
3278:                            //Workarounds for bug in jaxp cache?
3279:                            File tmpDevSample = new File(
3280:                                    devSampleDP.getAbsolutePath()
3281:                                            + "with"
3282:                                            + resDir.substring(resDir
3283:                                                    .lastIndexOf("/") + 1)
3284:                                            + "Changes");
3285:                            copy(devSampleDP, tmpDevSample);
3286:                            devSampleDP = tmpDevSample;
3287:
3288:                            FileUtil
3289:                                    .appendLineInFile(
3290:                                            devSampleDP,
3291:                                            "<?xml",
3292:                                            "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE DisplayProfile SYSTEM \"jar://resources/psdp.dtd\">\n<DisplayProfile version=\"1.0\" priority=\"10\">",
3293:                                            FileUtil.APPEND_FIRST_OCCURANCE);
3294:
3295:                            FileUtil.deleteLineInFile(devSampleDP, "<?xml",
3296:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3297:                            copy(devSampleDP, new File(fileSep + "var"
3298:                                    + fileSep + "tmp" + fileSep
3299:                                    + "UpdatedDPDevSample.xml"));
3300:                        } catch (UpgradeUtilException e) {
3301:                            logger.log(Level.SEVERE, e.getMessage());
3302:                            setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
3303:                        }
3304:                    }
3305:
3306:                    File commuSampleDP = new File(fileSep + "var" + fileSep
3307:                            + "tmp" + fileSep + "PSUpgradeDPCommuSample.xml");
3308:                    if (commuSampleDP.exists() && commuSampleDP.length() > 0) {
3309:                        try {
3310:                            FileUtil.deleteLineInFile(commuSampleDP,
3311:                                    "<!DOCTYPE DisplayProfile SYSTEM",
3312:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3313:                            UpgradeUtils.processDPUpdates(commuSampleDP,
3314:                                    DPChanges, "COMMUNITY_SAMPLE_ORG");
3315:                            //Workarounds for bug in jaxp cache?
3316:                            File tmpCommuSample = new File(
3317:                                    commuSampleDP.getAbsolutePath()
3318:                                            + "with"
3319:                                            + resDir.substring(resDir
3320:                                                    .lastIndexOf("/") + 1)
3321:                                            + "Changes");
3322:                            copy(commuSampleDP, tmpCommuSample);
3323:                            commuSampleDP = tmpCommuSample;
3324:
3325:                            FileUtil
3326:                                    .appendLineInFile(
3327:                                            commuSampleDP,
3328:                                            "<?xml",
3329:                                            "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE DisplayProfile SYSTEM \"jar://resources/psdp.dtd\">\n<DisplayProfile version=\"1.0\" priority=\"10\">",
3330:                                            FileUtil.APPEND_FIRST_OCCURANCE);
3331:
3332:                            FileUtil.deleteLineInFile(commuSampleDP, "<?xml",
3333:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3334:                            //Display profile element appears twice. Bug?? . Remedy is in the next lines
3335:                            FileUtil
3336:                                    .deleteLineInFile(
3337:                                            commuSampleDP,
3338:                                            "<DisplayProfile advanced=\"false\" lock=\"false\"",
3339:                                            FileUtil.DELETE_FIRST_OCCURANCE);
3340:                            FileUtil.deleteLineInFile(commuSampleDP,
3341:                                    "<DisplayProfile xmlns:DisplayProfile=",
3342:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3343:                            //FileUtil.deleteLineInFile(commuSampleDP,"<DisplayProfile version=\"1.0\" priority=\"10\"",FileUtil.DELETE_FIRST_OCCURANCE);
3344:                            copy(commuSampleDP, new File(fileSep + "var"
3345:                                    + fileSep + "tmp" + fileSep
3346:                                    + "UpdatedDPCommuSample.xml"));
3347:                        } catch (UpgradeUtilException e) {
3348:                            logger.log(Level.SEVERE, e.getMessage());
3349:                            setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
3350:                        }
3351:                    }
3352:
3353:                    File enterSampleDP = new File(fileSep + "var" + fileSep
3354:                            + "tmp" + fileSep + "PSUpgradeDPEnterSample.xml");
3355:                    if (enterSampleDP.exists() && enterSampleDP.length() > 0) {
3356:                        try {
3357:                            FileUtil.deleteLineInFile(enterSampleDP,
3358:                                    "<!DOCTYPE DisplayProfile SYSTEM",
3359:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3360:                            UpgradeUtils.processDPUpdates(enterSampleDP,
3361:                                    DPChanges, "ENTERPRISE_SAMPLE_ORG");
3362:                            //Workarounds for bug in jaxp cache?
3363:                            File tmpEnterSample = new File(
3364:                                    enterSampleDP.getAbsolutePath()
3365:                                            + "with"
3366:                                            + resDir.substring(resDir
3367:                                                    .lastIndexOf("/") + 1)
3368:                                            + "Changes");
3369:                            copy(enterSampleDP, tmpEnterSample);
3370:                            enterSampleDP = tmpEnterSample;
3371:
3372:                            FileUtil
3373:                                    .appendLineInFile(
3374:                                            enterSampleDP,
3375:                                            "<?xml",
3376:                                            "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE DisplayProfile SYSTEM \"jar://resources/psdp.dtd\">\n<DisplayProfile version=\"1.0\" priority=\"10\">",
3377:                                            FileUtil.APPEND_FIRST_OCCURANCE);
3378:
3379:                            FileUtil.deleteLineInFile(enterSampleDP, "<?xml",
3380:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3381:                            //Display profile element appears twice. Bug?? . Remedy is in the next lines
3382:                            FileUtil
3383:                                    .deleteLineInFile(
3384:                                            enterSampleDP,
3385:                                            "<DisplayProfile advanced=\"false\" lock=\"false\"",
3386:                                            FileUtil.DELETE_FIRST_OCCURANCE);
3387:                            FileUtil.deleteLineInFile(enterSampleDP,
3388:                                    "<DisplayProfile xmlns:DisplayProfile=",
3389:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3390:                            //FileUtil.deleteLineInFile(enterSampleDP,"<DisplayProfile version=\"1.0\" priority=\"10\"",FileUtil.DELETE_FIRST_OCCURANCE);
3391:                            copy(enterSampleDP, new File(fileSep + "var"
3392:                                    + fileSep + "tmp" + fileSep
3393:                                    + "UpdatedDPEnterSample.xml"));
3394:                        } catch (UpgradeUtilException e) {
3395:                            logger.log(Level.SEVERE, e.getMessage());
3396:                            setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
3397:                        }
3398:                    }
3399:
3400:                    File commonAuthlessDP = new File(fileSep + "var" + fileSep
3401:                            + "tmp" + fileSep + "PSUpgradeDPCommonAuthless.xml");
3402:                    if (commonAuthlessDP.exists()
3403:                            && commonAuthlessDP.length() > 0) {
3404:                        try {
3405:                            FileUtil.deleteLineInFile(commonAuthlessDP,
3406:                                    "<!DOCTYPE DisplayProfile SYSTEM",
3407:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3408:                            UpgradeUtils.processDPUpdates(commonAuthlessDP,
3409:                                    DPChanges, "AUTHLESS_ANON_USER_COMMON");
3410:                            //Workarounds for bug in jaxp cache?
3411:                            File tmpCommonAuthless = new File(
3412:                                    commonAuthlessDP.getAbsolutePath()
3413:                                            + "with"
3414:                                            + resDir.substring(resDir
3415:                                                    .lastIndexOf("/") + 1)
3416:                                            + "Changes");
3417:                            copy(commonAuthlessDP, tmpCommonAuthless);
3418:                            commonAuthlessDP = tmpCommonAuthless;
3419:
3420:                            FileUtil
3421:                                    .appendLineInFile(
3422:                                            commonAuthlessDP,
3423:                                            "<?xml",
3424:                                            "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE DisplayProfile SYSTEM \"jar://resources/psdp.dtd\">\n<DisplayProfile version=\"1.0\" priority=\"10\">",
3425:                                            FileUtil.APPEND_FIRST_OCCURANCE);
3426:
3427:                            FileUtil.deleteLineInFile(commonAuthlessDP,
3428:                                    "<?xml", FileUtil.DELETE_FIRST_OCCURANCE);
3429:                            //Display profile element appears twice. Bug?? . Remedy is in the next line
3430:                            FileUtil
3431:                                    .deleteLineInFile(
3432:                                            commonAuthlessDP,
3433:                                            "<DisplayProfile version=\"1.0\" priority=\"10\"",
3434:                                            FileUtil.DELETE_FIRST_OCCURANCE);
3435:                            copy(commonAuthlessDP, new File(fileSep + "var"
3436:                                    + fileSep + "tmp" + fileSep
3437:                                    + "UpdatedDPCommonAuthless.xml"));
3438:                        } catch (UpgradeUtilException e) {
3439:                            logger.log(Level.SEVERE, e.getMessage());
3440:                            setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
3441:                        }
3442:                    }
3443:
3444:                    File devSampleAuthlessDP = new File(fileSep + "var"
3445:                            + fileSep + "tmp" + fileSep
3446:                            + "PSUpgradeDPDevSampleAuthless.xml");
3447:                    if (devSampleAuthlessDP.exists()
3448:                            && devSampleAuthlessDP.length() > 0) {
3449:                        try {
3450:                            FileUtil.deleteLineInFile(devSampleAuthlessDP,
3451:                                    "<!DOCTYPE DisplayProfile SYSTEM",
3452:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3453:                            UpgradeUtils.processDPUpdates(devSampleAuthlessDP,
3454:                                    DPChanges,
3455:                                    "AUTHLESS_ANON_USER_DEVELOPER_SAMPLE_ORG");
3456:                            //Workarounds for bug in jaxp cache?
3457:                            File tmpDevSampleAuthless = new File(
3458:                                    devSampleAuthlessDP.getAbsolutePath()
3459:                                            + "with"
3460:                                            + resDir.substring(resDir
3461:                                                    .lastIndexOf("/") + 1)
3462:                                            + "Changes");
3463:                            copy(devSampleAuthlessDP, tmpDevSampleAuthless);
3464:                            devSampleAuthlessDP = tmpDevSampleAuthless;
3465:
3466:                            FileUtil
3467:                                    .appendLineInFile(
3468:                                            devSampleAuthlessDP,
3469:                                            "<?xml",
3470:                                            "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE DisplayProfile SYSTEM \"jar://resources/psdp.dtd\">\n<DisplayProfile version=\"1.0\" priority=\"10\">",
3471:                                            FileUtil.APPEND_FIRST_OCCURANCE);
3472:
3473:                            FileUtil.deleteLineInFile(devSampleAuthlessDP,
3474:                                    "<?xml", FileUtil.DELETE_FIRST_OCCURANCE);
3475:                            copy(devSampleAuthlessDP, new File(fileSep + "var"
3476:                                    + fileSep + "tmp" + fileSep
3477:                                    + "UpdatedDPDevSampleAuthless.xml"));
3478:                        } catch (UpgradeUtilException e) {
3479:                            logger.log(Level.SEVERE, e.getMessage());
3480:                            setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
3481:                        }
3482:                    }
3483:
3484:                    File enterSampleAuthlessDP = new File(fileSep + "var"
3485:                            + fileSep + "tmp" + fileSep
3486:                            + "PSUpgradeDPEnterSampleAuthless.xml");
3487:                    if (enterSampleAuthlessDP.exists()
3488:                            && enterSampleAuthlessDP.length() > 0) {
3489:                        try {
3490:                            FileUtil.deleteLineInFile(enterSampleAuthlessDP,
3491:                                    "<!DOCTYPE DisplayProfile SYSTEM",
3492:                                    FileUtil.DELETE_FIRST_OCCURANCE);
3493:                            UpgradeUtils.processDPUpdates(
3494:                                    enterSampleAuthlessDP, DPChanges,
3495:                                    "AUTHLESS_ANON_USER_ENTERPRISE_SAMPLE_ORG");
3496:                            //Workarounds for bug in jaxp cache?
3497:                            File tmpEnterSampleAuthless = new File(
3498:                                    enterSampleAuthlessDP.getAbsolutePath()
3499:                                            + "with"
3500:                                            + resDir.substring(resDir
3501:                                                    .lastIndexOf("/") + 1)
3502:                                            + "Changes");
3503:                            copy(enterSampleAuthlessDP, tmpEnterSampleAuthless);
3504:                            enterSampleAuthlessDP = tmpEnterSampleAuthless;
3505:
3506:                            FileUtil
3507:                                    .appendLineInFile(
3508:                                            enterSampleAuthlessDP,
3509:                                            "<?xml",
3510:                                            "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE DisplayProfile SYSTEM \"jar://resources/psdp.dtd\">\n<DisplayProfile version=\"1.0\" priority=\"10\">",
3511:                                            FileUtil.APPEND_FIRST_OCCURANCE);
3512:
3513:                            FileUtil.deleteLineInFile(enterSampleAuthlessDP,
3514:                                    "<?xml", FileUtil.DELETE_FIRST_OCCURANCE);
3515:                            //Display profile element appears twice. Bug?? . Remedy is in the next line
3516:                            FileUtil
3517:                                    .deleteLineInFile(
3518:                                            enterSampleAuthlessDP,
3519:                                            "<DisplayProfile version=\"1.0\" priority=",
3520:                                            FileUtil.DELETE_FIRST_OCCURANCE);
3521:                            copy(enterSampleAuthlessDP, new File(fileSep
3522:                                    + "var" + fileSep + "tmp" + fileSep
3523:                                    + "UpdatedDPEnterSampleAuthless.xml"));
3524:                        } catch (UpgradeUtilException e) {
3525:                            logger.log(Level.SEVERE, e.getMessage());
3526:                            setExitCode(UpgradeConstants.SPECIFIC_UPGRADE_ERROR_DP_UPDATES_EXIT_CODE);
3527:                        }
3528:                    }
3529:
3530:                } catch (IOException e) {
3531:                    if (logger.isLoggable(Level.SEVERE)) {
3532:                        LogRecord rec = new LogRecord(Level.SEVERE,
3533:                                "PSFB_CSPFUP0097");
3534:                        rec.setLoggerName(logger.getName());
3535:                        rec.setParameters(new Object[] { DPChanges
3536:                                .getAbsolutePath() });
3537:                        rec.setThrown(e);
3538:                        logger.log(rec);
3539:                    }
3540:                } catch (Exception e) {
3541:                    if (logger.isLoggable(Level.SEVERE)) {
3542:                        LogRecord rec = new LogRecord(Level.SEVERE,
3543:                                "PSFB_CSPFUP0097");
3544:                        rec.setLoggerName(logger.getName());
3545:                        rec.setParameters(new Object[] { DPChanges
3546:                                .getAbsolutePath() });
3547:                        rec.setThrown(e);
3548:                        logger.log(rec);
3549:                    }
3550:                }
3551:            }
3552:
3553:            public static void enableSRA(String[] platformConfs,
3554:                    Properties prop, String amadminPasswordFilePath) {
3555:                boolean success = false;
3556:                String command = prop.getProperty("PS_70_PRODUCT_DIR")
3557:                        + File.separator + "bin" + File.separator + "psadmin";
3558:                String[] args = new String[10];
3559:
3560:                args[0] = "provision-sra";
3561:                args[1] = "-u";
3562:                args[2] = prop.getProperty("ADMIN_DN");
3563:                args[3] = "-f";
3564:                args[4] = amadminPasswordFilePath;
3565:                args[5] = "--enable";
3566:                args[6] = "--portal";
3567:                args[7] = "Upgraded";
3568:                args[8] = "--gateway-profile";
3569:                String pname = null;
3570:
3571:                for (int i = 0; i < platformConfs.length; i++) {
3572:                    String str = platformConfs[i];
3573:                    StringTokenizer stk = new StringTokenizer(str, ".");
3574:                    while (stk.hasMoreElements()) {
3575:                        pname = stk.nextToken();
3576:                    }
3577:                    args[9] = pname;
3578:                    execUtil.storeOutput(true);
3579:                    try {
3580:                        execUtil.exec(command, args);
3581:                    } catch (Exception e) {
3582:                        logger.log(Level.INFO, "PSFB_CSPFUP0151", execUtil
3583:                                .getOutput());
3584:                    }
3585:
3586:                }
3587:            }
3588:
3589:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.