Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arayray.bootanimationutility.functions;
- import java.io.IOException;
- import java.net.URL;
- import javax.xml.parsers.ParserConfigurationException;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
- import org.xml.sax.InputSource;
- import org.xml.sax.SAXException;
- import org.xml.sax.XMLReader;
- import nl.matshofman.saxrssreader.RssFeed;
- import nl.matshofman.saxrssreader.RssHandler;
- import android.os.AsyncTask;
- public class DownloadUtils {
- public class retrieve extends AsyncTask<String, String, RssFeed> {
- RssHandler handler;
- private URL url;
- public retrieve(URL url) {
- this.url = url;
- }
- @Override
- protected RssFeed doInBackground(String... params) {
- try {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- SAXParser parser = factory.newSAXParser();
- XMLReader reader = parser.getXMLReader();
- handler = new RssHandler();
- InputSource input = new InputSource(url.openStream());
- reader.setContentHandler(handler);
- reader.parse(input);
- } catch (ParserConfigurationException e) {
- try {
- throw new SAXException();
- } catch (SAXException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- } catch (SAXException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- public RssFeed onPostExecute() {
- return handler.getResult();
- }
- }
- }
Add Comment
Please, Sign In to add comment