package net.Ox4a42.volksempfaenger.feedparser;

import java.io.IOException;
import java.io.Reader;
import java.util.Stack;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.util.Log;

public class FeedParser {
	private final String TAG = "FeedParser";
	private final String ATOM_NS = "http://www.w3.org/2005/Atom";

	public static Feed parse(Reader reader) throws XmlPullParserException, IOException { 
		XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
		factory.setNamespaceAware(true);
		XmlPullParser parser = factory.newPullParser();
		
		parser.setInput(reader);
		
		ParserHelper parserHelper = new ParserHelper(parser);
		return parserHelper.getFeed();
	}
	
	private static class ParserHelper {
		private XmlPullParser parser;
		private Feed feed = new Feed();
		Stack<String> parents = new Stack<String>();

		public ParserHelper(XmlPullParser parser) throws XmlPullParserException, IOException {
			this.parser = parser;
	    	int eventType = parser.getEventType();
	        while(eventType != XmlPullParser.END_DOCUMENT) {
	        	switch(eventType) {
	        		case XmlPullParser.START_TAG:
	        			parents.push(parser.getNamespace() + ":" + parser.getName());
	        			break;
	        		case XmlPullParser.END_TAG:
	        			parents.pop();
	        			break;
	        	}
	        	eventType = parser.next();
	        }
		}
		
		public Feed getFeed() {
			return new Feed();
		}
	}
}

@@ -342,71 +342,8 @@
 er%22;
-%0A%09private final String ATOM_NS = %22http://www.w3.org/2005/Atom%22;
 %0A%0A%09p
@@ -581,19 +581,17 @@
 rser();%0A
-%09%09
 %0A
+
 %09%09parser
@@ -743,16 +743,62 @@
 elper %7B%0A
+%09%09private static String TAG = %22ParserHelper%22;%0A
 %09%09privat
@@ -901,16 +901,80 @@
 ring%3E();
+%0A%09%09private final String ATOM_NS = %22http://www.w3.org/2005/Atom%22;
 %0A%0A%09%09publ
@@ -1271,67 +1271,96 @@
  %09%09%09
-parents.push(parser.getNamespace() + %22:%22 + parser.getName()
+onStartTag();%0A%09        %09%09%09break;%0A%09        %09%09case XmlPullParser.TEXT:%0A%09        %09%09%09onText(
 );%0A%09
@@ -1432,19 +1432,16 @@
  %09%09%09
-parents.pop
+onEndTag
 ();%0A
@@ -1562,24 +1562,494 @@
 %09return 
-new Feed
+feed;%0A%09%09%7D%0A%09%09%0A%09%09private void onStartTag() %7B%0A%09%09%09String fullName = parser.getNamespace() + %22:%22 + parser.getName();%0A%09%09%09parents.push(fullName);%0A%09%09%7D%0A%09%09%0A%09%09private void onText() %7B%0A%09%09%09if(parents.peek() == ATOM_NS + %22:title%22) %7B%0A%09%09%09%09String copy = parents.pop();%0A%09%09%09%09if(parents.peek() == ATOM_NS + %22:feed%22) %7B%0A%09%09%09%09%09// feed title%0A%09%09%09%09%7D%0A%09%09%09%09else if(parents.peek() == ATOM_NS + %22:entry%22) %7B%0A%09%09%09%09%09// entry title%0A%09%09%09%09%7D%0A%09%09%09%09parents.push(copy);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09private void onEndTag() %7B%0A%09%09%09parents.pop
 ();%0A%09%09%7D%0A

Add a bit more structure to FeedParserHelper