KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > RemoteDirectory


1 /*
2  * CVSGrab
3  * Author: Ludovic Claude (ludovicc@users.sourceforge.net)
4  * Distributable under BSD license.
5  */

6
7 package net.sourceforge.cvsgrab;
8
9 import org.apache.commons.logging.Log;
10 import org.w3c.dom.Document JavaDoc;
11
12 import java.io.PrintWriter JavaDoc;
13 import java.util.Vector JavaDoc;
14
15 /**
16  * Represents a directory from the remote CVS server
17  *
18  * @author Ludovic Claude
19  * @created April 19, 2002
20  * @version 1.0
21  */

22
23 public class RemoteDirectory {
24     private Vector JavaDoc _remoteFiles = new Vector JavaDoc();
25     private RemoteRepository _remoteRepository;
26     private String JavaDoc _dirPath;
27     private String JavaDoc _localDir;
28
29     /**
30      * Constructor for the RemoteDirectory object
31      *
32      * @param repository The repository
33      * @param dirPath The name of the directory
34      * @param localDir The local name of the directory
35      */

36     public RemoteDirectory(RemoteRepository repository, String JavaDoc dirPath, String JavaDoc localDir) {
37         _remoteRepository = repository;
38         _dirPath = WebBrowser.forceFinalSlash(dirPath);
39         _localDir = WebBrowser.forceFinalSlash(localDir);
40     }
41
42     /**
43      * Constructor for RemoteDirectory
44      * @param parentDirectory The parent directory
45      * @param name The name of the directory
46      */

47     public RemoteDirectory(RemoteDirectory parentDirectory, String JavaDoc name) {
48         _remoteRepository = parentDirectory.getRemoteRepository();
49         _dirPath = WebBrowser.forceFinalSlash(parentDirectory.getDirectoryPath() + name);
50         _localDir = WebBrowser.forceFinalSlash(parentDirectory.getLocalDir() + name);
51     }
52
53     /**
54      * Gets the url attribute
55      *
56      * @return The url value
57      */

58     public String JavaDoc getUrl() {
59         return _remoteRepository.getDirectoryUrl(_dirPath);
60     }
61
62     /**
63      * Gets the directory path
64      *
65      * @return The directory path
66      */

67     public String JavaDoc getDirectoryPath() {
68         return _dirPath;
69     }
70
71     /**
72      * @return the local name of the directory.
73      */

74     public String JavaDoc getLocalDir() {
75         return _localDir;
76     }
77
78     /**
79      * Gets the remote files attribute
80      *
81      * @return The remoteFiles value
82      */

83     public RemoteFile[] getRemoteFiles() {
84         return (RemoteFile[]) _remoteFiles.toArray(new RemoteFile[_remoteFiles.size()]);
85     }
86
87     /**
88      * @return the remote repository
89      */

90     public RemoteRepository getRemoteRepository() {
91         return _remoteRepository;
92     }
93
94     /**
95      * Registers the remote file in this directory
96      *
97      * @param file The remote file to register
98      */

99     public void registerRemoteFile(RemoteFile file) {
100         _remoteFiles.add(file);
101     }
102
103     /**
104      * Unregisters the remote file
105      *
106      * @param file The remote file to unrgister
107      */

108     public void unregisterRemoteFile(RemoteFile file) {
109         _remoteFiles.remove(file);
110     }
111
112     /**
113      * Load the contents of the web page and upload the set of versioned files and sub directories as needed.
114      */

115     public void loadContents() throws Exception JavaDoc {
116         String JavaDoc url = getUrl();
117         Log log = CVSGrab.getLog();
118         log.info("cvs update: Updating " + getDirectoryPath());
119         log.debug("Loading url " + url);
120         Document JavaDoc doc = WebBrowser.getInstance().getDocument(url);
121         RemoteFile[] files = _remoteRepository.getWebInterface().getFiles(doc);
122         for (int i = 0; i < files.length; i++) {
123             RemoteFile file = files[i];
124             file.setDirectory(this);
125             file.grab(_remoteRepository.getLocalRepository());
126         }
127         String JavaDoc[] directories = _remoteRepository.getWebInterface().getDirectories(doc);
128         for (int i = 0; i < directories.length; i++) {
129             _remoteRepository.registerDirectoryToProcess(new RemoteDirectory(this, directories[i]));
130         }
131     }
132
133     /**
134      * Diff the contents of the repository and store the diffs in the file
135      * @param writer
136      */

137     public void diffContents(PrintWriter JavaDoc writer) throws Exception JavaDoc {
138         String JavaDoc url = getUrl();
139         Log log = CVSGrab.getLog();
140         log.info("cvs update: Updating " + getDirectoryPath());
141         Document JavaDoc doc = WebBrowser.getInstance().getDocument(url);
142         RemoteFile[] files = _remoteRepository.getWebInterface().getFiles(doc);
143         for (int i = 0; i < files.length; i++) {
144             RemoteFile file = files[i];
145             file.setDirectory(this);
146             file.diff(_remoteRepository.getLocalRepository(), writer, _remoteRepository.getWebInterface().getGrabber());
147         }
148         String JavaDoc[] directories = _remoteRepository.getWebInterface().getDirectories(doc);
149         for (int i = 0; i < directories.length; i++) {
150             _remoteRepository.registerDirectoryToProcess(new RemoteDirectory(this, directories[i]));
151         }
152     }
153
154     /**
155      * {@inheritDoc}
156      * @return a string representation
157      */

158     public String JavaDoc toString() {
159         return getDirectoryPath();
160     }
161
162 }
163
Popular Tags