example1/SystemInfo.java
package example1;
import java.io.IOException;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sap.ip.me.api.logging.AbstractLogging;
import com.sap.ip.me.api.logging.AppLog;
import com.sap.ip.me.api.logging.Severities;
import com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet;
import example1.bean.TableViewBean;
import example1.dataHandler.BasicDataHandler;
// Display information about your ME client installation
public class SystemInfo extends AbstractMEHttpServlet implements Constants {
private TableViewBean dataBean;
private String headLine;
/**
* Must be overwritten - return the name of the application
*/
public String getApplicationName() {
return MI_APPLICATION_NAME;
}
/**
* doIntialize - called when the servlet is activated the first time
*/
public void doInitialize() throws ServletException {
// Prepare a log output - Level DEBUG - Information about classloader
ClassLoader cl = getClass().getClassLoader();
AbstractLogging aLogger = AppLog.getInstance(MI_APPLICATION_NAME);
aLogger.log(Severities.DEBUG, "MIClientInfo: Create MIClientInfoServlet.doInitialize with Classloader {0}", (cl == null ? "(null)" : cl.toString())); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* doHandleEvent - called any subsequent time when an event on the web client occurs.
*/
public String doHandleEvent(String eventName, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Set the name of the JSP that has to be called when this method is finished.
// INITIAL_JSP ist defined in the interface Constants.java
String nextJSP = INITIAL_JSP;
// Set default text for headline
headLine = WELCOME_MESSAGE;
// Get bean, if there is one, in the session context, otherwise create a new instance.
getBeansFromContext(request);
// Load bean with values.
loadBean(request);
// Put bean in the session context.
putBeansIntoContext(request);
// Exit with name of JSP.
return nextJSP;
}
private void getBeansFromContext(HttpServletRequest request) {
// Get bean from session context. There is a bean, when this servlet has already been called once.
dataBean = (TableViewBean) request.getSession().getAttribute(CONTEXT_BEAN);
// No bean in session context - create a new instance.
if (dataBean == null)
dataBean = new TableViewBean();
}
public void loadBean(HttpServletRequest request) {
dataBean.setString(headLine);
BasicDataHandler bdh = BasicDataHandler.instance();
bdh.setMiHomeFolder(getMIHome());
Vector data = bdh.getDataArray();
dataBean.setTableContent(data);
dataBean.setTableRows(bdh.getDataCount());
dataBean.setTableColumns(bdh.getColumns());
}
private void putBeansIntoContext(HttpServletRequest request) {
// Put bean in session context
if (dataBean == null) {
request.getSession().removeAttribute(CONTEXT_BEAN);
} else {
request.getSession().setAttribute(CONTEXT_BEAN, dataBean);
}
}
}