NewGroupsOrNewsQuerypublic final class NewGroupsOrNewsQuery extends Object The NewGroupsOrNewsQuery class. This is used to issue NNTP NEWGROUPS and
NEWNEWS queries, implemented by
{@link org.apache.commons.net.nntp.NNTPClient#listNewNewsgroups listNewNewsGroups }
and
{@link org.apache.commons.net.nntp.NNTPClient#listNewNews 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.
|
Fields Summary |
---|
private String | __date | private String | __time | private StringBuffer | __distributions | private StringBuffer | __newsgroups | private boolean | __isGMT |
Constructors Summary |
---|
public NewGroupsOrNewsQuery(Calendar date, boolean gmt)Creates a new query using the given time as a reference point.
int num;
String str;
StringBuffer buffer;
__distributions = null;
__newsgroups = null;
__isGMT = gmt;
buffer = new StringBuffer();
// Get year
num = date.get(Calendar.YEAR);
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(Calendar.MONTH) + 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(Calendar.DAY_OF_MONTH);
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");
__date = buffer.toString();
buffer.setLength(0);
// Get hour
num = date.get(Calendar.HOUR_OF_DAY);
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(Calendar.MINUTE);
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(Calendar.SECOND);
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");
__time = buffer.toString();
|
Methods Summary |
---|
public void | addDistribution(java.lang.String distribution)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.
if (__distributions != null)
__distributions.append(',");
else
__distributions = new StringBuffer();
__distributions.append(distribution);
| public void | addNewsgroup(java.lang.String newsgroup)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.
if (__newsgroups != null)
__newsgroups.append(',");
else
__newsgroups = new StringBuffer();
__newsgroups.append(newsgroup);
| public java.lang.String | getDate()Return the NNTP query formatted date (year, month, day in the form
YYMMDD.
return __date;
| public java.lang.String | getDistributions()Return the comma separated list of distributions. This may be null
if there are no distributions.
return (__distributions == null ? null : __distributions.toString());
| public java.lang.String | getNewsgroups()Return the comma separated list of newsgroups. This may be null
if there are no newsgroups
return (__newsgroups == null ? null : __newsgroups.toString());
| public java.lang.String | getTime()Return the NNTP query formatted time (hour, minutes, seconds in the form
HHMMSS.
return __time;
| public boolean | isGMT()Return whether or not the query date should be treated as GMT.
return __isGMT;
| public void | omitNewsgroup(java.lang.String 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");
addNewsgroup("!" + newsgroup);
|
|