You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2003/06/15 20:05:22 UTC

cvs commit: jakarta-james/src/java/org/apache/james/nntpserver/repository NNTPRepositoryImpl.java

noel        2003/06/15 11:05:22

  Modified:    src/java/org/apache/james/nntpserver/repository Tag:
                        branch_2_1_fcs NNTPRepositoryImpl.java
  Log:
  Completed the filtering introduced by Peter in revision 1.11.4.3.  Filtering is now conditional.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.11.4.4  +21 -7     jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java
  
  Index: NNTPRepositoryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPRepositoryImpl.java,v
  retrieving revision 1.11.4.3
  retrieving revision 1.11.4.4
  diff -u -r1.11.4.3 -r1.11.4.4
  --- NNTPRepositoryImpl.java	26 Mar 2003 06:31:17 -0000	1.11.4.3
  +++ NNTPRepositoryImpl.java	15 Jun 2003 18:05:22 -0000	1.11.4.4
  @@ -134,6 +134,11 @@
       private HashMap groupNameMap = null;
   
       /**
  +     * Restrict use to newsgroups specified in config only
  +     */
  +    private boolean definedGroupsOnly = false;
  +
  +    /**
        * The root path as a String.
        */
       private String rootPathString = null;
  @@ -212,6 +217,7 @@
               getLogger().debug("NNTP repository article ID path URL is " + articleIdPathString);
           }
           Configuration newsgroupConfiguration = configuration.getChild("newsgroups");
  +        definedGroupsOnly = newsgroupConfiguration.getAttributeAsBoolean("only", false);
           groupNameMap = new HashMap();
           if ( newsgroupConfiguration != null ) {
               Configuration[] children = newsgroupConfiguration.getChildren("newsgroup");
  @@ -310,7 +316,7 @@
        * @see org.apache.james.nntpserver.repository.NNTPRepository#getGroup(String)
        */
       public NNTPGroup getGroup(String groupName) {
  -        if (groupNameMap.get(groupName) == null) {
  +        if (definedGroupsOnly && groupNameMap.get(groupName) == null) {
               if (getLogger().isDebugEnabled()) {
                   getLogger().debug(groupName + " is not a newsgroup hosted on this server.");
               }
  @@ -386,13 +392,22 @@
           }
       }
   
  +    class GroupFilter implements java.io.FilenameFilter {
  +        public boolean accept(java.io.File dir, String name) {
  +            if (getLogger().isDebugEnabled()) {
  +                getLogger().debug(((definedGroupsOnly ? groupNameMap.containsKey(name) : true) ? "Accepting ": "Rejecting") + name);
  +            }
  +
  +            return definedGroupsOnly ? groupNameMap.containsKey(name) : true;
  +        }
  +    }
  +
       /**
        * @see org.apache.james.nntpserver.repository.NNTPRepository#getMatchedGroups(String)
        */
       public Iterator getMatchedGroups(String wildmat) {
  -        // TODO: Add filter for valid group names
  -        File[] f = rootPath.listFiles(new AndFileFilter
  -            (new DirectoryFileFilter(),new GlobFilenameFilter(wildmat)));
  +        File[] f = rootPath.listFiles(new AndFileFilter(new GroupFilter(), new AndFileFilter
  +            (new DirectoryFileFilter(),new GlobFilenameFilter(wildmat))));
           return getGroups(f);
       }
   
  @@ -418,9 +433,8 @@
        * @see org.apache.james.nntpserver.repository.NNTPRepository#getGroupsSince(Date)
        */
       public Iterator getGroupsSince(Date dt) {
  -        // TODO: Add filter for valid group names
  -        File[] f = rootPath.listFiles(new AndFileFilter
  -            (new DirectoryFileFilter(),new DateSinceFileFilter(dt.getTime())));
  +        File[] f = rootPath.listFiles(new AndFileFilter(new GroupFilter(), new AndFileFilter
  +            (new DirectoryFileFilter(),new DateSinceFileFilter(dt.getTime()))));
           return getGroups(f);
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org