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.DefaultFeedParserListener; 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: TestAtom.java 373622 2006-01-30 22:53:00Z mvdb $ 034 */ 035 public class TestAtom extends TestCase { 036 037 public TestAtom( String name ) throws Exception { 038 super( name ); 039 } 040 041 public void doTest( String resource ) throws Exception { 042 043 FeedParser parser = FeedParserFactory.newFeedParser(); 044 045 FeedParserListener listener = new DefaultFeedParserListener() { 046 047 public void onItem( FeedParserState state, 048 String title, 049 String weblog, 050 String description, 051 String permalink ) throws FeedParserException { 052 053 System.out.println( "title: " + title ); 054 System.out.println( "description: " + description ); 055 System.out.println( "permalink: " + permalink ); 056 057 } 058 059 public void onItemEnd() {} 060 061 public void finished() {} 062 063 // **** MetaFeedParserListener ********************************************** 064 065 public void onSubject( FeedParserState state, String content ) 066 throws FeedParserException { 067 068 System.out.println( "subject: " + content ); 069 070 } 071 072 public void onContent( FeedParserState state, 073 String type, 074 String format, 075 String encoding, 076 String mode, 077 String value ) throws FeedParserException { 078 079 System.out.println( "content (type): " + type ); 080 System.out.println( "content (mode): " + mode ); 081 System.out.println( "content (value): " + value ); 082 083 } 084 085 }; 086 087 listener.setContext( this ); 088 089 ResourceRequest request = ResourceRequestFactory.getResourceRequest( resource ); 090 091 parser.parse( listener, request.getInputStream(), resource ); 092 093 } 094 095 public void test1() throws Exception { 096 097 //String resource = "file:///projects/feedparser/src/java/org/apache/commons/feedparser/test/TestAtom.xml"; 098 099 //doTest( resource ); 100 doTest( "file:tests/feeds/atom-1.xml" ); 101 102 } 103 104 public static void main( String[] args ) throws Exception { 105 106 TestAtom test = new TestAtom( null ); 107 108 //test.testGetWeblogLinkForResource(); 109 test.test1(); 110 111 } 112 113 } 114