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

📄 websitedataaccesscontrolaction.java

📁 JEECSM是JavaEE版网站管理系统(Java Enterprise Edition Content Manage System)的简称。 基于java技术开发
💻 JAVA
字号:
package com.jeecms.core;

import java.io.Serializable;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.jeecms.core.entity.Website;
import com.jeecms.core.exception.DataNotFountException;
import com.ponyjava.common.hibernate3.BaseManager;
import com.ponyjava.common.struts2.interceptor.DataAccessException;
import com.ponyjava.common.struts2.interceptor.DataControlAware;

/**
 * 站点相关数据控制ACTION。
 * <p>
 * 站点相关数据只能在数据所在的站点中进行CURD操作
 * </p>
 * 
 * @author liufang
 * 
 */
public abstract class WebsiteDataAccessControlAction extends JeeCoreAction
		implements DataControlAware {
	private static final Log log = LogFactory
			.getLog(WebsiteDataAccessControlAction.class);

	public void controlSave() {
		setBeanWebsite(getBeanInput());
	}

	public void controlEdit() {
		if (!getPersistentDomain(super.id).equals(domainName)) {
			addActionError("无权访问!");
			throw new DataAccessException("无权访问!Entity="
					+ getPersistent(super.id).getClass().getName() + ";ID"
					+ getBeanId());
		}
	}

	public void controlUpdate() {
		if (!getPersistentDomain(null).equals(domainName)) {
			addActionError("无权访问!");
			throw new DataAccessException("无权访问!Entity=" + getBeanClassName()
					+ ";ID" + getBeanId());
		}
		setBeanWebsite(getBeanInput(), getPersistentWebsite(null));
	}

	public void controlDelete() {
		if (super.id != null) {
			checkDelete(super.id);
		}
		if (super.ids != null) {
			for (Long id : super.ids) {
				checkDelete(id);
			}
		}
	}

	private void checkDelete(Long id) {
		if (id != null && !getPersistentDomain(id).equals(domainName)) {
			addActionError("无权访问!");
			throw new DataAccessException("无权访问!Entity="
					+ getPersistent(super.id).getClass().getName() + ";ID" + id);
		}
	}

	protected Serializable getBeanId() {
		Object entity = getBeanInput();
		Serializable id;
		try {
			id = (Serializable) PropertyUtils.getSimpleProperty(entity, "id");
		} catch (Exception e) {
			throw new DataNotFountException("获取实体类ID失败!ID不存在。");
		}
		return id;
	}

	protected Object getPersistent(Serializable id) {
		if (id == null) {
			id = getBeanId();
		}
		Object po = getManager().load(id);
		return po;
	}

	protected Website getPersistentWebsite(Serializable id) {
		return (Website) getPersistentProperty("website", id);
	}

	protected String getPersistentDomain(Serializable id) {
		Website w = getPersistentWebsite(id);
		return w.getDomain();
	}

	protected Object getPersistentProperty(String field, Serializable id) {
		Object po = getPersistent(id);
		try {
			Object o = PropertyUtils.getSimpleProperty(po, field);
			return o;
		} catch (Exception e) {
			throw new DataNotFountException("获取实体类属性失败!Entity="
					+ getBeanClassName() + ",field=" + field);
		}
	}

	protected void setBeanWebsite(Object bean, Website website) {
		try {
			PropertyUtils.setSimpleProperty(bean, "website", website);
		} catch (Exception e) {
			log.error("setWebsite失败!", e);
		}
	}

	protected void setBeanWebsite(Object bean) {
		setBeanWebsite(bean, getWeb());
	}

	protected String getBeanClassName() {
		return getBeanInput().getClass().getName();
	}

	protected abstract Object getBeanInput();

	protected abstract BaseManager<Serializable> getManager();
}

⌨️ 快捷键说明

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