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 java.io.FileOutputStream;
020    import java.io.PrintStream;
021    import java.net.URL;
022    
023    import junit.framework.TestCase;
024    
025    import org.apache.commons.feedparser.FeedParser;
026    import org.apache.commons.feedparser.FeedParserFactory;
027    import org.apache.commons.feedparser.impl.DebugFeedParserListener;
028    
029    /**
030     *
031     * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
032     * @version $Id: TestFeedFilter.java 373622 2006-01-30 22:53:00Z mvdb $
033     */
034    public class TestFeedFilter extends TestCase {
035        protected String feedparserHome;
036        
037        public static int current = 0;
038    
039        public TestFeedFilter( String name ) throws Exception {
040            super( name );
041            
042            feedparserHome = System.getProperty("feedparser.home", ".");
043            // these come in as forward slashes, even on Windows, because of Ant,
044            // so it is safe to check them as / rather than File.separator
045            // Brad Neuberg
046            if (feedparserHome.endsWith("/") == false)
047                feedparserHome = feedparserHome + "/";
048        }
049    
050        private void doTest( String resource ) throws Exception {
051    
052            System.out.println( "resource: (" + current + ") " + resource );
053    
054            URL url = new URL( resource );
055    
056            FileOutputStream fos = new FileOutputStream( "/tmp/test-feed-filter-" + current + ".html" );
057    
058            PrintStream out = new PrintStream( fos, true, "UTF-8" );
059    
060            out.println( "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\"> " );
061            out.println( "<pre>" );
062    
063            DebugFeedParserListener listener = new DebugFeedParserListener( out );
064    
065            FeedParser parser=FeedParserFactory.newFeedParser();
066            parser.parse( listener, url.openStream(), resource );
067    
068            out.println( "</pre>" );
069    
070            ++current;
071    
072        }
073    
074        public void test1() throws Exception {
075            String path = "file:" + feedparserHome;
076    
077            doTest( path + "tests/feeds/rss-1.0-EUC-JP.rdf" );
078    
079            doTest( path + "tests/filter/nbsp-1.xml" );
080    
081            doTest( path + "tests/filter/entity-atom-1.xml" );
082    
083            doTest( path + "tests/filter/prolog-atom-1.xml" );
084            doTest( path + "tests/filter/prolog-atom-2.xml" );
085            doTest( path + "tests/filter/prolog-opml-1.xml" );
086    
087            doTest( path + "tests/filter/lisa.opml" );
088    
089            doTest( path + "tests/feeds/utf16.rss1" );
090            doTest( path + "tests/feeds/utf16.rss2" );
091            doTest( path + "tests/feeds/i18n.atom" );
092            doTest( path + "tests/feeds/utf16.atom" );
093    
094            doTest( path + "tests/feeds/atom-1.xml" );
095            doTest( path + "tests/feeds/rss-1.0-EUC-JP.rdf" );
096            doTest( path + "tests/feeds/rss-1.0-international-1.rdf" );
097    
098        }
099    
100        public static void main( String[] args ) throws Exception {
101    
102            TestFeedFilter test = new TestFeedFilter( null );
103    
104            //test.testGetWeblogLinkForResource();
105            test.test1();
106    
107        }
108    
109    }
110