BlogList.java
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:7k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.opensource.blog.web.action;
  2. import java.util.Date;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.commons.lang.StringUtils;
  7. import org.apache.struts.action.Action;
  8. import org.apache.struts.action.ActionForm;
  9. import org.apache.struts.action.ActionForward;
  10. import org.apache.struts.action.ActionMapping;
  11. import org.apache.struts.action.ActionMessage;
  12. import org.apache.struts.action.ActionMessages;
  13. import com.laoer.comm.util.Util;
  14. import com.laoer.comm.web.PageList;
  15. import com.laoer.comm.web.Pages;
  16. import com.opensource.blog.comm.Constant;
  17. import com.opensource.blog.model.Blog;
  18. import com.opensource.blog.service.ArticleService;
  19. import com.opensource.blog.service.LinksService;
  20. import com.opensource.blog.service.NoteService;
  21. import com.opensource.blog.service.cache.app.BlogCache;
  22. import com.opensource.blog.web.form.BlogListForm;
  23. public class BlogList
  24.     extends Action {
  25.   private BlogCache blogCache;
  26.   private ArticleService articleService;
  27.   private NoteService noteService;
  28.   private LinksService linksService;
  29.   public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
  30.                                HttpServletRequest servletRequest,
  31.                                HttpServletResponse servletResponse) {
  32.     ActionMessages errors = new ActionMessages();
  33.     BlogListForm form = (BlogListForm) actionForm;
  34.     Blog blog = this.getBlogCache().getFromCache(form.getUsername());
  35.     if (blog == null) {
  36.       errors.add("error.blogblog.getinfo", new ActionMessage("error.blogblog.getinfo"));
  37.       saveErrors(servletRequest, errors);
  38.       return actionMapping.findForward("error");
  39.     }
  40.     if (form.getAction().equalsIgnoreCase("all")) {
  41.       Pages pages = new Pages(servletRequest.getLocale());
  42.       pages.setPage(form.getPage());
  43.       pages.setPerPageNum(blog.getPerartnum());
  44.       pages.setStyle(1);
  45.       pages.setFileName("blogList.do?action=" + form.getAction() + "&blogid=" + form.getBlogid() +
  46.                         "&username=" + form.getUsername());
  47.       PageList pl = this.getArticleService().findArticlesByBlogID_IsHide(form.getBlogid(),
  48.           Constant.ART_NOT_HIDE, pages);
  49.       servletRequest.setAttribute("pl", pl);
  50.       pages.setPage(1);
  51.       pages.setPerPageNum(blog.getNewlyartnum());
  52.       pages.setTotals(blog.getNewlyartnum());
  53.       pl = this.getArticleService().findArticlesByBlogID_IsHide(blog.getId().longValue(),
  54.           Constant.ART_NOT_HIDE, pages);
  55.       List newartlist = pl.getObjectList();
  56.       pages.setPage(1);
  57.       pages.setPerPageNum(blog.getNewlycomnum());
  58.       pages.setTotals(blog.getNewlycomnum());
  59.       pl = this.getNoteService().findNotesByBlogID(blog.getId().longValue(), pages);
  60.       List notelist = pl.getObjectList();
  61.       List linktext = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
  62.           Constant.LINK_TEXT);
  63.       List linklogo = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
  64.           Constant.LINK_LOGO);
  65.       String postdates = this.getArticleService().getPostDateStr(blog.getId().longValue());
  66.       if (StringUtils.isBlank(postdates)) {
  67.         postdates = Util.formatDate7(new Date());
  68.       }
  69.       String showcc = Util.getFirstDay(new Date());
  70.       servletRequest.setAttribute("blog", blog);
  71.       servletRequest.setAttribute("newartlist", newartlist);
  72.       servletRequest.setAttribute("notelist", notelist);
  73.       servletRequest.setAttribute("linktext", linktext);
  74.       servletRequest.setAttribute("linklogo", linklogo);
  75.       servletRequest.setAttribute("postdates", postdates);
  76.       servletRequest.setAttribute("showcc", showcc);
  77.       return new ActionForward("/WEB-INF/template/skin" + blog.getSkin() + "_list.ftl");
  78.     }
  79.     if (form.getAction().equalsIgnoreCase("showdate")) {
  80.       Pages pages = new Pages(servletRequest.getLocale());
  81.       pages.setPage(form.getPage());
  82.       pages.setPerPageNum(blog.getPerartnum());
  83.       pages.setStyle(1);
  84.       pages.setFileName("blogList.do?action=" + form.getAction() + "&blogid=" + form.getBlogid() +
  85.                         "&username=" + form.getUsername());
  86.       PageList pl = this.getArticleService().findArticlesByPostDate(form.getBlogid(), form.getDate(),
  87.           pages);
  88.       servletRequest.setAttribute("pl", pl);
  89.       pages.setPage(1);
  90.       pages.setPerPageNum(blog.getNewlyartnum());
  91.       pages.setTotals(blog.getNewlyartnum());
  92.       pl = this.getArticleService().findArticlesByBlogID_IsHide(blog.getId().longValue(),
  93.           Constant.ART_NOT_HIDE, pages);
  94.       List newartlist = pl.getObjectList();
  95.       pages.setPage(1);
  96.       pages.setPerPageNum(blog.getNewlycomnum());
  97.       pages.setTotals(blog.getNewlycomnum());
  98.       pl = this.getNoteService().findNotesByBlogID(blog.getId().longValue(), pages);
  99.       List notelist = pl.getObjectList();
  100.       List linktext = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
  101.           Constant.LINK_TEXT);
  102.       List linklogo = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
  103.           Constant.LINK_LOGO);
  104.       String postdates = this.getArticleService().getPostDateStr(blog.getId().longValue());
  105.       if (StringUtils.isBlank(postdates)) {
  106.         postdates = Util.formatDate7(new Date());
  107.       }
  108.       String showcc = Util.getFirstDay(new Date());
  109.       servletRequest.setAttribute("blog", blog);
  110.       servletRequest.setAttribute("newartlist", newartlist);
  111.       servletRequest.setAttribute("notelist", notelist);
  112.       servletRequest.setAttribute("linktext", linktext);
  113.       servletRequest.setAttribute("linklogo", linklogo);
  114.       servletRequest.setAttribute("postdates", postdates);
  115.       servletRequest.setAttribute("showcc", showcc);
  116.       return new ActionForward("/WEB-INF/template/skin" + blog.getSkin() + "_list.ftl");
  117.     }
  118.     return actionMapping.findForward("error");
  119.   }
  120.   public ArticleService getArticleService() {
  121.     return articleService;
  122.   }
  123.   public BlogCache getBlogCache() {
  124.     return blogCache;
  125.   }
  126.   public LinksService getLinksService() {
  127.     return linksService;
  128.   }
  129.   public NoteService getNoteService() {
  130.     return noteService;
  131.   }
  132.   public void setArticleService(ArticleService articleService) {
  133.     this.articleService = articleService;
  134.   }
  135.   public void setBlogCache(BlogCache blogCache) {
  136.     this.blogCache = blogCache;
  137.   }
  138.   public void setLinksService(LinksService linksService) {
  139.     this.linksService = linksService;
  140.   }
  141.   public void setNoteService(NoteService noteService) {
  142.     this.noteService = noteService;
  143.   }
  144. }