コード例 #1
0
ファイル: TipiRssComponent.java プロジェクト: Dexels/navajo
  private void addItem(Message m, Item i) throws NavajoException {
    Navajo n = m.getRootDoc();

    Message itemMessage =
        NavajoFactory.getInstance().createMessage(n, "Rss", Message.MSG_TYPE_ARRAY_ELEMENT);
    m.addMessage(itemMessage);
    addProperty(itemMessage, "Title", i.getTitle(), Property.STRING_PROPERTY);
    addProperty(itemMessage, "Link", i.getLink(), Property.STRING_PROPERTY);
    addProperty(itemMessage, "Description", i.getDescription(), Property.MEMO_PROPERTY);
    addProperty(itemMessage, "Author", i.getAuthor(), Property.STRING_PROPERTY);
    addProperty(itemMessage, "PubDate", i.getPubDate(), Property.STRING_PROPERTY);
    addProperty(itemMessage, "Source", i.getSource(), Property.STRING_PROPERTY);
  }
コード例 #2
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;
  }