Index.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.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.IndexForm;
- public class Index
- 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) {
- IndexForm form = (IndexForm) actionForm;
- Blog blog = this.getBlogCache().getFromCache(form.getUsername());
- if (blog == null) {
- ActionMessages errors = new ActionMessages();
- errors.add("error.blogblog.getinfo", new ActionMessage("error.blogblog.getinfo"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- Pages pages = new Pages(servletRequest.getLocale());
- pages.setPage(1);
- pages.setPerPageNum(blog.getPerartnum());
- pages.setTotals(blog.getPerartnum());
- pages.setStyle(1);
- PageList pl = this.getArticleService().findArticlesByBlogID_IsHide(blog.getId().longValue(),
- Constant.ART_NOT_HIDE, pages);
- List artlist = pl.getObjectList();
- 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("artlist", artlist);
- 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() + "_index.ftl");
- }
- public BlogCache getBlogCache() {
- return blogCache;
- }
- public ArticleService getArticleService() {
- return articleService;
- }
- public NoteService getNoteService() {
- return noteService;
- }
- public LinksService getLinksService() {
- return linksService;
- }
- public void setBlogCache(BlogCache blogCache) {
- this.blogCache = blogCache;
- }
- public void setArticleService(ArticleService articleService) {
- this.articleService = articleService;
- }
- public void setNoteService(NoteService noteService) {
- this.noteService = noteService;
- }
- public void setLinksService(LinksService linksService) {
- this.linksService = linksService;
- }
- }