001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.versioning.system.cvss;
043:
044: import org.openide.ErrorManager;
045: import org.openide.xml.XMLUtil;
046: import org.openide.filesystems.FileLock;
047: import org.openide.filesystems.FileObject;
048: import org.openide.filesystems.Repository;
049: import org.openide.modules.ModuleInstall;
050: import org.openide.util.RequestProcessor;
051: import org.openide.util.NbBundle;
052: import org.w3c.dom.*;
053: import org.xml.sax.*;
054:
055: import javax.xml.parsers.DocumentBuilderFactory;
056: import javax.xml.parsers.DocumentBuilder;
057: import javax.xml.parsers.ParserConfigurationException;
058: import javax.swing.*;
059: import java.io.OutputStream;
060: import java.io.InputStream;
061: import java.io.IOException;
062: import java.io.ByteArrayInputStream;
063:
064: /**
065: * Handles module events distributed by NetBeans module
066: * framework.
067: *
068: * <p>It's registered and instantiated from module manifest.
069: *
070: * @author Petr Kuzel
071: * @author Maros Sandor
072: */
073: public final class ModuleLifecycleManager extends ModuleInstall
074: implements ErrorHandler, EntityResolver {
075:
076: static final String[] vcsGenericModules = {
077: "org.netbeans.modules.vcs.advanced", // NOI18N
078: "org.netbeans.modules.vcs.profiles.cvsprofiles", // NOI18N
079: "org.netbeans.modules.vcs.profiles.vss", // NOI18N
080: "org.netbeans.modules.vcs.profiles.pvcs", // NOI18N
081: "org.netbeans.modules.vcs.profiles.subversion", // NOI18N
082: "org.netbeans.modules.vcs.profiles.teamware" // NOI18N
083: };
084:
085: public void restored() {
086: disableOldModules();
087: }
088:
089: private void disableOldModules() {
090: Runnable runnable = new Runnable() {
091: public void run() {
092: boolean notified = false;
093: outter: for (int i = 0; i < vcsGenericModules.length; i++) {
094: FileLock lock = null;
095: OutputStream os = null;
096: try {
097: String newModule = vcsGenericModules[i];
098: String newModuleXML = "Modules/"
099: + newModule.replace('.', '-') + ".xml"; // NOI18N
100: FileObject fo = Repository.getDefault()
101: .getDefaultFileSystem().findResource(
102: newModuleXML);
103: if (fo == null)
104: continue;
105: Document document = readModuleDocument(fo);
106:
107: NodeList list = document.getDocumentElement()
108: .getElementsByTagName("param"); // NOI18N
109: int n = list.getLength();
110: for (int j = 0; j < n; j++) {
111: Element node = (Element) list.item(j);
112: if ("enabled".equals(node
113: .getAttribute("name"))) { // NOI18N
114: Text text = (Text) node.getChildNodes()
115: .item(0);
116: String value = text.getNodeValue();
117: if ("true".equals(value)) { // NOI18N
118: text.setNodeValue("false"); // NOI18N
119: break;
120: } else {
121: continue outter;
122: }
123: }
124: }
125: if (!notified) {
126: JOptionPane
127: .showMessageDialog(
128: null,
129: NbBundle
130: .getBundle(
131: ModuleLifecycleManager.class)
132: .getString(
133: "MSG_Install_Warning"),
134: NbBundle
135: .getBundle(
136: ModuleLifecycleManager.class)
137: .getString(
138: "MSG_Install_Warning_Title"),
139: JOptionPane.WARNING_MESSAGE);
140: notified = true;
141: }
142: lock = fo.lock();
143: os = fo.getOutputStream(lock);
144:
145: XMLUtil.write(document, os, "UTF-8"); // NOI18N
146: } catch (Exception e) {
147: ErrorManager.getDefault().notify(
148: ErrorManager.INFORMATIONAL, e);
149: } finally {
150: if (os != null)
151: try {
152: os.close();
153: } catch (IOException ex) {
154: }
155: if (lock != null)
156: lock.releaseLock();
157: }
158: }
159: }
160: };
161: RequestProcessor.getDefault().post(runnable);
162: }
163:
164: private Document readModuleDocument(FileObject fo)
165: throws ParserConfigurationException, SAXException,
166: IOException {
167: DocumentBuilderFactory dbf = DocumentBuilderFactory
168: .newInstance();
169: dbf.setValidating(false);
170: DocumentBuilder parser = dbf.newDocumentBuilder();
171: parser.setEntityResolver(this );
172: parser.setErrorHandler(this );
173: InputStream is = fo.getInputStream();
174: Document document = parser.parse(is);
175: is.close();
176: return document;
177: }
178:
179: public void uninstalled() {
180: CvsVersioningSystem.getInstance().shutdown();
181: }
182:
183: public InputSource resolveEntity(String publicId, String systemId) {
184: return new InputSource(new ByteArrayInputStream(new byte[0]));
185: }
186:
187: public void error(SAXParseException exception) {
188: ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
189: exception);
190: }
191:
192: public void fatalError(SAXParseException exception) {
193: ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
194: exception);
195: }
196:
197: public void warning(SAXParseException exception) {
198: ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
199: exception);
200: }
201: }
|