Exemplo n.º 1
0
  private SyndFeed createFeed() {

    SyndFeed feed = new SyndFeedImpl();

    SyndPerson auteur = new SyndPersonImpl();
    auteur.setName("Gildas Cuisinier");
    auteur.setEmail("*****@*****.**");

    feed.setTitle("RSS Veille Techno");
    feed.setAuthors(Collections.singletonList(auteur));
    feed.setDescription("RSS d'exemple !");
    feed.setLink("http://svn.cyg.be/");
    feed.setPublishedDate(new Date());
    feed.setLanguage("fr");

    SyndEntry entry = new SyndEntryImpl();
    entry.setTitle("Ajout du projet Rome sur le SVN");
    entry.setLink("https://rome.dev.java.net/");

    SyndContent description = new SyndContentImpl();
    description.setValue("Ajout d'un projet Rome sur le SVN afin de voir comment creer un RSS");
    description.setType("text");
    entry.setDescription(description);
    entry.setAuthors(Collections.singletonList(auteur));

    feed.getEntries().add(entry);

    return feed;
  }
Exemplo n.º 2
0
  @Override
  protected void createFeed(SyndFeed feed, Map model) {
    @SuppressWarnings("unchecked")
    List<PreparedUserEvent> list = (List<PreparedUserEvent>) model.get("topicsList");
    String s = "Ответы на комментарии пользователя " + model.get("nick");
    feed.setTitle(s);
    feed.setLink("http://www.linux.org.ru");
    feed.setUri("http://www.linux.org.ru");
    feed.setAuthor("");
    feed.setDescription(s);

    Date lastModified;
    if (!list.isEmpty()) {
      lastModified = list.get(0).getEvent().getEventDate();
    } else {
      lastModified = new Date();
    }
    feed.setPublishedDate(lastModified);

    List<SyndEntry> entries = new ArrayList<>();
    feed.setEntries(entries);
    for (PreparedUserEvent preparedUserEvent : list) {
      UserEvent item = preparedUserEvent.getEvent();

      SyndEntry feedEntry = new SyndEntryImpl();
      feedEntry.setPublishedDate(item.getEventDate());
      feedEntry.setTitle(StringEscapeUtils.unescapeHtml4(item.getSubj()));

      String link;

      if (item.getCid() != 0) {
        feedEntry.setAuthor(preparedUserEvent.getAuthor().getNick());

        link =
            String.format(
                "http://www.linux.org.ru/jump-message.jsp?msgid=%s&cid=%s",
                String.valueOf(item.getTopicId()), String.valueOf(item.getCid()));
      } else {
        link =
            String.format(
                "http://www.linux.org.ru/view-message.jsp?msgid=%s",
                String.valueOf(item.getTopicId()));
      }

      feedEntry.setLink(link);
      feedEntry.setUri(link);

      if (preparedUserEvent.getMessageText() != null) {
        SyndContent message = new SyndContentImpl();
        message.setValue(StringUtil.removeInvalidXmlChars(preparedUserEvent.getMessageText()));
        message.setType("text/html");
        feedEntry.setDescription(message);
      }
      entries.add(feedEntry);
    }
  }
Exemplo n.º 3
0
  private String getEntryContent(SyndEntry entry) {
    List contents = entry.getContents();
    StringBuffer buffer = new StringBuffer();
    for (int index = 0; contents != null && index < contents.size(); index++) {
      SyndContent content = (SyndContent) contents.get(index);
      buffer.append(content.getValue());
    }

    return (buffer.length() == 0) ? entry.getDescription().getValue() : buffer.toString();
  }
Exemplo n.º 4
0
  // Logs a new ATOM entry
  public static synchronized void addATOMEntry(
      String title, String link, String description, File atomFile, String context) {
    try {

      if (atomFile.exists()) {

        // System.out.println("ATOM file found!");
        /** Namespace URI for content:encoded elements */
        String CONTENT_NS = "http://www.w3.org/2005/Atom";

        /** Parses RSS or Atom to instantiate a SyndFeed. */
        SyndFeedInput input = new SyndFeedInput();

        /** Transforms SyndFeed to RSS or Atom XML. */
        SyndFeedOutput output = new SyndFeedOutput();

        // Load the feed, regardless of RSS or Atom type
        SyndFeed feed = input.build(new XmlReader(atomFile));

        // Set the output format of the feed
        feed.setFeedType("atom_1.0");

        List<SyndEntry> items = feed.getEntries();
        int numItems = items.size();
        if (numItems > 9) {
          items.remove(0);
          feed.setEntries(items);
        }

        SyndEntry newItem = new SyndEntryImpl();
        newItem.setTitle(title);
        newItem.setLink(link);
        newItem.setUri(link);
        SyndContent desc = new SyndContentImpl();
        desc.setType("text/html");
        desc.setValue(description);
        newItem.setDescription(desc);
        desc.setType("text/html");
        newItem.setPublishedDate(new java.util.Date());

        List<SyndCategory> categories = new ArrayList<SyndCategory>();
        if (CommonConfiguration.getProperty("htmlTitle", context) != null) {
          SyndCategory category2 = new SyndCategoryImpl();
          category2.setName(CommonConfiguration.getProperty("htmlTitle", context));
          categories.add(category2);
        }
        newItem.setCategories(categories);
        if (CommonConfiguration.getProperty("htmlAuthor", context) != null) {
          newItem.setAuthor(CommonConfiguration.getProperty("htmlAuthor", context));
        }
        items.add(newItem);
        feed.setEntries(items);

        feed.setPublishedDate(new java.util.Date());

        FileWriter writer = new FileWriter(atomFile);
        output.output(feed, writer);
        writer.toString();
      }
    } catch (IOException ioe) {
      System.out.println("ERROR: Could not find the ATOM file.");
      ioe.printStackTrace();
    } catch (Exception e) {
      System.out.println("Unknown exception trying to add an entry to the ATOM file.");
      e.printStackTrace();
    }
  }
 /**
  * Sets the entry title.
  *
  * <p>
  *
  * @param title the entry title to set, <b>null</b> if none.
  */
 public void setTitle(String title) {
   if (_title == null) _title = new SyndContentImpl();
   _title.setValue(title);
 }
 /**
  * Returns the entry title.
  *
  * <p>
  *
  * @return the entry title, <b>null</b> if none.
  */
 public String getTitle() {
   if (_title != null) return _title.getValue();
   return null;
 }