Source Code Cross Referenced for NewGroupsOrNewsQuery.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » nntp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache commons net 1.4.1 » org.apache.commons.net.nntp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2005 The Apache Software Foundation
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.apache.commons.net.nntp;
017:
018:        import java.util.Calendar;
019:
020:        /***
021:         * The NewGroupsOrNewsQuery class.  This is used to issue NNTP NEWGROUPS and
022:         * NEWNEWS queries, implemented by
023:         * {@link org.apache.commons.net.nntp.NNTPClient#listNewNewsgroups listNewNewsGroups }
024:         *  and
025:         * {@link org.apache.commons.net.nntp.NNTPClient#listNewNews listNewNews }
026:         *  respectively.  It prevents you from having to format
027:         * date, time, distribution, and newgroup arguments.
028:         * <p>
029:         * You might use the class as follows:
030:         * <pre>
031:         * query = new NewsGroupsOrNewsQuery(new GregorianCalendar(97, 11, 15), false);
032:         * query.addDistribution("comp");
033:         * NewsgroupInfo[] newsgroups = client.listNewgroups(query);
034:         * </pre>
035:         * This will retrieve the list of newsgroups starting with the comp.
036:         * distribution prefix created since midnight 11/15/97.
037:         * <p>
038:         * <p>
039:         * @author Daniel F. Savarese
040:         * @see NNTPClient
041:         ***/
042:
043:        public final class NewGroupsOrNewsQuery {
044:            private String __date, __time;
045:            private StringBuffer __distributions;
046:            private StringBuffer __newsgroups;
047:            private boolean __isGMT;
048:
049:            /***
050:             * Creates a new query using the given time as a reference point.
051:             * <p>
052:             * @param date  The date since which new groups or news have arrived.
053:             * @param gmt   True if the date should be considered as GMT, false if not.
054:             ***/
055:            public NewGroupsOrNewsQuery(Calendar date, boolean gmt) {
056:                int num;
057:                String str;
058:                StringBuffer buffer;
059:
060:                __distributions = null;
061:                __newsgroups = null;
062:                __isGMT = gmt;
063:
064:                buffer = new StringBuffer();
065:
066:                // Get year
067:                num = date.get(Calendar.YEAR);
068:                str = Integer.toString(num);
069:                num = str.length();
070:
071:                if (num >= 2)
072:                    buffer.append(str.substring(num - 2));
073:                else
074:                    buffer.append("00");
075:
076:                // Get month
077:                num = date.get(Calendar.MONTH) + 1;
078:                str = Integer.toString(num);
079:                num = str.length();
080:
081:                if (num == 1) {
082:                    buffer.append('0');
083:                    buffer.append(str);
084:                } else if (num == 2)
085:                    buffer.append(str);
086:                else
087:                    buffer.append("01");
088:
089:                // Get day
090:                num = date.get(Calendar.DAY_OF_MONTH);
091:                str = Integer.toString(num);
092:                num = str.length();
093:
094:                if (num == 1) {
095:                    buffer.append('0');
096:                    buffer.append(str);
097:                } else if (num == 2)
098:                    buffer.append(str);
099:                else
100:                    buffer.append("01");
101:
102:                __date = buffer.toString();
103:
104:                buffer.setLength(0);
105:
106:                // Get hour
107:                num = date.get(Calendar.HOUR_OF_DAY);
108:                str = Integer.toString(num);
109:                num = str.length();
110:
111:                if (num == 1) {
112:                    buffer.append('0');
113:                    buffer.append(str);
114:                } else if (num == 2)
115:                    buffer.append(str);
116:                else
117:                    buffer.append("00");
118:
119:                // Get minutes
120:                num = date.get(Calendar.MINUTE);
121:                str = Integer.toString(num);
122:                num = str.length();
123:
124:                if (num == 1) {
125:                    buffer.append('0');
126:                    buffer.append(str);
127:                } else if (num == 2)
128:                    buffer.append(str);
129:                else
130:                    buffer.append("00");
131:
132:                // Get seconds
133:                num = date.get(Calendar.SECOND);
134:                str = Integer.toString(num);
135:                num = str.length();
136:
137:                if (num == 1) {
138:                    buffer.append('0');
139:                    buffer.append(str);
140:                } else if (num == 2)
141:                    buffer.append(str);
142:                else
143:                    buffer.append("00");
144:
145:                __time = buffer.toString();
146:            }
147:
148:            /***
149:             * Add a newsgroup to the list of newsgroups being queried.  Newsgroups
150:             * added this way are only meaningful to the NEWNEWS command.  Newsgroup
151:             * names may include the <code> * </code> wildcard, as in
152:             * <code>comp.lang.* </code> or <code> comp.lang.java.* </code>.  Adding
153:             * at least one newsgroup is mandatory for the NEWNEWS command.
154:             * <p>
155:             * @param newsgroup  The newsgroup to add to the list of groups to be
156:             *                   checked for new news.
157:             ***/
158:            public void addNewsgroup(String newsgroup) {
159:                if (__newsgroups != null)
160:                    __newsgroups.append(',');
161:                else
162:                    __newsgroups = new StringBuffer();
163:                __newsgroups.append(newsgroup);
164:            }
165:
166:            /***
167:             * Add a newsgroup to the list of newsgroups being queried, but indicate
168:             * that group should not be checked for new news.  Newsgroups
169:             * added this way are only meaningful to the NEWNEWS command.
170:             * Newsgroup names may include the <code> * </code> wildcard, as in
171:             * <code>comp.lang.* </code> or <code> comp.lang.java.* </code>.
172:             * <p>
173:             * The following would create a query that searched for new news in
174:             * all comp.lang.java newsgroups except for comp.lang.java.advocacy.
175:             * <pre>
176:             * query.addNewsgroup("comp.lang.java.*");
177:             * query.omitNewsgroup("comp.lang.java.advocacy");
178:             * </pre>
179:             * <p>
180:             * @param newsgroup  The newsgroup to add to the list of groups to be
181:             *                   checked for new news, but which should be omitted from
182:             *                   the search for new news..
183:             ***/
184:            public void omitNewsgroup(String newsgroup) {
185:                addNewsgroup("!" + newsgroup);
186:            }
187:
188:            /***
189:             * Add a distribution group to the query.  The distribution part of a
190:             * newsgroup is the segment of the name preceding the first dot (e.g.,
191:             * comp, alt, rec).  Only those newsgroups matching one of the
192:             * distributions or, in the case of NEWNEWS, an article in a newsgroup
193:             * matching one of the distributions, will be reported as a query result.
194:             * Adding distributions is purely optional.
195:             * <p>
196:             * @param distribution A distribution to add to the query.
197:             ***/
198:            public void addDistribution(String distribution) {
199:                if (__distributions != null)
200:                    __distributions.append(',');
201:                else
202:                    __distributions = new StringBuffer();
203:                __distributions.append(distribution);
204:            }
205:
206:            /***
207:             * Return the NNTP query formatted date (year, month, day in the form
208:             * YYMMDD.
209:             * <p>
210:             * @return The NNTP query formatted date.
211:             ***/
212:            public String getDate() {
213:                return __date;
214:            }
215:
216:            /***
217:             * Return the NNTP query formatted time (hour, minutes, seconds in the form
218:             * HHMMSS.
219:             * <p>
220:             * @return The NNTP query formatted time.
221:             ***/
222:            public String getTime() {
223:                return __time;
224:            }
225:
226:            /***
227:             * Return whether or not the query date should be treated as GMT.
228:             * <p>
229:             * @return True if the query date is to be treated as GMT, false if not.
230:             ***/
231:            public boolean isGMT() {
232:                return __isGMT;
233:            }
234:
235:            /***
236:             * Return the comma separated list of distributions.  This may be null
237:             * if there are no distributions.
238:             * <p>
239:             * @return The list of distributions, which may be null if no distributions
240:             *         have been specified.
241:             ***/
242:            public String getDistributions() {
243:                return (__distributions == null ? null : __distributions
244:                        .toString());
245:            }
246:
247:            /***
248:             * Return the comma separated list of newsgroups.  This may be null
249:             * if there are no newsgroups
250:             * <p>
251:             * @return The list of newsgroups, which may be null if no newsgroups
252:             *         have been specified.
253:             ***/
254:            public String getNewsgroups() {
255:                return (__newsgroups == null ? null : __newsgroups.toString());
256:            }
257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.