Android Open Source - RSSReader Feed Parser






From Project

Back to project page RSSReader.

License

The source code is released under:

?????? ????? ?????? ?????? ?????????? ????????? 1.?????? ???????? ??????? ??????? ????? ?????? ????? ?????????...

If you think the Android project RSSReader 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.uyghurdev.avaroid.rssreader.operator;
/*from w ww  . j a  v  a 2 s.  c o m*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import net.uyghurdev.avaroid.rssreader.Item;
import net.uyghurdev.avaroid.rssreader.data.FeedData;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.content.Context;
import android.util.Log;

public class FeedParser {



  public FeedParser() {
    
  }



  public void parseFeed(Context ctx, int feedId, String feedUrl) throws Exception {
    
    FeedData data = new FeedData(ctx);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    try{
    
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document dom = builder.parse(feedUrl);
      Element root = dom.getDocumentElement();
      NodeList items = root.getElementsByTagName("item");
      for (int i=0;i<items.getLength();i++){
        boolean add = true;
        Item itm = new Item();
        Node item = items.item(i);
        NodeList properties = item.getChildNodes();
        for (int j=0;j<properties.getLength();j++){
          Node property = properties.item(j);
          String name = property.getNodeName();
          if (name.equalsIgnoreCase("title")){
            
            int count = data.getItemCount(property.getFirstChild().getNodeValue());
            if(count > 0){
              add = false;
              return;
            }
            
            itm.setTitle(property.getFirstChild().getNodeValue());
          } else if (name.equalsIgnoreCase( "author")){
            itm.setAuthor(property.getFirstChild().getNodeValue());
          } else if (name.equalsIgnoreCase("description")){
            itm.setDescription(property.getFirstChild().getNodeValue());
          } else if (name.equalsIgnoreCase("content:encoded")){
            itm.setDescription(property.getFirstChild().getNodeValue());
          } else if (name.equalsIgnoreCase( "link")){
            itm.setLink(property.getFirstChild().getNodeValue());
          } else if (name.equalsIgnoreCase( "img")){
            Element imgElement =  (Element) property;
            itm.setImageUrl(imgElement.getAttribute("src"));
          } else if (name.equalsIgnoreCase("pubDate")){
            itm.setPubDate(property.getFirstChild().getNodeValue());
          } 
        }

        if(add){
          data.addItem(feedId, itm);
          data.newItemAdded(feedId);
        }
        
      }
      
    }catch(Exception e){
      throw e;
    }

    
  }
  
}




Java Source Code List

ca.laplanete.mobile.example.ExampleActivity.java
ca.laplanete.mobile.example.ExamplePagedDragDropGridAdapter.java
ca.laplanete.mobile.example.Item.java
ca.laplanete.mobile.example.Page.java
ca.laplanete.mobile.pageddragdropgrid.DeleteDropZoneView.java
ca.laplanete.mobile.pageddragdropgrid.DragDropGrid.java
ca.laplanete.mobile.pageddragdropgrid.ItemsSource.java
ca.laplanete.mobile.pageddragdropgrid.OnPageChangedListener.java
ca.laplanete.mobile.pageddragdropgrid.PagedContainer.java
ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGridAdapter.java
ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGrid.java
net.uyghurdev.avaroid.rssreader.About.java
net.uyghurdev.avaroid.rssreader.AddFeedActivity.java
net.uyghurdev.avaroid.rssreader.Configs.java
net.uyghurdev.avaroid.rssreader.ContentActivity.java
net.uyghurdev.avaroid.rssreader.CustomAlertDialog.java
net.uyghurdev.avaroid.rssreader.EditFeedActivity.java
net.uyghurdev.avaroid.rssreader.ImageLoader.java
net.uyghurdev.avaroid.rssreader.ItemAdapter.java
net.uyghurdev.avaroid.rssreader.ItemListActivity.java
net.uyghurdev.avaroid.rssreader.Item.java
net.uyghurdev.avaroid.rssreader.LItem.java
net.uyghurdev.avaroid.rssreader.RSSReaderActivity.java
net.uyghurdev.avaroid.rssreader.SettingsActivity.java
net.uyghurdev.avaroid.rssreader.SplashActivity.java
net.uyghurdev.avaroid.rssreader.SuggestedFeedsActivity.java
net.uyghurdev.avaroid.rssreader.data.DataHelper_.java
net.uyghurdev.avaroid.rssreader.data.FeedData.java
net.uyghurdev.avaroid.rssreader.data.OpenHelper.java
net.uyghurdev.avaroid.rssreader.operator.FeedParser.java
net.uyghurdev.avaroid.rssreader.operator.Feed.java
net.uyghurdev.avaroid.rssreader.operator.FeedsAdapter.java
net.uyghurdev.avaroid.rssreader.operator.JSONManager.java
net.uyghurdev.avaroid.rssreader.operator.NetworkOperator.java
net.uyghurdev.avaroid.rssreader.service.AlarmReceiver.java
net.uyghurdev.avaroid.rssreader.service.UpdateService.java
net.uyghurdev.avaroid.rssreader.tools.FileCache.java
net.uyghurdev.avaroid.rssreader.tools.Helper.java
net.uyghurdev.avaroid.rssreader.tools.MemoryCache.java
net.uyghurdev.avaroid.rssreader.tools.UIManager.java
net.uyghurdev.avaroid.rssreader.tools.Utils.java