Guest User

Untitled

a guest
Jun 23rd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package com.arayray.bootanimationutility.functions;
  2.  
  3. import java.io.IOException;
  4. import java.net.URL;
  5.  
  6. import javax.xml.parsers.ParserConfigurationException;
  7. import javax.xml.parsers.SAXParser;
  8. import javax.xml.parsers.SAXParserFactory;
  9.  
  10. import org.xml.sax.InputSource;
  11. import org.xml.sax.SAXException;
  12. import org.xml.sax.XMLReader;
  13.  
  14. import nl.matshofman.saxrssreader.RssFeed;
  15. import nl.matshofman.saxrssreader.RssHandler;
  16. import android.os.AsyncTask;
  17.  
  18. public class DownloadUtils {
  19.  
  20. public class retrieve extends AsyncTask<String, String, RssFeed> {
  21. RssHandler handler;
  22. private URL url;
  23.  
  24. public retrieve(URL url) {
  25. this.url = url;
  26. }
  27.  
  28. @Override
  29. protected RssFeed doInBackground(String... params) {
  30. try {
  31. SAXParserFactory factory = SAXParserFactory.newInstance();
  32. SAXParser parser = factory.newSAXParser();
  33. XMLReader reader = parser.getXMLReader();
  34. handler = new RssHandler();
  35. InputSource input = new InputSource(url.openStream());
  36.  
  37. reader.setContentHandler(handler);
  38. reader.parse(input);
  39. } catch (ParserConfigurationException e) {
  40. try {
  41. throw new SAXException();
  42. } catch (SAXException e1) {
  43. // TODO Auto-generated catch block
  44. e1.printStackTrace();
  45. }
  46. } catch (SAXException e) {
  47. // TODO Auto-generated catch block
  48. e.printStackTrace();
  49. } catch (IOException e) {
  50. // TODO Auto-generated catch block
  51. e.printStackTrace();
  52. }
  53. return null;
  54. }
  55.  
  56. public RssFeed onPostExecute() {
  57. return handler.getResult();
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment