@Test
 public void testGetPodcastById()
     throws IOException, ParserConfigurationException, InvalidRssFeedException,
         InvalidDateFormatException, SAXException, NotFoundException {
   Feed actualFeed = rssFeedService.getRssFeedPodcastById("3", false);
   assertNotNull("Feed Object should not be null ", actualFeed);
   assertEquals(1, actualFeed.getPodcasts().size());
   assertEquals("3", actualFeed.getPodcasts().get(0).getId());
 }
예제 #2
0
 /** Delete files that aren't needed anymore */
 private void cleanup(Feed feed) {
   if (feed.getFile_url() != null) {
     if (new File(feed.getFile_url()).delete())
       if (BuildConfig.DEBUG) Log.d(TAG, "Successfully deleted cache file.");
       else Log.e(TAG, "Failed to delete cache file.");
     feed.setFile_url(null);
   } else if (BuildConfig.DEBUG) {
     Log.d(TAG, "Didn't delete cache file: File url is not set.");
   }
 }
 @Test
 public void testGetMostRecentPodcast()
     throws IOException, ParserConfigurationException, InvalidRssFeedException,
         InvalidDateFormatException, SAXException, NotFoundException {
   Feed actualFeed = rssFeedService.getRssFeedPodcasts(true);
   assertNotNull("Feed Object should not be null ", actualFeed);
   assertEquals(1, actualFeed.getPodcasts().size());
   String actualMostRecentDate =
       DateUtils.convertDateToGMTString(actualFeed.getPodcasts().get(0).getPubDate());
   assertEquals(ACTUAL_MOST_RECENT_DATE, actualMostRecentDate);
 }
예제 #4
0
 /**
  * Checks if the FeedItems of this feed have images that point to the same URL. If two FeedItems
  * have an image that points to the same URL, the reference of the second item is removed, so
  * that every image reference is unique.
  */
 private void removeDuplicateImages(Feed feed) {
   for (int x = 0; x < feed.getItems().size(); x++) {
     for (int y = x + 1; y < feed.getItems().size(); y++) {
       FeedItem item1 = feed.getItems().get(x);
       FeedItem item2 = feed.getItems().get(y);
       if (item1.hasItemImage() && item2.hasItemImage()) {
         if (StringUtils.equals(
             item1.getImage().getDownload_url(), item2.getImage().getDownload_url())) {
           item2.setImage(null);
         }
       }
     }
   }
 }
예제 #5
0
  public void run() {
    while (true) {

      try {
        // System.out.println(r+": Take(wait)");
        // String[] info = q.take();
        String blogID = q.poll(60, TimeUnit.SECONDS);
        if (blogID == null) {
          System.out.println("Poll.Timeout");
          continue;
        }

        // System.out.println(r+": Take(get) : "+blogID);

        if (blogID == NO_MORE_WORK) {
          break;
        }

        URL feedUrl = new URL("http://www.blogger.com/feeds/" + blogID + "/comments/default");
        Query myQuery = new Query(feedUrl);
        myQuery.setMaxResults(25);

        System.out.print(r + "+,");
        Feed resultFeed = myService.query(myQuery, Feed.class);

        for (Entry entry : resultFeed.getEntries()) {
          if (entry.getAuthors().get(0).getUri() != null) {
            String profileID = entry.getAuthors().get(0).getUri().replaceAll("[^\\d]", "");
            if (profileID.length() == 20) {
              try {
                myStm.executeUpdate(
                    "INSERT IGNORE INTO author SET profileID = '" + profileID + "'");
                // System.out.print(r+"+,");
              } catch (Exception e) {
              }
            }
          }
        }

      } catch (Exception e) {
        System.out.print(r + "ERR,");
      }
    }

    System.out.println("Bye(" + r + ")");
    try {
      myStm.close();
    } catch (Exception e) {
    }
  }
  @Test
  public void testGetPodcastAlternateTrue()
      throws NotFoundException, InvalidRssFeedException, SAXException, InvalidDateFormatException,
          ParserConfigurationException, IOException {
    Feed actualFeed = rssFeedService.getRssFeedPodcastById("3", true);

    assertNotNull("Feed Object should not be null ", actualFeed);
    assertEquals(4, actualFeed.getPodcasts().size());
    boolean isPresent = false;
    for (int i = 0; i < actualFeed.getPodcasts().size(); i++) {
      if (actualFeed.getPodcasts().get(i).getId().equals("3")) isPresent = true;
    }
    assertFalse("podcast with id=3 should not be included in the result", isPresent);
  }
예제 #7
0
 /** Checks if the feed was parsed correctly. */
 private boolean checkFeedData(Feed feed) {
   if (feed.getTitle() == null) {
     Log.e(TAG, "Feed has no title.");
     return false;
   }
   if (!hasValidFeedItems(feed)) {
     Log.e(TAG, "Feed has invalid items");
     return false;
   }
   return true;
 }
예제 #8
0
 private boolean hasValidFeedItems(Feed feed) {
   for (FeedItem item : feed.getItems()) {
     if (item.getTitle() == null) {
       Log.e(TAG, "Item has no title");
       return false;
     }
     if (item.getPubDate() == null) {
       Log.e(TAG, "Item has no pubDate. Using current time as pubDate");
       if (item.getTitle() != null) {
         Log.e(TAG, "Title of invalid item: " + item.getTitle());
       }
       item.setPubDate(new Date());
     }
   }
   return true;
 }
  private Feed getExpectedFeed() throws ParseException {
    Feed feed = new Feed();
    List<Podcast> podcasts = new ArrayList<>();

    feed.setTitle(CHANNEL_TITLE);
    feed.setLink(CHANNEL_LINK);
    feed.setDescription(CHANNEL_DESCRIPTION);
    feed.setLanguage(CHANNEL_LANGUAGE);
    feed.setCopyright(CHANNEL_COPYRIGHT);

    Itune itune = new Itune();
    itune.setSubtitle(CHANNEL_ITUNES_SUBTITLE);
    itune.setAuthor(CHANNEL_ITUNES_AUTHOR);
    itune.setSummary(CHANNEL_ITUNES_SUMMARY);
    itune.setImage(CHANNEL_ITUNES_IMAGE);
    itune.setIsExplicit(CHANNEL_ITUNES_EXPICIT);
    itune.setNewFeedUrl(CHANNEL_ITUNES_NEW_FEED_URL);
    itune.setOwner(new Owner(CHANNEL_ITUNES_OWNER_NAME, CHANNEL_ITUNES_OWNER_EMAIL));
    itune.setCategory(CHANNEL_ITUNES_CATEGORY);
    feed.setItune(itune);

    for (int i = 0; i < 5; i++) {
      String id = String.valueOf(i + 1);
      Podcast p = new Podcast();
      p.setId(id);
      p.setAuthor(ITEM_AUTHOR + id);
      p.setTitle(ITEM_TITLE + id);
      p.setDescription(ITEM_DESCRIPTION + id);
      Date d = getNewDate(i);
      p.setPubDate(getNewDate(i));
      p.setEnclosure(
          new Enclosure(ITEM_ENCLOSURE_URL + id, ITEM_ENCLOSURE_TYPE, ITEM_ENCLOSURE_LENGHT));

      Itune it = new Itune();
      it.setSubtitle(ITEM_ITUNE_SUBTITLE + id);
      it.setIsExplicit(ITEM_ITUNE_EXPLICIT);
      it.setSummary(ITEM_ITUNE_SUMMARY + id);
      it.setDuration(ITEM_ITUNE_DURATION);
      p.setItune(it);
      podcasts.add(p);
    }
    feed.setPodcasts(podcasts);
    return feed;
  }
예제 #10
0
    private Feed parseFeed(DownloadRequest request) {
      Feed savedFeed = null;

      Feed feed = new Feed(request.getSource(), new Date());
      feed.setFile_url(request.getDestination());
      feed.setId(request.getFeedfileId());
      feed.setDownloaded(true);
      feed.setPreferences(
          new FeedPreferences(0, true, request.getUsername(), request.getPassword()));

      DownloadError reason = null;
      String reasonDetailed = null;
      boolean successful = true;
      FeedHandler feedHandler = new FeedHandler();

      try {
        feed = feedHandler.parseFeed(feed).feed;
        if (BuildConfig.DEBUG) Log.d(TAG, feed.getTitle() + " parsed");
        if (checkFeedData(feed) == false) {
          throw new InvalidFeedException();
        }

      } catch (SAXException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      } catch (IOException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      } catch (ParserConfigurationException e) {
        successful = false;
        e.printStackTrace();
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      } catch (UnsupportedFeedtypeException e) {
        e.printStackTrace();
        successful = false;
        reason = DownloadError.ERROR_UNSUPPORTED_TYPE;
        reasonDetailed = e.getMessage();
      } catch (InvalidFeedException e) {
        e.printStackTrace();
        successful = false;
        reason = DownloadError.ERROR_PARSER_EXCEPTION;
        reasonDetailed = e.getMessage();
      }

      // cleanup();
      if (savedFeed == null) {
        savedFeed = feed;
      }

      if (successful) {
        return savedFeed;
      } else {
        saveDownloadStatus(
            new DownloadStatus(
                savedFeed,
                savedFeed.getHumanReadableIdentifier(),
                reason,
                successful,
                reasonDetailed));
        return null;
      }
    }