Read.java
资源名称:Myblog.rar [点击查看]
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:4k
源码类别:
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.Article;
- 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.ReadForm;
- public class Read
- 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();
- ReadForm form = (ReadForm) 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");
- }
- Article art = this.getArticleService().findArticleByID_BlogID(form.getArtid(), form.getBlogid());
- if (art == null) {
- errors.add("error.read.getart", new ActionMessage("error.read.getart"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- servletRequest.setAttribute("art", art);
- List artnotes = this.getNoteService().findNotesByArtID(form.getArtid());
- servletRequest.setAttribute("artnotes", artnotes);
- Pages pages = new Pages(servletRequest.getLocale());
- pages.setPage(1);
- pages.setPerPageNum(blog.getNewlyartnum());
- pages.setTotals(blog.getNewlyartnum());
- PageList 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() + "_read.ftl");
- }
- 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;
- }
- }