package m_ylf.cs.sicau.portal.action;
import com.opensymphony.xwork2.ActionSupport;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import m_ylf.cs.sicau.portal.domain.Article;
import m_ylf.cs.sicau.portal.domain.ArticleTopType;
import m_ylf.cs.sicau.portal.domain.Category;
import m_ylf.cs.sicau.portal.domain.Page;
import m_ylf.cs.sicau.portal.domain.User;
import m_ylf.cs.sicau.portal.globals.ActionMessageGlobals;
import m_ylf.cs.sicau.portal.globals.ActionReturnStringsGlobals;
import m_ylf.cs.sicau.portal.globals.AjaxMessageGlobals;
import m_ylf.cs.sicau.portal.globals.ProjectConfigureGlobals;
import m_ylf.cs.sicau.portal.service.IService;
import m_ylf.cs.sicau.portal.set.AjaxReturnSet;
import m_ylf.cs.sicau.portal.util.AjaxResponse;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.util.StringUtils;
/**
*
* @author Fly_m
*/
public class ArticleAction extends ActionSupport {
/** 业务层组件对象,负责提供相应的数据,和相应的逻辑操作 **/
private IService service;
/** 文章对象,负责从页面传递相应的数据并向页面返回相应的数据 **/
private Article article;
/** 页面组件,负责对页面上的请求对数据进行分页,并返回页面上的分页逻辑 **/
private Page page;
/** 向页面传递多个文章时运用,并尝试从页面取得多个对象,在进行批处理对象时运用 **/
private List<Article> articleList;
/** 特殊追加字段,此字段在某些处理单个对象的时候运用,以避免对某些细节方面的访问,通用单个关键值
* 对象id 值访问.在页面中,通常处理某些问题只需要提供相应的key值,如id,则此属性提供这种途径来
* 提供相应的支持,此避免页面可能出现比如article.id这种暴露性的提示字段.同时也简化了对相应
* 数据的处理.
*/
private int id;
/** 置顶组件,此字段用于置顶一些文章或者取消置顶所用.由于设计的原因,导致置顶标记不能与文章产生
* 一对一的关系,而成为多对一的关系.故type不能直接被删除,为一个文章置顶之时,就会产生一个新的
* type对象,而取消置顶时,仅仅是把关联关系去掉.而因为type的作用范围很小,故不会对type对象进行
* 其它的操作.此对象是相对数据库来说安全的.
*/
private ArticleTopType type;
/**
* 在查询时,表示是否是级联查询,如果是true,表示是级联,否则其它的数据(空值)均表示不能级联查询.
*/
private String cascade;
public void setService(IService service) {
this.service = service;
}
public void setArticle(Article article) {
this.article = article;
}
public void setArticleList(List<Article> articleList) {
this.articleList = articleList;
}
public void setId(int id) {
this.id = id;
}
public void setPage(Page page) {
this.page = page;
}
public Article getArticle() {
return article;
}
public List<Article> getArticleList() {
return articleList;
}
public String getCascade() {
return cascade;
}
public int getId() {
return id;
}
public Page getPage() {
return page;
}
public IService getService() {
return service;
}
public ArticleTopType getType() {
return type;
}
/**
* 保存一篇文章,根据此文章的类别对文章进行分类,以及建立索引.并对此文章进行分页保存.
* 必须条件:除了文章的各项内容之外,还需要此文章的类别,且保证此类别是存在于数据库中的,此外,创
* 建此文章的作者也是需要的.
*/
public String saveArticle() throws Exception {
/** 查找此文章类别,此类别在下文中对查询标记,或者路径标记均有相关作用,故为必须的 **/
Category category = this.service.getCategory(id);
if (category == null) {
this.addActionError(this.getText(ActionMessageGlobals.ARTICLEACTION_SAVEARTICLE_NOCATEGORY_FAIL));
return ActionReturnStringsGlobals.ARTICLEACTION_SAVEARTICLE_FAIL;
}
/** 设置此文章的路径标记,标记同一篇文章 **/
String pathMark = category.getName() + new SimpleDateFormat("-yyyy/MM/dd-HH/mm/ss-SSS").format(new Date());
/** 设置此文章的类别查询标记,标记同一类别文章 **/
String categoryChain = category.getCategoryChain();
/** 设置文章作者ip **/
String ip = ServletActionContext.getRequest().getRemoteAddr();
/** 设置来源,此默认来源由于国际化的需要,而引用相关资源文件key值 **/
String source = this.article.getSource() == null ? this.getText(ProjectConfigureGlobals.ARTICLE_DEFAULT_LOCALSOURCE_KEY) : this.article.getSource();
/** 设置文章摘要,默认有文章的前50个字符 **/
String summary = this.article.getSummary() == null ? (this.article.getContent().length() < 50 ? this.article.getContent() : this.article.getContent().substring(0, 50)) : this.article.getSummary();
/** 得到文章内容数组,因为文章可能是分页的,所以用分隔符将其隔开,分成几个页面 **/
String[] contents = this.article.getContent().split(ProjectConfigureGlobals.ARTICLE_DEFAULT_SEPARAROR);
/** 开始保存文章 **/
int pageTotalCount = contents.length; //文章总页数
int pageCurrentIndex = 1; //文章当前页数
for (int i = 0; i < pageTotalCount; i++) {
Article a = new Article();
a.setTitle(this.article.getTitle());
a.setPathMark(pathMark);
a.setTitleColor(this.article.getTitleColor());
a.setSummary(summary);
a.setSource(source);
a.setIp(ip);
a.setContent(contents[pageCurrentIndex - 1]);
a.setPageCount(pageTotalCount);
a.setPageCurrentIndex(pageCurrentIndex);
a.setCreateUser(this.article.getCreateUser());
a.setCategory(category);
a.setCategoryChain(categoryChain);
a.setTags(this.article.getTags());
this.service.saveArticle(a);
pageCurrentIndex++;
}
this.addActionMessage(this.getText(ActionMessageGlobals.ARTICLEACTION_SAVEARTICLE_SUCCESS, new String[] {this.article.getTitle()}));
return ActionReturnStringsGlobals.ARTICLEACTION_SAVEARTICLE_SUCCESS;
}
/**
* 显示文章,此方法除了处理显示第一页面的文章之外,还处理显示后续页面文章的能力.这就要求,从文章
* id值,进而得到文章的pathMark值,从而得到下一篇/上一篇文章.
* 要求参数,文章的id值,第几页的页面数,默认为第一页.
*/
public String showArticle() throws Exception {
/** 处理id值,此id值为文章第几页数 **/
id = (id == 0 ? 1 : id);
/** 得到文章对象,由文章id值,得到pathMark值,进而得到应该传递的article对象 **/
this.article = this.service.getArticle(this.article.getId());
if (this.article != null) {
this.article = this.service.getArticleByPathMarkAndPageCurrentIndex(this.article.getPathMark(), id);
}
/** 如果文章对象为空,追加对文章最终标志地判断 **/
if (this.article == null || this.article.isShiftDeleted() == true) {
this.addActionError(this.getText(ActionMessageGlobals.ARTICLEACTION_SHOWARTICLE_NOARTICLE_FAIL));
return ActionReturnStr
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
SSH整合例子 (359个子文件)
spellchecker.cfm 6KB
ArticleAction.class 21KB
Service.class 8KB
CategoryAction.class 7KB
Article.class 6KB
ActionMessageGlobals.class 6KB
ArticleDAO.class 4KB
Category.class 4KB
BeanUtil.class 4KB
ActionReturnStringsGlobals.class 3KB
JsonUtil$JsonHandle.class 3KB
IService.class 3KB
CategoryDAO.class 3KB
ArticleDAO$2.class 2KB
ArticleTopTypeDAO.class 2KB
User.class 2KB
Md5Digest.class 2KB
Page.class 1KB
ArticleDAO$1.class 1KB
ArticleTopType.class 1KB
JsonUtil.class 1KB
AjaxResponse.class 1KB
IArticleDAO.class 1KB
ArticleAction$1.class 895B
AjaxReturnSet.class 880B
UserDAO.class 834B
AjaxMessageGlobals.class 731B
ProjectConfigureGlobals.class 698B
ICategoryDAO.class 594B
IArticleTopTypeDAO.class 550B
UserAction.class 519B
Fly_m.class 395B
JspRemoteAction.class 353B
IUserDAO.class 199B
.classpath 526B
fck_editor.css 8KB
fck_editor.css 8KB
fck_editor.css 8KB
fck_internal.css 2KB
fck_dialog.css 2KB
fck_dialog.css 2KB
fck_dialog.css 2KB
fck_editorarea.css 2KB
browser.css 2KB
fck_dialog_common.css 2KB
fck_showtableborders_gecko.css 1KB
spellerStyle.css 888B
Thumbs.db 10KB
Thumbs.db 9KB
Thumbs.db 9KB
fck_strip.gif 9KB
fck_strip.gif 4KB
fck_strip.gif 4KB
logo_fckeditor.gif 2KB
html.gif 1KB
htm.gif 1KB
rdp.gif 1KB
ai.gif 1KB
embaressed_smile.gif 1KB
teeth_smile.gif 1KB
shades_smile.gif 1KB
tounge_smile.gif 1KB
wink_smile.gif 1KB
sad_smile.gif 1KB
regular_smile.gif 1KB
whatchutalkingabout_smile.gif 1KB
envelope.gif 1KB
heart.gif 1012B
thumbs_down.gif 992B
thumbs_up.gif 989B
kiss.gif 978B
fla.gif 946B
logo_fredck.gif 920B
toolbar.buttonbg.gif 829B
swf.gif 725B
swt.gif 724B
bmp.gif 709B
gif.gif 704B
html.gif 621B
htm.gif 621B
rdp.gif 606B
fck_flashlogo.gif 599B
pdf.gif 567B
cry_smile.gif 473B
png.gif 464B
jpg.gif 463B
mp3.gif 454B
avi.gif 454B
cake.gif 453B
angry_smile.gif 453B
angel_smile.gif 445B
devil_smile.gif 444B
broken_heart.gif 423B
template3.gif 422B
xml.gif 408B
ai.gif 403B
swt.gif 388B
swf.gif 388B
fla.gif 382B
template1.gif 375B
共 359 条
- 1
- 2
- 3
- 4
martin0711
- 粉丝: 1
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- tesseract安装包
- 1_32陀螺仪舵机.zip
- HITJ0302MP-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- XILINXFPGA源码PCIExpress标准概述
- HITJ0204MP-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- XILINXFPGA源码PCIExpressIP核应用参考设计
- XILINXFPGA源码LCD12864在Spartan-3E实现代码
- XILINXFPGA源码LCDIPCORE
- G6402-VB一款SOT23封装P-Channel场效应MOS管
- XILINXFPGA源码IPcamera的开源系统
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0