spacer

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

home / experts / xml / column7

RSS Viewer Applet: Window to the World of News

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

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