001: //$Id: Test.java,v 1.13 2004/05/06 16:04:42 taganaka Exp $
002: package org.gnu.stealthp.rsslib;
003:
004: import javax.xml.parsers.*;
005: import java.util.*;
006: import java.net.*;
007: import gnu.getopt.*;
008:
009: /**
010: * Main method for lib test.
011: *
012: * <blockquote>
013: * <em>This module, both source code and documentation, is in the
014: * Public Domain, and comes with <strong>NO WARRANTY</strong>.</em>
015: * </blockquote>
016: *
017: * @since RSSLIB4J 0.1
018: * @author Francesco aka 'Stealthp' stealthp[@]stealthp.org
019: * @version 0.2
020: */
021:
022: public class Test {
023:
024: public static void main(String[] args) {
025:
026: if (args.length < 2)
027: usage();
028:
029: RSSHandler hand = new RSSHandler();
030:
031: Getopt opt = new Getopt("Test", args, "f:u:");
032:
033: int c;
034: String arg;
035: while ((c = opt.getopt()) != -1) {
036: switch (c) {
037: case 'f':
038: arg = opt.getOptarg();
039: try {
040: RSSParser.parseXmlFile(arg, hand, false);
041: } catch (RSSException e) {
042: e.printStackTrace();
043: System.exit(1);
044: }
045: break;
046: case 'u':
047: arg = opt.getOptarg();
048: try {
049: URL u = new URL(arg);
050: RSSParser.parseXmlFile(u, hand, false);
051: } catch (Exception e) {
052: e.printStackTrace();
053: System.exit(1);
054: }
055: break;
056: case '?':
057: usage();
058:
059: }
060:
061: }
062:
063: RSSChannel ch = hand.getRSSChannel();
064: System.out.println("****************CHANNEL INFO ************");
065: System.out.println(ch.toString());
066:
067: if (ch.getRSSImage() != null) {
068: System.out.println("IMAGE INFO: \n"
069: + ch.getRSSImage().toString());
070: System.out.println("IMAGE IN HTML: \n"
071: + ch.getRSSImage().toHTML());
072:
073: } else
074: System.out.println("CHANNEL HAS NO IMAGE");
075:
076: if (ch.getRSSTextInput() != null) {
077: System.out.println("INPUT INFO: \n"
078: + ch.getRSSTextInput().toString());
079: System.out.println("HTML INPUT:\n"
080: + ch.getRSSTextInput().toHTML());
081: } else
082: System.out.println("CHANNEL HAS NO FORM INPUT");
083:
084: if (ch.getDoublinCoreElements() != null) {
085: System.out.println("DOUBLIN CORE INFO:");
086: // Hashtable tbl = ch.getDoublinCoreElements();
087:
088: System.out.println(ch.getDoublinCoreElements().toString());
089: } else
090: System.out.println("CHANNEL HAS NO DOUBLIN CORE TAGS");
091:
092: System.out.println("SEQUENCE INFO:");
093: if (ch.getItemsSequence() != null)
094: System.out.println(hand.getRSSChannel().getItemsSequence()
095: .toString());
096: else
097: System.out
098: .println("CHANNELL HAS NO SEQUENCE MYBE VERSION 0.9 or 2?");
099:
100: System.out.println("*****************************************");
101: LinkedList lst = hand.getRSSChannel().getItems();
102: System.out.println("****************ITEMS INFO *************");
103: System.out.println("ITEM SIZE: " + lst.size());
104: System.out.println("****************************************");
105:
106: for (int i = 0; i < lst.size(); i++) {
107: RSSItem itm = (RSSItem) lst.get(i);
108: System.out
109: .println("****************ITEM DETAILS *************");
110: System.out.println(itm.toString());
111:
112: if (itm.getDoublinCoreElements() != null) {
113: System.out.println("DOUBLIN CORE INFO FOR ITEM:");
114: System.out.println(itm.getDoublinCoreElements()
115: .toString());
116: } else
117: System.out.println("ITEM HAS NO DOUBLIN CORE TAGS");
118:
119: System.out
120: .println("******************************************");
121: }
122:
123: }
124:
125: private static void usage() {
126: String info = "Usage: java org.gnu.stealthp.rsslib.Test -f <local_file_name> | -u <remote_file_name>";
127: System.out.println(info);
128: System.exit(1);
129: }
130:
131: }
|