| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
package net.sourceforge.pebble.web.action; |
| 33 | |
|
| 34 | |
import net.sourceforge.pebble.Constants; |
| 35 | |
import net.sourceforge.pebble.comparator.BlogEntryComparator; |
| 36 | |
import net.sourceforge.pebble.domain.*; |
| 37 | |
import net.sourceforge.pebble.service.LastModifiedService; |
| 38 | |
import net.sourceforge.pebble.web.view.NotModifiedView; |
| 39 | |
import net.sourceforge.pebble.web.view.View; |
| 40 | |
import net.sourceforge.pebble.web.view.impl.AbstractRomeFeedView; |
| 41 | |
import net.sourceforge.pebble.web.view.impl.FeedView; |
| 42 | |
import net.sourceforge.pebble.web.view.impl.RdfView; |
| 43 | |
|
| 44 | |
import javax.inject.Inject; |
| 45 | |
import javax.servlet.ServletException; |
| 46 | |
import javax.servlet.http.HttpServletRequest; |
| 47 | |
import javax.servlet.http.HttpServletResponse; |
| 48 | |
import java.util.*; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | 12 | public class FeedAction extends Action { |
| 56 | |
|
| 57 | |
@Inject |
| 58 | |
private LastModifiedService lastModifiedService; |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException { |
| 68 | 12 | AbstractBlog blog = (AbstractBlog) getModel().get(Constants.BLOG_KEY); |
| 69 | 12 | String flavor = request.getParameter("flavor"); |
| 70 | |
|
| 71 | 12 | if (lastModifiedService.checkAndProcessLastModified(request, response, blog.getLastModified(), null)) { |
| 72 | 4 | return new NotModifiedView(); |
| 73 | |
} |
| 74 | |
|
| 75 | |
List<BlogEntry> blogEntries; |
| 76 | 8 | String s = request.getParameter("includeAggregatedContent"); |
| 77 | 8 | boolean includeAggregatedContent = (s == null || s.equalsIgnoreCase("true")); |
| 78 | |
|
| 79 | 8 | if (blog instanceof Blog) { |
| 80 | 8 | Tag tag = getTag((Blog) blog, request); |
| 81 | 8 | Category category = getCategory((Blog) blog, request); |
| 82 | 8 | String author = getAuthor(request); |
| 83 | |
|
| 84 | 8 | if (tag != null) { |
| 85 | 0 | blogEntries = ((Blog) blog).getRecentPublishedBlogEntries(tag); |
| 86 | 0 | getModel().put("tag", tag); |
| 87 | 8 | } else if (category != null) { |
| 88 | 4 | blogEntries = ((Blog) blog).getRecentPublishedBlogEntries(category); |
| 89 | 4 | getModel().put("category", category); |
| 90 | 4 | } else if (author != null) { |
| 91 | 0 | blogEntries = ((Blog) blog).getRecentPublishedBlogEntries(author); |
| 92 | 0 | getModel().put("author", author); |
| 93 | |
} else { |
| 94 | 4 | blogEntries = ((Blog) blog).getRecentPublishedBlogEntries(); |
| 95 | |
} |
| 96 | 8 | } else { |
| 97 | 0 | blogEntries = blog.getRecentBlogEntries(); |
| 98 | |
} |
| 99 | |
|
| 100 | 8 | List<BlogEntry> blogEntriesForFeed = new ArrayList<BlogEntry>(); |
| 101 | 8 | for (BlogEntry entry : blogEntries) { |
| 102 | 4 | if (includeAggregatedContent || !entry.isAggregated()) { |
| 103 | 4 | blogEntriesForFeed.add(entry); |
| 104 | |
} |
| 105 | |
} |
| 106 | |
|
| 107 | 8 | Collections.sort(blogEntriesForFeed, new BlogEntryComparator()); |
| 108 | |
|
| 109 | 8 | getModel().put(Constants.BLOG_ENTRIES, blogEntriesForFeed); |
| 110 | |
|
| 111 | |
|
| 112 | 8 | javax.servlet.jsp.jstl.core.Config.set( |
| 113 | |
request, |
| 114 | |
javax.servlet.jsp.jstl.core.Config.FMT_LOCALE, |
| 115 | |
Locale.ENGLISH); |
| 116 | |
|
| 117 | 8 | if (flavor != null && flavor.equalsIgnoreCase("atom")) { |
| 118 | 0 | return new FeedView(AbstractRomeFeedView.FeedType.ATOM); |
| 119 | 8 | } else if (flavor != null && flavor.equalsIgnoreCase("rdf")) { |
| 120 | 0 | return new RdfView(); |
| 121 | |
} else { |
| 122 | 8 | return new FeedView(AbstractRomeFeedView.FeedType.RSS); |
| 123 | |
} |
| 124 | |
} |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
private Tag getTag(Blog blog, HttpServletRequest request) { |
| 135 | 8 | String tag = request.getParameter("tag"); |
| 136 | 8 | if (tag != null) { |
| 137 | 0 | return new Tag(tag, blog); |
| 138 | |
} else { |
| 139 | 8 | return null; |
| 140 | |
} |
| 141 | |
} |
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
private Category getCategory(Blog blog, HttpServletRequest request) { |
| 152 | 8 | String categoryId = request.getParameter("category"); |
| 153 | 8 | if (categoryId != null) { |
| 154 | 4 | return blog.getCategory(categoryId); |
| 155 | |
} else { |
| 156 | 4 | return null; |
| 157 | |
} |
| 158 | |
} |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
private String getAuthor(HttpServletRequest request) { |
| 167 | 8 | return request.getParameter("author"); |
| 168 | |
} |
| 169 | |
|
| 170 | |
public void setLastModifiedService(LastModifiedService lastModifiedService) { |
| 171 | 12 | this.lastModifiedService = lastModifiedService; |
| 172 | 12 | } |
| 173 | |
} |