public ArrayList<Feedback> readFeedbacks(long idPost) { RssParser parser = null; Rss rss = null; // System.out.println("right? "+post); try { parser = RssParserFactory.createDefault(); rss = parser.parse(new URL(boardAddress + "feedbacks?action=READ&FeedbackName=" + idPost)); } catch (RssParserException e) { System.out.println(boardAddress + "feedbacks?action=READ&FeedbackName=" + idPost); System.out.println("RssParserException"); return null; } catch (MalformedURLException e) { System.out.println("MalformedURLException"); return null; } catch (IOException e) { System.out.println("IOException"); return null; } Channel c = rss.getChannel(); if (c.getItems() == null) { System.out.println("Non ci sono Feedback"); return new ArrayList<Feedback>(); } ArrayList<Item> items = new ArrayList<Item>(c.getItems()); Iterator<Item> iter = items.iterator(); ArrayList<Feedback> lista = new ArrayList<Feedback>(); while (iter.hasNext()) { Item x = iter.next(); String description = ""; String feed = ""; Title titolo = Title.AGREE; try { description = x.getDescription().getText(); } catch (NullPointerException e) { } try { feed = x.getTitle().getText(); } catch (NullPointerException e) { } if (feed != null) { if (!feed.isEmpty()) { if (feed.equals("AGREE")) titolo = Title.AGREE; else if (feed.equals("DISAGREE")) titolo = Title.DISAGREE; else if (feed.equals("PARTIALLY_AGREE")) titolo = Title.PARTIALLY_AGREE; else if (feed.equals("DETRACTOR")) titolo = Title.DETRACTOR; else continue; } } else continue; Date data = getPubDate(x); lista.add(new Feedback(description, titolo, data)); } return lista; }
public ArrayList<Post> readPosts(boolean advanced) { RssParser parser = null; Rss rss = null; try { parser = RssParserFactory.createDefault(); System.out.println(boardAddress); rss = parser.parse(new URL(boardAddress + "postboard?action=READ")); } catch (RssParserException e) { System.out.println("RssParserException"); return null; } catch (MalformedURLException e) { System.out.println("MalformedURLException"); return null; } catch (IOException e) { System.out.println("IOException"); return null; } Channel c = rss.getChannel(); if (c.getItems() == null) { System.out.println("Non ci sono Post"); return new ArrayList<Post>(); } ArrayList<Item> items = new ArrayList<Item>(c.getItems()); Iterator<Item> iter = items.iterator(); ArrayList<Post> res = new ArrayList<Post>(); while (iter.hasNext()) { Item i = (Item) iter.next(); if (advanced) if ((!bannished.equals("")) && (i.getText().indexOf(bannished) != -1)) continue; long id = getFeedbackName(i); // id sempre presente String titolo = ""; String link = ""; String description = ""; ArrayList<String> categories = new ArrayList<String>(); String enclosure = ""; String source = ""; Date date = getPubDate(i); // data sempre presente try { titolo = i.getTitle().getText(); } catch (NullPointerException e) { } try { link = i.getLink().getText(); } catch (NullPointerException e) { } try { description = i.getDescription().getText(); } catch (NullPointerException e) { } try { categories = getCategories(i); } catch (NullPointerException e) { } try { enclosure = i.getEnclosure().getText(); } catch (NullPointerException e) { } try { source = i.getSource().getText(); } catch (NullPointerException e) { } if (advanced) if (!(match(categories) && timestamp.before(date))) continue; Post p = new Post( id, titolo, link, description, "", categories, enclosure, source, date, readFeedbacks(id)); res.add(p); } if (advanced) if (res.size() > 0) timestamp = res.get(res.size() - 1).getPubDate(); return res; }