From 9ff0c16b05cb0eb7c3cc63eda763b0f75d84853c Mon Sep 17 00:00:00 2001 From: James Moger Date: Thu, 8 May 2014 13:09:08 -0400 Subject: Change enum name and unit test RSS tag queries --- src/main/java/com/gitblit/Constants.java | 6 +-- .../com/gitblit/servlet/SyndicationServlet.java | 6 +-- .../java/com/gitblit/utils/SyndicationUtils.java | 57 ++++++++++++++++++++++ 3 files changed, 63 insertions(+), 6 deletions(-) (limited to 'src/main/java/com/gitblit') diff --git a/src/main/java/com/gitblit/Constants.java b/src/main/java/com/gitblit/Constants.java index 2007c0a8..95eb944a 100644 --- a/src/main/java/com/gitblit/Constants.java +++ b/src/main/java/com/gitblit/Constants.java @@ -405,11 +405,11 @@ public class Constants { /** * Enumeration of the feed content object types. */ - public static enum FeedContentObjectType { + public static enum FeedObjectType { COMMIT, TAG; - public static FeedContentObjectType forName(String name) { - for (FeedContentObjectType type : values()) { + public static FeedObjectType forName(String name) { + for (FeedObjectType type : values()) { if (type.name().equalsIgnoreCase(name)) { return type; } diff --git a/src/main/java/com/gitblit/servlet/SyndicationServlet.java b/src/main/java/com/gitblit/servlet/SyndicationServlet.java index 9650ee3a..631df781 100644 --- a/src/main/java/com/gitblit/servlet/SyndicationServlet.java +++ b/src/main/java/com/gitblit/servlet/SyndicationServlet.java @@ -164,9 +164,9 @@ public class SyndicationServlet extends DaggerServlet { } } - Constants.FeedContentObjectType objectType = Constants.FeedContentObjectType.COMMIT; + Constants.FeedObjectType objectType = Constants.FeedObjectType.COMMIT; if (!StringUtils.isEmpty(request.getParameter("ot"))) { - Constants.FeedContentObjectType type = Constants.FeedContentObjectType.forName(request.getParameter("ot")); + Constants.FeedObjectType type = Constants.FeedObjectType.forName(request.getParameter("ot")); if (type != null) { objectType = type; } @@ -249,7 +249,7 @@ public class SyndicationServlet extends DaggerServlet { feedDescription = model.description; } - if (objectType == Constants.FeedContentObjectType.TAG) { + if (objectType == Constants.FeedObjectType.TAG) { String urlPattern; if (mountParameters) { diff --git a/src/main/java/com/gitblit/utils/SyndicationUtils.java b/src/main/java/com/gitblit/utils/SyndicationUtils.java index 2ee1cf69..93e9321a 100644 --- a/src/main/java/com/gitblit/utils/SyndicationUtils.java +++ b/src/main/java/com/gitblit/utils/SyndicationUtils.java @@ -25,6 +25,7 @@ import java.util.ArrayList; 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; @@ -137,6 +138,59 @@ public class SyndicationUtils { */ public static List 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 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 readFeed(String url, String repository, String branch, + FeedObjectType objectType, int numberOfEntries, int page, String username, + char[] password) throws IOException { // build feed url List parameters = new ArrayList(); if (numberOfEntries > 0) { @@ -148,6 +202,9 @@ public class SyndicationUtils { if (!StringUtils.isEmpty(branch)) { parameters.add("h=" + branch); } + if (objectType != null) { + parameters.add("ot=" + objectType.name()); + } return readFeed(url, parameters, repository, branch, username, password); } -- cgit v1.2.3