KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > selectors > Kit


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.versioning.system.cvss.ui.selectors;
21
22 import org.openide.ErrorManager;
23 import org.openide.filesystems.FileUtil;
24 import org.netbeans.lib.cvsclient.Client;
25 import org.netbeans.lib.cvsclient.CVSRoot;
26 import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
27 import org.netbeans.lib.cvsclient.connection.Connection;
28 import org.netbeans.modules.versioning.system.cvss.ClientRuntime;
29
30 import java.io.File JavaDoc;
31 import java.io.IOException JavaDoc;
32
33 /**
34  * Utilities
35  *
36  * @author Petr Kuzel
37  */

38 public final class Kit implements Client.Factory {
39
40     private CVSRoot factory_cvsRoot;
41
42     /** Creates Kit that servers as Client.Factory */
43     private Kit(CVSRoot factory_cvsRoot) {
44         this.factory_cvsRoot = factory_cvsRoot;
45     }
46
47     public static File JavaDoc createTmpFolder() {
48         String JavaDoc tmpDir = System.getProperty("java.io.tmpdir"); // NOI18N
49
File JavaDoc tmpFolder = new File JavaDoc(tmpDir);
50         File JavaDoc checkoutFolder = null;
51         try {
52             // generate unique name for checkout folder
53
File JavaDoc tmp = File.createTempFile("checkout", "", tmpFolder); // NOI18N
54
if (tmp.delete() == false) {
55                 return checkoutFolder;
56             }
57             if (tmp.mkdirs() == false) {
58                 return checkoutFolder;
59             }
60             tmp.deleteOnExit();
61             checkoutFolder = FileUtil.normalizeFile(tmp);
62         } catch (IOException JavaDoc e) {
63             ErrorManager err = ErrorManager.getDefault();
64             err.annotate(e, org.openide.util.NbBundle.getMessage(Kit.class, "BK2018"));
65             err.notify(e);
66         }
67         return checkoutFolder;
68     }
69
70     public static void deleteRecursively(File JavaDoc file) {
71         if (file == null) return;
72         if (file.isDirectory()) {
73             File JavaDoc[] files = file.listFiles();
74             for (int i = 0; i < files.length; i++) {
75                 File JavaDoc next = files[i];
76                 deleteRecursively(next); // RECURSION
77
}
78             file.delete();
79         }
80     }
81
82     /** Creates client suitable for read only operations */
83     public static Client createClient(CVSRoot cvsRoot) {
84         Connection connection = ClientRuntime.setupConnection(cvsRoot);
85         Client client = new Client(connection, new StandardAdminHandler());
86         return client;
87     }
88
89     public static Client.Factory createClientFactory(CVSRoot cvsRoot) {
90         return new Kit(cvsRoot);
91     }
92
93     public Client createClient() {
94         return createClient(factory_cvsRoot);
95     }
96 }
97
Popular Tags