spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / xml / column7

RSS Viewer Applet: Window to the World of News

C/C++ Developer (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Eclipse Helios Update Brings New PHP Tools
Internet Explorer 9 Ups Standards Support
JBoss Portal 5 Release Easier to Use


RSSChannel class

This class holds all the information about one news channel, it mirrors the RSS file in structure and content. All the channel items are stored in a vector, with entries for item title and link alternating. This is not very nice but simple.

package com.exploringxml.rss;

import com.microstar.xml.*;
import java.util.Vector;
import java.net.URL;

public class RSSChannel {

  String channelTitle;
  URL channelLink;
  String channelDescription;
  String imageTitle;
  URL imageURL;
  URL imageLink;
  Vector items;

  public RSSChannel() {
    items = new Vector();
  }
  public void load(String srcURL) throws Exception {
    XmlHandler handler = new RSSHandler(this);
    XmlParser parser = new XmlParser();
    parser.setHandler(handler);
    parser.parse(srcURL, null, (String) null);
  }

The channel object instantiates the handler and the parser, and tells the parser to parse the RSS file from the source location of srcURL. The parser triggers the handler in the parsing process, and the handler fills in the channel attributes as a consequence. Parsing done! Not that difficult, right?

  public String getChannelTitle() { return channelTitle; }
  public void   setChannelTitle(String s) { channelTitle = s; }
  public URL    getChannelLink() { return channelLink; }
  public void   setChannelLink(URL u) { channelLink = u; }
  public String getChannelDescription() { return channelDescription; }
  public void   setChannelDescription(String s) { channelDescription = s; }
  public String getImageTitle() { return imageTitle; }
  public void   setImageTitle(String s) { imageTitle = s; }
  public URL    getImageLink() { return imageLink; }
  public void   setImageLink(URL u) { imageLink = u; }
  public URL    getImageURL() { return imageURL; }
  public void   setImageURL(URL u) { imageURL = u; }
  public String getItemTitle(int pos) { return (String) items.elementAt(2*pos); }
  public void   setItemTitle(String s, int pos) { items.insertElementAt(s, 2*pos); }
  public URL    getItemLink(int pos) { return (URL) items.elementAt(2*pos+1); }
  public void   setItemLink(URL u, int pos) { items.insertElementAt(u, 2*pos+1); }
  public int    getNumberOfItems() { return items.size() / 2; }
  
  public static final String ChannelTag = "channel";
  public static final String ImageTag = "image";
  public static final String ItemTag = "item";
  public static final String TitleTag = "title";
  public static final String LinkTag = "link";
  public static final String DescriptionTag = "description";
  public static final String URLTag = "url";

}

Finally some boring getter and setter methods for all of the attributes, plus some string constants for the expected RSS tags. Who calls the load() method? Let's delve into the class that ties it all together: RSSViewerApplet.

http://www.internet.com

webref The latest from WebReference.com Browse >
Flashmaps' DynamicLocator: Interactive Maps for Small Areas · Flashmaps' AreaSelector: Interactive Maps for Wide Areas · The DB Mapper: Interactive Street-level Maps of U.S. and Canada
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

Produced by Michael Claßen
All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/xml/column7/2.html
Created: Feb. 08, 2000
Revised: Feb. 08, 2000