Paul Martin
2016-04-16 eecaad8b8e2c447429c31a01d49260ddd6b4ee03
src/main/java/com/gitblit/utils/SyndicationUtils.java
@@ -25,33 +25,34 @@
import java.util.List;
import com.gitblit.Constants;
import com.gitblit.Constants.FeedObjectType;
import com.gitblit.GitBlitException;
import com.gitblit.models.FeedEntryModel;
import com.sun.syndication.feed.synd.SyndCategory;
import com.sun.syndication.feed.synd.SyndCategoryImpl;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndContentImpl;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndEntryImpl;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.feed.synd.SyndImageImpl;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.SyndFeedOutput;
import com.sun.syndication.io.XmlReader;
import com.rometools.rome.feed.synd.SyndCategory;
import com.rometools.rome.feed.synd.SyndCategoryImpl;
import com.rometools.rome.feed.synd.SyndContent;
import com.rometools.rome.feed.synd.SyndContentImpl;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndEntryImpl;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.feed.synd.SyndFeedImpl;
import com.rometools.rome.feed.synd.SyndImageImpl;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.SyndFeedOutput;
import com.rometools.rome.io.XmlReader;
/**
 * Utility class for RSS feeds.
 *
 *
 * @author James Moger
 *
 *
 */
public class SyndicationUtils {
   /**
    * Outputs an RSS feed of the list of entries to the outputstream.
    *
    *
    * @param hostUrl
    * @param feedLink
    * @param title
@@ -70,7 +71,11 @@
      feed.setEncoding("UTF-8");
      feed.setTitle(title);
      feed.setLink(feedLink);
      feed.setDescription(description);
      if (StringUtils.isEmpty(description)) {
         feed.setDescription(title);
      } else {
         feed.setDescription(description);
      }
      SyndImageImpl image = new SyndImageImpl();
      image.setTitle(Constants.NAME);
      image.setUrl(hostUrl + "/gitblt_25.png");
@@ -118,7 +123,7 @@
   /**
    * Reads a Gitblit RSS feed.
    *
    *
    * @param url
    *            the url of the Gitblit server
    * @param repository
@@ -137,6 +142,59 @@
    */
   public static List<FeedEntryModel> readFeed(String url, String repository, String branch,
         int numberOfEntries, int page, String username, char[] password) throws IOException {
      return readFeed(url, repository, branch, FeedObjectType.COMMIT, numberOfEntries,
            page, username, password);
   }
   /**
    * Reads tags from the specified repository.
    *
    * @param url
    *            the url of the Gitblit server
    * @param repository
    *            the repository name
    * @param branch
    *            the branch name (optional)
    * @param numberOfEntries
    *            the number of entries to retrieve. if <= 0 the server default
    *            is used.
    * @param page
    *            0-indexed. used to paginate the results.
    * @param username
    * @param password
    * @return a list of SyndicationModel entries
    * @throws {@link IOException}
    */
   public static List<FeedEntryModel> readTags(String url, String repository,
         int numberOfEntries, int page, String username, char[] password) throws IOException {
      return readFeed(url, repository, null, FeedObjectType.TAG, numberOfEntries,
            page, username, password);
   }
   /**
    * Reads a Gitblit RSS feed.
    *
    * @param url
    *            the url of the Gitblit server
    * @param repository
    *            the repository name
    * @param branch
    *            the branch name (optional)
    * @param objectType
    *            the object type to return (optional, COMMIT assummed)
    * @param numberOfEntries
    *            the number of entries to retrieve. if <= 0 the server default
    *            is used.
    * @param page
    *            0-indexed. used to paginate the results.
    * @param username
    * @param password
    * @return a list of SyndicationModel entries
    * @throws {@link IOException}
    */
   private static List<FeedEntryModel> readFeed(String url, String repository, String branch,
         FeedObjectType objectType, int numberOfEntries, int page, String username,
         char[] password) throws IOException {
      // build feed url
      List<String> parameters = new ArrayList<String>();
      if (numberOfEntries > 0) {
@@ -148,12 +206,15 @@
      if (!StringUtils.isEmpty(branch)) {
         parameters.add("h=" + branch);
      }
      if (objectType != null) {
         parameters.add("ot=" + objectType.name());
      }
      return readFeed(url, parameters, repository, branch, username, password);
   }
   /**
    * Reads a Gitblit RSS search feed.
    *
    *
    * @param url
    *            the url of the Gitblit server
    * @param repository
@@ -195,7 +256,7 @@
   /**
    * Reads a Gitblit RSS feed.
    *
    *
    * @param url
    *            the url of the Gitblit server
    * @param parameters