protected List<SyndCategory> getCategories( Document doc, Map<String, Object> params, XWikiContext context) throws XWikiException { String mapping = (String) params.get(FIELD_CATEGORIES); if (mapping == null) { return getDefaultCategories(doc, params, context); } List<Object> categories; if (isVelocityCode(mapping)) { categories = parseList(mapping, doc, context); } else { categories = getListValue(mapping, doc, context); } List<SyndCategory> result = new ArrayList<SyndCategory>(); for (Object category : categories) { if (category instanceof SyndCategory) { result.add((SyndCategory) category); } else if (category != null) { SyndCategory scat = new SyndCategoryImpl(); scat.setName(category.toString()); result.add(scat); } } return result; }
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; }
// 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(); } }