1 19 20 package org.netbeans.modules.subversion; 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.teamware" }; 60 61 public void restored() { 62 disableOldModules(); 63 } 64 65 private void disableOldModules() { 66 Runnable runnable = new Runnable () { 67 public void run() { 68 boolean notified = false; 69 outter: for (int i = 0; i < vcsGenericModules.length; i++) { 70 FileLock lock = null; 71 OutputStream os = null; 72 try { 73 String newModule = vcsGenericModules[i]; 74 String newModuleXML = "Modules/" + newModule.replace('.', '-') + ".xml"; FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(newModuleXML); 76 if (fo == null) continue; 77 Document document = readModuleDocument(fo); 78 79 NodeList list = document.getDocumentElement().getElementsByTagName("param"); int n = list.getLength(); 81 for (int j = 0; j < n; j++) { 82 Element node = (Element) list.item(j); 83 if ("enabled".equals(node.getAttribute("name"))) { Text text = (Text) node.getChildNodes().item(0); 85 String value = text.getNodeValue(); 86 if ("true".equals(value)) { text.setNodeValue("false"); break; 89 } else { 90 continue outter; 91 } 92 } 93 } 94 if (!notified) { 95 JOptionPane.showMessageDialog(null, 96 NbBundle.getBundle(ModuleLifecycleManager.class).getString("MSG_Install_Warning"), NbBundle.getBundle(ModuleLifecycleManager.class).getString("MSG_Install_Warning_Title"), JOptionPane.WARNING_MESSAGE); 99 notified = true; 100 } 101 lock = fo.lock(); 102 os = fo.getOutputStream(lock); 103 104 XMLUtil.write(document, os, "UTF-8"); } catch (Exception e) { 106 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 107 } finally { 108 if (os != null) try { os.close(); } catch (IOException ex) {} 109 if (lock != null) lock.releaseLock(); 110 } 111 } 112 } 113 }; 114 RequestProcessor.getDefault().post(runnable); 115 } 116 117 private Document readModuleDocument(FileObject fo) throws ParserConfigurationException , SAXException, IOException { 118 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 119 dbf.setValidating(false); 120 DocumentBuilder parser = dbf.newDocumentBuilder(); 121 parser.setEntityResolver(this); 122 parser.setErrorHandler(this); 123 InputStream is = fo.getInputStream(); 124 Document document = parser.parse(is); 125 is.close(); 126 return document; 127 } 128 129 public void uninstalled() { 130 Subversion.getInstance().shutdown(); 131 } 132 133 public InputSource resolveEntity(String publicId, String systemId) { 134 return new InputSource(new ByteArrayInputStream (new byte[0])); 135 } 136 137 public void error(SAXParseException exception) { 138 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception); 139 } 140 141 public void fatalError(SAXParseException exception) { 142 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception); 143 } 144 145 public void warning(SAXParseException exception) { 146 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception); 147 } 148 } 149 | Popular Tags |