/**
* view a blog specified by id or code
*/
protected ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse resp, int selection) {
BlogManager blogMgr = new BlogManager(locale, session);
Blog blog = null;
String idParam = req.getAttribute("id") != null ? (String)req.getAttribute("id") : req.getParameter("id"); // allow parameter injection
String codeParam = req.getAttribute("code") != null ? (String)req.getAttribute("code") : req.getParameter("code");
String groupParam = req.getAttribute("group_id") != null ? (String)req.getAttribute("group_id") : req.getParameter("group_id");
String dateArchiveParam = req.getAttribute("datearchive") != null ? (String)req.getAttribute("datearchive") : req.getParameter("datearchive");
String labelArchiveParam = req.getAttribute("labelarchive") != null ? (String)req.getAttribute("labelarchive") : req.getParameter("labelarchive");
String unlabelledParam = req.getAttribute("unlabelled") != null ? (String)req.getAttribute("unlabelled") : req.getParameter("unlabelled");
if (idParam != null) {
blog = blogMgr.getBlog(Long.parseLong(idParam));
} else if (codeParam != null && groupParam != null) {
try {
long groupId = Long.parseLong(groupParam);
GroupManager groupMgr = new GroupManager(locale, session);
Group group = groupMgr.getGroup(groupId);
blog = blogMgr.getBlog(codeParam, group);
} catch (Exception e) {
blog = null;
}
} else {
if (webUser != null) {
blog = blogMgr.getBlog(webUser.getUsername(), webUser.getGroup());
}
}
if (blog == null) {
throw new InputException(getLocalizedMessage("BloggingWeb", "blog.BlogNotFound", idParam, codeParam));
}
Set<Long> permissions = getPermissions(blog, webUser);
if (!permissions.contains(PermissionManager.READ_PERMISSION)) {
throw new InputException(getLocalizedMessage("BloggingWeb", "blog.insufficientRights"));
}
req.setAttribute("blog", blog);
Collection<Article> articles = null;
List<DisplayableArticle> displayArticles = new ArrayList<DisplayableArticle>();
Date from = null, to = null;
if (dateArchiveParam != null && dateArchiveParam.length() > 0) {
Date archiveDate = new Date(Long.parseLong(dateArchiveParam));
articles = blogMgr.getArchivedArticles(blog, archiveDate);
SimpleDateFormat df = new SimpleDateFormat("yyyy");
String yearStr = df.format(archiveDate);
df = new SimpleDateFormat("MMMM");
String monthStr = df.format(archiveDate);
req.setAttribute("subheader", getLocalizedMessage("BloggingWeb", "blog.ArchiveForMonth", monthStr, yearStr));
Calendar cal = Calendar.getInstance();
df = new SimpleDateFormat("yyyy-MMMM");
try {
cal.setTime(df.parse(yearStr+"-"+monthStr));
from = cal.getTime();
cal.add(Calendar.MONTH, 1);
to = cal.getTime();
} catch (ParseException e) {
from = to = null;
}
} else if (labelArchiveParam != null && labelArchiveParam.length() > 0) {
Label label = blogMgr.getLabel(blog, Long.parseLong(labelArchiveParam));
articles = blogMgr.getArchivedArticles(blog, label);
req.setAttribute("subheader", getLocalizedMessage("BloggingWeb", "blog.ArchiveForLabel", label.getLabel()));
} else if (unlabelledParam != null) {
articles = blogMgr.getUnlabelledArticles(blog);
req.setAttribute("subheader", getLocalizedMessage("BloggingWeb", "blog.ArchiveForUnlabelled"));
} else {
articles = blog.getArticles();
}
for (Article a : articles) {
boolean display = true;
if(selection==BLOCKED) {
if(isArticleBlocked(a) || isACommentBlocked(a)){
display = true;
} else {
display = false;
}
}
if(selection==NOT_REVIEWED){
if(isArticleBlocked(a)){
display = false;
}else if(isArticleNotReviewed(a)){
display = true;
} else if(isACommentNotReviewed(a)){
display = true;
} else {
display = false;
}
}
if(selection==RELEASED){
if(isArticleReleased(a)){
display = true;
} else {
display = false;
}
}
if(display){
DisplayableArticle da = new DisplayableArticle(a, true);
if (da.getTitle() == null || da.getTitle().trim().length()==0) {
da.setTitle(getLocalizedMessage("BloggingWeb", "blog.noTitle"));
}
displayArticles.add(da);
}
}
req.setAttribute("mayAddArticles", permissions.contains(PermissionManager.WRITE_PERMISSION));
req.setAttribute("articleList", displayArticles);
req.setAttribute("countArticles", displayArticles.size());
req.setAttribute("countPosters", blogMgr.countAuthors(blog, from, to));
req.setAttribute("countComments", blogMgr.countComments(blog, from, to));
req.setAttribute("dateArchiveList", blogMgr.getArchives(blog));
req.setAttribute("labelCloud", blogMgr.getLabelCloud(blog, webUser, null, 20));
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) {