informationeditform.java

来自「这个是完整的wap项目的源码 开发语言 Java 系统架构 Struts +」· Java 代码 · 共 568 行

JAVA
568
字号
package com.longtime.wap.module.business.web.form;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.validator.GenericValidator;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import org.apache.struts.validator.ValidatorForm;

/**
 * 修改信息表单
 * 
 * @author gengb
 * @date Nov 20, 2007
 */
public class InformationEditForm extends ValidatorForm {
	
	private static final long serialVersionUID = 1L;
	
	private String detailType;
	private String editFlug;
	private String informationId;
	private String businessId;
	private String businessName;
	private String title;
	private String price;
	private boolean isHot;
	private boolean isRecommend;
	private boolean isPub;
	private boolean isOverdue;
	private String content;
	private String filePath;
	private FormFile uploadFile;
	
	private String searchValue;
	private String searchType;
	private String fromDate;
	private String toDate;
	private String state;
	
	private String currentPage;
	
	/**
	 * 重写回复函数
	 * 
	 * @param mapping
	 *            ActionMapping对象
	 * @param request
	 *            HttpServletRequest对象
	 */
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		informationId = null;
		detailType = null;
		editFlug = null;
		businessName = null;
		title = null;
		price = null;
		isHot = false;
		isRecommend = false;
		isPub = false;
		content = null;
		uploadFile = null;
		filePath = null;
		businessId = null;
		fromDate = null;
		toDate = null;
		searchValue = null;
		searchType = null;
		currentPage = null;
	}
	
	/**
	 * 错误验证
	 * 
	 * @param mapping
	 *            ActionMapping对象
	 * @param request
	 *            HttpServletRequest对象
	 * @return 错误提示信息
	 */
	@Override
	public ActionErrors validate(ActionMapping mapping, 
			HttpServletRequest request) {
		ActionErrors errors = null;
		errors = super.validate(mapping, request);
		if (!StringUtils.isBlank(price)){
			if (GenericValidator.isDouble(price)) {
				double informationPrice = Double.parseDouble(price);
				if (price.startsWith("-")) {
					errors.add("price", 
							new ActionError("errors.pricenegative"));
				} else if (informationPrice > 5.00){
					errors.add("price", 
							new ActionError("errors.priceoutofrange"));
				} else if (price.contains(".") 
						&& price.split("\\.")[1].length() > 2){
					errors.add("price", 
							new ActionError("errors.priceinvalidformat"));
				}
			} else {
				errors.add("price", new ActionError("errors.double"));
			}
		} else {
			errors.add("price", new ActionError("errors.required"));
		}
		//if (("save").equalsIgnoreCase(editFlug) 
		if(editFlug.equalsIgnoreCase("save")
				//&& !("text").equalsIgnoreCase(detailType)) {
				&& !detailType.equalsIgnoreCase("text")) {
			if (null != uploadFile 
					&& !StringUtils.isEmpty(uploadFile.getFileName())) {
				String[] fileNameArray = uploadFile.getFileName().split("\\.");
				if (fileNameArray.length == 2) {
					//if ((("pic").equalsIgnoreCase(detailType) && 
					if ((detailType.equalsIgnoreCase("pic") 
							&& !isAllowedPicType(
									fileNameArray[1].toLowerCase()))
							//|| ("music").equalsIgnoreCase(detailType) &&
							|| detailType.equalsIgnoreCase("music")
							&& !isAllowedMusicType(
									fileNameArray[1].toLowerCase())) 
					{
						errors.add("uploadFile", 
								new ActionError("errors.invalidtype"));
					}
				} else {
					errors.add("uploadFile", 
							new ActionError("errors.invalieduploadfilename"));
				}
			} else {
				errors.add("uploadFile", new ActionError("errors.required"));
			}
		}
		return errors;
	}

	/**
	 * 判断图片类型
	 * 
	 * @param extension
	 * 				图片范围
	 * @return 图片格式是否有效
	 */
	private boolean isAllowedPicType(String extension) {
		List<String> allowedPicType = new ArrayList<String>();
		allowedPicType.add("jpg");
		allowedPicType.add("jpeg");
		allowedPicType.add("png");
		allowedPicType.add("bmp");
		allowedPicType.add("gif");

		if (allowedPicType.contains(extension)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 判断音乐类型
	 * 
	 * @param extension
	 * 				音乐范围
	 * @return 音乐格式是否有效
	 */
	private boolean isAllowedMusicType(String extension) {
		List<String> allowedMusicType = new ArrayList<String>();
		allowedMusicType.add("mp3");
		allowedMusicType.add("m4a");
		allowedMusicType.add("wma");
		allowedMusicType.add("wav");

		if (allowedMusicType.contains(extension)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 获取业务id
	 * 
	 * @return 业务id
	 */
	public String getBusinessId() {
		return businessId;
	}

	/**
	 * 设置业务id
	 * 
	 * @param businessId
	 * 				业务id
	 */
	public void setBusinessId(String businessId) {
		this.businessId = businessId;
	}

	/**
	 * 获取业务名称
	 * 
	 * @return 业务名称
	 */
	public String getBusinessName() {
		return businessName;
	}

	/**
	 * 设置业务名称
	 * 
	 * @param businessName
	 * 				业务名称
	 */
	public void setBusinessName(String businessName) {
		this.businessName = businessName;
	}

	/**
	 * 获取内容
	 * 
	 * @return 内容
	 */
	public String getContent() {
		return content;
	}

	/**
	 * 设置内容
	 * 
	 * @param content
	 * 				内容
	 */
	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * 获取业务类型
	 * 
	 * @return 业务类型
	 */
	public String getDetailType() {
		return detailType;
	}

	/**
	 * 设置业务类型
	 * 
	 * @param detailType
	 * 				业务类型
	 */
	public void setDetailType(String detailType) {
		this.detailType = detailType;
	}

	/**
	 * 获取操作标记
	 * 
	 * @return 操作标记
	 */
	public String getEditFlug() {
		return editFlug;
	}

	/**
	 * 设置操作标记
	 * 
	 * @param editFlug
	 * 				操作标记
	 */
	public void setEditFlug(String editFlug) {
		this.editFlug = editFlug;
	}

	/**
	 * 获取文件路径
	 * 
	 * @return 文件路径
	 */
	public String getFilePath() {
		return filePath;
	}

	/**
	 * 设置文件路径
	 * 
	 * @param filePath
	 * 			文件路径
	 */
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	/**
	 * 获取信息id
	 * 
	 * @return 信息id
	 */
	public String getInformationId() {
		return informationId;
	}

	/**
	 * 设置信息id
	 * 
	 * @param informationId
	 * 				信息id
	 */
	public void setInformationId(String informationId) {
		this.informationId = informationId;
	}

	/**
	 * 获取是否热门
	 * 
	 * @return 是否热门
	 */
	public boolean getIsHot() {
		return isHot;
	}

	/**
	 * 设置是否热门
	 * 
	 * @param isHot
	 * 			是否热门
	 */
	public void setIsHot(boolean isHot) {
		this.isHot = isHot;
	}

	/**
	 * 获取是否过期
	 * 
	 * @return 是否过期
	 */
	public boolean getIsOverdue() {
		return isOverdue;
	}

	/**
	 * 设置是否过期
	 * @param isOverdue
	 * 				是否过期
	 */
	public void setIsOverdue(boolean isOverdue) {
		this.isOverdue = isOverdue;
	}

	/**
	 * 获取是否发布
	 * 
	 * @return 是否发布
	 */
	public boolean getIsPub() {
		return isPub;
	}

	/**
	 * 设置是否发布
	 * 
	 * @param isPub
	 * 			是否发布
	 */
	public void setIsPub(boolean isPub) {
		this.isPub = isPub;
	}

	/**
	 * 获取是否推荐
	 * 
	 * @return 是否推荐
	 */
	public boolean getIsRecommend() {
		return isRecommend;
	}

	/**
	 * 设置是否推荐
	 * 
	 * @param isRecommend
	 * 				是否推荐
	 */
	public void setIsRecommend(boolean isRecommend) {
		this.isRecommend = isRecommend;
	}

	/**
	 * 获取价格
	 * 
	 * @return 价格
	 */
	public String getPrice() {
		return price;
	}

	/**
	 * 设置价格
	 * 
	 * @param price
	 * 			价格
	 */
	public void setPrice(String price) {
		this.price = price;
	}

	/**
	 * 获取标题
	 * 
	 * @return 标题
	 * 
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * 设置标题
	 * 
	 * @param title
	 * 			标题
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * 获取上传路径
	 * 
	 * @return 上传路径
	 */
	public FormFile getUploadFile() {
		return uploadFile;
	}

	/**
	 * 设置上传路径
	 * 
	 * @param uploadFile
	 * 				上传路径
	 */
	public void setUploadFile(FormFile uploadFile) {
		this.uploadFile = uploadFile;
	}

	/**
	 * 获取起始时间
	 * 
	 * @return 起始时间
	 */
	public String getFromDate() {
		return fromDate;
	}

	/**
	 * 设置起始时间
	 * 
	 * @param fromDate
	 * 				起始时间
	 */
	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}

	/**
	 * 获取查询类型
	 * 
	 * @return 查询类型
	 */
	public String getSearchType() {
		return searchType;
	}

	/**
	 * 设置查询类型
	 * 
	 * @param searchType
	 * 				查询类型
	 */
	public void setSearchType(String searchType) {
		this.searchType = searchType;
	}

	/**
	 * 获取查询内容
	 * 
	 * @return 查询内容
	 */
	public String getSearchValue() {
		return searchValue;
	}

	/**
	 * 设置查询内容
	 * 
	 * @param searchValue
	 * 				查询内容
	 */
	public void setSearchValue(String searchValue) {
		this.searchValue = searchValue;
	}

	/**
	 * 获取终止日期
	 * 
	 * @return 终止日期
	 */
	public String getToDate() {
		return toDate;
	}

	/**
	 * 设置终止日期
	 * 
	 * @param toDate
	 * 			终止日期
	 */
	public void setToDate(String toDate) {
		this.toDate = toDate;
	}

	/**
	 * 获取状态
	 * 
	 * @return 状态
	 */
	public String getState() {
		return state;
	}

	/**
	 * 设置状态
	 * 
	 * @param state
	 * 			状态
	 */
	public void setState(String state) {
		this.state = state;
	}

	/**
	 * 获取当前页
	 * 
	 * @return 当前页
	 */
	public String getCurrentPage() {
		return currentPage;
	}

	/**
	 * 设置当前页
	 * 
	 * @param currentPage
	 * 				当前页
	 */
	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}

}

⌨️ 快捷键说明

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