1 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 34 35 public class Channel implements Serializable { 36 37 38 40 41 44 protected ArrayList items = new ArrayList (); 45 46 47 50 protected ArrayList skipDays = new ArrayList (); 51 52 53 56 protected ArrayList skipHours = new ArrayList (); 57 58 59 61 62 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 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 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 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 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 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 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 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 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 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 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 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 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 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 260 261 266 public void addItem(Item item) { 267 synchronized (items) { 268 items.add(item); 269 } 270 } 271 272 273 278 public void addSkipDay(String skipDay) { 279 synchronized (skipDays) { 280 skipDays.add(skipDay); 281 } 282 } 283 284 285 290 public void addSkipHour(String skipHour) { 291 synchronized (skipHours) { 292 skipHours.add(skipHour); 293 } 294 } 295 296 297 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 311 public Item[] getItems() { 312 return findItems(); 313 } 314 315 316 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 330 public String [] getSkipHours() { 331 return findSkipHours(); 332 } 333 334 335 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 349 public String [] getSkipDays() { 350 return findSkipDays(); 351 } 352 353 354 359 public void removeItem(Item item) { 360 synchronized (items) { 361 items.remove(item); 362 } 363 } 364 365 366 371 public void removeSkipDay(String skipDay) { 372 synchronized (skipDays) { 373 skipDays.remove(skipDay); 374 } 375 } 376 377 378 383 public void removeSkipHour(String skipHour) { 384 synchronized (skipHours) { 385 skipHours.remove(skipHour); 386 } 387 } 388 389 390 397 public void render(OutputStream stream) { 398 399 try { 400 render(stream, null); 401 } catch (UnsupportedEncodingException e) { 402 ; } 404 405 } 406 407 408 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 440 public void render(Writer writer) { 441 442 render(writer, null); 443 444 } 445 446 447 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 470 public void render(PrintWriter writer) { 471 472 render(writer, null); 473 474 } 475 476 477 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 } 616 | Popular Tags |