⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contentmanageaction.java

📁 利用STRUTS2+SPRING+HIBERNATE/IBATIS建立的基本开发框架
💻 JAVA
字号:
/**
 * 
 */
package com.sunwah.baseapp.content.action;

import java.io.File;
import java.io.FileInputStream;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.springframework.util.FileCopyUtils;

import com.sunwah.baseapp.action.QueryManageAction;
import com.sunwah.baseapp.common.ActionConstants;
import com.sunwah.baseapp.common.Constants;
import com.sunwah.baseapp.common.DictionaryConstants;
import com.sunwah.baseapp.common.SqlConstants;
import com.sunwah.baseapp.content.criteria.ContentQueryCriteria;
import com.sunwah.baseapp.content.model.Accessory;
import com.sunwah.baseapp.content.model.Content;
import com.sunwah.baseapp.service.GenericManager;
import com.sunwah.baseapp.system.vo.UserVO;
import com.sunwah.baseapp.util.Tools;

/**
 * 内容发布Action类
 * 
 * @author MARK
 * 
 */
public class ContentManageAction extends QueryManageAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1071317664992023015L;

	private GenericManager<Content, String> contentManager;

	private ContentQueryCriteria queryCriteria;

	// 内容对象
	private Content content;

	// 内容ID
	private String contentId;

	private File upload;
	private String uploadContentType;
	private String uploadFileName;

	@SkipValidation
	public String findContents() {
		super.query(SqlConstants.GET_CONTENTS, SqlConstants.GET_CONTENT_COUNT,
				queryCriteria);

		// 页面资源权限校验
		super.check(ActionConstants.CONTENT_MANAGE_FIND_CONTENTS,
				ActionConstants.CONTENT_MANAGE_VIEW_CONTENT,
				ActionConstants.CONTENT_MANAGE_ADD_CONTENT,
				ActionConstants.CONTENT_MANAGE_EDIT_CONTENT,
				ActionConstants.CONTENT_MANAGE_DELETE_CONTENT);
		return SUCCESS;
	}

	@SkipValidation
	public String toCreateContent() {
		content = new Content();
		content.setAccessLevel(DictionaryConstants.ACCESS_LEVEL_REGISTERED);
		content.setIsPublish(DictionaryConstants.IS_PUBLISH_Y);
		content.setContentEffDate(new Date());
		content.setContentExpDate(Tools.stringToDate(Constants.MAXIMAL_DATE,
				Constants.DATE_PATTERN));
		content.setContentText(getText("content.contentText.default"));
		return SUCCESS;
	}

	public String createContent() throws Exception {
		// 检查上传文件是否存在
		if (StringUtils.isNotEmpty(uploadFileName) && !upload.exists()) {
			super.addActionError(this
					.getText("content.upload.file.not.existed"));
			return INPUT;
		}

		UserVO user = super.getSessionUser();
		content.setCreateUserId(user.getUserId());
		content.setCreateDate(new Date());
		content.setModifyUserId(user.getUserId());
		content.setModifyDate(new Date());

		// 处理附件
		if (this.getUpload() != null) {
			Set<Accessory> accessorySet = new HashSet<Accessory>();
			accessorySet.add(new Accessory(content, this.getUploadFileName(),
					this.getUploadContentType(), this.getUpload().length(),
					FileCopyUtils.copyToByteArray(new FileInputStream(this
							.getUpload()))));
			content.setAccessories(accessorySet);
		}

		this.contentManager.save(content);
		return SUCCESS;
	}

	@SkipValidation
	public String toUpdateContent() {
		content = this.contentManager.get(contentId);
		return SUCCESS;
	}

	public String updateContent() throws Exception {
		// 检查上传文件是否存在
		if (StringUtils.isNotEmpty(uploadFileName) && !upload.exists()) {
			super.addActionError(this
					.getText("content.upload.file.not.existed"));
			return INPUT;
		}
		UserVO user = super.getSessionUser();
		content.setModifyUserId(user.getUserId());
		content.setModifyDate(new Date());
		// 处理附件
		if (this.getUpload() != null) {
			Set<Accessory> accessorySet = new HashSet<Accessory>();
			accessorySet.add(new Accessory(content, this.getUploadFileName(),
					this.getUploadContentType(), this.getUpload().length(),
					FileCopyUtils.copyToByteArray(new FileInputStream(this
							.getUpload()))));
			content.setAccessories(accessorySet);
			this.contentManager.merge(content);
		} else
			this.contentManager.update(content);

		return SUCCESS;
	}

	@SkipValidation
	public String deleteContent() {
		this.contentManager.remove(contentId);
		return SUCCESS;
	}

	@SkipValidation
	public String findContent() {
		content = this.contentManager.get(contentId);
		return NONE;
	}

	public void setContentManager(GenericManager<Content, String> contentManager) {
		this.contentManager = contentManager;
	}

	public ContentQueryCriteria getQueryCriteria() {
		return queryCriteria;
	}

	public void setQueryCriteria(ContentQueryCriteria queryCriteria) {
		this.queryCriteria = queryCriteria;
	}

	public Content getContent() {
		return content;
	}

	public void setContent(Content content) {
		this.content = content;
	}

	public String getContentId() {
		return contentId;
	}

	public void setContentId(String contentId) {
		this.contentId = contentId;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public File getUpload() {
		return upload;
	}

	public String getUploadContentType() {
		return uploadContentType;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -