KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > CvsLiteAdminHandler


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;
21
22 import org.netbeans.lib.cvsclient.admin.StandardAdminHandler;
23 import org.netbeans.lib.cvsclient.admin.AdminHandler;
24 import org.netbeans.lib.cvsclient.admin.Entry;
25 import org.netbeans.lib.cvsclient.command.GlobalOptions;
26 import org.netbeans.modules.versioning.util.Utils;
27 import org.openide.filesystems.FileUtil;
28
29 import java.io.*;
30 import java.util.*;
31
32 /**
33  * Behaves as standard admin handler except for deleted files and directories where it acts as if the files
34  * were removed with 'cvs remove'.
35  *
36  * @author Maros Sandor
37  */

38 class CvsLiteAdminHandler implements AdminHandler {
39
40     static final String JavaDoc INVALID_METADATA_MARKER = "invalid-metadata"; // NOI18N
41

42     private static final String JavaDoc INVALID_METADATA_MARKER_PATH = CvsVersioningSystem.FILENAME_CVS + "/" + INVALID_METADATA_MARKER; // NOI18N
43

44     private StandardAdminHandler stdHandler;
45
46     public CvsLiteAdminHandler() {
47         this.stdHandler = new StandardAdminHandler();
48     }
49
50     private void checkForInvalidMetadata(File dir) {
51         File marker = new File(dir, INVALID_METADATA_MARKER_PATH);
52         if (marker.exists()) {
53             Utils.deleteRecursively(marker.getParentFile());
54         }
55     }
56
57     public void updateAdminData(String JavaDoc localDirectory, String JavaDoc repositoryPath,
58                          Entry entry, GlobalOptions globalOptions)
59             throws IOException {
60         checkForInvalidMetadata(new File(localDirectory));
61         stdHandler.updateAdminData(localDirectory, repositoryPath, entry, globalOptions);
62     }
63
64     public Entry getEntry(File file) throws IOException {
65         checkForInvalidMetadata(file.getParentFile());
66         return stdHandler.getEntry(file);
67     }
68
69     public boolean exists(File file) {
70         if (file.exists()) return true;
71         if (CvsVersioningSystem.FILENAME_CVS.equals(file.getName())) file = file.getParentFile(); // NOI18N
72
return false;
73     }
74
75     public Iterator<Entry> getEntries(File directory) throws IOException {
76         checkForInvalidMetadata(directory);
77         if (new File(directory, CvsVersioningSystem.FILENAME_CVS).isDirectory()) {
78             return stdHandler.getEntries(directory);
79         }
80         directory = FileUtil.normalizeFile(directory);
81         return stdHandler.getEntries(directory);
82     }
83     
84     public Entry[] getEntriesAsArray(File directory)
85             throws IOException {
86         checkForInvalidMetadata(directory);
87         List<Entry> entries = new ArrayList<Entry>();
88         for (Iterator<Entry> i = getEntries(directory); i.hasNext(); ) {
89             entries.add(i.next());
90         }
91         return entries.toArray(new Entry[entries.size()]);
92     }
93
94     public void setEntry(File file, Entry entry) throws IOException {
95         checkForInvalidMetadata(file.getParentFile());
96         // create missing directories beforehand
97
File adminDir = new File(file.getParentFile(), CvsVersioningSystem.FILENAME_CVS);
98         createAdminDirs(adminDir);
99         stdHandler.setEntry(file, entry);
100     }
101
102     /**
103      * Restores all administration files in the given directory and all parent directories recursively.
104      *
105      * @param adminDir directory to restore
106      * @throws IOException
107      */

108     private void createAdminDirs(File adminDir) throws IOException {
109         if (!adminDir.exists()) {
110             if (adminDir.getParentFile() != null && adminDir.getParentFile().getParentFile() != null) {
111                 createAdminDirs(new File(adminDir.getParentFile().getParentFile(), CvsVersioningSystem.FILENAME_CVS));
112             }
113         }
114     }
115
116     public String JavaDoc getRepositoryForDirectory(String JavaDoc directory, String JavaDoc repository)
117             throws IOException {
118
119         checkForInvalidMetadata(new File(directory));
120         // TODO consult MetadataAttic.getScheduledRepository
121

122         File dirFile = new File(directory);
123         if (dirFile.exists()) return stdHandler.getRepositoryForDirectory(directory, repository);
124         
125         return stdHandler.getRepositoryForDirectory(directory, repository);
126     }
127
128     public void removeEntry(File file) throws IOException {
129         File parent = file.getParentFile();
130         checkForInvalidMetadata(parent);
131         stdHandler.removeEntry(file);
132     }
133
134     public Set getAllFiles(File directory) throws IOException {
135         checkForInvalidMetadata(directory);
136         // TODO: override
137
return stdHandler.getAllFiles(directory);
138     }
139
140     public String JavaDoc getStickyTagForDirectory(File directory) {
141         checkForInvalidMetadata(directory);
142         return stdHandler.getStickyTagForDirectory(directory);
143     }
144 }
145
Popular Tags