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.api.decorator.ContentDecoratorContext; |
36 | |
import net.sourceforge.pebble.util.SecurityUtils; |
37 | |
import net.sourceforge.pebble.util.CookieUtils; |
38 | |
import net.sourceforge.pebble.domain.*; |
39 | |
import net.sourceforge.pebble.web.view.NotFoundView; |
40 | |
import net.sourceforge.pebble.web.view.View; |
41 | |
import net.sourceforge.pebble.web.view.impl.BlogEntryView; |
42 | |
|
43 | |
import javax.servlet.ServletException; |
44 | |
import javax.servlet.http.HttpServletRequest; |
45 | |
import javax.servlet.http.HttpServletResponse; |
46 | |
import javax.servlet.http.Cookie; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 20 | public class ViewBlogEntryAction extends AbstractCommentAction { |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException { |
63 | 20 | Blog blog = (Blog)getModel().get(Constants.BLOG_KEY); |
64 | 20 | String entryId = request.getParameter("entry"); |
65 | |
|
66 | 20 | BlogEntry blogEntry = null; |
67 | 20 | if (entryId != null) { |
68 | 16 | BlogService service = new BlogService(); |
69 | |
try { |
70 | 16 | blogEntry = service.getBlogEntry(blog, entryId); |
71 | 0 | } catch (BlogServiceException e) { |
72 | 0 | throw new ServletException(e); |
73 | 16 | } |
74 | |
} |
75 | |
|
76 | 20 | if (blogEntry == null) { |
77 | |
|
78 | |
|
79 | |
|
80 | 8 | return new NotFoundView(); |
81 | 12 | } else if (!blogEntry.isPublished() && !(SecurityUtils.isUserAuthorisedForBlog(blog))) { |
82 | |
|
83 | 4 | return new NotFoundView(); |
84 | |
} else { |
85 | 8 | getModel().put(Constants.BLOG_ENTRY_KEY, blogEntry); |
86 | 8 | getModel().put(Constants.MONTHLY_BLOG, blog.getBlogForDay(blogEntry.getDate()).getMonth()); |
87 | 8 | getModel().put("displayMode", "detail"); |
88 | |
|
89 | |
|
90 | |
|
91 | 8 | Cookie rememberMe = CookieUtils.getCookie(request.getCookies(), "rememberMe"); |
92 | 8 | if (rememberMe != null) { |
93 | 0 | getModel().put("rememberMe", "true"); |
94 | |
} |
95 | |
|
96 | 8 | ContentDecoratorContext decoratorContext = new ContentDecoratorContext(); |
97 | 8 | decoratorContext.setView(ContentDecoratorContext.DETAIL_VIEW); |
98 | 8 | decoratorContext.setMedia(ContentDecoratorContext.HTML_PAGE); |
99 | 8 | Comment comment = createBlankComment(blog, blogEntry, request); |
100 | 8 | Comment decoratedComment = (Comment)comment.clone(); |
101 | 8 | blog.getContentDecoratorChain().decorate(decoratorContext, decoratedComment); |
102 | 8 | getModel().put("decoratedComment", decoratedComment); |
103 | 8 | getModel().put("undecoratedComment", comment); |
104 | |
|
105 | 8 | return new BlogEntryView(); |
106 | |
} |
107 | |
} |
108 | |
|
109 | |
} |