public static List<RssFeed> loadFeeds() { loadDriver(); Connection conn = null; ResultSet rs = null; List<RssFeed> feeds = new ArrayList<>(); try { // database name String dbName = "demoDB"; conn = DriverManager.getConnection(protocol + dbName + ";create=true", props); rs = conn.createStatement().executeQuery("select id, title, url from rssFeed"); while (rs.next()) { String title = rs.getString("title"); String url = rs.getString("url"); RssFeed rssFeed = new RssFeed(title, url); rssFeed.id = rssFeed.link.hashCode(); feeds.add(rssFeed); } shutdown(); } catch (SQLException sqle) { sqle.printStackTrace(); } finally { close(rs); close(conn); } return feeds; }
public RssFeed fetchRssFeed(String url) { try { SAXParser saxParser = factory.newSAXParser(); SaxRssHandler handler = new SaxRssHandler(); saxParser.parse(new URL(url).openStream(), handler); RssFeed rssFeed = handler.getRssFeed(); rssFeed.setUrl(url); cleaner.clean(rssFeed); return rssFeed; } catch (Exception e) { throw new RuntimeException(e); } }
private void updateListView() { rssList.clear(); if (rssFeed != null) rssList.addAll(rssFeed.getList()); rssAdapter.config().notifyDataSetChanged(); dbQuery.updateRssItems(); this.getListView().setSelection(0); }
public Response makeResponse(FitNesseContext context, Request request) throws Exception { WikiPage contextPage = getContextPage(context, request.getResource()); WikiPage recentChangesPage = context.root.getChildPage(RecentChanges.RECENT_CHANGES); feed = new RssFeed(getConfiguredRssLinkPrefixFrom(contextPage)); buildItemReportIfRecentChangesExists(recentChangesPage, request.getResource()); return feed.asResponse(); }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) { chars.delete(0, chars.length()); if (qName.equalsIgnoreCase("image")) { if (!isItem) { isImage = true; } } else if (qName.equalsIgnoreCase("item")) { isItem = true; item = new RssItem(); feed.addItem(item); } }
@Override public void endElement(String uri, String localName, String qName) { if (localName.equalsIgnoreCase("image")) { if (!isItem) { isImage = false; } } else if (localName.equalsIgnoreCase("url")) { if (isImage) { feed.setLogo(StringEscapeUtils.unescapeXml(chars.toString())); } } else if (localName.equalsIgnoreCase("ttl")) { if (!isItem) { feed.setTtl(Integer.parseInt(StringEscapeUtils.unescapeXml(chars.toString()))); } } else if (localName.equalsIgnoreCase("title")) { if (!isImage) { if (isItem) { item.setTitle(StringEscapeUtils.unescapeXml(chars.toString())); } else { feed.setTitle(StringEscapeUtils.unescapeXml(chars.toString())); } } } else if (localName.equalsIgnoreCase("description")) { if (isItem) { item.setDescription(StringEscapeUtils.unescapeXml(chars.toString())); } else { feed.setDescription(StringEscapeUtils.unescapeXml(chars.toString())); } } else if (localName.equalsIgnoreCase("pubDate")) { if (isItem) { try { item.setDate(dateFormat.parse(StringEscapeUtils.unescapeXml(chars.toString()))); } catch (Exception e) { Log.e(LOG_CAT, "pubDate", e); } } else { try { feed.setDate(dateFormat.parse(StringEscapeUtils.unescapeXml(chars.toString()))); } catch (Exception e) { Log.e(LOG_CAT, "pubDate", e); } } } else if (localName.equalsIgnoreCase("item")) { isItem = false; } else if (localName.equalsIgnoreCase("link")) { if (isItem) { item.setLink(StringEscapeUtils.unescapeXml(chars.toString())); } else { feed.setLink(StringEscapeUtils.unescapeXml(chars.toString())); } } if (localName.equalsIgnoreCase("item")) {} }
private void buildItemReport(String resource, RecentChangesPage recentChangesPage) throws Exception { for (RecentChangesPageEntry line : recentChangesPage.getLinesApplicableTo(resource)) { feed.addItem(line); } }