FileDocCategorySizeDatePackage
RssConsumer.javaAPI DocExample3658Fri Feb 01 13:27:00 GMT 2002None

RssConsumer

public class RssConsumer extends DefaultHandler
Unmarshaling SAX Events into RSS Data

Fields Summary
private RssChannel
channel
private RssChannel.RssItem
item
private RssChannel.RssImage
image
private RssChannel.RssTextInput
input
private Stack
stack
private Locator
locator
Constructors Summary
Methods Summary
public voidcharacters(char[] buf, int off, int len)

	String	top = getCurrentElementName ();
	String	value = new String (buf, off, len);

	if ("title".equals (top)) {
	    if (item != null)
		item.title += value;
	    else if (image != null)
		image.title += value;
	    else if (input != null)
		input.title += value;
	    else
		channel.title += value;
	} else if ("description".equals (top)) {
	    if (item != null)
		item.description += value;
	    else if (image != null)
		image.description += value;
	    else if (input != null)
		input.description += value;
	    else
		channel.description += value;
	} else if ("link".equals (top)) {
	    if (item != null)
		item.link += value;
	    else if (image != null)
		image.link += value;
	    else if (input != null)
		input.link += value;
	    else
		channel.link += value;

	} else if ("url".equals (top)) {
	    image.url += value;

	} else if ("name".equals (top)) {
	    input.name += value;

	} else if ("language".equals (top)) {
	    channel.language += value;
	} else if ("managingEditor".equals (top)) {
	    channel.managingEditor += value;
	} else if ("webMaster".equals (top)) {
	    channel.webMaster += value;

	} else if ("copyright".equals (top)) {
	    channel.copyright += value;
	} else if ("lastBuildDate".equals (top)) {
	    channel.lastBuildDate += value;
	} else if ("pubDate".equals (top)) {
	    channel.pubDate += value;
	} else if ("docs".equals (top)) {
	    channel.docs += value;
	} else if ("rating".equals (top)) {
	    channel.rating += value;

	} // else ignore ... skipDays and so on.
    
public voidendElement(java.lang.String namespace, java.lang.String local, java.lang.String name)

	if ("item".equals (name)) {
	    // patch item.link
	    channel.items.addElement (item);
	    item = null;
	} else if ("image".equals (name)) {
	    // patch image.link
	    // (patch image.url)
	    channel.image = image;
	    image = null;
	} else if ("textinput".equals (name)) {
	    // patch input.link
	    channel.textinput = input;
	    input = null;
	} else if ("channel".equals (name)) {
	    // patch channel.link
	}
    
public RssChannelgetChannel()

 return channel; 
private java.lang.StringgetCurrentElementName()

 return (String) stack.peek (); 
public voidsetDocumentLocator(org.xml.sax.Locator l)

 locator = l; 
public voidstartDocument()

	channel = new RssChannel ();
	if (locator != null)
	    channel.sourceUri = locator.getSystemId ();
	stack = new Stack ();
    
public voidstartElement(java.lang.String namespace, java.lang.String local, java.lang.String name, org.xml.sax.Attributes attrs)

	stack.push (name);

	if ("item".equals (name))
	    item = new RssItem ();
	else if ("image".equals (name))
	    image = new RssImage ();
	else if ("textinput".equals (name))
	    input = new RssTextInput ();
	// parser misconfigured?
	else if (name.length () == 0)
	    throw new SAXParseException ("XML names not available", locator);