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 $
4
* $Date: 2003/04/16 11:23:51 $
6
* ====================================================================
8
* The Apache Software License, Version 1.1
10
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
13
* Redistribution and use in source and binary forms, with or without
14
* modification, are permitted provided that the following conditions
17
* 1. Redistributions of source code must retain the above copyright
18
* notice, this list of conditions and the following disclaimer.
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
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.
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.
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.
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
53
* ====================================================================
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/>.
63
package org.apache.commons.digester.rss;
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;
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>
79
* @author Craig R. McClanahan
81
* @version $Revision: 1.6 $ $Date: 2003/04/16 11:23:51 $
84
public class Channel implements Serializable {
87
// ----------------------------------------------------- Instance Variables
91
* The set of items associated with this Channel.
93
protected ArrayList items = new ArrayList();
97
* The set of skip days for this channel.
99
protected ArrayList skipDays = new ArrayList();
103
* The set of skip hours for this channel.
105
protected ArrayList skipHours = new ArrayList();
108
// ------------------------------------------------------------- Properties
112
* The channel copyright (1-100 characters).
114
protected String copyright = null;
116
public String getCopyright() {
117
return (this.copyright);
120
public void setCopyright(String copyright) {
121
this.copyright = copyright;
126
* The channel description (1-500 characters).
128
protected String description = null;
130
public String getDescription() {
131
return (this.description);
134
public void setDescription(String description) {
135
this.description = description;
140
* The channel description file URL (1-500 characters).
142
protected String docs = null;
144
public String getDocs() {
148
public void setDocs(String docs) {
154
* The image describing this channel.
156
protected Image image = null;
158
public Image getImage() {
162
public void setImage(Image image) {
168
* The channel language (2-5 characters).
170
protected String language = null;
172
public String getLanguage() {
173
return (this.language);
176
public void setLanguage(String language) {
177
this.language = language;
182
* The channel last build date (1-100 characters).
184
protected String lastBuildDate = null;
186
public String getLastBuildDate() {
187
return (this.lastBuildDate);
190
public void setLastBuildDate(String lastBuildDate) {
191
this.lastBuildDate = lastBuildDate;
196
* The channel link (1-500 characters).
198
protected String link = null;
200
public String getLink() {
204
public void setLink(String link) {
210
* The managing editor (1-100 characters).
212
protected String managingEditor = null;
214
public String getManagingEditor() {
215
return (this.managingEditor);
218
public void setManagingEditor(String managingEditor) {
219
this.managingEditor = managingEditor;
224
* The channel publication date (1-100 characters).
226
protected String pubDate = null;
228
public String getPubDate() {
229
return (this.pubDate);
232
public void setPubDate(String pubDate) {
233
this.pubDate = pubDate;
238
* The channel rating (20-500 characters).
240
protected String rating = null;
242
public String getRating() {
243
return (this.rating);
246
public void setRating(String rating) {
247
this.rating = rating;
252
* The text input description for this channel.
254
protected TextInput textInput = null;
256
public TextInput getTextInput() {
257
return (this.textInput);
260
public void setTextInput(TextInput textInput) {
261
this.textInput = textInput;
266
* The channel title (1-100 characters).
268
protected String title = null;
270
public String getTitle() {
274
public void setTitle(String title) {
280
* The RSS specification version number used to create this Channel.
282
protected double version = 0.91;
284
public double getVersion() {
285
return (this.version);
288
public void setVersion(double version) {
289
this.version = version;
294
* The webmaster email address (1-100 characters).
296
protected String webMaster = null;
298
public String getWebMaster() {
299
return (this.webMaster);
302
public void setWebMaster(String webMaster) {
303
this.webMaster = webMaster;
307
// --------------------------------------------------------- Public Methods
311
* Add an additional item.
313
* @param item The item to be added
315
public void addItem(Item item) {
316
synchronized (items) {
323
* Add an additional skip day name.
325
* @param skipDay The skip day to be added
327
public void addSkipDay(String skipDay) {
328
synchronized (skipDays) {
329
skipDays.add(skipDay);
335
* Add an additional skip day name.
337
* @param skipDay The skip day to be added
339
public void addSkipHour(String skipHour) {
340
synchronized (skipHours) {
341
skipHours.add(skipHour);
347
* Return the items for this channel.
349
public Item[] findItems() {
350
synchronized (items) {
351
Item items[] = new Item[this.items.size()];
352
return ((Item[]) this.items.toArray(items));
358
* Return the items for this channel.
360
public Item[] getItems() {
366
* Return the skip days for this channel.
368
public String[] findSkipDays() {
369
synchronized (skipDays) {
370
String skipDays[] = new String[this.skipDays.size()];
371
return ((String[]) this.skipDays.toArray(skipDays));
377
* Return the skip hours for this channel.
379
public String[] getSkipHours() {
380
return findSkipHours();
385
* Return the skip hours for this channel.
387
public String[] findSkipHours() {
388
synchronized (skipHours) {
389
String skipHours[] = new String[this.skipHours.size()];
390
return ((String[]) this.skipHours.toArray(skipHours));
396
* Return the skip days for this channel.
398
public String[] getSkipDays() {
399
return findSkipDays();
404
* Remove an item for this channel.
406
* @param item The item to be removed
408
public void removeItem(Item item) {
409
synchronized (items) {
416
* Remove a skip day for this channel.
418
* @param skipDay The skip day to be removed
420
public void removeSkipDay(String skipDay) {
421
synchronized (skipDays) {
422
skipDays.remove(skipDay);
428
* Remove a skip hour for this channel.
430
* @param skipHour The skip hour to be removed
432
public void removeSkipHour(String skipHour) {
433
synchronized (skipHours) {
434
skipHours.remove(skipHour);
440
* Render this channel as XML conforming to the RSS 0.91 specification,
441
* to the specified output stream, with no indication of character
444
* @param stream The output stream to write to
446
public void render(OutputStream stream) {
449
render(stream, null);
450
} catch (UnsupportedEncodingException e) {
458
* Render this channel as XML conforming to the RSS 0.91 specification,
459
* to the specified output stream, with the specified character encoding.
461
* @param stream The output stream to write to
462
* @param encoding The character encoding to declare, or <code>null</code>
465
* @exception UnsupportedEncodingException if the named encoding
468
public void render(OutputStream stream, String encoding)
469
throws UnsupportedEncodingException {
471
PrintWriter pw = null;
472
if (encoding == null) {
473
pw = new PrintWriter(stream);
475
pw = new PrintWriter(new OutputStreamWriter(stream, encoding));
477
render(pw, encoding);
484
* Render this channel as XML conforming to the RSS 0.91 specification,
485
* to the specified writer, with no indication of character encoding.
487
* @param writer The writer to render output to
489
public void render(Writer writer) {
491
render(writer, null);
497
* Render this channel as XML conforming to the RSS 0.91 specification,
498
* to the specified writer, indicating the specified character encoding.
500
* @param writer The writer to render output to
501
* @param encoding The character encoding to declare, or <code>null</code>
504
public void render(Writer writer, String encoding) {
506
PrintWriter pw = new PrintWriter(writer);
507
render(pw, encoding);
514
* Render this channel as XML conforming to the RSS 0.91 specification,
515
* to the specified writer, with no indication of character encoding.
517
* @param writer The writer to render output to
519
public void render(PrintWriter writer) {
521
render(writer, null);
527
* Render this channel as XML conforming to the RSS 0.91 specification,
528
* to the specified writer, indicating the specified character encoding.
530
* @param writer The writer to render output to
531
* @param encoding The character encoding to declare, or <code>null</code>
534
public void render(PrintWriter writer, String encoding) {
536
writer.print("<?xml version=\"1.0\"");
537
if (encoding != null) {
538
writer.print(" encoding=\"");
539
writer.print(encoding);
542
writer.println("?>");
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\">");
550
writer.println("<rss version=\"0.91\">");
553
writer.println(" <channel>");
556
writer.print(" <title>");
558
writer.println("</title>");
560
writer.print(" <description>");
561
writer.print(description);
562
writer.println("</description>");
564
writer.print(" <link>");
566
writer.println("</link>");
568
writer.print(" <language>");
569
writer.print(language);
570
writer.println("</language>");
572
if (rating != null) {
573
writer.print(" <rating>");
574
writer.print(rating);
575
writer.println("</rating>");
578
if (copyright != null) {
579
writer.print(" <copyright>");
580
writer.print(copyright);
581
writer.print("</copyright>");
585
if (pubDate != null) {
586
writer.print(" <pubDate>");
587
writer.print(pubDate);
588
writer.println("</pubDate>");
591
if (lastBuildDate != null) {
592
writer.print(" <lastBuildDate>");
593
writer.print(lastBuildDate);
594
writer.println("</lastBuildDate>");
598
writer.print(" <docs>");
600
writer.println("</docs>");
603
if (managingEditor != null) {
604
writer.print(" <managingEditor>");
605
writer.print(managingEditor);
606
writer.println("</managingEditor>");
609
if (webMaster != null) {
610
writer.print(" <webMaster>");
611
writer.print(webMaster);
612
writer.println("</webMaster>");
618
image.render(writer);
622
if (textInput != null) {
623
textInput.render(writer);
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>");
635
writer.println(" </skipDays>");
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>");
646
writer.println(" </skipHours>");
650
Item items[] = findItems();
651
for (int i = 0; i < items.length; i++) {
652
items[i].render(writer);
656
writer.println(" </channel>");
659
writer.println("</rss>");