1 23 package com.sun.enterprise.diagnostics.collect; 24 import com.sun.logging.LogDomains; 25 import com.sun.enterprise.diagnostics.Data; 26 import com.sun.enterprise.diagnostics.Constants; 27 import com.sun.enterprise.diagnostics.ReportTarget; 28 import com.sun.enterprise.diagnostics.DiagnosticException; 29 import com.sun.enterprise.diagnostics.util.DiagnosticServiceHelper; 30 import com.sun.enterprise.diagnostics.util.XmlUtils; 31 import com.sun.enterprise.diagnostics.util.FileUtils; 32 33 import java.io.File ; 34 import java.io.IOException ; 35 import javax.xml.transform.TransformerException ; 36 import javax.xml.transform.TransformerConfigurationException ; 37 import javax.xml.parsers.ParserConfigurationException ; 38 import java.util.logging.Level ; 39 import java.util.logging.Logger ; 40 import org.xml.sax.SAXException ; 41 import org.w3c.dom.*; 42 43 44 45 50 public class ConfigCollector implements Collector { 51 52 private static final String PASSWORD_REPLACEMENT ="****"; 53 private static final String PASSWORD = "password"; 54 55 private String repositoryDir ; 56 private String reportDir ; 57 58 private static Logger logger = 59 LogDomains.getLogger(LogDomains.ADMIN_LOGGER); 60 61 67 public ConfigCollector(String repositoryDir, String reportDir) { 68 this.repositoryDir = repositoryDir; 69 this.reportDir = reportDir; 70 } 71 72 73 77 public Data capture() throws DiagnosticException { 78 WritableDataImpl dataImpl = new WritableDataImpl(DataType.CONFIG_DETAILS); 79 80 dataImpl.addChild(captureXMLFile(Constants.DOMAIN_XML)); 81 dataImpl.addChild(captureFile(Constants.SERVER_POLICY)); 82 dataImpl.addChild(captureFile(Constants.LOGIN_CONF)); 83 dataImpl.addChild(captureFile(Constants.SUN_ACC)); 84 return dataImpl; 85 } 87 92 public Data captureXMLFile(String fileName) throws DiagnosticException { 93 try { 94 String xmlFileToModify = repositoryDir + fileName; 95 String destFile = reportDir + fileName; 96 String domainXMLDTD = 97 DiagnosticServiceHelper.getInstallationRoot() + 98 Constants.DOMAIN_XML_DTD; 99 100 Document serverXml = XmlUtils.loadXML(xmlFileToModify, 101 domainXMLDTD); 102 XmlUtils.attrSearchReplace(serverXml.getDocumentElement(), 103 PASSWORD, PASSWORD_REPLACEMENT); 104 XmlUtils.copyXMLFile(serverXml, destFile); 105 return new FileData(destFile, DataType.CONFIG_DETAILS); 106 107 } catch (SAXException se) { 108 logger.log(Level.WARNING, se.getMessage()); 109 } catch (IOException ie) { 110 logger.log(Level.WARNING, ie.getMessage()); 111 } catch (TransformerConfigurationException tce) { 112 logger.log(Level.WARNING, tce.getMessage()); 113 } catch (TransformerException te) { 114 logger.log(Level.WARNING,te.getMessage()); 115 } catch (ParserConfigurationException pce) { 116 logger.log(Level.WARNING,pce.getMessage()); 117 } 118 return null; 119 } 120 121 126 public Data captureFile(String fileName) throws DiagnosticException { 127 try { 128 FileUtils.copyFile(repositoryDir + fileName, 129 reportDir +fileName); 130 return new FileData(reportDir + fileName, DataType.CONFIG_DETAILS); 131 } catch(IOException ioe) { 132 logger.log(Level.WARNING,ioe.getMessage()); 133 } 134 return null; 135 } 136 137 } 138 | Popular Tags |