コード例 #1
0
ファイル: TipiRssComponent.java プロジェクト: Dexels/navajo
  @SuppressWarnings({"unchecked"})
  private Navajo getRssNavajo(Channel c, String service) throws NavajoException {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Header h = NavajoFactory.getInstance().createHeader(n, service, "unknown", "unknown", -1);
    n.addHeader(h);
    Message channelMessage = NavajoFactory.getInstance().createMessage(n, "Channel");
    n.addMessage(channelMessage);
    addProperty(channelMessage, "Title", c.getTitle(), Property.STRING_PROPERTY);
    addProperty(channelMessage, "Link", c.getLink(), Property.STRING_PROPERTY);
    addProperty(channelMessage, "Description", c.getDescription(), Property.STRING_PROPERTY);
    addProperty(channelMessage, "Language", c.getLanguage(), Property.STRING_PROPERTY);
    addProperty(channelMessage, "Copyright", c.getCopyright(), Property.STRING_PROPERTY);
    addProperty(channelMessage, "PubDate", c.getPubDate(), Property.STRING_PROPERTY);
    addProperty(channelMessage, "Ttl", c.getTtl(), Property.STRING_PROPERTY);
    addImage(channelMessage, c.getImage());

    Message m = NavajoFactory.getInstance().createMessage(n, "Rss", Message.MSG_TYPE_ARRAY);
    n.addMessage(m);
    Collection<Item> s = c.getItems();
    for (Iterator<Item> iterator = s.iterator(); iterator.hasNext(); ) {
      Item i = iterator.next();
      addItem(m, i);
    }
    return n;
  }
コード例 #2
0
ファイル: RssReader.java プロジェクト: giacomolm/rssconnector
  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;
  }
コード例 #3
0
ファイル: TipiRssComponent.java プロジェクト: Dexels/navajo
  @SuppressWarnings("unchecked")
  public static void main(String[] args)
      throws MalformedURLException, RssParserException, IOException {
    TipiRssComponent trc = new TipiRssComponent();
    Rss r = trc.createRssFeed("http://search-result.com/directhit/xml/NL_algemeen.xml");
    //		http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml
    Channel ccc = r.getChannel();

    //		Navajo n = trc.getRssNavajo(ccc,null);
    Collection<Item> s = ccc.getItems();
    for (Iterator<Item> iterator = s.iterator(); iterator.hasNext(); ) {
      Item i = iterator.next();
      Title t = i.getTitle();
      logger.info("TT: " + t.getText());
    }
    logger.info("s: " + s);
  }
コード例 #4
0
ファイル: RssReader.java プロジェクト: giacomolm/rssconnector
  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;
  }