001    /*
002     * Copyright 1999,2004 The Apache Software Foundation.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.apache.commons.feedparser.test;
018    
019    import junit.framework.TestCase;
020    
021    import org.apache.commons.feedparser.DefaultFeedDirectoryParserListener;
022    import org.apache.commons.feedparser.FeedParser;
023    import org.apache.commons.feedparser.FeedParserException;
024    import org.apache.commons.feedparser.FeedParserFactory;
025    import org.apache.commons.feedparser.FeedParserListener;
026    import org.apache.commons.feedparser.FeedParserState;
027    import org.apache.commons.feedparser.network.ResourceRequest;
028    import org.apache.commons.feedparser.network.ResourceRequestFactory;
029    
030    /**
031     *
032     * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
033     * @version $Id: TestFeedParser.java 373622 2006-01-30 22:53:00Z mvdb $
034     */
035    public class TestFeedParser extends TestCase {
036    
037        public TestFeedParser( String name ) throws Exception {
038            super( name );
039        }
040    
041        public void testParseOPML() throws Exception {
042    
043            String resource = "http://weblog.infoworld.com/udell/gems/mySubscriptions.opml";
044            
045            FeedParser parser = FeedParserFactory.newFeedParser();
046    
047            FeedParserListener listener = new DefaultFeedDirectoryParserListener() {
048    
049                    public void onItem( FeedParserState state,
050                                        String title,
051                                        String weblog,
052                                        String description,
053                                        String feed ) throws FeedParserException {
054    
055                        System.out.println( "title" + title );
056                        System.out.println( "feed: " + feed );
057                        
058                    }
059    
060                    public void onItemEnd() {}
061    
062                    public void finished() {}
063                    
064                };
065            
066            listener.setContext( this );
067            
068            ResourceRequest request = ResourceRequestFactory.getResourceRequest( resource );
069            
070            parser.parse( listener, request.getInputStream(), resource );
071                
072        }
073    
074        public static void main( String[] args ) {
075    
076            try { 
077    
078                TestFeedParser test = new TestFeedParser( null );
079    
080                //test.testGetWeblogLinkForResource();
081                test.testParseOPML();
082                
083            } catch ( Throwable t ) {
084                
085                t.printStackTrace();
086                
087            }
088            
089        }
090    
091    }
092