Android Open Source - ildn-hub Base 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;
/* ww  w.  ja v a  2 s. c  om*/
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

import org.apache.http.util.ByteArrayBuffer;

public abstract class BaseFeedParser implements FeedParser {

  // names of the XML tags
  static final String CHANNEL = "channel";
  static final String PUB_DATE = "pubDate";
  static final String DESCRIPTION = "description";
  static final String LINK = "link";
  static final String TITLE = "title";
  static final String ITEM = "item";
  static final String CREATOR = "creator";

  protected static HashMap<String,String> nameSpacesHash=new HashMap<String, String>();
  
  private final URL feedUrl;

  protected BaseFeedParser(String feedUrl) {
    try {
      this.feedUrl = new URL(feedUrl);
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }

  protected InputStream getInputStream() {
    try {
      return feedUrl.openConnection().getInputStream();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  protected String getXml() {
    InputStream stream = null;
    try {
      byte[] tmp = new byte[1024];
      stream = getInputStream();
      ByteArrayBuffer buff = new ByteArrayBuffer(0);
      int n;
      while ((n = stream.read(tmp)) != -1) {
        buff.append(tmp, 0, n);
      }
      String xml = new String(buff.toByteArray(), "UTF-8");
      return xml.trim();
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      try {
        if (stream != null)
          stream.close();
      } catch (Exception e) {
      }
    }
  }
  
  protected String getElementNamespace(String elementName){
    String result="";
    if (nameSpacesHash.get(elementName)!=null){
      result=nameSpacesHash.get(elementName);
    }
    return result;
  }
  
}




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