1 23 24 29 package com.sun.enterprise.tools.upgrade.deployment; 30 31 import java.io.*; 32 import java.util.*; 33 import java.util.jar.*; 34 import java.util.logging.*; 35 36 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 37 import com.sun.enterprise.deployment.deploy.shared.FileArchiveFactory; 38 import com.sun.enterprise.deployment.deploy.shared.JarArchiveFactory; 39 import com.sun.enterprise.deployment.deploy.shared.OutputJarArchive; 40 import com.sun.enterprise.tools.upgrade.common.*; 41 import com.sun.enterprise.util.i18n.StringManager; 42 43 import javax.xml.parsers.DocumentBuilder ; 44 import javax.xml.parsers.DocumentBuilderFactory ; 45 46 import org.w3c.dom.Document ; 47 import org.w3c.dom.Node ; 48 import org.w3c.dom.NodeList ; 49 import org.w3c.dom.NamedNodeMap ; 50 51 import javax.xml.transform.Transformer ; 52 import javax.xml.transform.TransformerFactory ; 53 54 import javax.xml.transform.dom.DOMSource ; 55 import javax.xml.transform.stream.StreamResult ; 56 import javax.xml.transform.OutputKeys ; 57 import com.sun.enterprise.cli.framework.CommandException; 58 import com.sun.enterprise.deployment.WebBundleDescriptor; 59 import com.sun.enterprise.deployment.io.runtime.WebRuntimeDDFile; 60 import com.sun.enterprise.deployment.node.SaxParserHandler; 61 import org.w3c.dom.Element ; 62 63 64 68 public class DeploymentUpgrade implements com.sun.enterprise.tools.upgrade.common.BaseModule { 69 70 private static String EAR_DIR = "j2ee-apps"; 71 private static String MODULE_DIR = "j2ee-modules"; 72 private static String SOURCE_LIBRARY_DIR = "lib"; 73 private static String TARGET_LIBRARY_DIR = "lib"; 74 private static String MEJB_APP = "MEjbApp"; 75 private static String TIMER_APP = "__ejb_container_timer"; 76 private static Hashtable deployedModules = new Hashtable(); 77 78 File sourceDir; 79 String targetDir; 80 boolean success = true; 81 boolean domainRunning = false; CommonInfoModel commonInfo; 83 84 private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.deployment"); 85 private Logger logger = CommonInfoModel.getDefaultLogger(); 86 87 88 public DeploymentUpgrade() { 89 } 90 91 public boolean upgrade(com.sun.enterprise.tools.upgrade.common.CommonInfoModel commonInfo) { 92 this.commonInfo = commonInfo; 93 DomainInfo dInfo = new DomainInfo(commonInfo.getCurrentDomain(), 95 commonInfo.getSourceDomainPath()); 96 String applicationRoot = dInfo.getDomainApplicationRoot(); 97 99 if (deployedModules.get(commonInfo.getCurrentDomain()) == null) { 100 deployedModules.put(commonInfo.getCurrentDomain(), new ArrayList()); 101 } 102 logger.log(Level.INFO, stringManager.getString("upgrade.deployment.startMessage")); 103 String sourceInstance = commonInfo.getSourceDomainPath(); 105 String targetInstance = commonInfo.getDestinationDomainPath(); 108 domainRunning = false; 109 110 processLibraries(sourceInstance, targetInstance); 111 sourceDir = new File(sourceInstance, applicationRoot); 114 116 try { 118 File tmp = File.createTempFile("upgrade", null); 119 targetDir = tmp.getParent(); 120 tmp.delete(); 121 } catch (IOException ioe) { 122 logger.severe(stringManager.getString("upgrade.deployment.ioExceptionMsg")+ioe.getMessage()); 123 return false; 124 } 125 126 processLifecycles(); 128 129 130 131 File srcEarDir = new File(sourceDir, EAR_DIR); 133 if(srcEarDir != null) { 135 if (srcEarDir.listFiles() != null && srcEarDir.listFiles().length > 0) { 137 domainRunning = startDomain(commonInfo.getCurrentDomain()); 138 if (domainRunning) { 139 processApplications(srcEarDir); 140 } else { 141 return false; 142 } 143 } 144 } 145 146 File srcJarDir = new File(sourceDir, MODULE_DIR); 148 if(srcJarDir != null) { 150 if(srcJarDir.listFiles() != null && srcJarDir.listFiles().length > 0) { 151 if (!domainRunning) { 154 domainRunning = startDomain(commonInfo.getCurrentDomain()); 155 } 156 if (domainRunning) { 157 processStandaloneModules(srcJarDir); 158 } else { 159 return false; 160 } 161 } 162 } 163 164 if (domainRunning) { 165 stopDomain(commonInfo.getCurrentDomain()); 166 } 167 return success; 168 169 170 } 171 172 public void recovery(CommonInfoModel commonInfo) { 173 commonInfo.deletePasswordFile(); 174 } 175 176 178 private void processApplications(File srcDir) { 179 180 File [] earDirs = srcDir.listFiles(); 181 for (int i=0;i<earDirs.length;i++) { 182 String earDirName = earDirs[i].getName(); 183 String earName; 184 if (earDirName.lastIndexOf("_ear") > -1) { 186 earName = earDirName.substring(0,earDirName.lastIndexOf("_")); 187 } else { 189 earName = earDirName; 190 } 191 String appName = earName; 192 if (appName.startsWith(MEJB_APP) || appName.startsWith(TIMER_APP)) { 193 continue; 194 } 195 earName=earName+".ear"; 196 try { 197 JarArchiveFactory jaf = new JarArchiveFactory(); 198 OutputJarArchive targetJar = (OutputJarArchive)jaf.createArchive(new File(targetDir, earName).getAbsolutePath()); 199 FileArchiveFactory faf = new FileArchiveFactory(); 200 FileArchive farc = (FileArchive)faf.openArchive((new File(srcDir, earDirName)).getAbsolutePath()); 201 Enumeration e = farc.entries(); 202 String lastModuleProcessed = ""; 203 while(e.hasMoreElements()) { 204 String s = (String )e.nextElement(); 205 String moduleDir; 206 try { 207 moduleDir = s.substring(0, s.lastIndexOf('_')+4); 208 } catch (StringIndexOutOfBoundsException sob) { 209 moduleDir = ""; 210 } 211 212 FileInputStream fis = null; 213 OutputStream out = null; 214 try { 215 if (moduleDir.endsWith("_jar") || moduleDir.endsWith("_war") || moduleDir.endsWith("_rar")) { 216 if(lastModuleProcessed.equals(moduleDir)) { 217 continue; 218 } 219 File jar = processModule(EAR_DIR, earDirName, moduleDir); 220 lastModuleProcessed = moduleDir; 221 out = targetJar.putNextEntry(jar.getName()); 222 fis = new FileInputStream(jar); 223 } else { 224 if (!s.endsWith("Client.jar")) { out = targetJar.putNextEntry(s); 226 fis = new FileInputStream(new File(new File(srcDir, earDirName), s)); 227 } else { 228 continue; 229 } 230 231 } 232 233 while(fis.available() > 0) { 234 int ix = fis.read(); 235 out.write(ix); 236 } 237 238 } catch(java.util.zip.ZipException z) { 239 logger.warning(stringManager.getString("upgrade.deployment.zipExceptionMsg")+z.getMessage()); 240 } catch (IOException ioe) { 241 logger.severe(stringManager.getString("upgrade.deployment.ioExceptionMsg")+ioe.getMessage()); 242 } 243 targetJar.closeEntry(); 244 } 245 targetJar.close(); 246 if(deploy((new File(targetJar.getArchiveUri())).getAbsolutePath())) { 247 logger.info(stringManager.getString("upgrade.deployment.finishedProcessingMsg") + appName); 248 } else { 249 logger.warning(appName + " " + stringManager.getString("upgrade.deployment.errorProcessingMsg")); 250 } 251 } catch(Exception ex) { 252 logger.severe(stringManager.getString("upgrade.deployment.generalExceptionMsg")+ ex.toString() + ": " + ex.getMessage()); 253 } 254 } 255 } 256 257 private void processStandaloneModules(File srcModuleDir) { 258 259 File [] moduleDirs = srcModuleDir.listFiles(); 260 for (int i=0;i<moduleDirs.length;i++) { 261 String moduleDirName = moduleDirs[i].getName(); 262 File jarFile = processModule(MODULE_DIR, "", moduleDirName); 263 String moduleName; 264 if (moduleDirName.lastIndexOf('_') > -1 ) { 265 moduleName = moduleDirName.substring(0,moduleDirName.lastIndexOf('_')); 266 } else { 267 moduleName = moduleDirName; 268 } 269 if(deploy(jarFile.getAbsolutePath())) { 271 logger.info(stringManager.getString("upgrade.deployment.finishedProcessingMsg") + moduleName ); 272 } else { 273 logger.warning(moduleName + " " + stringManager.getString("upgrade.deployment.errorProcessingMsg")); 274 } 275 } 276 } 277 278 private File processModule(String appDir, String earDirName, String moduleDirName) { 280 String moduleName; 281 if ((moduleDirName.lastIndexOf("_war") > -1) || 283 (moduleDirName.lastIndexOf("_rar") > -1) || 284 (moduleDirName.lastIndexOf("_jar") > -1)){ 285 moduleName = moduleDirName.substring(0,moduleDirName.lastIndexOf('_')); 287 } else { 288 moduleName = moduleDirName; 289 } 290 291 try { 292 293 JarArchiveFactory jaf = new JarArchiveFactory(); 294 FileArchiveFactory faf = new FileArchiveFactory(); 295 FileArchive farc = (FileArchive)faf.openArchive(new File(new File(new File(sourceDir, appDir), earDirName), moduleDirName).getAbsolutePath()); 296 String suffix = ".jar"; Enumeration e = farc.entries(); 299 while(e.hasMoreElements()) { 301 String entry = (String )e.nextElement(); 302 if (entry.equalsIgnoreCase("WEB-INF/web.xml")) { 303 suffix = ".war"; 304 } else if (entry.equalsIgnoreCase("META-INF/ra.xml")) { 305 suffix = ".rar"; 306 } 307 } 308 File tempJar = new File(targetDir, moduleName + suffix); 310 String path = tempJar.getAbsolutePath(); 311 OutputJarArchive targetModule = (OutputJarArchive)jaf.createArchive(path); 313 logger.fine(stringManager.getString("upgrade.deployment.addingInfoMsg") + targetModule.getArchiveUri()); 314 e = farc.entries(); 315 while(e.hasMoreElements()) { 316 String entry = (String )e.nextElement(); 317 InputStream in = farc.getEntry(entry); 318 if (entry.equals("WEB-INF/web.xml")) { 319 InputStream fixedDescriptor = fixWebServiceDescriptor(farc); 320 if(fixedDescriptor != null) { 321 in = fixedDescriptor; 322 } 323 } 324 if(entry.equals("WEB-INF/sun-web.xml")) { 326 checkDescriptors(farc, "sun-web.xml", "WEB-INF"); 327 } 328 if(entry.equals("META-INF/sun-ejb-jar.xml")) { 329 checkDescriptors(farc, "sun-ejb-jar.xml", "META-INF"); 330 } 331 OutputStream out = null; 333 try { 334 out = targetModule.putNextEntry(entry); 335 int i = in.read(); 336 do { 337 out.write(i); 338 i = in.read(); 339 } while (i > -1); 340 } catch(java.util.zip.ZipException z) { 341 logger.warning(stringManager.getString("upgrade.deployment.zipExceptionMsg")+z.getMessage()); 342 }catch (IOException ioe) { 343 logger.severe(stringManager.getString("upgrade.deployment.ioExceptionMsg")+ioe.getMessage()); 344 } 345 targetModule.closeEntry(); 346 } 347 InputStream in = farc.getEntry(JarFile.MANIFEST_NAME); 348 OutputStream out = null; 349 try { 350 out = targetModule.putNextEntry(JarFile.MANIFEST_NAME); 351 int i = in.read(); 352 do { 353 out.write(i); 354 i = in.read(); 355 } while (i > -1); 356 } catch(java.util.zip.ZipException z) { 357 logger.warning(stringManager.getString("upgrade.deployment.zipExceptionMsg")+z.getMessage()); 358 }catch (IOException ioe) { 359 logger.severe(stringManager.getString("upgrade.deployment.ioExceptionMsg")+ioe.getMessage()); 360 } 361 targetModule.closeEntry(); 362 363 targetModule.close(); 364 return tempJar; 365 } catch(Exception ex) { 366 logger.severe(stringManager.getString("upgrade.deployment.generalExceptionMsg")+ ex.toString() + ": " + ex.getMessage()); 367 } 368 return null; 369 } 370 371 373 private void processLifecycles(){ 374 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 375 factory.setNamespaceAware(true); 377 if(commonInfo.getSourceDomainRootFlag()) { 378 factory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd",Boolean.FALSE); 379 } 380 try { 381 DocumentBuilder builder = factory.newDocumentBuilder(); 382 builder.setEntityResolver((org.xml.sax.helpers.DefaultHandler )Class.forName 383 ("com.sun.enterprise.config.serverbeans.ServerValidationHandler").newInstance()); 384 Document sourceDoc = builder.parse( new File(commonInfo.getSourceConfigXMLFile()) ); 385 Document targetDoc = builder.parse( new File(commonInfo.getTargetConfigXMLFile()) ); 386 387 NodeList nl = sourceDoc.getElementsByTagName("lifecycle-module"); 388 for(int i =0; i < nl.getLength(); i++){ 389 Node node = nl.item(i); 390 Node newNode = targetDoc.importNode(node, true); 391 NamedNodeMap attributes = newNode.getAttributes(); 392 String lcname = attributes.getNamedItem("name").getNodeValue(); 393 Node classpathNode = attributes.getNamedItem("classpath"); 394 try { 395 String classpath = null; 396 if (classpathNode != null) { 397 classpath = classpathNode.getNodeValue(); 398 File testPath = new File(classpath); 399 if(!testPath.exists()) { 400 logger.warning( stringManager.getString("upgrade.deployment.lifecycleErrorMsg") + lcname ); 401 logger.warning( stringManager.getString("upgrade.deployment.lifecycleClasspathMsg" + classpath, lcname) ); 402 continue; 403 } 404 } 405 NodeList appNodeList = targetDoc.getElementsByTagName("applications"); 406 Node applicationsNode = appNodeList.item(0); NodeList applicationsList = applicationsNode.getChildNodes(); 409 boolean foundDup = false; 410 for (int n=0; n < applicationsList.getLength(); n++) { 411 Node appNode = (Node )applicationsList.item(n); 412 if ( appNode.getNodeName().equals(newNode.getNodeName()) ) { 413 NamedNodeMap appNodeAttrs = appNode.getAttributes(); 414 NamedNodeMap newNodeAttrs = newNode.getAttributes(); 415 Node appNodeName = appNodeAttrs.getNamedItem("name"); 416 Node newNodeName = appNodeAttrs.getNamedItem("name"); 417 String newNodeNameString = newNodeName.getNodeValue(); 418 if (newNodeNameString.equals(appNodeName.getNodeValue())) { 419 logger.warning(stringManager.getString("upgrade.deployment.lifecycleExistsMsg", newNodeNameString )); 420 foundDup = true; 421 break; 422 } 423 } 424 } 425 if (!foundDup) { 426 applicationsNode.appendChild(newNode); 427 } 428 429 } catch (SecurityException se) { 430 logger.warning(stringManager.getString("upgrade.deployment.lifecycleClasspathMsg", node.getNodeName()) + se.getMessage()); 431 } 432 433 434 435 } 436 TransformerFactory tFactory = TransformerFactory.newInstance(); 437 Transformer transformer = tFactory.newTransformer(); 438 if (targetDoc.getDoctype() != null){ 439 String systemValue = targetDoc.getDoctype().getSystemId(); 440 transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemValue); 441 String pubValue = targetDoc.getDoctype().getPublicId(); 442 transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pubValue); 443 } 444 DOMSource source = new DOMSource (targetDoc); 445 StreamResult result = new StreamResult (new FileOutputStream(commonInfo.getTargetConfigXMLFile())); 446 transformer.transform(source, result); 447 448 } catch (Exception ex){ 449 logger.log(Level.SEVERE, stringManager.getString("upgrade.deployment.generalExceptionMsg"), ex); 450 } 451 } 452 453 455 private void processLibraries(String sourceInstance, String targetInstance){ 456 File sourceDir = new File(sourceInstance, SOURCE_LIBRARY_DIR); 457 File targetDir = new File(targetInstance, TARGET_LIBRARY_DIR); 458 try { 459 copyDir(sourceDir, targetDir); 460 } catch(FileNotFoundException fnf) { 461 logger.severe(stringManager.getString("upgrade.deployment.generalExceptionMsg")+ fnf.toString() + ": " + fnf.getMessage()); 462 } catch(IOException ioe) { 463 logger.severe(stringManager.getString("upgrade.deployment.ioExceptionMsg")+ioe.getMessage()); 464 } 465 } 466 467 private void copyDir(File inputDir, File outputDir) throws FileNotFoundException, IOException { 468 File [] srcFiles = inputDir.listFiles(); 469 if (srcFiles != null) { 470 for(int i=0; i< srcFiles.length; i++) { 471 File dest = new File(outputDir, srcFiles[i].getName()); 472 if( srcFiles[i].isDirectory() ) { 473 if (!dest.exists()) { 474 dest.mkdir(); 475 } 476 copyDir(srcFiles[i], dest); 477 } else { 478 if (!dest.exists()) { 479 dest.createNewFile(); 480 } 481 copyFile(srcFiles[i], new File(outputDir, srcFiles[i].getName())); 482 483 } 484 } 485 } 486 } 487 488 private void copyFile(File inputFile, File outputFile) throws FileNotFoundException, IOException { 489 FileReader in = new FileReader(inputFile); 490 FileWriter out = new FileWriter(outputFile); 491 int c; 492 493 while ((c = in.read()) != -1) { 494 out.write(c); 495 } 496 497 in.close(); 498 out.close(); 499 } 500 501 private boolean deploy(String modulePath) { 502 if (commonInfo.getTargetEdition().equals(UpgradeConstants.EDITION_EE)) { 503 ArrayList mods = (ArrayList)deployedModules.get(commonInfo.getCurrentDomain()); 504 String fileName = new File(modulePath).getName(); 505 String moduleName = fileName.substring(0, fileName.lastIndexOf('.')); 506 if (mods.contains(moduleName)) { 507 String currentDomain = commonInfo.getCurrentDomain(); 508 String adminPort = DomainsProcessor.getTargetDomainPort(currentDomain, commonInfo); 509 String adminSecurity = DomainsProcessor.getTargetDomainSecurity(currentDomain, commonInfo); 510 String [] createAppRefCommand = { 511 "create-application-ref", 512 "--user", commonInfo.getAdminUserName(), 513 "--passwordfile ", "\"" + commonInfo.getPasswordFile()+ "\"", 514 "--port",adminPort, 515 "--secure=" + adminSecurity, 516 "--target", commonInfo.getCurrentSourceInstance(), 517 moduleName 518 }; 519 try { 520 return Commands.executeCommand(createAppRefCommand); 521 } catch(CommandException ce) { 522 logger.log(Level.SEVERE, stringManager.getString("upgrade.deployment.generalExceptionMsg"), ce); 523 return false; 524 } 525 } else { 526 if (Commands.deploy(modulePath, commonInfo)) { 527 mods.add(moduleName); 528 return true; 529 } 530 return false; 531 } 532 } 533 return Commands.deploy(modulePath, commonInfo); 534 } 535 536 private boolean startDomain(String domainName) { 537 return Commands.startDomain(domainName, commonInfo); 538 } 539 540 private boolean stopDomain(String domainName) { 541 return Commands.stopDomain(domainName, commonInfo); 542 } 543 544 545 public static void main(String [] args) { 546 try{ 547 com.sun.enterprise.tools.upgrade.logging.LogService.initialize("upgradetest.log"); 548 }catch(Exception e){ 549 e.printStackTrace(); 550 } 551 CommonInfoModel cim = new CommonInfoModel(); 552 cim.setSourceInstallDir("C:\\Sun\\AppServer80"); 553 cim.setTargetInstallDir("C:\\Sun\\AppServer"); 554 cim.setCurrentDomain("domain1"); 555 cim.setTargetDomainRoot("C:\\Sun\\AppServer\\domains"); 557 cim.setSourceDomainRoot("C:\\Sun\\AppServer80\\domains"); 558 java.util.Hashtable ht = new java.util.Hashtable (); 559 ht.put("domain1", "C:\\Sun\\AppServer80\\domains\\domain1"); 560 cim.setDomainMapping(ht); 561 cim.enlistDomainsFromSource(); 562 cim.setAdminUserName("admin"); 563 cim.setAdminPassword("adminadmin"); 564 new DeploymentUpgrade().upgrade(cim); 565 } 566 567 568 public String getName() { 569 return stringManager.getString("upgrade.deployment.moduleName"); 570 } 571 572 private void checkDescriptors(FileArchive farc, String fileName, String dirName) throws IOException { 574 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 575 factory.setValidating(false); 576 try { 577 DocumentBuilder docBuilder = factory.newDocumentBuilder(); 578 docBuilder.setEntityResolver(new SaxParserHandler()); 579 String dirPath = farc.getArchiveUri(); 580 Document document = docBuilder.parse(dirPath + File.separatorChar + dirName + File.separatorChar + fileName); 581 Element docEle = document.getDocumentElement(); 582 NodeList securityBindingList = docEle.getElementsByTagName("message-security-binding"); 583 for(int i=0; i<securityBindingList.getLength();i++) { 584 Element element = (Element ) securityBindingList.item(i); 585 if(element != null) { 586 if(element.getAttribute("provider-id") != null) { 587 if(element.getAttribute("provider-id").equals("ClientProvider")) 588 logger.log(Level.WARNING, stringManager.getString("upgrade.deployment.messageSecurityConfig", 589 fileName, "ClientProvider")); 590 else if(element.getAttribute("provider-id").equals("ServerProvider")) 591 logger.log(Level.WARNING, stringManager.getString("upgrade.deployment.messageSecurityConfig", 592 fileName, "ServerProvider")); 593 } 594 } 595 } 596 } catch(IOException ioe) { 597 logger.log(Level.WARNING, stringManager.getString("upgrade.deployment.ioExceptionMsg") + ioe.getLocalizedMessage()); 598 } catch (Exception e) { 599 logger.log(Level.WARNING, stringManager.getString("upgrade.deployment.generalExceptionMsg") + e.getLocalizedMessage()); 600 } 601 602 } 603 604 606 private InputStream fixWebServiceDescriptor(FileArchive farc) throws IOException { 607 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 608 factory.setValidating(false); 609 try { 610 DocumentBuilder docBuilder = factory.newDocumentBuilder(); 611 docBuilder.setEntityResolver(new SaxParserHandler()); 612 String dirPath = farc.getArchiveUri(); 613 Document document = docBuilder.parse(dirPath + File.separatorChar + "WEB-INF" + File.separatorChar + "web.xml"); 614 Element docEle = document.getDocumentElement(); 615 NodeList servletList = docEle.getElementsByTagName("servlet"); 616 for(int i=0; i<servletList.getLength();i++) { 617 Node currentServletNode = servletList.item(i); 618 NodeList nodeList = ((Element )currentServletNode).getElementsByTagName("servlet-name"); 619 String servletName = getTextNodeData(nodeList.item(0)); 620 nodeList = ((Element )currentServletNode).getElementsByTagName("servlet-class"); 621 Node servletClassNode = nodeList.item(0); if(servletClassNode == null) { 623 return null; 624 } 625 String servletClass = getTextNodeData(servletClassNode); 626 if(servletClass.equals("com.sun.enterprise.webservice.JAXRPCServlet")) { 627 Document sunWebXml = docBuilder.parse(dirPath + File.separatorChar + "WEB-INF" + File.separatorChar + "sun-web.xml"); 630 Element de = sunWebXml.getDocumentElement(); 631 NodeList sunServletList = de.getElementsByTagName("servlet"); 632 for(int x=0;x<sunServletList.getLength();x++){ 633 Node sunServletNode = sunServletList.item(x); 634 NodeList list = ((Element )sunServletNode).getElementsByTagName("servlet-name"); 635 String sunServletName = getTextNodeData(list.item(0)); 636 if(sunServletName.equals(servletName)) { 637 NodeList nList = ((Element )sunServletNode).getElementsByTagName("servlet-impl-class"); 638 Node servletImplNode = nList.item(0); 639 String origServletClass = getTextNodeData(servletImplNode); 640 setTextNodeData(servletClassNode, origServletClass); 641 } 642 } 643 } 644 } 645 TransformerFactory tFactory = TransformerFactory.newInstance(); 648 Transformer transformer = tFactory.newTransformer(); 649 if (document.getDoctype() != null){ 650 String systemValue = document.getDoctype().getSystemId(); 651 transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, systemValue); 652 String pubValue = document.getDoctype().getPublicId(); 653 transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pubValue); 654 } 655 DOMSource source = new DOMSource (document); 656 File webTempFile = File.createTempFile("web","xml"); 657 StreamResult result = new StreamResult (new FileOutputStream(webTempFile)); 658 transformer.transform(source, result); 659 return new FileInputStream(webTempFile); 660 } catch (IOException ioe) { 661 logger.log(Level.WARNING, stringManager.getString("upgrade.deployment.ioExceptionMsg") + ioe.getLocalizedMessage()); 662 } catch (Exception e) { 663 logger.log(Level.WARNING, stringManager.getString("upgrade.deployment.generalExceptionMsg") + e.getLocalizedMessage()); 664 } 665 666 return farc.getEntry("WEB-INF/web.xml"); 667 } 668 669 private String getTextNodeData(Node node){ 670 NodeList children = ((Element )node).getChildNodes(); 671 for(int index=0; index < children.getLength(); index++){ 672 if(children.item(index).getNodeType() == Node.TEXT_NODE){ 673 return children.item(index).getNodeValue(); 674 } 675 } 676 return ""; 677 } 678 679 private void setTextNodeData(Node node, String text){ 680 NodeList children = ((Element )node).getChildNodes(); 681 for(int index=0; index < children.getLength(); index++){ 682 if(children.item(index).getNodeType() == Node.TEXT_NODE){ 683 children.item(index).setNodeValue(text); 684 } 685 } 686 } 687 } 688 | Popular Tags |