~ubuntu-branches/ubuntu/maverick/libcommons-digester-java/maverick

« back to all changes in this revision

Viewing changes to src/java/org/apache/commons/digester/rss/Channel.java

  • Committer: Bazaar Package Importer
  • Author(s): Takashi Okamoto
  • Date: 2004-08-13 01:59:24 UTC
  • Revision ID: james.westby@ubuntu.com-20040813015924-kxkbfi0a1u5cbxbr
Tags: 1.5.0.1-3
rebuild with J2SDK1.3 comparible mode.(closes: #265253)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Header: /home/cvspublic/jakarta-commons/digester/src/java/org/apache/commons/digester/rss/Channel.java,v 1.6 2003/04/16 11:23:51 jstrachan Exp $
 
3
 * $Revision: 1.6 $
 
4
 * $Date: 2003/04/16 11:23:51 $
 
5
 *
 
6
 * ====================================================================
 
7
 *
 
8
 * The Apache Software License, Version 1.1
 
9
 *
 
10
 * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
 
11
 * reserved.
 
12
 *
 
13
 * Redistribution and use in source and binary forms, with or without
 
14
 * modification, are permitted provided that the following conditions
 
15
 * are met:
 
16
 *
 
17
 * 1. Redistributions of source code must retain the above copyright
 
18
 *    notice, this list of conditions and the following disclaimer.
 
19
 *
 
20
 * 2. Redistributions in binary form must reproduce the above copyright
 
21
 *    notice, this list of conditions and the following disclaimer in
 
22
 *    the documentation and/or other materials provided with the
 
23
 *    distribution.
 
24
 *
 
25
 * 3. The end-user documentation included with the redistribution, if
 
26
 *    any, must include the following acknowlegement:
 
27
 *       "This product includes software developed by the
 
28
 *        Apache Software Foundation (http://www.apache.org/)."
 
29
 *    Alternately, this acknowlegement may appear in the software itself,
 
30
 *    if and wherever such third-party acknowlegements normally appear.
 
31
 *
 
32
 * 4. The names "The Jakarta Project", "Commons", and "Apache Software
 
33
 *    Foundation" must not be used to endorse or promote products derived
 
34
 *    from this software without prior written permission. For written
 
35
 *    permission, please contact apache@apache.org.
 
36
 *
 
37
 * 5. Products derived from this software may not be called "Apache"
 
38
 *    nor may "Apache" appear in their names without prior written
 
39
 *    permission of the Apache Group.
 
40
 *
 
41
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 
42
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
43
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
44
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 
45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
47
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 
48
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
49
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
50
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 
51
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
52
 * SUCH DAMAGE.
 
53
 * ====================================================================
 
54
 *
 
55
 * This software consists of voluntary contributions made by many
 
56
 * individuals on behalf of the Apache Software Foundation.  For more
 
57
 * information on the Apache Software Foundation, please see
 
58
 * <http://www.apache.org/>.
 
59
 *
 
60
 */
 
61
 
 
62
 
 
63
package org.apache.commons.digester.rss;
 
64
 
 
65
import java.io.OutputStream;
 
66
import java.io.OutputStreamWriter;
 
67
import java.io.PrintWriter;
 
68
import java.io.Serializable;
 
69
import java.io.UnsupportedEncodingException;
 
70
import java.io.Writer;
 
71
import java.util.ArrayList;
 
72
 
 
73
 
 
74
/**
 
75
 * <p>Implementation object representing a <strong>channel</strong> in the
 
76
 * <em>Rich Site Summary</em> DTD, version 0.91.  This class may be subclassed
 
77
 * to further specialize its behavior.</p>
 
78
 *
 
79
 * @author Craig R. McClanahan
 
80
 * @author Ted Husted
 
81
 * @version $Revision: 1.6 $ $Date: 2003/04/16 11:23:51 $
 
82
 */
 
83
 
 
84
public class Channel implements Serializable {
 
85
 
 
86
 
 
87
    // ----------------------------------------------------- Instance Variables
 
88
 
 
89
 
 
90
    /**
 
91
     * The set of items associated with this Channel.
 
92
     */
 
93
    protected ArrayList items = new ArrayList();
 
94
 
 
95
 
 
96
    /**
 
97
     * The set of skip days for this channel.
 
98
     */
 
99
    protected ArrayList skipDays = new ArrayList();
 
100
 
 
101
 
 
102
    /**
 
103
     * The set of skip hours for this channel.
 
104
     */
 
105
    protected ArrayList skipHours = new ArrayList();
 
106
 
 
107
 
 
108
    // ------------------------------------------------------------- Properties
 
109
 
 
110
 
 
111
    /**
 
112
     * The channel copyright (1-100 characters).
 
113
     */
 
114
    protected String copyright = null;
 
115
 
 
116
    public String getCopyright() {
 
117
        return (this.copyright);
 
118
    }
 
119
 
 
120
    public void setCopyright(String copyright) {
 
121
        this.copyright = copyright;
 
122
    }
 
123
 
 
124
 
 
125
    /**
 
126
     * The channel description (1-500 characters).
 
127
     */
 
128
    protected String description = null;
 
129
 
 
130
    public String getDescription() {
 
131
        return (this.description);
 
132
    }
 
133
 
 
134
    public void setDescription(String description) {
 
135
        this.description = description;
 
136
    }
 
137
 
 
138
 
 
139
    /**
 
140
     * The channel description file URL (1-500 characters).
 
141
     */
 
142
    protected String docs = null;
 
143
 
 
144
    public String getDocs() {
 
145
        return (this.docs);
 
146
    }
 
147
 
 
148
    public void setDocs(String docs) {
 
149
        this.docs = docs;
 
150
    }
 
151
 
 
152
 
 
153
    /**
 
154
     * The image describing this channel.
 
155
     */
 
156
    protected Image image = null;
 
157
 
 
158
    public Image getImage() {
 
159
        return (this.image);
 
160
    }
 
161
 
 
162
    public void setImage(Image image) {
 
163
        this.image = image;
 
164
    }
 
165
 
 
166
 
 
167
    /**
 
168
     * The channel language (2-5 characters).
 
169
     */
 
170
    protected String language = null;
 
171
 
 
172
    public String getLanguage() {
 
173
        return (this.language);
 
174
    }
 
175
 
 
176
    public void setLanguage(String language) {
 
177
        this.language = language;
 
178
    }
 
179
 
 
180
 
 
181
    /**
 
182
     * The channel last build date (1-100 characters).
 
183
     */
 
184
    protected String lastBuildDate = null;
 
185
 
 
186
    public String getLastBuildDate() {
 
187
        return (this.lastBuildDate);
 
188
    }
 
189
 
 
190
    public void setLastBuildDate(String lastBuildDate) {
 
191
        this.lastBuildDate = lastBuildDate;
 
192
    }
 
193
 
 
194
 
 
195
    /**
 
196
     * The channel link (1-500 characters).
 
197
     */
 
198
    protected String link = null;
 
199
 
 
200
    public String getLink() {
 
201
        return (this.link);
 
202
    }
 
203
 
 
204
    public void setLink(String link) {
 
205
        this.link = link;
 
206
    }
 
207
 
 
208
 
 
209
    /**
 
210
     * The managing editor (1-100 characters).
 
211
     */
 
212
    protected String managingEditor = null;
 
213
 
 
214
    public String getManagingEditor() {
 
215
        return (this.managingEditor);
 
216
    }
 
217
 
 
218
    public void setManagingEditor(String managingEditor) {
 
219
        this.managingEditor = managingEditor;
 
220
    }
 
221
 
 
222
 
 
223
    /**
 
224
     * The channel publication date (1-100 characters).
 
225
     */
 
226
    protected String pubDate = null;
 
227
 
 
228
    public String getPubDate() {
 
229
        return (this.pubDate);
 
230
    }
 
231
 
 
232
    public void setPubDate(String pubDate) {
 
233
        this.pubDate = pubDate;
 
234
    }
 
235
 
 
236
 
 
237
    /**
 
238
     * The channel rating (20-500 characters).
 
239
     */
 
240
    protected String rating = null;
 
241
 
 
242
    public String getRating() {
 
243
        return (this.rating);
 
244
    }
 
245
 
 
246
    public void setRating(String rating) {
 
247
        this.rating = rating;
 
248
    }
 
249
 
 
250
 
 
251
    /**
 
252
     * The text input description for this channel.
 
253
     */
 
254
    protected TextInput textInput = null;
 
255
 
 
256
    public TextInput getTextInput() {
 
257
        return (this.textInput);
 
258
    }
 
259
 
 
260
    public void setTextInput(TextInput textInput) {
 
261
        this.textInput = textInput;
 
262
    }
 
263
 
 
264
 
 
265
    /**
 
266
     * The channel title (1-100 characters).
 
267
     */
 
268
    protected String title = null;
 
269
 
 
270
    public String getTitle() {
 
271
        return (this.title);
 
272
    }
 
273
 
 
274
    public void setTitle(String title) {
 
275
        this.title = title;
 
276
    }
 
277
 
 
278
 
 
279
    /**
 
280
     * The RSS specification version number used to create this Channel.
 
281
     */
 
282
    protected double version = 0.91;
 
283
 
 
284
    public double getVersion() {
 
285
        return (this.version);
 
286
    }
 
287
 
 
288
    public void setVersion(double version) {
 
289
        this.version = version;
 
290
    }
 
291
 
 
292
 
 
293
    /**
 
294
     * The webmaster email address (1-100 characters).
 
295
     */
 
296
    protected String webMaster = null;
 
297
 
 
298
    public String getWebMaster() {
 
299
        return (this.webMaster);
 
300
    }
 
301
 
 
302
    public void setWebMaster(String webMaster) {
 
303
        this.webMaster = webMaster;
 
304
    }
 
305
 
 
306
 
 
307
    // --------------------------------------------------------- Public Methods
 
308
 
 
309
 
 
310
    /**
 
311
     * Add an additional item.
 
312
     *
 
313
     * @param item The item to be added
 
314
     */
 
315
    public void addItem(Item item) {
 
316
        synchronized (items) {
 
317
            items.add(item);
 
318
        }
 
319
    }
 
320
 
 
321
 
 
322
    /**
 
323
     * Add an additional skip day name.
 
324
     *
 
325
     * @param skipDay The skip day to be added
 
326
     */
 
327
    public void addSkipDay(String skipDay) {
 
328
        synchronized (skipDays) {
 
329
            skipDays.add(skipDay);
 
330
        }
 
331
    }
 
332
 
 
333
 
 
334
    /**
 
335
     * Add an additional skip day name.
 
336
     *
 
337
     * @param skipDay The skip day to be added
 
338
     */
 
339
    public void addSkipHour(String skipHour) {
 
340
        synchronized (skipHours) {
 
341
            skipHours.add(skipHour);
 
342
        }
 
343
    }
 
344
 
 
345
 
 
346
    /**
 
347
     * Return the items for this channel.
 
348
     */
 
349
    public Item[] findItems() {
 
350
        synchronized (items) {
 
351
            Item items[] = new Item[this.items.size()];
 
352
            return ((Item[]) this.items.toArray(items));
 
353
        }
 
354
    }
 
355
 
 
356
 
 
357
    /**
 
358
     * Return the items for this channel.
 
359
     */
 
360
    public Item[] getItems() {
 
361
        return findItems();
 
362
    }
 
363
 
 
364
 
 
365
    /**
 
366
     * Return the skip days for this channel.
 
367
     */
 
368
    public String[] findSkipDays() {
 
369
        synchronized (skipDays) {
 
370
            String skipDays[] = new String[this.skipDays.size()];
 
371
            return ((String[]) this.skipDays.toArray(skipDays));
 
372
        }
 
373
    }
 
374
 
 
375
 
 
376
    /**
 
377
     * Return the skip hours for this channel.
 
378
     */
 
379
    public String[] getSkipHours() {
 
380
        return findSkipHours();
 
381
    }
 
382
 
 
383
 
 
384
    /**
 
385
     * Return the skip hours for this channel.
 
386
     */
 
387
    public String[] findSkipHours() {
 
388
        synchronized (skipHours) {
 
389
            String skipHours[] = new String[this.skipHours.size()];
 
390
            return ((String[]) this.skipHours.toArray(skipHours));
 
391
        }
 
392
    }
 
393
 
 
394
 
 
395
    /**
 
396
     * Return the skip days for this channel.
 
397
     */
 
398
    public String[] getSkipDays() {
 
399
        return findSkipDays();
 
400
    }
 
401
 
 
402
 
 
403
    /**
 
404
     * Remove an item for this channel.
 
405
     *
 
406
     * @param item The item to be removed
 
407
     */
 
408
    public void removeItem(Item item) {
 
409
        synchronized (items) {
 
410
            items.remove(item);
 
411
        }
 
412
    }
 
413
 
 
414
 
 
415
    /**
 
416
     * Remove a skip day for this channel.
 
417
     *
 
418
     * @param skipDay The skip day to be removed
 
419
     */
 
420
    public void removeSkipDay(String skipDay) {
 
421
        synchronized (skipDays) {
 
422
            skipDays.remove(skipDay);
 
423
        }
 
424
    }
 
425
 
 
426
 
 
427
    /**
 
428
     * Remove a skip hour for this channel.
 
429
     *
 
430
     * @param skipHour The skip hour to be removed
 
431
     */
 
432
    public void removeSkipHour(String skipHour) {
 
433
        synchronized (skipHours) {
 
434
            skipHours.remove(skipHour);
 
435
        }
 
436
    }
 
437
 
 
438
 
 
439
    /**
 
440
     * Render this channel as XML conforming to the RSS 0.91 specification,
 
441
     * to the specified output stream, with no indication of character
 
442
     * encoding.
 
443
     *
 
444
     * @param stream The output stream to write to
 
445
     */
 
446
    public void render(OutputStream stream) {
 
447
 
 
448
        try {
 
449
            render(stream, null);
 
450
        } catch (UnsupportedEncodingException e) {
 
451
            ; // Can not happen
 
452
        }
 
453
 
 
454
    }
 
455
 
 
456
 
 
457
    /**
 
458
     * Render this channel as XML conforming to the RSS 0.91 specification,
 
459
     * to the specified output stream, with the specified character encoding.
 
460
     *
 
461
     * @param stream The output stream to write to
 
462
     * @param encoding The character encoding to declare, or <code>null</code>
 
463
     *  for no declaration
 
464
     *
 
465
     * @exception UnsupportedEncodingException if the named encoding
 
466
     *  is not supported
 
467
     */
 
468
    public void render(OutputStream stream, String encoding)
 
469
            throws UnsupportedEncodingException {
 
470
 
 
471
        PrintWriter pw = null;
 
472
        if (encoding == null) {
 
473
            pw = new PrintWriter(stream);
 
474
        } else {
 
475
            pw = new PrintWriter(new OutputStreamWriter(stream, encoding));
 
476
        }
 
477
        render(pw, encoding);
 
478
        pw.flush();
 
479
 
 
480
    }
 
481
 
 
482
 
 
483
    /**
 
484
     * Render this channel as XML conforming to the RSS 0.91 specification,
 
485
     * to the specified writer, with no indication of character encoding.
 
486
     *
 
487
     * @param writer The writer to render output to
 
488
     */
 
489
    public void render(Writer writer) {
 
490
 
 
491
        render(writer, null);
 
492
 
 
493
    }
 
494
 
 
495
 
 
496
    /**
 
497
     * Render this channel as XML conforming to the RSS 0.91 specification,
 
498
     * to the specified writer, indicating the specified character encoding.
 
499
     *
 
500
     * @param writer The writer to render output to
 
501
     * @param encoding The character encoding to declare, or <code>null</code>
 
502
     *  for no declaration
 
503
     */
 
504
    public void render(Writer writer, String encoding) {
 
505
 
 
506
        PrintWriter pw = new PrintWriter(writer);
 
507
        render(pw, encoding);
 
508
        pw.flush();
 
509
 
 
510
    }
 
511
 
 
512
 
 
513
    /**
 
514
     * Render this channel as XML conforming to the RSS 0.91 specification,
 
515
     * to the specified writer, with no indication of character encoding.
 
516
     *
 
517
     * @param writer The writer to render output to
 
518
     */
 
519
    public void render(PrintWriter writer) {
 
520
 
 
521
        render(writer, null);
 
522
 
 
523
    }
 
524
 
 
525
 
 
526
    /**
 
527
     * Render this channel as XML conforming to the RSS 0.91 specification,
 
528
     * to the specified writer, indicating the specified character encoding.
 
529
     *
 
530
     * @param writer The writer to render output to
 
531
     * @param encoding The character encoding to declare, or <code>null</code>
 
532
     *  for no declaration
 
533
     */
 
534
    public void render(PrintWriter writer, String encoding) {
 
535
 
 
536
        writer.print("<?xml version=\"1.0\"");
 
537
        if (encoding != null) {
 
538
            writer.print(" encoding=\"");
 
539
            writer.print(encoding);
 
540
            writer.print("\"");
 
541
        }
 
542
        writer.println("?>");
 
543
        writer.println();
 
544
 
 
545
        writer.println("<!DOCTYPE rss PUBLIC");
 
546
        writer.println("  \"-//Netscape Communications//DTD RSS 0.91//EN\"");
 
547
        writer.println("  \"http://my.netscape.com/publish/formats/rss-0.91.dtd\">");
 
548
        writer.println();
 
549
 
 
550
        writer.println("<rss version=\"0.91\">");
 
551
        writer.println();
 
552
 
 
553
        writer.println("  <channel>");
 
554
        writer.println();
 
555
 
 
556
        writer.print("    <title>");
 
557
        writer.print(title);
 
558
        writer.println("</title>");
 
559
 
 
560
        writer.print("    <description>");
 
561
        writer.print(description);
 
562
        writer.println("</description>");
 
563
 
 
564
        writer.print("    <link>");
 
565
        writer.print(link);
 
566
        writer.println("</link>");
 
567
 
 
568
        writer.print("    <language>");
 
569
        writer.print(language);
 
570
        writer.println("</language>");
 
571
 
 
572
        if (rating != null) {
 
573
            writer.print("    <rating>");
 
574
            writer.print(rating);
 
575
            writer.println("</rating>");
 
576
        }
 
577
 
 
578
        if (copyright != null) {
 
579
            writer.print("    <copyright>");
 
580
            writer.print(copyright);
 
581
            writer.print("</copyright>");
 
582
        }
 
583
 
 
584
 
 
585
        if (pubDate != null) {
 
586
            writer.print("    <pubDate>");
 
587
            writer.print(pubDate);
 
588
            writer.println("</pubDate>");
 
589
        }
 
590
 
 
591
        if (lastBuildDate != null) {
 
592
            writer.print("    <lastBuildDate>");
 
593
            writer.print(lastBuildDate);
 
594
            writer.println("</lastBuildDate>");
 
595
        }
 
596
 
 
597
        if (docs != null) {
 
598
            writer.print("    <docs>");
 
599
            writer.print(docs);
 
600
            writer.println("</docs>");
 
601
        }
 
602
 
 
603
        if (managingEditor != null) {
 
604
            writer.print("    <managingEditor>");
 
605
            writer.print(managingEditor);
 
606
            writer.println("</managingEditor>");
 
607
        }
 
608
 
 
609
        if (webMaster != null) {
 
610
            writer.print("    <webMaster>");
 
611
            writer.print(webMaster);
 
612
            writer.println("</webMaster>");
 
613
        }
 
614
 
 
615
        writer.println();
 
616
 
 
617
        if (image != null) {
 
618
            image.render(writer);
 
619
            writer.println();
 
620
        }
 
621
 
 
622
        if (textInput != null) {
 
623
            textInput.render(writer);
 
624
            writer.println();
 
625
        }
 
626
 
 
627
        String skipDays[] = findSkipDays();
 
628
        if (skipDays.length > 0) {
 
629
            writer.println("    <skipDays>");
 
630
            for (int i = 0; i < skipDays.length; i++) {
 
631
                writer.print("      <skipDay>");
 
632
                writer.print(skipDays[i]);
 
633
                writer.println("</skipDay>");
 
634
            }
 
635
            writer.println("    </skipDays>");
 
636
        }
 
637
 
 
638
        String skipHours[] = findSkipHours();
 
639
        if (skipHours.length > 0) {
 
640
            writer.println("    <skipHours>");
 
641
            for (int i = 0; i < skipHours.length; i++) {
 
642
                writer.print("      <skipHour>");
 
643
                writer.print(skipHours[i]);
 
644
                writer.println("</skipHour>");
 
645
            }
 
646
            writer.println("    </skipHours>");
 
647
            writer.println();
 
648
        }
 
649
 
 
650
        Item items[] = findItems();
 
651
        for (int i = 0; i < items.length; i++) {
 
652
            items[i].render(writer);
 
653
            writer.println();
 
654
        }
 
655
 
 
656
        writer.println("  </channel>");
 
657
        writer.println();
 
658
 
 
659
        writer.println("</rss>");
 
660
 
 
661
    }
 
662
 
 
663
 
 
664
}