protected void addFeed(Feed feed, Element parent) throws FeedException { Element eFeed = parent; populateFeedHeader(feed, eFeed); generateForeignMarkup(eFeed, (List) feed.getForeignMarkup()); checkFeedHeaderConstraints(eFeed); generateFeedModules(feed.getModules(), eFeed); }
@SuppressWarnings("unchecked") public String getFeedContent(Feed feed) { if (feed == null) { LOGGER.warning("Feed is unknown!"); return null; } Date updated = new Date(System.currentTimeMillis()); feed.setUpdated(updated); List<Module> modules = feed.getModules(); if (!ListUtil.isEmpty(modules)) { for (Module module : modules) { if (module instanceof DCModule) { ((DCModule) module).setDate(updated); } } } try { return wfo.outputString(feed); } catch (Exception e) { LOGGER.log(Level.WARNING, "Error while outputing feed to string: " + feed, e); return null; } }
/** Build Feed Meta Data. */ @Override protected void buildFeedMetadata( Map<String, Object> model, Feed feed, HttpServletRequest request) { setAtomTitle( model.get("feedTitle") == null ? "Project Published " : model.get("feedTitle").toString()); feed.setId(getAtomTitle()); feed.setTitle(getAtomTitle()); }
@SuppressWarnings("unchecked") protected List<String> getAllFeedSubscribers(String processInstanceId, Integer authorId) { Feed comments = getCommentsFeed(processInstanceId); if (comments == null) { return null; } return getEmails(comments.getEntries(), getUserMail(authorId)); }
public void testTitle() throws Exception { Feed feed = (Feed) getWireFeed(); assertEquals("1", feed.getId()); assertEquals("xxx1", feed.getOtherLinks().get(0).getRel()); assertEquals("xxx2", feed.getOtherLinks().get(1).getRel()); assertEquals("xxx11", feed.getOtherLinks().get(0).getType()); assertEquals("xxx22", feed.getOtherLinks().get(1).getType()); assertEquals("http://foo.com/1", feed.getOtherLinks().get(0).getHref()); assertEquals("http://foo.com/2", feed.getOtherLinks().get(1).getHref()); }
protected Element createRootElement(Feed feed) { Element root = new Element("feed", getFeedNamespace()); root.addNamespaceDeclaration(getFeedNamespace()); // Attribute version = new Attribute("version", getVersion()); // root.setAttribute(version); if (feed.getXmlBase() != null) { root.setAttribute("base", feed.getXmlBase(), Namespace.XML_NAMESPACE); } generateModuleNamespaceDefs(root); return root; }
/** * Fetch the log entries as an atom feed. May trigger a purge of old messages, according to this * log service's purge policy. Includes paging options. * * @param maxResults maximum number of log results * @param startIndex starting index of log results * @return a {@code Feed} containing all the entries in the log */ public synchronized Feed getFeed(Integer maxResults, Integer startIndex) { Feed feed = new Feed(); feed.setTitle( "Plugin management log for " + applicationProperties.getDisplayName() + " (" + applicationProperties.getBaseUrl() + ")"); feed.setModified(lastModified); addLink(feed, applicationProperties.getBaseUrl(), "base"); addAuditLogEntries(feed, maxResults, startIndex); return feed; }
protected void addEntries(Feed feed, Element parent) throws FeedException { List items = feed.getEntries(); for (int i = 0; i < items.size(); i++) { addEntry((Entry) items.get(i), parent); } checkEntriesConstraints(parent); }
@SuppressWarnings("unchecked") private void addLink(Feed feed, String url, String rel) { Link link = new Link(); link.setHref(url); link.setRel(rel); feed.getOtherLinks().add(link); }
@SuppressWarnings("unchecked") private void addAuditLogEntries(Feed feed, Integer maxResults, Integer startIndex) { FeedData feedData = getFeedData(maxResults, startIndex); addTotalEntriesMarkup(feed, feedData.totalEntries); addStartIndexMarkup(feed, feedData.startIndex); // add links to next and previous pages if any exist, and to first/last pages int nextPageStartIndex = feedData.startIndex + feedData.maxResults; int previousPageStartIndex = max(feedData.startIndex - feedData.maxResults, 0); int firstPageStartIndex = 0; int lastPageStartIndex = (int) Math.floor((feedData.totalEntries - 1) / feedData.maxResults) * feedData.maxResults; if (nextPageStartIndex < feedData.totalEntries) { addLink( feed, uriBuilder.buildAuditLogFeedUri(feedData.maxResults, nextPageStartIndex), "next"); addLink( feed, uriBuilder.buildAuditLogFeedUri(feedData.maxResults, lastPageStartIndex), "last"); } if (feedData.startIndex > 0) { addLink( feed, uriBuilder.buildAuditLogFeedUri(feedData.maxResults, firstPageStartIndex), "first"); addLink( feed, uriBuilder.buildAuditLogFeedUri(feedData.maxResults, previousPageStartIndex), "previous"); } // transform AuditLogEntry elements to rome Entry elements and add to the feed feed.getEntries() .addAll(Collections2.transform(feedData.entries, auditLogEntryToFeedEntryFn())); }
/** Utility method to serialize an entry to writer. */ public static void serializeEntry(Entry entry, Writer writer) throws IllegalArgumentException, FeedException, IOException { // Build a feed containing only the entry List entries = new ArrayList(); entries.add(entry); Feed feed1 = new Feed(); feed1.setFeedType("atom_1.0"); feed1.setEntries(entries); // Get Rome to output feed as a JDOM document WireFeedOutput wireFeedOutput = new WireFeedOutput(); Document feedDoc = wireFeedOutput.outputJDom(feed1); // Grab entry element from feed and get JDOM to serialize it Element entryElement = (Element) feedDoc.getRootElement().getChildren().get(0); XMLOutputter outputter = new XMLOutputter(); outputter.output(entryElement, writer); }
protected WireFeed parseFeed(final Element eFeed, final Locale locale) throws FeedException { String baseURI = null; try { baseURI = findBaseURI(eFeed); } catch (final Exception e) { throw new FeedException("ERROR while finding base URI of feed", e); } final Feed feed = parseFeedMetadata(baseURI, eFeed, locale); feed.setStyleSheet(getStyleSheet(eFeed.getDocument())); final String xmlBase = eFeed.getAttributeValue("base", Namespace.XML_NAMESPACE); if (xmlBase != null) { feed.setXmlBase(xmlBase); } feed.setModules(parseFeedModules(eFeed, locale)); final List<Element> eList = eFeed.getChildren("entry", getAtomNamespace()); if (eList.size() > 0) { feed.setEntries(parseEntries(feed, baseURI, eList, locale)); } final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace()); if (foreignMarkup.size() > 0) { feed.setForeignMarkup(foreignMarkup); } return feed; }
/** Parse entry from reader. */ public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale) throws JDOMException, IOException, IllegalArgumentException, FeedException { // Parse entry into JDOM tree final SAXBuilder builder = new SAXBuilder(); final Document entryDoc = builder.build(rd); final Element fetchedEntryElement = entryDoc.getRootElement(); fetchedEntryElement.detach(); // Put entry into a JDOM document with 'feed' root so that Rome can // handle it final Feed feed = new Feed(); feed.setFeedType("atom_1.0"); final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(feed); feedDoc.getRootElement().addContent(fetchedEntryElement); if (baseURI != null) { feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE); } final WireFeedInput input = new WireFeedInput(false, locale); final Feed parsedFeed = (Feed) input.build(feedDoc); return parsedFeed.getEntries().get(0); }
protected void populateFeedHeader(Feed feed, Element eFeed) throws FeedException { if (feed.getTitleEx() != null) { Element titleElement = new Element("title", getFeedNamespace()); fillContentElement(titleElement, feed.getTitleEx()); eFeed.addContent(titleElement); } List links = feed.getAlternateLinks(); if (links != null) for (int i = 0; i < links.size(); i++) { eFeed.addContent(generateLinkElement((Link) links.get(i))); } links = feed.getOtherLinks(); if (links != null) for (int j = 0; j < links.size(); j++) { eFeed.addContent(generateLinkElement((Link) links.get(j))); } List cats = feed.getCategories(); if (cats != null) for (Iterator iter = cats.iterator(); iter.hasNext(); ) { eFeed.addContent(generateCategoryElement((Category) iter.next())); } List authors = feed.getAuthors(); if (authors != null && authors.size() > 0) { for (int i = 0; i < authors.size(); i++) { Element authorElement = new Element("author", getFeedNamespace()); fillPersonElement(authorElement, (Person) feed.getAuthors().get(i)); eFeed.addContent(authorElement); } } List contributors = feed.getContributors(); if (contributors != null && contributors.size() > 0) { for (int i = 0; i < contributors.size(); i++) { Element contributorElement = new Element("contributor", getFeedNamespace()); fillPersonElement(contributorElement, (Person) contributors.get(i)); eFeed.addContent(contributorElement); } } if (feed.getSubtitle() != null) { Element subtitleElement = new Element("subtitle", getFeedNamespace()); fillContentElement(subtitleElement, feed.getSubtitle()); eFeed.addContent(subtitleElement); } if (feed.getId() != null) { eFeed.addContent(generateSimpleElement("id", feed.getId())); } if (feed.getGenerator() != null) { eFeed.addContent(generateGeneratorElement(feed.getGenerator())); } if (feed.getRights() != null) { eFeed.addContent(generateSimpleElement("rights", feed.getRights())); } if (feed.getIcon() != null) { eFeed.addContent(generateSimpleElement("icon", feed.getIcon())); } if (feed.getLogo() != null) { eFeed.addContent(generateSimpleElement("logo", feed.getLogo())); } if (feed.getUpdated() != null) { Element updatedElement = new Element("updated", getFeedNamespace()); updatedElement.addContent(DateParser.formatW3CDateTime(feed.getUpdated())); eFeed.addContent(updatedElement); } }
public static boolean isABrandFeed(Feed source) { return BRAND_PAGE_ID_PATTERN.matcher(source.getId()).matches(); }
protected WireFeed parseFeed(Element eFeed) { com.sun.syndication.feed.atom.Feed feed = new com.sun.syndication.feed.atom.Feed(getType()); Element e = eFeed.getChild("title", getAtomNamespace()); if (e != null) { feed.setTitleEx(parseContent(e)); } List<Element> eList = eFeed.getChildren("link", getAtomNamespace()); feed.setAlternateLinks(parseAlternateLinks(eList)); feed.setOtherLinks(parseOtherLinks(eList)); e = eFeed.getChild("author", getAtomNamespace()); if (e != null) { List<Person> authors = new ArrayList<Person>(); authors.add(parsePerson(e)); feed.setAuthors(authors); } eList = eFeed.getChildren("contributor", getAtomNamespace()); if (eList.size() > 0) { feed.setContributors(parsePersons(eList)); } e = eFeed.getChild("tagline", getAtomNamespace()); if (e != null) { feed.setTagline(parseContent(e)); } e = eFeed.getChild("id", getAtomNamespace()); if (e != null) { feed.setId(e.getText()); } e = eFeed.getChild("generator", getAtomNamespace()); if (e != null) { Generator gen = new Generator(); gen.setValue(e.getText()); String att = getAttributeValue(e, "url"); if (att != null) { gen.setUrl(att); } att = getAttributeValue(e, "version"); if (att != null) { gen.setVersion(att); } feed.setGenerator(gen); } e = eFeed.getChild("copyright", getAtomNamespace()); if (e != null) { feed.setCopyright(e.getText()); } e = eFeed.getChild("info", getAtomNamespace()); if (e != null) { feed.setInfo(parseContent(e)); } e = eFeed.getChild("modified", getAtomNamespace()); if (e != null) { feed.setModified(DateParser.parseDate(e.getText())); } feed.setModules(parseFeedModules(eFeed)); eList = eFeed.getChildren("entry", getAtomNamespace()); if (eList.size() > 0) { feed.setEntries(parseEntries(eList)); } List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace()); if (foreignMarkup.size() > 0) { feed.setForeignMarkup(foreignMarkup); } return feed; }
public static boolean isASeriesFeed(Feed source) { return SERIES_PAGE_ID_PATTERN.matcher(source.getId()).matches(); }
private Feed parseFeedMetadata(final String baseURI, final Element eFeed, final Locale locale) { final com.sun.syndication.feed.atom.Feed feed = new com.sun.syndication.feed.atom.Feed(getType()); Element e = eFeed.getChild("title", getAtomNamespace()); if (e != null) { final Content c = new Content(); c.setValue(parseTextConstructToString(e)); c.setType(getAttributeValue(e, "type")); feed.setTitleEx(c); } List<Element> eList = eFeed.getChildren("link", getAtomNamespace()); feed.setAlternateLinks(parseAlternateLinks(feed, null, baseURI, eList)); feed.setOtherLinks(parseOtherLinks(feed, null, baseURI, eList)); final List<Element> cList = eFeed.getChildren("category", getAtomNamespace()); feed.setCategories(parseCategories(baseURI, cList)); eList = eFeed.getChildren("author", getAtomNamespace()); if (eList.size() > 0) { feed.setAuthors(parsePersons(baseURI, eList, locale)); } eList = eFeed.getChildren("contributor", getAtomNamespace()); if (eList.size() > 0) { feed.setContributors(parsePersons(baseURI, eList, locale)); } e = eFeed.getChild("subtitle", getAtomNamespace()); if (e != null) { final Content subtitle = new Content(); subtitle.setValue(parseTextConstructToString(e)); subtitle.setType(getAttributeValue(e, "type")); feed.setSubtitle(subtitle); } e = eFeed.getChild("id", getAtomNamespace()); if (e != null) { feed.setId(e.getText()); } e = eFeed.getChild("generator", getAtomNamespace()); if (e != null) { final Generator gen = new Generator(); gen.setValue(e.getText()); String att = getAttributeValue(e, "uri"); if (att != null) { gen.setUrl(att); } att = getAttributeValue(e, "version"); if (att != null) { gen.setVersion(att); } feed.setGenerator(gen); } e = eFeed.getChild("rights", getAtomNamespace()); if (e != null) { feed.setRights(parseTextConstructToString(e)); } e = eFeed.getChild("icon", getAtomNamespace()); if (e != null) { feed.setIcon(e.getText()); } e = eFeed.getChild("logo", getAtomNamespace()); if (e != null) { feed.setLogo(e.getText()); } e = eFeed.getChild("updated", getAtomNamespace()); if (e != null) { feed.setUpdated(DateParser.parseDate(e.getText(), locale)); } return feed; }
@SuppressWarnings("unchecked") private void addForeignMarkup(Feed feed, String name, String value) { final Element elem = new Element(name); elem.setText(String.valueOf(value)); ((List) feed.getForeignMarkup()).add(elem); }