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

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.IndexForm;
  23. public class Index
  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.     IndexForm form = (IndexForm) actionForm;
  33.     Blog blog = this.getBlogCache().getFromCache(form.getUsername());
  34.     if (blog == null) {
  35.       ActionMessages errors = new ActionMessages();
  36.       errors.add("error.blogblog.getinfo", new ActionMessage("error.blogblog.getinfo"));
  37.       saveErrors(servletRequest, errors);
  38.       return actionMapping.findForward("error");
  39.     }
  40.     Pages pages = new Pages(servletRequest.getLocale());
  41.     pages.setPage(1);
  42.     pages.setPerPageNum(blog.getPerartnum());
  43.     pages.setTotals(blog.getPerartnum());
  44.     pages.setStyle(1);
  45.     PageList pl = this.getArticleService().findArticlesByBlogID_IsHide(blog.getId().longValue(),
  46.         Constant.ART_NOT_HIDE, pages);
  47.     List artlist = pl.getObjectList();
  48.     pages.setPage(1);
  49.     pages.setPerPageNum(blog.getNewlyartnum());
  50.     pages.setTotals(blog.getNewlyartnum());
  51.     pl = this.getArticleService().findArticlesByBlogID_IsHide(blog.getId().longValue(),
  52.         Constant.ART_NOT_HIDE, pages);
  53.     List newartlist = pl.getObjectList();
  54.     pages.setPage(1);
  55.     pages.setPerPageNum(blog.getNewlycomnum());
  56.     pages.setTotals(blog.getNewlycomnum());
  57.     pl = this.getNoteService().findNotesByBlogID(blog.getId().longValue(), pages);
  58.     List notelist = pl.getObjectList();
  59.     List linktext = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
  60.         Constant.LINK_TEXT);
  61.     List linklogo = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
  62.         Constant.LINK_LOGO);
  63.     String postdates = this.getArticleService().getPostDateStr(blog.getId().longValue());
  64.     if (StringUtils.isBlank(postdates)) {
  65.       postdates = Util.formatDate7(new Date());
  66.     }
  67.     String showcc = Util.getFirstDay(new Date());
  68.     servletRequest.setAttribute("blog", blog);
  69.     servletRequest.setAttribute("artlist", artlist);
  70.     servletRequest.setAttribute("newartlist", newartlist);
  71.     servletRequest.setAttribute("notelist", notelist);
  72.     servletRequest.setAttribute("linktext", linktext);
  73.     servletRequest.setAttribute("linklogo", linklogo);
  74.     servletRequest.setAttribute("postdates", postdates);
  75.     servletRequest.setAttribute("showcc", showcc);
  76.     return new ActionForward("/WEB-INF/template/skin" + blog.getSkin() + "_index.ftl");
  77.   }
  78.   public BlogCache getBlogCache() {
  79.     return blogCache;
  80.   }
  81.   public ArticleService getArticleService() {
  82.     return articleService;
  83.   }
  84.   public NoteService getNoteService() {
  85.     return noteService;
  86.   }
  87.   public LinksService getLinksService() {
  88.     return linksService;
  89.   }
  90.   public void setBlogCache(BlogCache blogCache) {
  91.     this.blogCache = blogCache;
  92.   }
  93.   public void setArticleService(ArticleService articleService) {
  94.     this.articleService = articleService;
  95.   }
  96.   public void setNoteService(NoteService noteService) {
  97.     this.noteService = noteService;
  98.   }
  99.   public void setLinksService(LinksService linksService) {
  100.     this.linksService = linksService;
  101.   }
  102. }