1 16 package org.apache.commons.net.nntp; 17 18 import java.util.Calendar ; 19 20 42 43 public final class NewGroupsOrNewsQuery 44 { 45 private String __date, __time; 46 private StringBuffer __distributions; 47 private StringBuffer __newsgroups; 48 private boolean __isGMT; 49 50 51 57 public NewGroupsOrNewsQuery(Calendar date, boolean gmt) 58 { 59 int num; 60 String str; 61 StringBuffer buffer; 62 63 __distributions = null; 64 __newsgroups = null; 65 __isGMT = gmt; 66 67 buffer = new StringBuffer (); 68 69 num = date.get(Calendar.YEAR); 71 str = Integer.toString(num); 72 num = str.length(); 73 74 if (num >= 2) 75 buffer.append(str.substring(num - 2)); 76 else 77 buffer.append("00"); 78 79 num = date.get(Calendar.MONTH) + 1; 81 str = Integer.toString(num); 82 num = str.length(); 83 84 if (num == 1) 85 { 86 buffer.append('0'); 87 buffer.append(str); 88 } 89 else if (num == 2) 90 buffer.append(str); 91 else 92 buffer.append("01"); 93 94 num = date.get(Calendar.DAY_OF_MONTH); 96 str = Integer.toString(num); 97 num = str.length(); 98 99 if (num == 1) 100 { 101 buffer.append('0'); 102 buffer.append(str); 103 } 104 else if (num == 2) 105 buffer.append(str); 106 else 107 buffer.append("01"); 108 109 __date = buffer.toString(); 110 111 buffer.setLength(0); 112 113 num = date.get(Calendar.HOUR_OF_DAY); 115 str = Integer.toString(num); 116 num = str.length(); 117 118 if (num == 1) 119 { 120 buffer.append('0'); 121 buffer.append(str); 122 } 123 else if (num == 2) 124 buffer.append(str); 125 else 126 buffer.append("00"); 127 128 num = date.get(Calendar.MINUTE); 130 str = Integer.toString(num); 131 num = str.length(); 132 133 if (num == 1) 134 { 135 buffer.append('0'); 136 buffer.append(str); 137 } 138 else if (num == 2) 139 buffer.append(str); 140 else 141 buffer.append("00"); 142 143 144 num = date.get(Calendar.SECOND); 146 str = Integer.toString(num); 147 num = str.length(); 148 149 if (num == 1) 150 { 151 buffer.append('0'); 152 buffer.append(str); 153 } 154 else if (num == 2) 155 buffer.append(str); 156 else 157 buffer.append("00"); 158 159 __time = buffer.toString(); 160 } 161 162 163 173 public void addNewsgroup(String newsgroup) 174 { 175 if (__newsgroups != null) 176 __newsgroups.append(','); 177 else 178 __newsgroups = new StringBuffer (); 179 __newsgroups.append(newsgroup); 180 } 181 182 183 201 public void omitNewsgroup(String newsgroup) 202 { 203 addNewsgroup("!" + newsgroup); 204 } 205 206 207 217 public void addDistribution(String distribution) 218 { 219 if (__distributions != null) 220 __distributions.append(','); 221 else 222 __distributions = new StringBuffer (); 223 __distributions.append(distribution); 224 } 225 226 232 public String getDate() 233 { 234 return __date; 235 } 236 237 243 public String getTime() 244 { 245 return __time; 246 } 247 248 253 public boolean isGMT() 254 { 255 return __isGMT; 256 } 257 258 265 public String getDistributions() 266 { 267 return (__distributions == null ? null : __distributions.toString()); 268 } 269 270 277 public String getNewsgroups() 278 { 279 return (__newsgroups == null ? null : __newsgroups.toString()); 280 } 281 } 282 | Popular Tags |