Android Open Source - android-tools Feed Xml Parser






From Project

Back to project page android-tools.

License

The source code is released under:

MIT License

If you think the Android project android-tools listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.comfreeze.lib.xml.wordpress;
//www  . j  ava 2s  . c  o  m
import net.comfreeze.lib.xml.XMLParser;

import org.xml.sax.Attributes;

import java.io.InputStream;
import java.util.ArrayList;

public class FeedXmlParser extends XMLParser {
    private static final String TAG = FeedXmlParser.class.getSimpleName();

    public ArrayList<FeedItem> items = null;

    public FeedItem current = null;

    public String currentKey = null;

    public FeedXmlParser() {
        super();
        items = new ArrayList<FeedItem>();
    }

    public FeedXmlParser(InputStream in) {
        super(in);
        items = new ArrayList<FeedItem>();
        process();
    }

    @Override
    public FeedXmlParser setSource(InputStream source) {
        super.setSource(source);
        if (null != source)
            process();
        return this;
    }

    @Override
    protected void processElement(String namespace, String element, String qualifiedName, Attributes attributes) {
        if (element.equals("item")) {
            log("Started new item");
            current = new FeedItem();
        }
        if (element.equals("title")) {
            if (current != null) {
                buffering = true;
            }
        }
        if (element.equals("description")) {
            if (current != null) {
                buffering = true;
            }
        }
        if (element.equals("encoded")) {
            if (current != null) {
                buffering = true;
            }
        }
        if (element.equals("link")) {
            if (current != null) {
                buffering = true;
            }
        }
        if (element.equals("pubDate")) {
            if (current != null) {
                buffering = true;
            }
        }
    }

    @Override
    protected void finishElement(String namespace, String element, String qualifiedName) {
        if (element.equals("item")) {
            items.add(current);
            current = null;
            currentIndex++;
            log("Finished item");
        }
        if (element.equals("title")) {
            if (current != null) {
                buffering = false;
                current.title = buff.toString();
                buff = null;
            }
        }
        if (element.equals("description")) {
            if (current != null) {
                buffering = false;
                current.description = buff.toString();
                buff = null;
            }
        }
        if (element.equals("encoded")) {
            if (current != null) {
                buffering = false;
                current.content = buff.toString();
                buff = null;
            }
        }
        if (element.equals("link")) {
            if (current != null) {
                buffering = false;
                current.link = buff.toString();
                buff = null;
            }
        }
        if (element.equals("pubDate")) {
            if (current != null) {
                buffering = false;
                current.date = buff.toString();
                buff = null;
            }
        }
    }

    public static class FeedItem {
        public String title;
        public String description;
        public String content;
        public String link;
        public String date;
    }
}




Java Source Code List

net.comfreeze.lib.BundleBuilder.java
net.comfreeze.lib.CFZApplication.java
net.comfreeze.lib.ContentValueBuilder.java
net.comfreeze.lib.FragmentMap.java
net.comfreeze.lib.adapter.HeaderListAdapter.java
net.comfreeze.lib.adapter.IHeaderListAdapter.java
net.comfreeze.lib.adapter.SeparatedListAdapter.java
net.comfreeze.lib.api.BaseAPI.java
net.comfreeze.lib.api.RestAPI.java
net.comfreeze.lib.api.XMLAPI.java
net.comfreeze.lib.api.helper.CursorHelper.java
net.comfreeze.lib.api.helper.JSONHelper.java
net.comfreeze.lib.api.helper.ModelHelper.java
net.comfreeze.lib.api.xml.WordpressAPI.java
net.comfreeze.lib.audio.SoundManager.java
net.comfreeze.lib.db.DatabaseHelper.java
net.comfreeze.lib.db.DatabaseTable.java
net.comfreeze.lib.db.helper.HelperCursor.java
net.comfreeze.lib.db.model.CFZModel.java
net.comfreeze.lib.db.model.FieldColumnMap.java
net.comfreeze.lib.fragments.CFZListFragment.java
net.comfreeze.lib.provider.CFZSimpleProvider.java
net.comfreeze.lib.service.CFZService.java
net.comfreeze.lib.ui.SupportFragmentActivity.java
net.comfreeze.lib.ui.dialog.CFZDialogProgress.java
net.comfreeze.lib.ui.fragment.CFZFragmentBase.java
net.comfreeze.lib.views.BiScrollView.java
net.comfreeze.lib.views.CFZViewHelper.java
net.comfreeze.lib.views.FlowLayout.java
net.comfreeze.lib.views.GestureHelper.java
net.comfreeze.lib.views.HeaderListView.java
net.comfreeze.lib.views.ResizingView.java
net.comfreeze.lib.views.ViewCollection.java
net.comfreeze.lib.views.ViewUtils.java
net.comfreeze.lib.xml.XMLParser.java
net.comfreeze.lib.xml.wordpress.FeedXmlParser.java