1 19 20 package org.netbeans.modules.versioning.system.cvss; 21 22 import org.openide.ErrorManager; 23 import org.openide.xml.XMLUtil; 24 import org.openide.filesystems.FileLock; 25 import org.openide.filesystems.FileObject; 26 import org.openide.filesystems.Repository; 27 import org.openide.modules.ModuleInstall; 28 import org.openide.util.RequestProcessor; 29 import org.openide.util.NbBundle; 30 import org.w3c.dom.*; 31 import org.xml.sax.*; 32 33 import javax.xml.parsers.DocumentBuilderFactory ; 34 import javax.xml.parsers.DocumentBuilder ; 35 import javax.xml.parsers.ParserConfigurationException ; 36 import javax.swing.*; 37 import java.io.OutputStream ; 38 import java.io.InputStream ; 39 import java.io.IOException ; 40 import java.io.ByteArrayInputStream ; 41 42 51 public final class ModuleLifecycleManager extends ModuleInstall implements ErrorHandler, EntityResolver { 52 53 static final String [] vcsGenericModules = { 54 "org.netbeans.modules.vcs.advanced", "org.netbeans.modules.vcs.profiles.cvsprofiles", "org.netbeans.modules.vcs.profiles.vss", "org.netbeans.modules.vcs.profiles.pvcs", "org.netbeans.modules.vcs.profiles.subversion", "org.netbeans.modules.vcs.profiles.teamware" }; 61 62 public void restored() { 63 disableOldModules(); 64 } 65 66 private void disableOldModules() { 67 Runnable runnable = new Runnable () { 68 public void run() { 69 boolean notified = false; 70 outter: for (int i = 0; i < vcsGenericModules.length; i++) { 71 FileLock lock = null; 72 OutputStream os = null; 73 try { 74 String newModule = vcsGenericModules[i]; 75 String newModuleXML = "Modules/" + newModule.replace('.', '-') + ".xml"; FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(newModuleXML); 77 if (fo == null) continue; 78 Document document = readModuleDocument(fo); 79 80 NodeList list = document.getDocumentElement().getElementsByTagName("param"); int n = list.getLength(); 82 for (int j = 0; j < n; j++) { 83 Element node = (Element) list.item(j); 84 if ("enabled".equals(node.getAttribute("name"))) { Text text = (Text) node.getChildNodes().item(0); 86 String value = text.getNodeValue(); 87 if ("true".equals(value)) { text.setNodeValue("false"); break; 90 } else { 91 continue outter; 92 } 93 } 94 } 95 if (!notified) { 96 JOptionPane.showMessageDialog(null, 97 NbBundle.getBundle(ModuleLifecycleManager.class).getString("MSG_Install_Warning"), 98 NbBundle.getBundle(ModuleLifecycleManager.class).getString("MSG_Install_Warning_Title"), 99 JOptionPane.WARNING_MESSAGE); 100 notified = true; 101 } 102 lock = fo.lock(); 103 os = fo.getOutputStream(lock); 104 105 XMLUtil.write(document, os, "UTF-8"); } catch (Exception e) { 107 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 108 } finally { 109 if (os != null) try { os.close(); } catch (IOException ex) {} 110 if (lock != null) lock.releaseLock(); 111 } 112 } 113 } 114 }; 115 RequestProcessor.getDefault().post(runnable); 116 } 117 118 private Document readModuleDocument(FileObject fo) throws ParserConfigurationException , SAXException, IOException { 119 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 120 dbf.setValidating(false); 121 DocumentBuilder parser = dbf.newDocumentBuilder(); 122 parser.setEntityResolver(this); 123 parser.setErrorHandler(this); 124 InputStream is = fo.getInputStream(); 125 Document document = parser.parse(is); 126 is.close(); 127 return document; 128 } 129 130 public void uninstalled() { 131 CvsVersioningSystem.getInstance().shutdown(); 132 } 133 134 public InputSource resolveEntity(String publicId, String systemId) { 135 return new InputSource(new ByteArrayInputStream (new byte[0])); 136 } 137 138 public void error(SAXParseException exception) { 139 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception); 140 } 141 142 public void fatalError(SAXParseException exception) { 143 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception); 144 } 145 146 public void warning(SAXParseException exception) { 147 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception); 148 } 149 } 150 | Popular Tags |