KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webdav > ant > WebdavFileSet


1 // vi: set ts=3 sw=3:
2
/*
3  * $Header: /home/cvs/jakarta-slide/webdavclient/ant/src/java/org/apache/webdav/ant/WebdavFileSet.java,v 1.3.2.1 2004/08/15 13:01:15 luetzkendorf Exp $
4  * $Revision: 1.3.2.1 $
5  * $Date: 2004/08/15 13:01:15 $
6  * ========================================================================
7  * Copyright 2004 The Apache Software Foundation
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ========================================================================
21  */

22 package org.apache.webdav.ant;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
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 /**
37  */

38 public class WebdavFileSet {
39    private PatternSet patterns = new PatternSet();
40    private List JavaDoc patternSets = new ArrayList JavaDoc();
41    
42    private String JavaDoc directory = null;
43    private boolean isCaseSensitive = true;
44    
45    private static final String JavaDoc[] 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 JavaDoc 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    /**
92     * Sets the <code>dir</code> attribute.
93     * @param dir
94     */

95    public void setDir(String JavaDoc 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    /**
106     * Sets the <code>casesensitive</code> attribute.
107     * @param b
108     */

109    public void setCasesensitive(boolean b) {
110       this.isCaseSensitive = b;
111    }
112    
113    /**
114     * Creates nested include and adds it to the patterns.
115     */

116    public PatternSet.NameEntry createInclude() {
117        return this.patterns.createInclude();
118    }
119
120    /**
121     * Creates nested includesfile and adds it to the patterns.
122     */

123    public PatternSet.NameEntry createIncludesFile() {
124        return this.patterns.createIncludesFile();
125    }
126
127    /**
128     * Creates nested exclude and adds it to the patterns.
129     */

130    public PatternSet.NameEntry createExclude() {
131        return this.patterns.createExclude();
132    }
133
134    /**
135     * Creates nested excludesfile and adds it to the patterns.
136     */

137    public PatternSet.NameEntry createExcludesFile() {
138        return this.patterns.createExcludesFile();
139    }
140    
141    /**
142     * Creates a nested patternset.
143     */

144    public PatternSet createPatternSet() {
145        PatternSet patterns = new PatternSet();
146        this.patternSets.add(patterns);
147        return patterns;
148    }
149 }
150
Popular Tags