KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > protocol > URLListerBase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.net.protocol;
23
24 import java.util.Arrays JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 /**
32  * Support class for URLLister's providing protocol independent functionality.
33  *
34  * @author Scott.Stark@jboss.org
35  * @version $Revision: 1958 $
36  */

37 public abstract class URLListerBase implements URLLister
38 {
39    public Collection JavaDoc listMembers (URL JavaDoc baseUrl, String JavaDoc patterns,
40       boolean scanNonDottedSubDirs) throws IOException JavaDoc
41    {
42       // @todo, externalize the separator?
43
StringTokenizer JavaDoc tokens = new StringTokenizer JavaDoc (patterns, ",");
44       String JavaDoc[] members = new String JavaDoc[tokens.countTokens ()];
45       for (int i=0; tokens.hasMoreTokens (); i++)
46       {
47          String JavaDoc token = tokens.nextToken ();
48          // Trim leading/trailing spaces as its unlikely they are meaningful
49
members[i] = token.trim();
50       }
51       URLFilter filter = new URLFilterImpl (members);
52       return listMembers (baseUrl, filter, scanNonDottedSubDirs);
53    }
54
55    public Collection JavaDoc listMembers (URL JavaDoc baseUrl, String JavaDoc patterns) throws IOException JavaDoc
56    {
57       return listMembers (baseUrl, patterns, false);
58    }
59    
60    /**
61     * Inner class representing Filter criteria to be applied to the members
62     * of the returned Collection
63     */

64    public static class URLFilterImpl implements URLFilter
65    {
66       protected boolean allowAll;
67       protected HashSet JavaDoc constants;
68       
69       public URLFilterImpl (String JavaDoc[] patterns)
70       {
71          constants = new HashSet JavaDoc (Arrays.asList (patterns));
72          allowAll = constants.contains ("*");
73       }
74       
75       public boolean accept (URL JavaDoc baseUrl, String JavaDoc name)
76       {
77          if (allowAll)
78          {
79             return true;
80          }
81          if (constants.contains (name))
82          {
83             return true;
84          }
85          return false;
86       }
87    }
88    
89    protected static final URLFilter acceptAllFilter = new URLFilter ()
90    {
91       public boolean accept (URL JavaDoc baseURL, String JavaDoc memberName)
92       {
93          return true;
94       }
95    };
96 }
97
Popular Tags