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.subversion;
043:
044: import org.openide.xml.XMLUtil;
045: import org.openide.filesystems.FileLock;
046: import org.openide.filesystems.FileObject;
047: import org.openide.filesystems.Repository;
048: import org.openide.modules.ModuleInstall;
049: import org.openide.util.RequestProcessor;
050: import org.openide.util.NbBundle;
051: import org.w3c.dom.*;
052: import org.xml.sax.*;
053:
054: import javax.xml.parsers.DocumentBuilderFactory;
055: import javax.xml.parsers.DocumentBuilder;
056: import javax.xml.parsers.ParserConfigurationException;
057: import javax.swing.*;
058: import java.io.OutputStream;
059: import java.io.InputStream;
060: import java.io.IOException;
061: import java.io.ByteArrayInputStream;
062: import java.util.logging.Level;
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.teamware" // NOI18N
082: };
083:
084: public void restored() {
085: disableOldModules();
086: }
087:
088: private void disableOldModules() {
089: Runnable runnable = new Runnable() {
090: public void run() {
091: boolean notified = false;
092: outter: for (int i = 0; i < vcsGenericModules.length; i++) {
093: FileLock lock = null;
094: OutputStream os = null;
095: try {
096: String newModule = vcsGenericModules[i];
097: String newModuleXML = "Modules/"
098: + newModule.replace('.', '-') + ".xml"; // NOI18N
099: FileObject fo = Repository.getDefault()
100: .getDefaultFileSystem().findResource(
101: newModuleXML);
102: if (fo == null)
103: continue;
104: Document document = readModuleDocument(fo);
105:
106: NodeList list = document.getDocumentElement()
107: .getElementsByTagName("param"); // NOI18N
108: int n = list.getLength();
109: for (int j = 0; j < n; j++) {
110: Element node = (Element) list.item(j);
111: if ("enabled".equals(node
112: .getAttribute("name"))) { // NOI18N
113: Text text = (Text) node.getChildNodes()
114: .item(0);
115: String value = text.getNodeValue();
116: if ("true".equals(value)) { // NOI18N
117: text.setNodeValue("false"); // NOI18N
118: break;
119: } else {
120: continue outter;
121: }
122: }
123: }
124: if (!notified) {
125: JOptionPane
126: .showMessageDialog(
127: null,
128: NbBundle
129: .getBundle(
130: ModuleLifecycleManager.class)
131: .getString(
132: "MSG_Install_Warning"), // NOI18N
133: NbBundle
134: .getBundle(
135: ModuleLifecycleManager.class)
136: .getString(
137: "MSG_Install_Warning_Title"), // NOI18N
138: JOptionPane.WARNING_MESSAGE);
139: notified = true;
140: }
141: lock = fo.lock();
142: os = fo.getOutputStream(lock);
143:
144: XMLUtil.write(document, os, "UTF-8"); // NOI18N
145: } catch (Exception e) {
146: Subversion.LOG.log(Level.INFO, e.getMessage(),
147: e);
148: } finally {
149: if (os != null)
150: try {
151: os.close();
152: } catch (IOException ex) {
153: }
154: if (lock != null)
155: lock.releaseLock();
156: }
157: }
158: }
159: };
160: RequestProcessor.getDefault().post(runnable);
161: }
162:
163: private Document readModuleDocument(FileObject fo)
164: throws ParserConfigurationException, SAXException,
165: IOException {
166: DocumentBuilderFactory dbf = DocumentBuilderFactory
167: .newInstance();
168: dbf.setValidating(false);
169: DocumentBuilder parser = dbf.newDocumentBuilder();
170: parser.setEntityResolver(this );
171: parser.setErrorHandler(this );
172: InputStream is = fo.getInputStream();
173: Document document = parser.parse(is);
174: is.close();
175: return document;
176: }
177:
178: public void uninstalled() {
179: Subversion.getInstance().shutdown();
180: }
181:
182: public InputSource resolveEntity(String publicId, String systemId) {
183: return new InputSource(new ByteArrayInputStream(new byte[0]));
184: }
185:
186: public void error(SAXParseException exception) {
187: Subversion.LOG.log(Level.INFO, exception.getMessage(),
188: exception);
189: }
190:
191: public void fatalError(SAXParseException exception) {
192: Subversion.LOG.log(Level.INFO, exception.getMessage(),
193: exception);
194: }
195:
196: public void warning(SAXParseException exception) {
197: Subversion.LOG.log(Level.INFO, exception.getMessage(),
198: exception);
199: }
200: }
|