Java tutorial
package com.zving.platform; import com.zving.framework.Config; import com.zving.framework.Constant; import com.zving.framework.Page; import com.zving.framework.ResponseImpl; import com.zving.framework.SessionListener; import com.zving.framework.User; import com.zving.framework.controls.DataListAction; import com.zving.framework.data.DBConnConfig; import com.zving.framework.data.DBConnPool; import com.zving.framework.data.DataTable; import com.zving.framework.license.LicenseInfo; import com.zving.framework.messages.LongTimeTask; import com.zving.framework.orm.DBExport; import com.zving.framework.orm.DBImport; import com.zving.framework.schedule.CronManager; import com.zving.framework.utility.DateUtil; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.Date; import java.util.Iterator; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; public class SysInfo extends Page { public static String getLoginStatus() { if (!(Config.isAllowLogin)) { return "???"; } return "?"; } public void changeLoginStatus() { Config.isAllowLogin = !(Config.isAllowLogin); if (!(Config.isAllowLogin)) $S("LoginStatus", "???"); else $S("LoginStatus", "?"); } public void forceExit() { SessionListener.forceExit(); this.Response.setStatus(1); } public static void list1DataBind(DataListAction dla) { DataTable dt = new DataTable(); dt.insertColumn("Name"); dt.insertColumn("Value"); dt.insertRow(new Object[] { "???", Config.getAppCode() + "(" + Config.getAppName() + ")" }); dt.insertRow( new Object[] { "?", Config.getMainVersion() + "." + Config.getMinorVersion() }); dt.insertRow(new Object[] { "?", DateUtil .toString(new Date(Long.parseLong(Config.getValue("App.Uptime"))), "yyyy-MM-dd HH:mm:ss") }); dt.insertRow(new Object[] { "?", new Long(Config.getLoginUserCount()) }); dt.insertRow(new Object[] { "??", Config.getValue("App.DebugMode") }); dt.insertRow(new Object[] { "???", Config.getValue("System.OSName") }); dt.insertRow(new Object[] { "?", Config.getValue("System.OSVersion") }); dt.insertRow(new Object[] { "??", Config.getValue("System.OSPatchLevel") }); dt.insertRow(new Object[] { "JDK", Config.getValue("System.JavaVendor") }); dt.insertRow(new Object[] { "JDK", Config.getValue("System.JavaVersion") }); dt.insertRow(new Object[] { "JDK", Config.getValue("System.JavaHome") }); dt.insertRow(new Object[] { "Servlet??", Config.getValue("System.ContainerInfo") }); dt.insertRow(new Object[] { "?Servlet??", Config.getValue("System.OSUserName") }); dt.insertRow(new Object[] { "JDK/?", (Runtime.getRuntime().totalMemory() / 1024L / 1024L) + "M/" + (Runtime.getRuntime().maxMemory() / 1024L / 1024L) + "M" }); dt.insertRow(new Object[] { "?", Config.getFileEncode() }); dla.bindData(dt); } public static void list2DataBind(DataListAction dla) { DataTable dt = new DataTable(); dt.insertColumn("Name"); dt.insertColumn("Value"); DBConnConfig dcc = DBConnPool.getDBConnConfig(); dt.insertRow(new Object[] { "?", dcc.DBType }); if (dcc.isJNDIPool) { dt.insertRow(new Object[] { "JNDI??", dcc.JNDIName }); } else { dt.insertRow(new Object[] { "???", dcc.DBServerAddress }); dt.insertRow(new Object[] { "???", dcc.DBPort }); dt.insertRow(new Object[] { "???", dcc.DBName }); dt.insertRow(new Object[] { "??", dcc.DBUserName }); } dla.bindData(dt); } public static void list3DataBind(DataListAction dla) { DataTable dt = new DataTable(); dt.insertColumn("Name"); dt.insertColumn("Value"); dt.insertRow(new Object[] { "?", LicenseInfo.getName() }); dt.insertRow(new Object[] { "", DateUtil.toString(LicenseInfo.getEndDate(), "yyyy-MM-dd HH:mm:ss") }); dt.insertRow(new Object[] { "?", new Long(LicenseInfo.getUserLimit()) }); dt.insertRow(new Object[] { "???", LicenseInfo.getProduct() }); dt.insertRow(new Object[] { "?MAC?", LicenseInfo.getMacAddress() }); dla.bindData(dt); } public static void downloadDB(HttpServletRequest request, HttpServletResponse response) { try { request.setCharacterEncoding(Constant.GlobalCharset); response.reset(); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=DB_" + DateUtil.getCurrentDate("yyyyMMddHHmmss") + ".dat"); OutputStream os = response.getOutputStream(); String path = Config.getContextRealPath() + "WEB-INF/data/backup/DB_" + DateUtil.getCurrentDate("yyyyMMddHHmmss") + ".dat"; new DBExport().exportDB(path); byte[] buffer = new byte[1024]; int read = -1; FileInputStream fis = null; try { fis = new FileInputStream(path); while ((read = fis.read(buffer)) != -1) if (read > 0) { byte[] chunk = (byte[]) null; if (read == 1024) { chunk = buffer; } else { chunk = new byte[read]; System.arraycopy(buffer, 0, chunk, 0, read); } os.write(chunk); os.flush(); } } finally { if (fis != null) { fis.close(); } } os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } public static void uploadDB(HttpServletRequest request, HttpServletResponse response) { try { DiskFileItemFactory fileFactory = new DiskFileItemFactory(); ServletFileUpload fu = new ServletFileUpload(fileFactory); List fileItems = fu.parseRequest(request); fu.setHeaderEncoding("UTF-8"); Iterator iter = fileItems.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!(item.isFormField())) { String OldFileName = item.getName(); System.out.println("Upload DB FileName:" + OldFileName); long size = item.getSize(); if ((((OldFileName == null) || (OldFileName.equals("")))) && (size == 0L)) { continue; } OldFileName = OldFileName.substring(OldFileName.lastIndexOf("\\") + 1); String ext = OldFileName.substring(OldFileName.lastIndexOf(".")); if (!(ext.toLowerCase().equals(".dat"))) { response.sendRedirect("DBUpload.jsp?Error=?dat?"); return; } final String FileName = Config.getContextRealPath() + "WEB-INF/data/backup/DBUpload_" + DateUtil.getCurrentDate("yyyyMMddHHmmss") + ".dat"; item.write(new File(FileName)); LongTimeTask ltt = LongTimeTask.getInstanceByType("Install"); if (ltt != null) { response.sendRedirect("DBUpload.jsp?Error=??"); return; } SessionListener.forceExit(); Config.isAllowLogin = false; ltt = new LongTimeTask() { public void execute() { DBImport di = new DBImport(); di.setTask(this); di.importDB(FileName, "Default"); setPercent(100); Config.loadConfig(); CronManager.getInstance().init(); } }; ltt.setType("Install"); ltt.setUser(User.getCurrent()); ltt.start(); response.sendRedirect("DBUpload.jsp?TaskID=" + ltt.getTaskID()); } } } catch (Exception e) { e.printStackTrace(); } finally { Config.isAllowLogin = true; } } } /* * Location: F:\JAVA\Tomcat5.5\webapps\zcms\WEB-INF\classes\ Qualified Name: * com.zving.platform.SysInfo JD-Core Version: 0.5.3 */