コード例 #1
0
 /**
  * Overwrites the current values of the given feed entry with new ones computed from the specified
  * source document.
  *
  * @param entry the feed entry whose fields are going to be overwritten
  * @param doc the source for the new values to be set on the fields of the feed entry
  * @param params parameters to adjust the computation. Each concrete strategy may define its own
  *     (key, value) pairs
  * @param context the XWiki context
  * @throws XWikiException
  */
 public void sourceDocument(
     SyndEntry entry, Document doc, Map<String, Object> params, XWikiContext context)
     throws XWikiException {
   entry.setUri(getURI(doc, params, context));
   entry.setLink(getLink(doc, params, context));
   entry.setTitle(getTitle(doc, params, context));
   entry.setDescription(getDescription(doc, params, context));
   entry.setCategories(getCategories(doc, params, context));
   entry.setPublishedDate(getPublishedDate(doc, params, context));
   entry.setUpdatedDate(getUpdateDate(doc, params, context));
   entry.setAuthor(getAuthor(doc, params, context));
   entry.setContributors(getContributors(doc, params, context));
 }
コード例 #2
0
ファイル: SyndFeedFactory.java プロジェクト: GUEDDES/gnizr
 public static SyndFeed create(
     List<Bookmark> bookmarks,
     String author,
     String title,
     String link,
     Date pubDate,
     String feedUri) {
   logger.debug("SyndFeedFactory create method called");
   logger.debug("bookmarks=" + bookmarks);
   logger.debug("author=" + author);
   logger.debug("title=" + title);
   logger.debug("link=" + link);
   logger.debug("pubDate=" + pubDate);
   logger.debug("feedUri=" + feedUri);
   SyndFeed syndFeed = new SyndFeedImpl();
   syndFeed.setAuthor(author);
   syndFeed.setTitle(title);
   syndFeed.setUri(feedUri);
   syndFeed.setLink(link);
   syndFeed.setPublishedDate(pubDate);
   List<SyndEntry> entries = new ArrayList<SyndEntry>();
   for (Bookmark bmark : bookmarks) {
     SyndEntry entry = new SyndEntryImpl();
     entry.setTitle(bmark.getTitle());
     entry.setAuthor(bmark.getUser().getUsername());
     entry.setLink(bmark.getLink().getUrl());
     entry.setUri("urn:bookmark:" + bmark.getId());
     entry.setUpdatedDate(bmark.getLastUpdated());
     List<String> tags = bmark.getTagList();
     List<SyndCategory> cats = new ArrayList<SyndCategory>();
     for (String aTag : tags) {
       SyndCategory aCat = new SyndCategoryImpl();
       aCat.setName(aTag);
       cats.add(aCat);
     }
     if (cats.isEmpty() == false) {
       entry.setCategories(cats);
     }
     SyndContent cnt = new SyndContentImpl();
     cnt.setType("text/html");
     cnt.setValue(bmark.getNotes());
     entry.setDescription(cnt);
     entries.add(entry);
   }
   syndFeed.setEntries(entries);
   syndFeed.setEncoding("UTF-8");
   logger.debug("done initializing syndFeed object");
   return syndFeed;
 }
コード例 #3
0
ファイル: EntryBuilder.java プロジェクト: abremar/portal3
  public SyndEntry build() {
    final SyndEntry entry = new SyndEntryImpl();

    if (uri != null) {
      entry.setUri(uri);
    }
    if (title != null) {
      entry.setTitleEx(title);
    }
    if (link != null) {
      entry.setLink(link);
    }
    if (links != null) {
      entry.setLinks(links);
    }
    if (description != null) {
      entry.setDescription(description);
    }
    if (contents != null) {
      entry.setContents(contents);
    }
    if (enclosures != null) {
      entry.setEnclosures(enclosures);
    }
    if (publishedDate != null) {
      entry.setPublishedDate(publishedDate);
    }
    if (updatedDate != null) {
      entry.setUpdatedDate(updatedDate);
    }
    if (author != null) {
      entry.setAuthor(author);
    }
    if (authors != null) {
      entry.setAuthors(authors);
    }
    if (contributors != null) {
      entry.setContributors(contributors);
    }
    if (categories != null) {
      entry.setCategories(categories);
    }

    return entry;
  }
コード例 #4
0
  @Override
  public SyndEntry getSyndEntry(
      HttpServletRequest request, HttpServletResponse response, Object bean) {
    CMTeasable teasable = (CMTeasable) bean;

    SyndPerson syndPerson = new SyndPersonImpl();
    syndPerson.setName(AUTHOR_NAME);

    SyndEntry entry = new SyndEntryImpl();
    entry.setAuthor(AUTHOR_NAME);
    entry.setAuthors(Collections.singletonList(syndPerson));
    entry.getModules().add(createMediaEntryModule(request, response, teasable)); // NOSONAR
    entry.setCategories(Collections.<String>emptyList());
    entry.setTitle(getTitle(request, response, teasable));
    entry.setPublishedDate(teasable.getContent().getCreationDate().getTime());
    entry.setUpdatedDate(teasable.getContent().getModificationDate().getTime());
    entry.setLink(getLink(request, response, teasable, null));
    entry.setDescription(createSyndContent(teasable));

    return entry;
  }
コード例 #5
0
  protected SyndEntry createSyndEntry(Item item) {
    SyndEntry syndEntry = new SyndEntryImpl();

    syndEntry.setModules(ModuleUtils.cloneModules(item.getModules()));

    if (((List) item.getForeignMarkup()).size() > 0) {
      syndEntry.setForeignMarkup(item.getForeignMarkup());
    }

    syndEntry.setUri(item.getUri());
    syndEntry.setLink(item.getLink());
    syndEntry.setTitle(item.getTitle());
    if (item.getDescription() != null) {
      SyndContent description = new SyndContentImpl();
      description.setValue(item.getDescription().getValue());
      syndEntry.setDescription(description);
    }
    if (item.getAuthor() != null) syndEntry.setAuthor(item.getAuthor());
    if (item.getPubDate() != null) syndEntry.setPublishedDate(item.getPubDate());
    syndEntry.setCategories(item.getCategories());
    return syndEntry;
  }
コード例 #6
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();
    }
  }