Read.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.Article;
  18. import com.opensource.blog.model.Blog;
  19. import com.opensource.blog.service.ArticleService;
  20. import com.opensource.blog.service.LinksService;
  21. import com.opensource.blog.service.NoteService;
  22. import com.opensource.blog.service.cache.app.BlogCache;
  23. import com.opensource.blog.web.form.ReadForm;
  24. public class Read
  25.     extends Action {
  26.   private BlogCache blogCache;
  27.   private ArticleService articleService;
  28.   private NoteService noteService;
  29.   private LinksService linksService;
  30.   public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
  31.                                HttpServletRequest servletRequest,
  32.                                HttpServletResponse servletResponse) {
  33.     ActionMessages errors = new ActionMessages();
  34.     ReadForm form = (ReadForm) actionForm;
  35.     Blog blog = this.getBlogCache().getFromCache(form.getUsername());
  36.     if (blog == null) {
  37.       errors.add("error.blogblog.getinfo", new ActionMessage("error.blogblog.getinfo"));
  38.       saveErrors(servletRequest, errors);
  39.       return actionMapping.findForward("error");
  40.     }
  41.     Article art = this.getArticleService().findArticleByID_BlogID(form.getArtid(), form.getBlogid());
  42.     if (art == null) {
  43.       errors.add("error.read.getart", new ActionMessage("error.read.getart"));
  44.       saveErrors(servletRequest, errors);
  45.       return actionMapping.findForward("error");
  46.     }
  47.     servletRequest.setAttribute("art", art);
  48.     List artnotes = this.getNoteService().findNotesByArtID(form.getArtid());
  49.     servletRequest.setAttribute("artnotes", artnotes);
  50.     Pages pages = new Pages(servletRequest.getLocale());
  51.     pages.setPage(1);
  52.     pages.setPerPageNum(blog.getNewlyartnum());
  53.     pages.setTotals(blog.getNewlyartnum());
  54.     PageList pl = this.getArticleService().findArticlesByBlogID_IsHide(blog.getId().longValue(),
  55.         Constant.ART_NOT_HIDE, pages);
  56.     List newartlist = pl.getObjectList();
  57.     pages.setPage(1);
  58.     pages.setPerPageNum(blog.getNewlycomnum());
  59.     pages.setTotals(blog.getNewlycomnum());
  60.     pl = this.getNoteService().findNotesByBlogID(blog.getId().longValue(), pages);
  61.     List notelist = pl.getObjectList();
  62.     List linktext = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
  63.         Constant.LINK_TEXT);
  64.     List linklogo = this.getLinksService().findLinksByBlogID_Type(blog.getId().longValue(),
  65.         Constant.LINK_LOGO);
  66.     String postdates = this.getArticleService().getPostDateStr(blog.getId().longValue());
  67.     if (StringUtils.isBlank(postdates)) {
  68.       postdates = Util.formatDate7(new Date());
  69.     }
  70.     String showcc = Util.getFirstDay(new Date());
  71.     servletRequest.setAttribute("blog", blog);
  72.     servletRequest.setAttribute("newartlist", newartlist);
  73.     servletRequest.setAttribute("notelist", notelist);
  74.     servletRequest.setAttribute("linktext", linktext);
  75.     servletRequest.setAttribute("linklogo", linklogo);
  76.     servletRequest.setAttribute("postdates", postdates);
  77.     servletRequest.setAttribute("showcc", showcc);
  78.     return new ActionForward("/WEB-INF/template/skin" + blog.getSkin() + "_read.ftl");
  79.   }
  80.   public ArticleService getArticleService() {
  81.     return articleService;
  82.   }
  83.   public BlogCache getBlogCache() {
  84.     return blogCache;
  85.   }
  86.   public LinksService getLinksService() {
  87.     return linksService;
  88.   }
  89.   public NoteService getNoteService() {
  90.     return noteService;
  91.   }
  92.   public void setArticleService(ArticleService articleService) {
  93.     this.articleService = articleService;
  94.   }
  95.   public void setBlogCache(BlogCache blogCache) {
  96.     this.blogCache = blogCache;
  97.   }
  98.   public void setLinksService(LinksService linksService) {
  99.     this.linksService = linksService;
  100.   }
  101.   public void setNoteService(NoteService noteService) {
  102.     this.noteService = noteService;
  103.   }
  104. }