Ejemplo n.º 1
0
 public Feed getFeed(Integer page) {
   try {
     Feed feed = new Feed();
     feed.setId(getFeedId());
     feed.setTitle(getFeedTitle());
     feed.getLinks().addAll(generateLinks(page));
     feed.getAuthors().addAll(getAuthors());
     feed.getEntries().addAll(generateEntries(page));
     feed.setUpdated(
         feed.getEntries().isEmpty() ? new Date() : feed.getEntries().get(0).getUpdated());
     return feed;
   } catch (URISyntaxException e) {
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 2
0
  @GET
  @Produces(MediaType.APPLICATION_ATOM_XML)
  public Feed getFeed() throws URISyntaxException, MalformedURLException {
    log.info("appel feed stories sur baseuri : ");
    if (rq != null) {
      log.info("le request available : " + rq.getContextPath());
    } else {
      return null;
    }
    // gestion de l'adresse
    URL u = new URL("http", rq.getServerName(), rq.getLocalPort(), rq.getContextPath());
    String adresse = u.toExternalForm();
    log.info("uri base : " + u.toExternalForm());

    // gestion des histoires
    Feed feed = new Feed();
    feed.setId(new URI(adresse + "/stories.html"));
    feed.setUpdated(new Date());
    feed.setTitle("Listes histoires");
    feed.getAuthors().add(new Person("Play Writers"));

    // boucle sur chaque histoires
    List<Story> ls = storyList.getStoriesForFeed(20);
    String baseSto = "/stories/story/";
    for (Story s : ls) {
      // construction du lien de l'histoire
      Link link = new Link();
      link.setTitle(s.getStoTitle());
      link.setHref(new URI(adresse + baseSto + s.getStoURL() + ".html"));

      // construction de l'entree
      Entry entry = new Entry();
      entry.setTitle(s.getStoTitle());
      entry.setPublished(s.getStoDate());
      entry.setUpdated(s.getStoDateUpd());

      // ajout du lien dans l'entree
      entry.getLinks().add(link);
      Content content = new Content();
      content.setType(MediaType.TEXT_HTML_TYPE);
      content.setText(s.getStoSyn());
      entry.setContent(content);

      // ajout de l'entree dans le flux de sortie
      feed.getEntries().add(entry);
    }
    return feed;
  }