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

📄 frontbaseaction.java

📁 这个是完整的wap项目的源码 开发语言 Java 系统架构 Struts + hibernate + spring 数据库 Mysql5.0 应用服务器Tomcat5.0 开发工具 MyEc
💻 JAVA
字号:
package com.longtime.wap.module.front.web.action;

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

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.GenericValidator;
import org.springframework.web.struts.DispatchActionSupport;

import com.longtime.wap.common.WapConstant;
import com.longtime.wap.common.web.Page;
import com.longtime.wap.frame.common.UserSessionVO;
import com.longtime.wap.model.Information;
import com.longtime.wap.model.UncommandWord;
import com.longtime.wap.module.front.common.FrontConstant;
import com.longtime.wap.module.front.service.FrontService;

/**
 * 处理前台信息请求
 * 
 * @author bulc
 * @date Nov 19, 2007
 */
public abstract class FrontBaseAction extends DispatchActionSupport {
	private static final Log LOGGER = LogFactory.getLog(FrontBaseAction.class);

	/**
	 * 热点推荐信息设置
	 * 
	 * @param request
	 *            HttpServletRequest对象
	 * @param frontService
	 *            服务对象
	 */
	public void setLeft(HttpServletRequest request, FrontService frontService) {
		try {
			request.setAttribute(FrontConstant.HOT_TOPVIEW_INFOS,
					filtInformationsContent(frontService
							.getInfosByIsHotAndIsPub(new Page(1, 20)),
							frontService, 5));
			request.setAttribute(FrontConstant.RECOMMEND_TOPVIEW_INFOS,
					filtInformationsContent(frontService
							.getInfosByIsRecommendAndIsPub(new Page(1, 20)),
							frontService, 5));
		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
	}

	/**
	 * head业务专题设置
	 * 
	 * @param request
	 *            HttpServletRequest对象
	 * @param frontService
	 *            服务对象
	 */
	public void setHeader(HttpServletRequest request, 
			FrontService frontService) {
		try {
			request.setAttribute(FrontConstant.FRAME_BUSINESSES, frontService
					.getBusinesses(new Page(1, 14)));
		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
	}

	/**
	 * 信息内容过滤请求处理
	 * 
	 * @param informations
	 *            信息列表对象
	 * @param frontService
	 *            服务对象
	 * @param page
	 *            分页参数
	 * @return 信息列表
	 */
	protected List filtInformationsContent(List informations,
			FrontService frontService, Page page) {
		try {
			Iterator it = informations.iterator();
			while (it.hasNext()) {
				Information info = (Information) it.next();
				info = this.filtInformationContent(info, frontService);
				if ((info.getTitle().trim()).length() == 0) {
					it.remove();
					if (null != page && page.getTotalCount() > 0) {
						page.setTotalCount(page.getTotalCount() - 1);
					}
				}
			}
		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
		return informations;
	}

	/**
	 * 信息内容过滤请求处理
	 * 
	 * @param informations
	 *            信息列表对象
	 * @param frontService
	 *            服务对象
	 * @param topValue
	 *            靠前参数
	 * @return 信息列表对象
	 */
	@SuppressWarnings("unchecked")
	protected List filtInformationsContent(List informations,
			FrontService frontService, int topValue) {
		List returnList = new ArrayList();
		try {
			for (int i = 0; i < informations.size(); i++) {
				Information info = (Information) informations.get(i);
				info = this.filtInformationContent(info, frontService);
				if ((info.getTitle().trim()).length() != 0) {
					returnList.add(info);
				}
				if (returnList.size() == topValue) {
					break;
				}
			}
		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
		return returnList;
	}

	/**
	 * 信息内容过滤请求处理
	 * 
	 * @param information
	 *            信息对象
	 * @param frontService
	 *            服务对象
	 * @return 信息对象
	 */
	protected Information filtInformationContent(Information information,
			FrontService frontService) {
		try {
			List uncommandWords = frontService.getUncommandWords();

			Iterator it = uncommandWords.iterator();
			while (it.hasNext()) {
				UncommandWord ucWord = (UncommandWord) it.next();
				if (!GenericValidator.isBlankOrNull(information.getTitle())) {
					if (information.getTitle().contains(ucWord.getWord())) {
						StringBuilder replaceWord = new StringBuilder();
						for (int i = 0; i < ucWord.getWord().length(); i++) {
							replaceWord.append("*");
						}
						information.setTitle(information.getTitle().replaceAll(
								ucWord.getWord(), replaceWord.toString()));
					}
				}
				if (!GenericValidator.isBlankOrNull(information.getContent())) {
					if (information.getContent().contains(ucWord.getWord())) {
						StringBuilder replaceWord = new StringBuilder();
						for (int i = 0; i < ucWord.getWord().length(); i++) {
							replaceWord.append("*");
						}
						information.setContent(information.getContent()
								.replaceAll(ucWord.getWord(),
										replaceWord.toString()));
					}
				}
			}
		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
		return information;
	}

	/**
	 * 判断是否不是用户
	 * 
	 * @param request
	 *            HttpServletRequest
	 * @return 是否不是用户
	 */
	protected boolean isUser(HttpServletRequest request) {
		boolean tag = true;
		UserSessionVO usVo = (UserSessionVO) request.getSession().getAttribute(
				WapConstant.USER_SESSION);
		if (null != usVo) {
			if (2 != usVo.getUserGroup()) {
				tag = false;
			}
		}

		return tag;
	}
}

⌨️ 快捷键说明

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