1 6 7 package net.sourceforge.cvsgrab; 8 9 import org.apache.commons.logging.Log; 10 import org.w3c.dom.Document ; 11 12 import java.io.PrintWriter ; 13 import java.util.Vector ; 14 15 22 23 public class RemoteDirectory { 24 private Vector _remoteFiles = new Vector (); 25 private RemoteRepository _remoteRepository; 26 private String _dirPath; 27 private String _localDir; 28 29 36 public RemoteDirectory(RemoteRepository repository, String dirPath, String localDir) { 37 _remoteRepository = repository; 38 _dirPath = WebBrowser.forceFinalSlash(dirPath); 39 _localDir = WebBrowser.forceFinalSlash(localDir); 40 } 41 42 47 public RemoteDirectory(RemoteDirectory parentDirectory, String name) { 48 _remoteRepository = parentDirectory.getRemoteRepository(); 49 _dirPath = WebBrowser.forceFinalSlash(parentDirectory.getDirectoryPath() + name); 50 _localDir = WebBrowser.forceFinalSlash(parentDirectory.getLocalDir() + name); 51 } 52 53 58 public String getUrl() { 59 return _remoteRepository.getDirectoryUrl(_dirPath); 60 } 61 62 67 public String getDirectoryPath() { 68 return _dirPath; 69 } 70 71 74 public String getLocalDir() { 75 return _localDir; 76 } 77 78 83 public RemoteFile[] getRemoteFiles() { 84 return (RemoteFile[]) _remoteFiles.toArray(new RemoteFile[_remoteFiles.size()]); 85 } 86 87 90 public RemoteRepository getRemoteRepository() { 91 return _remoteRepository; 92 } 93 94 99 public void registerRemoteFile(RemoteFile file) { 100 _remoteFiles.add(file); 101 } 102 103 108 public void unregisterRemoteFile(RemoteFile file) { 109 _remoteFiles.remove(file); 110 } 111 112 115 public void loadContents() throws Exception { 116 String url = getUrl(); 117 Log log = CVSGrab.getLog(); 118 log.info("cvs update: Updating " + getDirectoryPath()); 119 log.debug("Loading url " + url); 120 Document 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 [] 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 137 public void diffContents(PrintWriter writer) throws Exception { 138 String url = getUrl(); 139 Log log = CVSGrab.getLog(); 140 log.info("cvs update: Updating " + getDirectoryPath()); 141 Document 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 [] 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 158 public String toString() { 159 return getDirectoryPath(); 160 } 161 162 } 163 | Popular Tags |