/**
* view an article specified by id
*/
protected ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp, boolean viewReleasedCommentsOnly) {
BlogManager blogMgr = new BlogManager(locale, session);
String idParam = req.getParameter("id");
Article article = blogMgr.getArticle(Long.parseLong(idParam));
if (article == null) {
throw new InputException(getLocalizedMessage("BloggingWeb", "blog.ArticleNotFound", idParam));
}
Blog blog = blogMgr.getBlog(article.getBlog().getId());
Set<Long> permissions = getPermissions(blog, webUser);
if (!permissions.contains(PermissionManager.READ_PERMISSION)) {
throw new InputException(getLocalizedMessage("BloggingWeb", "blog.insufficientRights"));
}
req.setAttribute("blog", blog);
req.getSession().setAttribute("blogCode", blog.getCode()); // for fckeditor ...
DisplayableArticle da = new DisplayableArticle(article, true);
if (da.getTitle() == null || da.getTitle().trim().length()==0) {
da.setTitle(getLocalizedMessage("BloggingWeb", "blog.noTitle"));
}
req.setAttribute("article", da);
// anonymous users must not edit existing entries,
// users with WRITE permission may edit their own articles only,
// users with EDIT_OTHERS permission may also edit articles of others
req.setAttribute("mayEditArticle", webUser != null && ((article.getAuthor() != null && webUser.getId() == article.getAuthor().getId() && permissions.contains(PermissionManager.WRITE_PERMISSION)) || permissions.contains(PermissionManager.EDIT_OTHERS_PERMISSION)));
req.setAttribute("mayAddComment", permissions.contains(PermissionManager.ADD_COMMENT_PERMISSION));
if (article.getAuthor() != null) {
session.load(User.class, article.getAuthor().getId());
}
List<DisplayableComment> comments = new ArrayList<DisplayableComment>();
for (Comment c : article.getComments()) {
if(viewReleasedCommentsOnly && c.getReviewStatus() != 1){
} else {
DisplayableComment dc = new DisplayableComment(c);
comments.add(dc);
}
}
da.setCommentCount(comments.size());
req.setAttribute("commentList", comments);
req.setAttribute("dateArchiveList", blogMgr.getArchives(blog));
req.setAttribute("labelCloud", blogMgr.getLabelCloud(blog, webUser, null, 20));
req.setAttribute("previousarticle", blogMgr.getPreviousArticle(article));
req.setAttribute("nextarticle", blogMgr.getNextArticle(article));
try {
req.setAttribute("articleRssUrl", getBaseUrl(req)+"/viewBlog.do?method=rss&id="+blog.getId());
req.setAttribute("commentRssUrl", getBaseUrl(req)+"/viewBlog.do?method=commentrss&id="+blog.getId());
} catch (Exception e) {