1 22 package org.apache.webdav.ant; 23 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 import org.apache.commons.httpclient.HttpClient; 29 import org.apache.commons.httpclient.HttpURL; 30 import org.apache.commons.httpclient.URIException; 31 32 import org.apache.tools.ant.BuildException; 33 import org.apache.tools.ant.Project; 34 import org.apache.tools.ant.types.PatternSet; 35 36 38 public class WebdavFileSet { 39 private PatternSet patterns = new PatternSet(); 40 private List patternSets = new ArrayList (); 41 42 private String directory = null; 43 private boolean isCaseSensitive = true; 44 45 private static final String [] DEFAULT_INCLUDES = { 46 "**/*" 47 }; 48 49 public WebdavFileSet() { 50 } 51 52 public CollectionScanner getCollectionScanner( 53 Project project, 54 HttpClient httpClient, 55 HttpURL baseUrl) 56 { 57 validate(); 58 59 CollectionScanner scanner = new CollectionScanner(); 60 61 try { 62 scanner.setBaseURL(Utils.createHttpURL(baseUrl, directory)); 63 } catch (URIException e) { 64 throw new BuildException("Invalid URL. " + e.toString(), e); 65 } 66 scanner.setHttpClient(httpClient); 67 68 scanner.setCaseSensitive(this.isCaseSensitive); 69 70 if (this.patterns.getExcludePatterns(project) == null && 71 this.patterns.getIncludePatterns(project) == null && 72 this.patternSets.size() == 0) { 73 scanner.setIncludes(DEFAULT_INCLUDES); 74 } else { 75 scanner.setExcludes(this.patterns.getExcludePatterns(project)); 76 scanner.setIncludes(this.patterns.getIncludePatterns(project)); 77 for (Iterator i = this.patternSets.iterator(); i.hasNext();) { 78 PatternSet patternSet = (PatternSet)i.next(); 79 scanner.addExcludes(patternSet.getExcludePatterns(project)); 80 scanner.addIncludes(patternSet.getIncludePatterns(project)); 81 } 82 } 83 scanner.scan(); 84 return scanner; 85 } 86 87 protected void validate() { 88 if (this.directory == null) this.directory = ""; 89 } 90 91 95 public void setDir(String dir) { 96 this.directory = dir; 97 if (!this.directory.endsWith("/")) { 98 this.directory += "/"; 99 } 100 if (this.directory.startsWith("/")) { 101 this.directory = this.directory.substring(1); 102 } 103 } 104 105 109 public void setCasesensitive(boolean b) { 110 this.isCaseSensitive = b; 111 } 112 113 116 public PatternSet.NameEntry createInclude() { 117 return this.patterns.createInclude(); 118 } 119 120 123 public PatternSet.NameEntry createIncludesFile() { 124 return this.patterns.createIncludesFile(); 125 } 126 127 130 public PatternSet.NameEntry createExclude() { 131 return this.patterns.createExclude(); 132 } 133 134 137 public PatternSet.NameEntry createExcludesFile() { 138 return this.patterns.createExcludesFile(); 139 } 140 141 144 public PatternSet createPatternSet() { 145 PatternSet patterns = new PatternSet(); 146 this.patternSets.add(patterns); 147 return patterns; 148 } 149 } 150 | Popular Tags |