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

📄 abstractaction.java

📁 本源码为教学管理信息系统
💻 JAVA
字号:
package com.hibernate.action;import java.io.ByteArrayOutputStream;import java.util.Map;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.springframework.context.ApplicationContext;import org.springframework.web.context.WebApplicationContext;import com.opensymphony.webwork.ServletActionContext;import com.opensymphony.xwork.ActionContext;import com.opensymphony.xwork.ActionSupport;import com.wygl.dbdao.DbDao;import com.wygl.session.SessionInfo;import com.wygl.xtgl.domain.Department;import com.wygl.xtgl.domain.User;/** * Superclass for Hibernate-aware actions. Demonstrates the use of an XWork IoC * component in an Action. *  * @see org.hibernate.component.HibernateSession * @author Gavin King * @author Christian Bauer <christian@hibernate.org> */public abstract class AbstractAction extends ActionSupport {	private static final Log LOG = LogFactory.getLog(AbstractAction.class);	/**	 * Excel打印输出流	 */	protected ByteArrayOutputStream exportExcel = new ByteArrayOutputStream();	/**	 * 程序入口编号	 */	protected String progID;	/**	 * 导航信息	 */	protected String navigation;		/**	 * 数据库操作服务	 */	protected DbDao dbDao;			/**	 * 初始化服务  	 */	protected void initDbDao() {		if(dbDao == null){			ApplicationContext ctx = (ApplicationContext) ActionContext.getContext().getApplication().get(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);			dbDao = (DbDao) ctx.getBean("dbDao");		}	}	/**	 * 针对模型驱动的action,进行查询条件初始化	 * @throws Exception	 */	protected void initModel() throws Exception{			}	/**	 * 获得导航信息	 * @return	 * @throws Exception	 */	protected void getSysNavigation() throws Exception{				progID = ServletActionContext.getRequest().getParameter("ProgID");		if(progID == null || progID.equals("")){			progID = (String) get("HwjProgID");					set("IsPortal","0");		}else{			set("HwjProgID",progID);			set("IsPortal","1");			try {				initModel();			} catch (Exception e) {				e.printStackTrace();				throw new Exception("初始化模型错误!");			}		}				try {					initDbDao();			String tmpProgID = progID;			navigation = "";			if(progID == null || progID.equals("")){			}else{				do{					HICProgrameDef hICProgrameDef = (HICProgrameDef)dbDao.queryObjectById(HICProgrameDef.class,tmpProgID);					if(navigation == null || navigation.equals("")){						navigation = hICProgrameDef.getProgramCaption();					}else{						navigation = hICProgrameDef.getProgramCaption() + ">>" + navigation;					}					if(hICProgrameDef.getProgramParent() == null || hICProgrameDef.getProgramParent().equals("")){						tmpProgID = "";					}else{						tmpProgID = hICProgrameDef.getProgramParent();					}				}while(!tmpProgID.equals(""));				}		} catch (Exception e) {			e.printStackTrace();			throw new Exception("获取导航信息错误!");		}	}		/**	 * @return java.lang.Strings	 * @throws java.lang.Exception	 * @roseuid 431F92DB001D	 */	public String execute() throws Exception {		if ( hasErrors() ) {			LOG.debug("action not executed, field or action errors");			LOG.debug( "Field errors: " + getFieldErrors() );			LOG.debug( "Action errors: " + getActionErrors() );			return INPUT;		}		LOG.debug("executing action");		return SUCCESS;	}		/**	 * 获得服务	 * @return Object	 */	protected Object getServiceBean(String beanName){		try {			getSysNavigation();		} catch (Exception e) {					}		ApplicationContext ctx = (ApplicationContext) ActionContext.getContext().getApplication().get(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);		return ctx.getBean(beanName);	}	/**	 * Get an object from the WebWork user session	 * 	 * @param name	 * @return java.lang.Object	 * @roseuid 431F92DB00BD	 */	protected Object get(String name) {		return ActionContext.getContext().getSession().get(name);	}	/**	 * Put an object in the WebWork user session	 * 	 * @param name	 * @param value	 * @roseuid 431F92DB00D1	 */	protected void set(String name, Object value) {		ActionContext.getContext().getSession().put(name, value);			}		/**	 * Remove an object in the WebWork user session	 * 	 * @param key	 * @roseuid 431F92DB00D2	 */	protected void remove(Object key) {		ActionContext.getContext().getSession().remove(key);			}	/**	 * 获得登陆用户信息	 * @return SessionInfo	 */	protected SessionInfo getSessionInfo(){		SessionInfo sessionInfo = new SessionInfo();		Map session = (Map)ActionContext.getContext().getSession();		User user=(User) session.get("currentUser");		Department depa = (Department)user.getEmployee().getDepartment();		sessionInfo.setUserLoginId((String)session.get("LoginID"));		sessionInfo.setUserId(user.getEmployee().getEmployeeId());		sessionInfo.setUserName(user.getEmployee().getName());		sessionInfo.setUserDescription((String)session.get("UserDesc"));		sessionInfo.setRoleId((String)session.get("RoleID"));		sessionInfo.setRoleName((String)session.get("RoleName"));		sessionInfo.setDeptId(depa.getDwdm());			sessionInfo.setYgdm(user.getEmployee().getYgdm());		sessionInfo.setDeptName(depa.getDwmc());				return sessionInfo;	}		public ByteArrayOutputStream getExportExcel() {		return exportExcel;	}	public void setExportExcel(ByteArrayOutputStream exportExcel) {		this.exportExcel = exportExcel;	}		public String getProgID() {		return progID;	}	public void setProgID(String progID) {		this.progID = progID;	}	public String getNavigation() {		return navigation;	}	public void setNavigation(String navigation) {		this.navigation = navigation;	}	}

⌨️ 快捷键说明

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