KickJava   Java API By Example, From Geeks To Geeks.

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


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

6 package net.sourceforge.cvsgrab;
7
8 import java.util.Iterator JavaDoc;
9 import java.util.Vector JavaDoc;
10
11 /**
12  * Represents the remote repository available via the ViewCVS web interface.
13  *
14  * @author Ludovic Claude
15  * @created April 16, 2002
16  * @version 1.0
17  */

18
19 public class RemoteRepository {
20
21     private Vector JavaDoc _remoteDirectories = new Vector JavaDoc();
22     private Vector JavaDoc _directoriesToProcess = new Vector JavaDoc();
23
24     private String JavaDoc _rootUrl;
25     private LocalRepository _localRepository;
26     private CvsWebInterface _webInterface;
27
28     /**
29      * Constructor for the RemoteRepository object
30      *
31      * @param rootUrl Description of the Parameter
32      * @param localRepository Description of the Parameter
33      */

34     public RemoteRepository(String JavaDoc rootUrl, LocalRepository localRepository) {
35         this._rootUrl = rootUrl;
36         this._localRepository = localRepository;
37     }
38
39     /**
40      * Gets the root url attribute
41      *
42      * @return The rootUrl value
43      */

44     public String JavaDoc getRootUrl() {
45         return _rootUrl;
46     }
47
48     /**
49      * Gets the local repository attribute
50      *
51      * @return The localRepository value
52      */

53     public LocalRepository getLocalRepository() {
54         return _localRepository;
55     }
56     
57     /**
58      * Gets the remote directory attribute
59      *
60      * @param dirPath The directory path, relative to the root url
61      * @return The remoteDirectory value
62      */

63     public RemoteDirectory getRemoteDirectory(String JavaDoc dirPath) {
64         for (Iterator JavaDoc i = _remoteDirectories.iterator(); i.hasNext(); ) {
65             RemoteDirectory remoteDir = (RemoteDirectory) i.next();
66             if (remoteDir.getDirectoryPath().equals(dirPath)) {
67                 return remoteDir;
68             }
69         }
70         return null;
71     }
72
73     /**
74      * @return the web interface
75      */

76     public CvsWebInterface getWebInterface() {
77         return _webInterface;
78     }
79     
80     /**
81      * Sets the web interface
82      *
83      * @param webInterface the web interface
84      */

85     public void setWebInterface(CvsWebInterface webInterface) {
86         _webInterface = webInterface;
87     }
88
89     /**
90      * Registers a directory to process
91      *
92      * @param remoteDir The remote directory to register
93      */

94     public void registerDirectoryToProcess(RemoteDirectory remoteDir) {
95         if (getRemoteDirectory(remoteDir.getDirectoryPath()) != null) {
96             return;
97         }
98         _remoteDirectories.add(remoteDir);
99         _directoriesToProcess.add(remoteDir);
100         _localRepository.add(remoteDir);
101     }
102
103     /**
104      * @return true if there are remote directories that need to be processed
105      */

106     public boolean hasDirectoryToProcess() {
107         return (_directoriesToProcess.size() > 0);
108     }
109
110     /**
111      * @return the next directory to process, and remove it from the list of directories to process
112      */

113     public RemoteDirectory nextDirectoryToProcess() {
114         if (!_directoriesToProcess.isEmpty()) {
115             RemoteDirectory rDir = (RemoteDirectory) _directoriesToProcess.get(0);
116             _directoriesToProcess.remove(0);
117             return rDir;
118         }
119         return null;
120     }
121
122     /**
123      * @param directoryName The name of the directory
124      * @return The full url to use to access the contents of the directory
125      */

126     public String JavaDoc getDirectoryUrl(String JavaDoc directoryName) {
127         String JavaDoc url = _webInterface.getDirectoryUrl(getRootUrl(), directoryName);
128         return url;
129     }
130
131     /**
132      * @param file
133      * @return
134      */

135     public String JavaDoc getDownloadUrl(RemoteFile file) {
136         String JavaDoc url = _webInterface.getDownloadUrl(file);
137         return url;
138     }
139
140 }
141
Popular Tags