Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.apache.commons.net.nntp;
 
The NewGroupsOrNewsQuery class. This is used to issue NNTP NEWGROUPS and NEWNEWS queries, implemented by listNewNewsGroups and listNewNews respectively. It prevents you from having to format date, time, distribution, and newgroup arguments.

You might use the class as follows:

 query = new NewsGroupsOrNewsQuery(new GregorianCalendar(97, 11, 15), false);
 query.addDistribution("comp");
 NewsgroupInfo[] newsgroups = client.listNewgroups(query);
 
This will retrieve the list of newsgroups starting with the comp. distribution prefix created since midnight 11/15/97.

See also:
NNTPClient
 
 
 public final class NewGroupsOrNewsQuery
 {
     private final String __date__time;
     private StringBuffer __distributions;
     private StringBuffer __newsgroups;
     private final boolean __isGMT;


    
Creates a new query using the given time as a reference point.

Parameters:
date The date since which new groups or news have arrived.
gmt True if the date should be considered as GMT, false if not.
 
     public NewGroupsOrNewsQuery(Calendar dateboolean gmt)
     {
         int num;
         String str;
         StringBuilder buffer;
 
          = null;
          = null;
          = gmt;
 
         buffer = new StringBuilder();
 
         // Get year
         num = date.get(.);
         str = Integer.toString(num);
         num = str.length();
 
         if (num >= 2) {
             buffer.append(str.substring(num - 2));
         } else {
             buffer.append("00");
         }
 
         // Get month
         num = date.get(.) + 1;
         str = Integer.toString(num);
         num = str.length();
 
         if (num == 1) {
             buffer.append('0');
             buffer.append(str);
         } else if (num == 2) {
             buffer.append(str);
         } else {
             buffer.append("01");
         }
 
         // Get day
         num = date.get(.);
         str = Integer.toString(num);
         num = str.length();
 
        if (num == 1) {
            buffer.append('0');
            buffer.append(str);
        } else if (num == 2) {
            buffer.append(str);
        } else {
            buffer.append("01");
        }
         = buffer.toString();
        buffer.setLength(0);
        // Get hour
        num = date.get(.);
        str = Integer.toString(num);
        num = str.length();
        if (num == 1) {
            buffer.append('0');
            buffer.append(str);
        } else if (num == 2) {
            buffer.append(str);
        } else {
            buffer.append("00");
        }
        // Get minutes
        num = date.get(.);
        str = Integer.toString(num);
        num = str.length();
        if (num == 1) {
            buffer.append('0');
            buffer.append(str);
        } else if (num == 2) {
            buffer.append(str);
        } else {
            buffer.append("00");
        }
        // Get seconds
        num = date.get(.);
        str = Integer.toString(num);
        num = str.length();
        if (num == 1) {
            buffer.append('0');
            buffer.append(str);
        } else if (num == 2) {
            buffer.append(str);
        } else {
            buffer.append("00");
        }
         = buffer.toString();
    }


    
Add a newsgroup to the list of newsgroups being queried. Newsgroups added this way are only meaningful to the NEWNEWS command. Newsgroup names may include the * wildcard, as in comp.lang.* or comp.lang.java.* . Adding at least one newsgroup is mandatory for the NEWNEWS command.

Parameters:
newsgroup The newsgroup to add to the list of groups to be checked for new news.
    public void addNewsgroup(String newsgroup)
    {
        if ( != null) {
            .append(',');
        } else {
             = new StringBuffer();
        }
        .append(newsgroup);
    }


    
Add a newsgroup to the list of newsgroups being queried, but indicate that group should not be checked for new news. Newsgroups added this way are only meaningful to the NEWNEWS command. Newsgroup names may include the * wildcard, as in comp.lang.* or comp.lang.java.* .

The following would create a query that searched for new news in all comp.lang.java newsgroups except for comp.lang.java.advocacy.

 query.addNewsgroup("comp.lang.java.*");
 query.omitNewsgroup("comp.lang.java.advocacy");
 

Parameters:
newsgroup The newsgroup to add to the list of groups to be checked for new news, but which should be omitted from the search for new news..
    public void omitNewsgroup(String newsgroup)
    {
        addNewsgroup("!" + newsgroup);
    }


    
Add a distribution group to the query. The distribution part of a newsgroup is the segment of the name preceding the first dot (e.g., comp, alt, rec). Only those newsgroups matching one of the distributions or, in the case of NEWNEWS, an article in a newsgroup matching one of the distributions, will be reported as a query result. Adding distributions is purely optional.

Parameters:
distribution A distribution to add to the query.
    public void addDistribution(String distribution)
    {
        if ( != null) {
            .append(',');
        } else {
             = new StringBuffer();
        }
        .append(distribution);
    }

    
Return the NNTP query formatted date (year, month, day in the form YYMMDD.

Returns:
The NNTP query formatted date.
    public String getDate()
    {
        return ;
    }

    
Return the NNTP query formatted time (hour, minutes, seconds in the form HHMMSS.

Returns:
The NNTP query formatted time.
    public String getTime()
    {
        return ;
    }

    
Return whether or not the query date should be treated as GMT.

Returns:
True if the query date is to be treated as GMT, false if not.
    public boolean isGMT()
    {
        return ;
    }

    
Return the comma separated list of distributions. This may be null if there are no distributions.

Returns:
The list of distributions, which may be null if no distributions have been specified.
    public String getDistributions()
    {
        return ( == null ? null : .toString());
    }

    
Return the comma separated list of newsgroups. This may be null if there are no newsgroups

Returns:
The list of newsgroups, which may be null if no newsgroups have been specified.
    public String getNewsgroups()
    {
        return ( == null ? null : .toString());
    }
New to GrepCode? Check out our FAQ X