コード例 #1
0
ファイル: arXivDB.java プロジェクト: metao1/mlearning
  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;
  }
コード例 #2
0
ファイル: FeedLinkListParser.java プロジェクト: Lee-Jaeho/RSS
  public List<Feed> getFeeds(String url, int maxSize) {
    List<Feed> result = new ArrayList<>();

    try {
      org.jsoup.nodes.Document doc = Jsoup.connect(url).timeout(15000).get();

      Indicator titleIndicator = indicators.get(TAG_TITLE);
      Indicator linkIndicator = indicators.get(TAG_LINK);
      Indicator descriptionIndicator = indicators.get(TAG_DESCRIPTION);
      Indicator pubDateIndicator = indicators.get(TAG_PUB_DATE);
      Indicator authorIndicator = indicators.get(TAG_AUTOR);

      Elements links = null;

      if (linkIndicator != null && !linkIndicator.equals("")) {
        links = doc.select(linkIndicator.indicator);
      }

      int size =
          links == null
              ? 0
              : (links.size()
                      - linkIndicator.frontSkipCount
                      - linkIndicator.rearSkipCount
                      + linkIndicator.middleSkipCount)
                  / (linkIndicator.middleSkipCount + 1);
      if (maxSize != 0) {
        size = size > maxSize ? maxSize : size;
      }
      for (int i = 0; i < size; i++) {
        Feed feed = new Feed();

        try {
          Element e =
              links.get(i * (linkIndicator.middleSkipCount + 1) + linkIndicator.frontSkipCount);
          feed.link = e.attr("href");
          if (feed.link == null || feed.link.equals("")) {
            feed.link = e.text();
          }
          if (feed.link == null) {
            feed.link = url;
          }
          if (feed.link != null && feed.link.startsWith("/")) {
            URL u = new URL(url);
            feed.link = u.getProtocol() + "://" + u.getHost() + feed.link;
          }
          feed.link = convertLink(feed.link);
        } catch (Exception ignore) {
        }

        org.jsoup.nodes.Document doc2 = Jsoup.connect(feed.link).timeout(15000).get();

        try {
          feed.title =
              doc2.select(titleIndicator.indicator).get(titleIndicator.frontSkipCount).text();
        } catch (Exception ignore) {
        }
        if (descriptionIndicator != null) {
          try {
            feed.description =
                doc2.select(descriptionIndicator.indicator)
                    .get(descriptionIndicator.frontSkipCount)
                    .text();
          } catch (Exception ignore) {
          }
        }
        if (pubDateIndicator != null) {
          try {
            feed.pubDate =
                doc2.select(pubDateIndicator.indicator).get(pubDateIndicator.frontSkipCount).text();
          } catch (Exception ignore) {
          }
        }
        if (authorIndicator != null) {
          try {
            feed.author =
                doc2.select(authorIndicator.indicator).get(authorIndicator.frontSkipCount).text();
          } catch (Exception ignore) {
          }
        }

        result.add(feed);
      }
    } catch (IOException e) {
    }

    return result;
  }