?? websitedataaccesscontrolaction.java
字號:
package com.jeecms.core;
import java.io.Serializable;
import org.apache.commons.beanutils.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jeecms.core.entity.Website;
import com.jeecms.core.exception.DataNotFountException;
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 {
protected static final Logger log = LoggerFactory
.getLogger(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().findByIdForCheck(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) {
e.printStackTrace();
throw new DataNotFountException("獲取實體類屬性失敗!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 JeeCoreManager<? extends Serializable> getManager();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -