List of usage examples for org.apache.commons.collections ListUtils transformedList
public static List transformedList(List list, Transformer transformer)
From source file:com.xpn.xwiki.plugin.watchlist.WatchListEventFeedManager.java
/** * @param user user to get the RSS feed for * @param entryNumber number of entries to retrieve * @param context the XWiki context//from w w w .j av a2 s .c o m * @return The watchlist RSS feed for the given user * @throws XWikiException if the retrieval of RSS entries fails */ @SuppressWarnings("unchecked") public SyndFeed getFeed(String user, int entryNumber, XWikiContext context) throws XWikiException { List<String> wikis = plugin.getStore().getWatchedElements(user, WatchListStore.ElementType.WIKI, context); List<String> spaces = plugin.getStore().getWatchedElements(user, WatchListStore.ElementType.SPACE, context); List<String> documents = plugin.getStore().getWatchedElements(user, WatchListStore.ElementType.DOCUMENT, context); List<Object> parameters = new ArrayList<Object>(); ActivityStreamPluginApi asApi = (ActivityStreamPluginApi) context.getWiki().getPluginApi("activitystream", context); parameters.addAll(wikis); parameters.addAll(spaces); parameters.addAll(documents); Transformer transformer = new ConstantTransformer("?"); List<String> wikisPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer); wikisPlaceholders.addAll(wikis); List<String> spacesPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer); spacesPlaceholders.addAll(spaces); List<String> documentsPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer); documentsPlaceholders.addAll(documents); String listItemsJoint = ","; String concatWiki = " or concat(act.wiki,'"; String query = "1=0"; if (!wikis.isEmpty()) { query += " or act.wiki in (" + StringUtils.join(wikisPlaceholders, listItemsJoint) + ')'; } if (!spaces.isEmpty()) { query += concatWiki + WatchListStore.WIKI_SPACE_SEP + "',act.space) in (" + StringUtils.join(spacesPlaceholders, listItemsJoint) + ')'; } if (!documents.isEmpty()) { query += concatWiki + WatchListStore.WIKI_SPACE_SEP + "',act.page) in (" + StringUtils.join(documentsPlaceholders, listItemsJoint) + ')'; } List<ActivityEvent> events = asApi.searchEvents(query, false, true, entryNumber, 0, parameters); SyndFeed feed = asApi.getFeed(events); setFeedMetaData(feed, context); return feed; }
From source file:org.xwiki.watchlist.internal.DefaultWatchListEventFeedManager.java
@Override @SuppressWarnings("unchecked") public SyndFeed getFeed(String user, int entryNumber) throws XWikiException { XWikiContext context = contextProvider.get(); Collection<String> wikis = store.getWatchedElements(user, WatchedElementType.WIKI); Collection<String> spaces = store.getWatchedElements(user, WatchedElementType.SPACE); Collection<String> documents = store.getWatchedElements(user, WatchedElementType.DOCUMENT); List<Object> parameters = new ArrayList<Object>(); ActivityStreamPluginApi asApi = (ActivityStreamPluginApi) context.getWiki().getPluginApi("activitystream", context);/*w ww . j a v a 2 s. co m*/ parameters.addAll(wikis); parameters.addAll(spaces); parameters.addAll(documents); Transformer transformer = new ConstantTransformer("?"); List<String> wikisPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer); wikisPlaceholders.addAll(wikis); List<String> spacesPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer); spacesPlaceholders.addAll(spaces); List<String> documentsPlaceholders = ListUtils.transformedList(new ArrayList<String>(), transformer); documentsPlaceholders.addAll(documents); String listItemsJoint = ","; String concatWiki = " or concat(act.wiki,'"; String query = "1=0"; if (!wikis.isEmpty()) { query += " or act.wiki in (" + StringUtils.join(wikisPlaceholders, listItemsJoint) + ')'; } if (!spaces.isEmpty()) { query += concatWiki + DefaultWatchListStore.WIKI_SPACE_SEP + "',act.space) in (" + StringUtils.join(spacesPlaceholders, listItemsJoint) + ')'; } if (!documents.isEmpty()) { query += concatWiki + DefaultWatchListStore.WIKI_SPACE_SEP + "',act.page) in (" + StringUtils.join(documentsPlaceholders, listItemsJoint) + ')'; } List<ActivityEvent> events = asApi.searchEvents(query, false, true, entryNumber, 0, parameters); SyndFeed feed = asApi.getFeed(events); setFeedMetaData(feed, context); return feed; }