|
Commons Net example source code file (NewGroupsOrNewsQuery.java)
The Commons Net NewGroupsOrNewsQuery.java source code
/*
* 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;
import java.util.Calendar;
/***
* 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.
* <p>
* You might use the class as follows:
* <pre>
* query = new NewsGroupsOrNewsQuery(new GregorianCalendar(97, 11, 15), false);
* query.addDistribution("comp");
* NewsgroupInfo[] newsgroups = client.listNewgroups(query);
* </pre>
* This will retrieve the list of newsgroups starting with the comp.
* distribution prefix created since midnight 11/15/97.
* <p>
* <p>
* @see NNTPClient
***/
public final class NewGroupsOrNewsQuery
{
private String __date, __time;
private StringBuffer __distributions;
private StringBuffer __newsgroups;
private boolean __isGMT;
/***
* Creates a new query using the given time as a reference point.
* <p>
* @param date The date since which new groups or news have arrived.
* @param gmt True if the date should be considered as GMT, false if not.
***/
public NewGroupsOrNewsQuery(Calendar date, boolean gmt)
{
int num;
String str;
StringBuilder buffer;
__distributions = null;
__newsgroups = null;
__isGMT = gmt;
buffer = new StringBuilder();
// 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();
}
/***
* 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 <code> * wildcard, as in
* <code>comp.lang.* or
Other Commons Net examples (source code examples)Here is a short list of links related to this Commons Net NewGroupsOrNewsQuery.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.