BlogList.java
资源名称:Myblog.rar [点击查看]
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:7k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.opensource.blog.web.action;
- import java.util.Date;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.commons.lang.StringUtils;
- import org.apache.struts.action.Action;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionMessage;
- import org.apache.struts.action.ActionMessages;
- import com.laoer.comm.util.Util;
- import com.laoer.comm.web.PageList;
- import com.laoer.comm.web.Pages;
- import com.opensource.blog.comm.Constant;
- import com.opensource.blog.model.Blog;
- import com.opensource.blog.service.ArticleService;
- import com.opensource.blog.service.LinksService;
- import com.opensource.blog.service.NoteService;
- import com.opensource.blog.service.cache.app.BlogCache;
- import com.opensource.blog.web.form.BlogListForm;
- public class BlogList
- extends Action {
- private BlogCache blogCache;
- private ArticleService articleService;
- private NoteService noteService;
- private LinksService linksService;
- public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- ActionMessages errors = new ActionMessages();
- BlogListForm form = (BlogListForm) actionForm;
- Blog blog = this.getBlogCache().getFromCache(form.getUsername());
- if (blog == null) {
- errors.add("error.blogblog.getinfo", new ActionMessage("error.blogblog.getinfo"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- if (form.getAction().equalsIgnoreCase("all")) {
- Pages pages = new Pages(servletRequest.getLocale());
- pages.setPage(form.getPage());
- pages.setPerPageNum(blog.getPerartnum());
- pages.setStyle(1);
- pages.setFileName("blogList.do?action=" + form.getAction() + "&blogid=" + form.getBlogid() +
- "&username=" + form.getUsername());
- PageList pl = this.getArticleService().findArticlesByBlogID_IsHide(form.getBlogid(),
- Constant.ART_NOT_HIDE, pages);
- servletRequest.setAttribute("pl", pl);
- pages.setPage(1);
- pages.setPerPageNum(blog.getNewlyartnum());
- pages.setTotals(blog.getNewlyartnum());
- pl = this.getArticleService().findArticlesByBlogID_IsHide(blog.getId().longValue(),
- Constant.ART_NOT_HIDE, pages);
- List newartlist = pl.getObjectList();
- pages.setPage(1);
- pages.setPerPageNum(blog.getNewlycomnum());
- pages.setTotals(blog.getNewlycomnum());
- pl = this.getNoteService().findNotesByBlogID(blog.getId().longValue(), pages);
- List notelist = pl.getObjectList();
- List linktext = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
- Constant.LINK_TEXT);
- List linklogo = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
- Constant.LINK_LOGO);
- String postdates = this.getArticleService().getPostDateStr(blog.getId().longValue());
- if (StringUtils.isBlank(postdates)) {
- postdates = Util.formatDate7(new Date());
- }
- String showcc = Util.getFirstDay(new Date());
- servletRequest.setAttribute("blog", blog);
- servletRequest.setAttribute("newartlist", newartlist);
- servletRequest.setAttribute("notelist", notelist);
- servletRequest.setAttribute("linktext", linktext);
- servletRequest.setAttribute("linklogo", linklogo);
- servletRequest.setAttribute("postdates", postdates);
- servletRequest.setAttribute("showcc", showcc);
- return new ActionForward("/WEB-INF/template/skin" + blog.getSkin() + "_list.ftl");
- }
- if (form.getAction().equalsIgnoreCase("showdate")) {
- Pages pages = new Pages(servletRequest.getLocale());
- pages.setPage(form.getPage());
- pages.setPerPageNum(blog.getPerartnum());
- pages.setStyle(1);
- pages.setFileName("blogList.do?action=" + form.getAction() + "&blogid=" + form.getBlogid() +
- "&username=" + form.getUsername());
- PageList pl = this.getArticleService().findArticlesByPostDate(form.getBlogid(), form.getDate(),
- pages);
- servletRequest.setAttribute("pl", pl);
- pages.setPage(1);
- pages.setPerPageNum(blog.getNewlyartnum());
- pages.setTotals(blog.getNewlyartnum());
- pl = this.getArticleService().findArticlesByBlogID_IsHide(blog.getId().longValue(),
- Constant.ART_NOT_HIDE, pages);
- List newartlist = pl.getObjectList();
- pages.setPage(1);
- pages.setPerPageNum(blog.getNewlycomnum());
- pages.setTotals(blog.getNewlycomnum());
- pl = this.getNoteService().findNotesByBlogID(blog.getId().longValue(), pages);
- List notelist = pl.getObjectList();
- List linktext = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
- Constant.LINK_TEXT);
- List linklogo = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
- Constant.LINK_LOGO);
- String postdates = this.getArticleService().getPostDateStr(blog.getId().longValue());
- if (StringUtils.isBlank(postdates)) {
- postdates = Util.formatDate7(new Date());
- }
- String showcc = Util.getFirstDay(new Date());
- servletRequest.setAttribute("blog", blog);
- servletRequest.setAttribute("newartlist", newartlist);
- servletRequest.setAttribute("notelist", notelist);
- servletRequest.setAttribute("linktext", linktext);
- servletRequest.setAttribute("linklogo", linklogo);
- servletRequest.setAttribute("postdates", postdates);
- servletRequest.setAttribute("showcc", showcc);
- return new ActionForward("/WEB-INF/template/skin" + blog.getSkin() + "_list.ftl");
- }
- return actionMapping.findForward("error");
- }
- public ArticleService getArticleService() {
- return articleService;
- }
- public BlogCache getBlogCache() {
- return blogCache;
- }
- public LinksService getLinksService() {
- return linksService;
- }
- public NoteService getNoteService() {
- return noteService;
- }
- public void setArticleService(ArticleService articleService) {
- this.articleService = articleService;
- }
- public void setBlogCache(BlogCache blogCache) {
- this.blogCache = blogCache;
- }
- public void setLinksService(LinksService linksService) {
- this.linksService = linksService;
- }
- public void setNoteService(NoteService noteService) {
- this.noteService = noteService;
- }
- }