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.domain.Blog; |
36 | |
import net.sourceforge.pebble.domain.BlogEntry; |
37 | |
import net.sourceforge.pebble.domain.BlogService; |
38 | |
import net.sourceforge.pebble.domain.BlogServiceException; |
39 | |
import net.sourceforge.pebble.util.StringUtils; |
40 | |
import net.sourceforge.pebble.web.security.RequireSecurityToken; |
41 | |
import net.sourceforge.pebble.web.view.RedirectView; |
42 | |
import net.sourceforge.pebble.web.view.View; |
43 | |
import org.apache.commons.logging.Log; |
44 | |
import org.apache.commons.logging.LogFactory; |
45 | |
|
46 | |
import javax.servlet.ServletException; |
47 | |
import javax.servlet.http.HttpServletRequest; |
48 | |
import javax.servlet.http.HttpServletResponse; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
@RequireSecurityToken |
56 | 0 | public class ManageBlogEntriesAction extends SecureAction { |
57 | |
|
58 | |
|
59 | 0 | private static final Log log = LogFactory.getLog(ManageBlogEntriesAction.class); |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException { |
69 | 0 | Blog blog = (Blog)getModel().get(Constants.BLOG_KEY); |
70 | 0 | String ids[] = request.getParameterValues("entry"); |
71 | 0 | String submit = request.getParameter("submit"); |
72 | |
|
73 | 0 | if (ids != null) { |
74 | 0 | for (String id : ids) { |
75 | 0 | BlogService service = new BlogService(); |
76 | 0 | BlogEntry blogEntry = null; |
77 | |
try { |
78 | 0 | blogEntry = service.getBlogEntry(blog, id); |
79 | 0 | } catch (BlogServiceException e) { |
80 | 0 | throw new ServletException(e); |
81 | 0 | } |
82 | |
|
83 | 0 | if (blogEntry != null) { |
84 | 0 | if (submit.equalsIgnoreCase("Remove")) { |
85 | |
try { |
86 | 0 | service.removeBlogEntry(blogEntry); |
87 | 0 | blog.info("Blog entry \"" + StringUtils.transformHTML(blogEntry.getTitle()) + "\" removed."); |
88 | 0 | } catch (BlogServiceException be) { |
89 | 0 | throw new ServletException(be); |
90 | 0 | } |
91 | 0 | } else if (submit.equals("Publish")) { |
92 | |
|
93 | |
|
94 | |
try { |
95 | 0 | blogEntry.setPublished(true); |
96 | 0 | service.putBlogEntry(blogEntry); |
97 | 0 | blog.info("Blog entry <a href=\"" + blogEntry.getLocalPermalink() + "\">" + blogEntry.getTitle() + "</a> published."); |
98 | 0 | } catch (BlogServiceException be) { |
99 | 0 | throw new ServletException(be); |
100 | 0 | } |
101 | |
} |
102 | |
} |
103 | |
} |
104 | |
} |
105 | |
|
106 | 0 | String redirectUrl = request.getParameter("redirectUrl"); |
107 | 0 | if (redirectUrl != null && redirectUrl.trim().length() > 0) { |
108 | 0 | return new RedirectView(redirectUrl); |
109 | |
} else { |
110 | 0 | return new RedirectView(blog.getUrl()); |
111 | |
} |
112 | |
} |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public String[] getRoles(HttpServletRequest request) { |
121 | 0 | String submit = request.getParameter("submit"); |
122 | |
|
123 | 0 | if (submit != null) { |
124 | 0 | if (submit.equalsIgnoreCase("Remove")) { |
125 | 0 | return new String[]{Constants.BLOG_CONTRIBUTOR_ROLE}; |
126 | 0 | } else if (submit.equalsIgnoreCase("Publish")) { |
127 | 0 | return new String[]{Constants.BLOG_PUBLISHER_ROLE}; |
128 | |
} |
129 | |
} |
130 | |
|
131 | |
|
132 | 0 | return new String[]{Constants.BLOG_OWNER_ROLE}; |
133 | |
} |
134 | |
|
135 | |
} |