Android Open Source - ildn-hub Android Sax Feed Parser






From Project

Back to project page ildn-hub.

License

The source code is released under:

GNU General Public License

If you think the Android project ildn-hub 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.ildn.feed;
/* w ww.j  a v a  2 s . c om*/
import java.util.ArrayList;
import java.util.List;

import android.sax.Element;
import android.sax.EndElementListener;
import android.sax.EndTextElementListener;
import android.sax.RootElement;
import android.util.Log;
import android.util.Xml;

public class AndroidSaxFeedParser extends BaseFeedParser {

  static final String RSS = "rss";
  
  private static final String LOG_ID = "ILDN Hub - AndroidSaxFeedParser";

  
  static{
    try{
    nameSpacesHash.put(CREATOR, "http://purl.org/dc/elements/1.1/");
    }catch (Throwable e){
      Log.e(LOG_ID,"Error in intializing: "+e.toString(),e);
    }
  }
  

  public AndroidSaxFeedParser(String feedUrl) {
    super(feedUrl);
  }

  public List<Message> parse(){
    final Message currentMessage = new Message();
    RootElement root = new RootElement(RSS);
    final List<Message> messages = new ArrayList<Message>();
    Element channel = root.getChild(CHANNEL);
    Element item = channel.getChild(ITEM);
    item.setEndElementListener(new EndElementListener() {
      public void end() {
        try{
        messages.add((Message)currentMessage.clone());
        }catch(Throwable e){
          Log.e(LOG_ID,"Enable to add message "+currentMessage.toString()+": "+e.toString(),e);
          throw new RuntimeException(e);
        }
      }
    });
    item.getChild(getElementNamespace(TITLE),TITLE).setEndTextElementListener(
        new EndTextElementListener() {
          public void end(String body) {
            currentMessage.setTitle(body);
          }
        });
    item.getChild(getElementNamespace(LINK),LINK).setEndTextElementListener(
        new EndTextElementListener() {
          public void end(String body) {
            currentMessage.setLink(body);
          }
        });
    item.getChild(getElementNamespace(DESCRIPTION),DESCRIPTION).setEndTextElementListener(
        new EndTextElementListener() {
          public void end(String body) {
            currentMessage.setDescription(body);
          }
        });
    item.getChild(getElementNamespace(PUB_DATE),PUB_DATE).setEndTextElementListener(
        new EndTextElementListener() {
          public void end(String body) {
            currentMessage.setDate(body);
          }
        });
    item.getChild(getElementNamespace(CREATOR),CREATOR).setEndTextElementListener(
        new EndTextElementListener() {
          public void end(String body) {
            currentMessage.setCreator(body);
          }
        });
    try {
      Xml.parse(this.getXml(), root.getContentHandler());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    return messages;
  }
}




Java Source Code List

net.ildn.Authentication.java
net.ildn.CoverFlow.java
net.ildn.DataRetriever.java
net.ildn.GlobalMenu.java
net.ildn.ImageAdapter.java
net.ildn.ListaPortali.java
net.ildn.NewsAdapter.java
net.ildn.NewsItemRow.java
net.ildn.OtherActivity.java
net.ildn.SexySplash.java
net.ildn.SimpleCrypto.java
net.ildn.Splash.java
net.ildn.UserCredential.java
net.ildn.WebContent.java
net.ildn.debianitalia.DebianBlogActivity.java
net.ildn.debianitalia.DebianForumActivity.java
net.ildn.debianitalia.DebianGuideActivity.java
net.ildn.debianitalia.DebianItalia.java
net.ildn.debianitalia.DebianNewsActivity.java
net.ildn.fedorait.BlogActivity.java
net.ildn.fedorait.ForumActivity.java
net.ildn.fedorait.GuideActivity.java
net.ildn.fedorait.NewsActivity.java
net.ildn.fedorait.fedorait.java
net.ildn.feed.AndroidSaxFeedParser.java
net.ildn.feed.BaseFeedParser.java
net.ildn.feed.FeedParser.java
net.ildn.feed.Message.java
net.ildn.mageiaitalia.MageiaBlogActivity.java
net.ildn.mageiaitalia.MageiaForumActivity.java
net.ildn.mageiaitalia.MageiaGuideActivity.java
net.ildn.mageiaitalia.MageiaItalia.java
net.ildn.mageiaitalia.MageiaNewsActivity.java
net.ildn.mandrivaitalia.MandrivaBlogActivity.java
net.ildn.mandrivaitalia.MandrivaForumActivity.java
net.ildn.mandrivaitalia.MandrivaGuideActivity.java
net.ildn.mandrivaitalia.MandrivaItalia.java
net.ildn.mandrivaitalia.MandrivaNewsActivity.java
net.ildn.suseitalia.SuseBlogActivity.java
net.ildn.suseitalia.SuseForumActivity.java
net.ildn.suseitalia.SuseGuideActivity.java
net.ildn.suseitalia.SuseItalia.java
net.ildn.suseitalia.SuseNewsActivity.java