1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.digester.rss;
19
20 import java.io.OutputStream;
21 import java.io.OutputStreamWriter;
22 import java.io.PrintWriter;
23 import java.io.Serializable;
24 import java.io.UnsupportedEncodingException;
25 import java.io.Writer;
26 import java.util.ArrayList;
27
28
29
30
31
32
33
34
35 public class Channel implements Serializable {
36
37
38
39
40
41
42
43
44 protected ArrayList items = new ArrayList();
45
46
47
48
49
50 protected ArrayList skipDays = new ArrayList();
51
52
53
54
55
56 protected ArrayList skipHours = new ArrayList();
57
58
59
60
61
62
63
64
65 protected String copyright = null;
66
67 public String getCopyright() {
68 return (this.copyright);
69 }
70
71 public void setCopyright(String copyright) {
72 this.copyright = copyright;
73 }
74
75
76
77
78
79 protected String description = null;
80
81 public String getDescription() {
82 return (this.description);
83 }
84
85 public void setDescription(String description) {
86 this.description = description;
87 }
88
89
90
91
92
93 protected String docs = null;
94
95 public String getDocs() {
96 return (this.docs);
97 }
98
99 public void setDocs(String docs) {
100 this.docs = docs;
101 }
102
103
104
105
106
107 protected Image image = null;
108
109 public Image getImage() {
110 return (this.image);
111 }
112
113 public void setImage(Image image) {
114 this.image = image;
115 }
116
117
118
119
120
121 protected String language = null;
122
123 public String getLanguage() {
124 return (this.language);
125 }
126
127 public void setLanguage(String language) {
128 this.language = language;
129 }
130
131
132
133
134
135 protected String lastBuildDate = null;
136
137 public String getLastBuildDate() {
138 return (this.lastBuildDate);
139 }
140
141 public void setLastBuildDate(String lastBuildDate) {
142 this.lastBuildDate = lastBuildDate;
143 }
144
145
146
147
148
149 protected String link = null;
150
151 public String getLink() {
152 return (this.link);
153 }
154
155 public void setLink(String link) {
156 this.link = link;
157 }
158
159
160
161
162
163 protected String managingEditor = null;
164
165 public String getManagingEditor() {
166 return (this.managingEditor);
167 }
168
169 public void setManagingEditor(String managingEditor) {
170 this.managingEditor = managingEditor;
171 }
172
173
174
175
176
177 protected String pubDate = null;
178
179 public String getPubDate() {
180 return (this.pubDate);
181 }
182
183 public void setPubDate(String pubDate) {
184 this.pubDate = pubDate;
185 }
186
187
188
189
190
191 protected String rating = null;
192
193 public String getRating() {
194 return (this.rating);
195 }
196
197 public void setRating(String rating) {
198 this.rating = rating;
199 }
200
201
202
203
204
205 protected TextInput textInput = null;
206
207 public TextInput getTextInput() {
208 return (this.textInput);
209 }
210
211 public void setTextInput(TextInput textInput) {
212 this.textInput = textInput;
213 }
214
215
216
217
218
219 protected String title = null;
220
221 public String getTitle() {
222 return (this.title);
223 }
224
225 public void setTitle(String title) {
226 this.title = title;
227 }
228
229
230
231
232
233 protected double version = 0.91;
234
235 public double getVersion() {
236 return (this.version);
237 }
238
239 public void setVersion(double version) {
240 this.version = version;
241 }
242
243
244
245
246
247 protected String webMaster = null;
248
249 public String getWebMaster() {
250 return (this.webMaster);
251 }
252
253 public void setWebMaster(String webMaster) {
254 this.webMaster = webMaster;
255 }
256
257
258
259
260
261
262
263
264
265
266 public void addItem(Item item) {
267 synchronized (items) {
268 items.add(item);
269 }
270 }
271
272
273
274
275
276
277
278 public void addSkipDay(String skipDay) {
279 synchronized (skipDays) {
280 skipDays.add(skipDay);
281 }
282 }
283
284
285
286
287
288
289
290 public void addSkipHour(String skipHour) {
291 synchronized (skipHours) {
292 skipHours.add(skipHour);
293 }
294 }
295
296
297
298
299
300 public Item[] findItems() {
301 synchronized (items) {
302 Item items[] = new Item[this.items.size()];
303 return ((Item[]) this.items.toArray(items));
304 }
305 }
306
307
308
309
310
311 public Item[] getItems() {
312 return findItems();
313 }
314
315
316
317
318
319 public String[] findSkipDays() {
320 synchronized (skipDays) {
321 String skipDays[] = new String[this.skipDays.size()];
322 return ((String[]) this.skipDays.toArray(skipDays));
323 }
324 }
325
326
327
328
329
330 public String[] getSkipHours() {
331 return findSkipHours();
332 }
333
334
335
336
337
338 public String[] findSkipHours() {
339 synchronized (skipHours) {
340 String skipHours[] = new String[this.skipHours.size()];
341 return ((String[]) this.skipHours.toArray(skipHours));
342 }
343 }
344
345
346
347
348
349 public String[] getSkipDays() {
350 return findSkipDays();
351 }
352
353
354
355
356
357
358
359 public void removeItem(Item item) {
360 synchronized (items) {
361 items.remove(item);
362 }
363 }
364
365
366
367
368
369
370
371 public void removeSkipDay(String skipDay) {
372 synchronized (skipDays) {
373 skipDays.remove(skipDay);
374 }
375 }
376
377
378
379
380
381
382
383 public void removeSkipHour(String skipHour) {
384 synchronized (skipHours) {
385 skipHours.remove(skipHour);
386 }
387 }
388
389
390
391
392
393
394
395
396
397 public void render(OutputStream stream) {
398
399 try {
400 render(stream, null);
401 } catch (UnsupportedEncodingException e) {
402 ;
403 }
404
405 }
406
407
408
409
410
411
412
413
414
415
416
417
418
419 public void render(OutputStream stream, String encoding)
420 throws UnsupportedEncodingException {
421
422 PrintWriter pw = null;
423 if (encoding == null) {
424 pw = new PrintWriter(stream);
425 } else {
426 pw = new PrintWriter(new OutputStreamWriter(stream, encoding));
427 }
428 render(pw, encoding);
429 pw.flush();
430
431 }
432
433
434
435
436
437
438
439
440 public void render(Writer writer) {
441
442 render(writer, null);
443
444 }
445
446
447
448
449
450
451
452
453
454
455 public void render(Writer writer, String encoding) {
456
457 PrintWriter pw = new PrintWriter(writer);
458 render(pw, encoding);
459 pw.flush();
460
461 }
462
463
464
465
466
467
468
469
470 public void render(PrintWriter writer) {
471
472 render(writer, null);
473
474 }
475
476
477
478
479
480
481
482
483
484
485 public void render(PrintWriter writer, String encoding) {
486
487 writer.print("<?xml version=\"1.0\"");
488 if (encoding != null) {
489 writer.print(" encoding=\"");
490 writer.print(encoding);
491 writer.print("\"");
492 }
493 writer.println("?>");
494 writer.println();
495
496 writer.println("<!DOCTYPE rss PUBLIC");
497 writer.println(" \"-//Netscape Communications//DTD RSS 0.91//EN\"");
498 writer.println(" \"http://my.netscape.com/publish/formats/rss-0.91.dtd\">");
499 writer.println();
500
501 writer.println("<rss version=\"0.91\">");
502 writer.println();
503
504 writer.println(" <channel>");
505 writer.println();
506
507 writer.print(" <title>");
508 writer.print(title);
509 writer.println("</title>");
510
511 writer.print(" <description>");
512 writer.print(description);
513 writer.println("</description>");
514
515 writer.print(" <link>");
516 writer.print(link);
517 writer.println("</link>");
518
519 writer.print(" <language>");
520 writer.print(language);
521 writer.println("</language>");
522
523 if (rating != null) {
524 writer.print(" <rating>");
525 writer.print(rating);
526 writer.println("</rating>");
527 }
528
529 if (copyright != null) {
530 writer.print(" <copyright>");
531 writer.print(copyright);
532 writer.print("</copyright>");
533 }
534
535
536 if (pubDate != null) {
537 writer.print(" <pubDate>");
538 writer.print(pubDate);
539 writer.println("</pubDate>");
540 }
541
542 if (lastBuildDate != null) {
543 writer.print(" <lastBuildDate>");
544 writer.print(lastBuildDate);
545 writer.println("</lastBuildDate>");
546 }
547
548 if (docs != null) {
549 writer.print(" <docs>");
550 writer.print(docs);
551 writer.println("</docs>");
552 }
553
554 if (managingEditor != null) {
555 writer.print(" <managingEditor>");
556 writer.print(managingEditor);
557 writer.println("</managingEditor>");
558 }
559
560 if (webMaster != null) {
561 writer.print(" <webMaster>");
562 writer.print(webMaster);
563 writer.println("</webMaster>");
564 }
565
566 writer.println();
567
568 if (image != null) {
569 image.render(writer);
570 writer.println();
571 }
572
573 if (textInput != null) {
574 textInput.render(writer);
575 writer.println();
576 }
577
578 String skipDays[] = findSkipDays();
579 if (skipDays.length > 0) {
580 writer.println(" <skipDays>");
581 for (int i = 0; i < skipDays.length; i++) {
582 writer.print(" <skipDay>");
583 writer.print(skipDays[i]);
584 writer.println("</skipDay>");
585 }
586 writer.println(" </skipDays>");
587 }
588
589 String skipHours[] = findSkipHours();
590 if (skipHours.length > 0) {
591 writer.println(" <skipHours>");
592 for (int i = 0; i < skipHours.length; i++) {
593 writer.print(" <skipHour>");
594 writer.print(skipHours[i]);
595 writer.println("</skipHour>");
596 }
597 writer.println(" </skipHours>");
598 writer.println();
599 }
600
601 Item items[] = findItems();
602 for (int i = 0; i < items.length; i++) {
603 items[i].render(writer);
604 writer.println();
605 }
606
607 writer.println(" </channel>");
608 writer.println();
609
610 writer.println("</rss>");
611
612 }
613
614
615 }