📄 netstorebaseaction.java
字号:
package netstore.framework;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Iterator;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import netstore.framework.util.IConstants;
import netstore.framework.exceptions.*;
import netstore.service.INetstoreService;
import netstore.service.INetstoreServiceFactory;
/**
* An abstract Action class that all Netstore action classes should
* extend.
*/
abstract public class NetstoreBaseAction extends Action {
Log log = LogFactory.getLog( this.getClass() );
protected INetstoreService getNetstoreService(){
INetstoreServiceFactory factory = (INetstoreServiceFactory)getApplicationObject( IConstants.SERVICE_FACTORY_KEY );
INetstoreService service = null;
try{
service = factory.createService();
}catch( Exception ex ){
log.error( "Problem creating the Netstore Service", ex );
}
return service;
}
/**
* Retrieve a session object based on the request and the attribute name.
*/
protected Object getSessionObject(HttpServletRequest req,
String attrName) {
Object sessionObj = null;
HttpSession session = req.getSession(false);
if ( session != null ){
sessionObj = session.getAttribute(attrName);
}
return sessionObj;
}
/**
* Return the instance of the ApplicationContainer object.
*/
protected ApplicationContainer getApplicationContainer() {
return (ApplicationContainer)getApplicationObject(IConstants.APPLICATION_CONTAINER_KEY);
}
/**
* Retrieve the SessionContainer for the user tier to the request.
*/
protected SessionContainer getSessionContainer(HttpServletRequest request) {
SessionContainer sessionContainer = (SessionContainer)getSessionObject(request, IConstants.SESSION_CONTAINER_KEY);
// Create a SessionContainer for the user if it doesn't exist already
if(sessionContainer == null) {
sessionContainer = new SessionContainer();
sessionContainer.setLocale(request.getLocale());
HttpSession session = request.getSession(true);
session.setAttribute(IConstants.SESSION_CONTAINER_KEY, sessionContainer);
}
return sessionContainer;
}
/**
* Retrieve an object from the application scope by its name. This is
* a convience method.
*/
protected Object getApplicationObject(String attrName) {
return servlet.getServletContext().getAttribute(attrName);
}
public boolean isLoggedIn( HttpServletRequest request ){
SessionContainer container = getSessionContainer(request);
if ( container.getUserView() != null ){
return true;
}else{
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -