FileDocCategorySizeDatePackage
RssMain.javaAPI DocExample2573Fri Feb 01 13:10:04 GMT 2002None

RssMain

public class RssMain extends Object
RSS Data Dump

Fields Summary
private static String
featurePrefix
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)
Invoke with one argument, a URI or filename


             
          
    
	if (argv.length != 1) {
	    System.err.println ("Usage: RssMain [file|URL]");
	    System.exit (1);
	}

	try {
	    XMLReader		reader;
	    RssConsumer		consumer;
	    Hashtable		hashtable;
	    Resolver		resolver;
	    
	    reader = XMLReaderFactory.createXMLReader ();

	    consumer = new RssConsumer ();
	    reader.setContentHandler (consumer);

	    // handle the "official" DTD server being off-line
	    hashtable = new Hashtable (5);
	    hashtable.put (
		"-//Netscape Communications//DTD RSS 0.91//EN",
		Resolver.fileNameToURL ("rss-0_91.dtd"));
	    resolver = new Resolver (hashtable);
	    reader.setEntityResolver (resolver);

	    // we rely on qNames, and 0.91 doesn't use namespaces
	    reader.setFeature (featurePrefix + "namespace-prefixes", true);
	    reader.setFeature (featurePrefix + "namespaces", false);

	    argv [0] = Resolver.getURL (argv [0]);
	    reader.parse (argv [0]);

	    RssChannel		channel = consumer.getChannel ();

	    System.out.println ("Partial RSS 0.91 channel info");
	    System.out.println ("SOURCE = " + channel.sourceUri);
	    System.out.println ();

	    System.out.println ("         Title: " + channel.title);
	    System.out.println ("   Description: " + channel.description);
	    System.out.println ("          Link: " + channel.link);
	    System.out.println ("      Language: " + channel.language);
	    System.out.println ("     WebMaster: " + channel.webMaster);
	    System.out.println ("ManagingEditor: " + channel.managingEditor);
	    System.out.println ();

	    System.out.println ("    Item Count: " + channel.items.size ());
	    for (int i = 0; i < channel.items.size (); i++) {
		RssItem		item = (RssItem)
				    channel.items.elementAt (i);
		System.out.println ("ITEM # " + i);
		if (item != null) {
		    System.out.println ("         Title: " + item.title);
		    System.out.println ("   Description: " + item.description);
		    System.out.println ("          Link: " + item.link);
		}
	    }

	// Good error handling is not shown here, for simplicity
	} catch (Exception e) {
	    System.err.println ("Whoa: " + e.getMessage ());
	    System.exit (1);
	}
	System.exit (0);