versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/ModuleLifecycleManager.java
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
30 * If you wish your version of this file to be governed by only the CDDL
31 * or only the GPL Version 2, indicate your decision by adding
32 * "[Contributor] elects to include this software in this distribution
33 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34 * single choice of license, a recipient has the option to distribute
35 * your version of this file under either the CDDL, the GPL Version 2 or
36 * to extend the choice of license to its licensees as provided above.
37 * However, if you add GPL Version 2 code and therefore, elected the GPL
38 * Version 2 license, then the option applies only if the new code is
39 * made subject to such option by the copyright holder.
42 package org.netbeans.modules.versioning.system.cvss;
44 import org.openide.ErrorManager;
45 import org.openide.xml.XMLUtil;
46 import org.openide.filesystems.FileLock;
47 import org.openide.filesystems.FileObject;
48 import org.openide.modules.ModuleInstall;
49 import org.openide.util.RequestProcessor;
50 import org.openide.util.NbBundle;
54 import javax.xml.parsers.DocumentBuilderFactory;
55 import javax.xml.parsers.DocumentBuilder;
56 import javax.xml.parsers.ParserConfigurationException;
58 import java.io.OutputStream;
59 import java.io.InputStream;
60 import java.io.IOException;
61 import java.io.ByteArrayInputStream;
62 import org.openide.filesystems.FileUtil;
65 * Handles module events distributed by NetBeans module
68 * <p>It's registered and instantiated from module manifest.
71 * @author Maros Sandor
73 public final class ModuleLifecycleManager extends ModuleInstall implements ErrorHandler, EntityResolver {
75 static final String [] vcsGenericModules = {
76 "org.netbeans.modules.vcs.advanced", // NOI18N
77 "org.netbeans.modules.vcs.profiles.cvsprofiles", // NOI18N
78 "org.netbeans.modules.vcs.profiles.vss", // NOI18N
79 "org.netbeans.modules.vcs.profiles.pvcs", // NOI18N
80 "org.netbeans.modules.vcs.profiles.subversion", // NOI18N
81 "org.netbeans.modules.vcs.profiles.teamware" // NOI18N
84 public void restored() {
88 private void disableOldModules() {
89 Runnable runnable = new Runnable() {
91 boolean notified = false;
92 outter: for (int i = 0; i < vcsGenericModules.length; i++) {
94 OutputStream os = null;
96 String newModule = vcsGenericModules[i];
97 String newModuleXML = "Modules/" + newModule.replace('.', '-') + ".xml"; // NOI18N
98 FileObject fo = FileUtil.getConfigFile(newModuleXML);
99 if (fo == null) continue;
100 Document document = readModuleDocument(fo);
102 NodeList list = document.getDocumentElement().getElementsByTagName("param"); // NOI18N
103 int n = list.getLength();
104 for (int j = 0; j < n; j++) {
105 Element node = (Element) list.item(j);
106 if ("enabled".equals(node.getAttribute("name"))) { // NOI18N
107 Text text = (Text) node.getChildNodes().item(0);
108 String value = text.getNodeValue();
109 if ("true".equals(value)) { // NOI18N
110 text.setNodeValue("false"); // NOI18N
118 JOptionPane.showMessageDialog(null,
119 NbBundle.getBundle(ModuleLifecycleManager.class).getString("MSG_Install_Warning"),
120 NbBundle.getBundle(ModuleLifecycleManager.class).getString("MSG_Install_Warning_Title"),
121 JOptionPane.WARNING_MESSAGE);
125 os = fo.getOutputStream(lock);
127 XMLUtil.write(document, os, "UTF-8"); // NOI18N
128 } catch (Exception e) {
129 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
131 if (os != null) try { os.close(); } catch (IOException ex) {}
132 if (lock != null) lock.releaseLock();
137 RequestProcessor.getDefault().post(runnable);
140 private Document readModuleDocument(FileObject fo) throws ParserConfigurationException, SAXException, IOException {
141 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
142 dbf.setValidating(false);
143 DocumentBuilder parser = dbf.newDocumentBuilder();
144 parser.setEntityResolver(this);
145 parser.setErrorHandler(this);
146 InputStream is = fo.getInputStream();
147 Document document = parser.parse(is);
152 public void uninstalled() {
153 CvsVersioningSystem.getInstance().shutdown();
156 public InputSource resolveEntity(String publicId, String systemId) {
157 return new InputSource(new ByteArrayInputStream(new byte[0]));
160 public void error(SAXParseException exception) {
161 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception);
164 public void fatalError(SAXParseException exception) {
165 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception);
168 public void warning(SAXParseException exception) {
169 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exception);