public static void main(final String[] args) {
    ApplicationContext ctx =
        new ClassPathXmlApplicationContext("classpath:application-context.xml");
    FeedDao feedDao = (FeedDao) ctx.getBean("feedDao");

    LOGGER.info("Getting all the feeds in the database");
    Collection<Feed> feeds = feedDao.findAll();
    for (Feed feed : feeds) {
      LOGGER.info(feed);
    }

    LOGGER.info("Seeking for feed with id = 1");
    Feed feed = feedDao.findFeedById(1);
    LOGGER.info(feed);

    LOGGER.info("Setting the feed inactive");
    feed.setActive(false);
    feedDao.update(feed);
    LOGGER.info(feedDao.findFeedById(feed.getFeedId()));

    Feed newFeed = new Feed(0, "yodle", "yodle", 4, true);
    LOGGER.info("Adding a new feed: " + newFeed.toString());
    feedDao.insert(newFeed);

    LOGGER.info("Getting all the feeds in the database again");
    feeds = feedDao.findAll();
    for (Feed f : feeds) {
      LOGGER.info(f);
    }
  }
 /** Test method read */
 @Test
 public void testReadPodcast() {
   final Feed readPodcast = feedManager.getFeed(feed);
   assertNotNull(readPodcast);
   assertNotNull(readPodcast.getId());
   assertEquals(PODCAST_TITLE, readPodcast.getTitle());
 }
 /** Test method update */
 @Test
 public void testUpdate() {
   feed.setTitle("The title changed");
   feedManager.updateFeedMetadata(feed);
   // re-read for assertion
   final Feed readPodcast = feedManager.getFeed(feed);
   assertEquals(feed.getTitle(), readPodcast.getTitle());
 }
Exemplo n.º 4
0
 // get datastreams
 public Datastream[] getDatastreams(Integer feedid) throws CosmException {
   try {
     Feed feed = getFeed(feedid.intValue());
     return feed.getDatastreams();
   } catch (Exception e) {
     throw new CosmException(e.getMessage());
   }
 }
 @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());
 }
Exemplo n.º 6
0
 private void insertOutline(Feed feed, Element body) {
   Element outline = new Element("outline");
   String title = feed.getTitle();
   outline.setAttribute("text", title);
   outline.setAttribute("title", title);
   outline.setAttribute("type", "rss");
   outline.setAttribute("xmlUrl", feed.getUrl());
   outline.setAttribute("htmlUrl", feed.getUrl());
   body.addContent(outline);
 }
Exemplo n.º 7
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.");
   }
 }
Exemplo n.º 8
0
 public void onDataSave(File dir) {
   ArrayList<String> lines = new ArrayList<String>();
   for (Feed feed : feeds) {
     lines.add(feed.getURL().toString());
     lines.add(Long.toString((feed.getDate() != null) ? feed.getDate().getTime() : 0L));
     lines.add(Long.toString(feed.getInterval()));
     lines.add(StringTools.implode(feed.channels.toArray(new String[feed.channels.size()]), " "));
   }
   FileLine.write(new File(dir, "rss.cfg"), lines);
 }
 @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);
 }
  /** Test method create */
  @Test
  public void testCreatePodcast() {
    final OLATResourceable podcastResource = feedManager.createPodcastResource();
    final Feed newPodcast = feedManager.getFeed(podcastResource);
    assertNotNull(newPodcast);
    assertNotNull(newPodcast.getId());

    // Has a feed folder been created?
    final VFSContainer podcastContainer = feedManager.getFeedContainer(newPodcast);
    assertNotNull(podcastContainer);
    feedManager.delete(newPodcast);
  }
 /** Test method remove */
 @Test
 @DirtiesContext
 public void testRemove() {
   final Item item = feed.getItems().get(0);
   // Count episodes before
   final int initialCount = feed.getItems().size();
   feedManager.remove(item, feed);
   // re-read feed and count episodes after adding a new one
   feed = feedManager.getFeed(feed);
   final int newCount = feed.getItems().size();
   // Compare
   assertEquals(initialCount - 1, newCount);
 }
Exemplo n.º 12
0
  protected void showDetail() {
    Intent intent = new Intent(this, DetailActivity.class);

    String title = selectedFeed.getTitle();
    String description = selectedFeed.getDescription();
    String link = selectedFeed.getLink();

    intent.putExtra("title", title);
    intent.putExtra("description", description);
    intent.putExtra("link", link);

    startActivity(intent);
  }
 /** Test method add */
 @Test
 public void testAdd() {
   final Item newEpisode = new Item();
   newEpisode.setGuid(CodeHelper.getGlobalForeverUniqueID());
   newEpisode.setTitle("This is my new Item");
   // Count episodes before
   final int initialCount = feed.getItems().size();
   feedManager.addItem(newEpisode, null, feed, PublishEventTO.getNoPublishInstance());
   // re-read feed and count episodes
   feed = feedManager.getFeed(feed);
   final int newCount = feed.getItems().size();
   // Compare
   assertEquals(initialCount + 1, newCount);
 }
Exemplo n.º 14
0
  public ArrayList<ArrayList<Feed>> getCategoriesForNewsPapers(ArrayList<String> newsPaperNames) {
    Cursor result = null;
    ArrayList<ArrayList<Feed>> categories = new ArrayList<ArrayList<Feed>>();
    ArrayList<Feed> category = new ArrayList<Feed>();

    try {
      db = appCtx.openOrCreateDatabase(databaseName, Context.MODE_PRIVATE, null);

      for (String newsPaper : newsPaperNames) {
        result =
            db.query(
                tableName,
                new String[] {"Category", "FeedURL", "Subscribed"},
                "NewsPaperName=?",
                new String[] {newsPaper},
                null,
                null,
                null);
        result.moveToFirst();
        Feed feed = new Feed();

        int categoryIndex = result.getColumnIndex("Category");
        int subscribedIndex = result.getColumnIndex("Subscribed");
        int feedUrlIndex = result.getColumnIndex("FeedURL");
        // Add to corresponding array list
        while (!result.isAfterLast()) {
          feed.setNewsPaper(newsPaper);
          feed.setCategory(result.getString(categoryIndex));
          feed.setFeedURL(result.getString(feedUrlIndex));
          feed.setSubscribed(result.getInt(subscribedIndex));

          category.add(feed);
          result.moveToNext();
        }
        categories.add(category);
        category = new ArrayList<Feed>();
      }
      result.close();
      db.close();

    } catch (SQLiteException exception) {
      Log.e(
          "NewsPaperTableHandler::getCategoriesForNewsPapers",
          "Categories could not be got " + exception.getMessage());
    } catch (Exception exception) {
      Log.e("NewsPaperTableHandler::getCategoriesForNewsPapers", exception.getMessage());
    }

    return categories;
  }
Exemplo n.º 15
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);
         }
       }
     }
   }
 }
  @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);
  }
Exemplo n.º 17
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) {
    }
  }
Exemplo n.º 18
0
 private void endTag(String name) {
   if (ITEM.equals(name)) {
     feed.addItem(currentItem);
     currentItem = Item.NONE;
   }
   state = ParseState.NONE;
 }
Exemplo n.º 19
0
 // update feed
 public void updateFeed(Feed feed) throws CosmException {
   try {
     HttpPut hr =
         new HttpPut(
             API_BASE_URL_V2 + API_RESOURCE_FEEDS + "/" + feed.getId() + JSON_FILE_EXTENSION);
     hr.setEntity(new StringEntity(feed.toJSONObject().toString()));
     HttpResponse response = this.client.execute(hr);
     StatusLine statusLine = response.getStatusLine();
     if (statusLine.getStatusCode() != 200) {
       throw new CosmException(response.getStatusLine().toString());
     }
   } catch (Exception e) {
     e.printStackTrace();
     throw new CosmException("Caught exception in create Feed");
   }
 }
Exemplo n.º 20
0
  // parsing the XML
  public void parseXMLAndStoreIt(XmlPullParser myParser) {
    int event;
    String text = null;
    // Create item
    try {
      event = myParser.getEventType();
      Item item = null;
      boolean checkItem = true;
      boolean newItem = false;

      while (event != XmlPullParser.END_DOCUMENT) {
        String name = myParser.getName();
        if (checkItem) {
          item = new Item();
          checkItem = false;
        }

        switch (event) {
          case XmlPullParser.START_TAG:
            if (name.equals("item")) {
              newItem = true;
            }
            break;
          case XmlPullParser.TEXT:
            text = myParser.getText();
            break;
          case XmlPullParser.END_TAG:
            switch (name) {
              case "title":
                if (newItem) {
                  item.setTitle(text);
                }
                break;
              case "description":
                if (newItem) {
                  item.setDescription(text);
                }
                break;
              case "link":
                if (newItem) {
                  item.setLink(text);
                }
                break;
            }
            break;
        }
        // add to an array list
        if (item.itemReady()) {
          feed.addItem(item);
          newItem = false;
          checkItem = true;
        }
        event = myParser.next();
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 21
0
 @Override
 public void run() {
   Feed f = null;
   try {
     while (true) {
       if (feeds.isEmpty()) return;
       if (feeds.size() > 1) Collections.sort(feeds);
       f = feeds.iterator().next();
       long sleep = f.getNext() - System.currentTimeMillis();
       if (sleep > 0) Thread.sleep(sleep);
       f.update();
     }
   } catch (InterruptedException e) {
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 22
0
  public List<Feed> getFeeds() {
    ArrayList<Feed> feeds = new ArrayList<Feed>();
    try {

      Cursor c =
          db.query(
              FEEDS_TABLE,
              new String[] {"feed_id", "title", "shorttitle", "url", "count", "unread"},
              null,
              null,
              null,
              null,
              null);

      int numRows = c.getCount();
      c.moveToFirst();
      for (int i = 0; i < numRows; ++i) {
        Feed feed = new Feed();
        feed.feedId = c.getLong(0);
        feed.title = c.getString(1);
        feed.shortTitle = c.getString(2);
        feed.url = c.getString(3);
        feed.count = c.getInt(4);
        feed.unread = c.getInt(5);
        feeds.add(feed);
        c.moveToNext();
      }
      c.close();

    } catch (Exception e) {
    }
    return feeds;
  }
Exemplo n.º 23
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.items);

    ItemsFragment items = (ItemsFragment) getSupportFragmentManager().findFragmentById(R.id.items);

    items.setOnItemListener(this);

    String key = getIntent().getStringExtra(EXTRA_FEED_KEY);

    if (key != null) {
      Feed feed = Feed.getFeed(key);

      setTitle(String.format(getString(R.string.feed_title), feed.toString()));
      items.loadUrl(feed.getUrl());
    }
  }
Exemplo n.º 24
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;
 }
Exemplo n.º 25
0
  public static void process(XmlPullParser parser, FeedParser feedParser)
      throws XmlPullParserException, IOException {

    Feed feed = new Feed();

    for (int eventType = parser.getEventType();
        eventType != XmlPullParser.END_DOCUMENT;
        eventType = parser.next()) {
      if (eventType == XmlPullParser.START_TAG) {
        if (isAtomElement(parser, "title")) feed.setTitle(parser.nextText());
        else if (isAtomElement(parser, "icon")) feed.setThumbnail(parser.nextText());
        else if (isAtomElement(parser, "updated"))
          feed.setLastBuildDate(Utils.parseDate(parser.nextText()));
        else if (isAtomElement(parser, "entry")) break;
      }
    }

    if (feedParser.getOnFeedInfoHandler() != null)
      feedParser.getOnFeedInfoHandler().OnFeedInfo(feedParser, feed);
    if (feedParser.shouldStopProcessing()) return;

    parseEntries(parser, feedParser);
  }
 public void setFeed(Feed feed) {
   MySeriesLogger.logger.log(Level.INFO, "Setting feed to {0}", feed);
   this.feed = feed;
   removeAll();
   feedPanel = new MyScrollableFlowPanel();
   JScrollPane panel = new JScrollPane(feedPanel);
   panel.getViewport().setOpaque(false);
   panel.setOpaque(false);
   feedPanel.setOpaque(false);
   panel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
   add(panel, BorderLayout.CENTER);
   feedPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
   int count = 0;
   MySeriesLogger.logger.log(Level.INFO, "Creating {0} feed entries", feed.getEntries().size());
   for (Iterator<SyndEntryImpl> it = feed.getEntries().iterator(); it.hasNext(); ) {
     SyndEntryImpl entry = it.next();
     FeedPanel p = new FeedPanel(feedPanel, entry, this);
     p.run();
     count++;
   }
   revalidate();
   repaint();
 }
Exemplo n.º 27
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;
  }
  /** @see junit.framework.TestCase#setUp() */
  @Before
  public void setup() {
    setupMocking();

    // Create a feed that can be read, updated or deleted.
    final OLATResourceable podcastResource = feedManager.createPodcastResource();
    feed = feedManager.getFeed(podcastResource);
    feed.setTitle(PODCAST_TITLE);
    feedManager.updateFeedMetadata(feed);

    // Add an episode
    // A feed can only be edited when it is an internal feed (meaning that
    // it is made within OLAT). Obviously, external feeds cannot be changed.
    final Item item = new Item();
    item.setTitle("My Test Item");
    feed = feedManager.updateFeedMode(Boolean.FALSE, feed);
    feedManager.addItem(item, null, feed, PublishEventTO.getNoPublishInstance());
  }
Exemplo n.º 30
0
  // create feed
  public Feed createFeed(Feed feed) throws CosmException {
    try {
      HttpPost hr = new HttpPost(API_BASE_URL_V2 + API_RESOURCE_FEEDS + JSON_FILE_EXTENSION);
      hr.setEntity(new StringEntity(feed.toJSONObject().toString()));
      HttpResponse response = this.client.execute(hr);
      StatusLine statusLine = response.getStatusLine();
      if (statusLine.getStatusCode() == 201) {
        String a[] = response.getHeaders(HEADER_PARAM_LOCATION)[0].getValue().split("/");
        Integer feedid = Integer.valueOf(a[a.length - 1]);
        this.client.getBody(response);
        return this.getFeed(feedid.intValue());
      }

      throw new CosmException(response.getStatusLine().toString());
    } catch (Exception e) {
      e.printStackTrace();
      throw new CosmException("Caught exception in create Feed" + e.getMessage());
    }
  }