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.impl; 018 019 import java.io.PrintStream; 020 import java.util.Date; 021 import java.util.Locale; 022 023 import org.apache.commons.feedparser.DefaultFeedParserListener; 024 import org.apache.commons.feedparser.FeedDirectoryParserListener; 025 import org.apache.commons.feedparser.FeedParserException; 026 import org.apache.commons.feedparser.FeedParserListener; 027 import org.apache.commons.feedparser.FeedParserState; 028 import org.apache.commons.feedparser.FeedVersion; 029 import org.apache.commons.feedparser.LinkFeedParserListener; 030 import org.apache.commons.feedparser.MetaFeedParserListener; 031 import org.apache.commons.feedparser.ModContentFeedParserListener; 032 import org.apache.commons.feedparser.TagFeedParserListener; 033 import org.jdom.Element; 034 035 /** 036 * 037 * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a> 038 * @version $Id: DebugFeedParserListener.java 373622 2006-01-30 22:53:00Z mvdb $ 039 */ 040 public class DebugFeedParserListener 041 extends DefaultFeedParserListener 042 implements FeedParserListener, 043 FeedDirectoryParserListener, 044 MetaFeedParserListener, 045 LinkFeedParserListener, 046 TagFeedParserListener, 047 ModContentFeedParserListener { 048 049 PrintStream out = System.out; 050 051 public DebugFeedParserListener() { } 052 053 public DebugFeedParserListener( PrintStream out ) { 054 this.out = out; 055 } 056 057 /** 058 * Called prior to event parsing to signal the parsing of a new feed. 059 * 060 * 061 */ 062 public void init() { 063 out.println( "init()" ); 064 } 065 066 public void onFeedVersion( FeedVersion version ) throws FeedParserException { 067 out.println( "onFeedVersion: " + version ); 068 } 069 070 public void setContext( Object context ) {} 071 072 /** 073 * Called when a channel item is found. 074 * 075 * 076 */ 077 public void onChannel( FeedParserState state, 078 String title, 079 String link, 080 String description ) { 081 082 out.println( "onChannel" ); 083 out.println( "\ttitle : " + title ); 084 out.println( "\tlink : '" + link + "'" ); 085 out.println( "\tdescription : " + description ); 086 087 } 088 089 public void onChannelEnd() { 090 091 out.println( "onChannelEnd" ); 092 093 } 094 095 /** 096 * Called when an RSS image is found. 097 * 098 * 099 */ 100 public void onImage( FeedParserState state, 101 String title, 102 String link, 103 String url ) { 104 105 out.println( "onImage" ); 106 107 } 108 109 public void onImageEnd() { 110 out.println( "onImageEnd" ); 111 } 112 113 /** 114 * Called when an RSS item or Atom entry is found. 115 * 116 * 117 */ 118 public void onItem( FeedParserState state, 119 String title, 120 String link, 121 String description, 122 String permalink ) { 123 124 out.println( "onItem" ); 125 126 out.println( "\ttitle : " + title ); 127 out.println( "\tlink : '" + link + "'" ); 128 out.println( "\tdescription : " + description ); 129 130 } 131 132 public void onItemEnd() { 133 out.println( "onItemEnd" ); 134 } 135 136 /** 137 * Called when the feed has finished parsing. 138 * 139 * 140 */ 141 public void finished() { 142 out.println( "finished" ); 143 } 144 145 /** 146 * Called when a new Folder is found. If feeds are in the default root 147 * folder this method is not called. 148 * 149 * 150 */ 151 public void onFolder( FeedParserState state, 152 String name ) throws FeedParserException { 153 154 out.println( "onFolder: " + name ); 155 156 } 157 158 public void onFolderEnd() throws FeedParserException { 159 160 } 161 162 public void onContent( FeedParserState state, 163 String type, 164 String format, 165 String encoding, 166 String mode, 167 String value, 168 boolean isSummary ) throws FeedParserException { 169 170 out.println( "onContent: " ); 171 out.println( value ); 172 173 } 174 175 public void onCreated( FeedParserState state, Date date ) throws FeedParserException { 176 177 out.println( "onCreated: " + date.toString() ); 178 179 } 180 181 public void onGUID( FeedParserState state, 182 String value, 183 boolean isPermalink ) throws FeedParserException { 184 185 out.println( "onGUID: " + value ); 186 out.println( " isPermalink: " + isPermalink ); 187 188 } 189 190 public void onAuthor( FeedParserState state, 191 String name, 192 String email, 193 String resource ) throws FeedParserException { 194 195 out.println( "onAuthor: name:" + name ); 196 out.println( " email: " + email ); 197 out.println( " resource: " + resource ); 198 199 } 200 201 public void onComments( FeedParserState state, 202 String resource ) throws FeedParserException { 203 204 out.println( "onComments: " + resource ); 205 206 } 207 208 public void onCommentsFeed( FeedParserState state, 209 String resource ) throws FeedParserException { 210 211 out.println( "onCommentsFeed: " + resource ); 212 213 } 214 215 // **** LinkFeedParserListener ********************************************** 216 217 /** 218 * 219 * 220 * @param length The length of the content or -1 if not specified. 221 */ 222 public void onLink( FeedParserState state, 223 String rel, 224 String type, 225 String href, 226 String title, 227 long length ) throws FeedParserException { 228 229 out.println( "onLink: " ); 230 out.println( "\trel: " + rel ); 231 out.println( "\thref: " + href ); 232 out.println( "\ttype: " + type ); 233 234 } 235 236 public void onLocale( FeedParserState state, Locale locale ) throws FeedParserException { 237 238 out.println( "onLocale: " + locale ); 239 240 } 241 242 public void onLocaleEnd() throws FeedParserException { 243 244 out.println( "onLocaleEnd" ); 245 246 } 247 248 public void onRelation( FeedParserState state, 249 String value ) { 250 251 out.println( "onRelation: " + value ); 252 253 } 254 255 public void onRelationEnd() { 256 out.println( "onRelationEnd" ); 257 } 258 259 // **** TagFeedParserListener *********************************************** 260 261 public void onTag( FeedParserState state, 262 String tag, 263 String tagspace ) throws FeedParserException { 264 265 out.println( "onTag: tag: " + tag + " tagspace: " + tagspace ); 266 267 } 268 269 public void onTagEnd() throws FeedParserException { 270 out.println( "onTagEnd" ); 271 } 272 273 // **** ModContentFeedParserListener **************************************** 274 275 public void onContentEncoded( FeedParserState state, 276 String value ) throws FeedParserException { 277 278 out.println( "onContentEncoded: " ); 279 out.println( value ); 280 281 } 282 283 public void onContentItem( FeedParserState state, 284 String format, 285 String encoding, 286 Element value ) throws FeedParserException { 287 288 out.println( "onContentItem: " ); 289 out.println( value ); 290 291 } 292 293 }