private ArrayList<String> getCategories(Item item) { ArrayList<String> lista = new ArrayList<String>(); Iterator<Category> it = item.getCategories().iterator(); while (it.hasNext()) { lista.add(it.next().getText()); } return lista; }
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 long findFeedbackName(Post post) { RssReader r = new RssReader(boardAddress, "noOne"); ArrayList<Post> posts = r.readPosts(false); if (posts != null) { if (!posts.isEmpty()) { for (Iterator<Post> it = posts.iterator(); it.hasNext(); ) { Post p = (Post) it.next(); /*&& post.getCategory().equals(p.getCategory()) && post.getEnclosure().equals(p.getEnclosure()) */ if (post.getDescription().equals(p.getDescription()) && post.getLink().equals(p.getLink()) && post.getTitle().equals(p.getTitle())) { return p.getId(); } } } } return 0; }
private boolean match(ArrayList<String> postsTags) { if (tag.isEmpty()) { return true; } Iterator<String> it = postsTags.iterator(); while (it.hasNext()) { String comp = it.next(); Iterator<String> itTag = tag.iterator(); while (itTag.hasNext()) { String comp2 = itTag.next(); if ((comp.toLowerCase().equals(comp2.toLowerCase())) || ((comp.toLowerCase().indexOf(comp2.toLowerCase()))) != -1) { return true; } } } return false; }
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; }