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

📄 expaction.java

📁 OBPM是一个开源
💻 JAVA
字号:
package cn.myapps.core.expimp.exp.action;

import java.io.File;

import cn.myapps.base.action.BaseAction;
import cn.myapps.base.dao.PersistenceUtils;
import cn.myapps.core.deploy.module.ejb.ModuleProcess;
import cn.myapps.core.deploy.module.ejb.ModuleVO;
import cn.myapps.core.expimp.exp.ejb.ExpObject;
import cn.myapps.core.expimp.exp.util.ExpOperator;
import cn.myapps.util.DateUtil;
import cn.myapps.util.ProcessFactory;
import cn.myapps.util.ZipUtil;
import cn.myapps.util.property.DefaultProperty;

public class ExpAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6603303079282994162L;

	private ExpObject _expobj = null; // 导出的对象

	private String filePath; // 下载文件路径

	public ExpAction() throws ClassNotFoundException {
		super(ProcessFactory.createProcess(ModuleProcess.class), new ModuleVO());
		_expobj = new ExpObject();
	}

	public String doStart() throws Exception {
		return SUCCESS;

	}

	public String doNext() throws Exception {
		return SUCCESS;
	}

	public String doExp() throws Exception {
		try {
			String fileName = DateUtil.getCurDateStr("yyyyMMddhhmmss");
			String dataPath = getDataPath(fileName);

			ExpOperator eo = new ExpOperator(PersistenceUtils.getDataSource());
			eo.setDataPath(dataPath);
			eo.writeDataToXML(_expobj.getAllSQLs(application));

			// 所有图片路径
			String[] imagePaths = _expobj.getAllExpImagePaths(getEnvironment());

			// 所有要压缩文件的路径
			String[] compressFilePaths = new String[imagePaths.length + 1];

			// 图片文件路径 + 数据文件路径
			System.arraycopy(imagePaths, 0, compressFilePaths, 0,
					imagePaths.length);
			compressFilePaths[imagePaths.length] = dataPath;

			// 压缩
			ZipUtil.compressFiles(fileName, compressFilePaths, getExportDir());

			// 压缩文件web路径
			String path = DefaultProperty.getProperty("EXPORT_PATH");
			String zipFilePath = path + "/" + fileName + ".zip";
			setFilePath(zipFilePath);

			// 删除xml data file
			File xmlFile = new File(dataPath);
			if (xmlFile.isFile()) {
				xmlFile.delete();
			}
		} catch (Exception e) {
			System.out.println("Export error:" + e.getMessage());
			addFieldError("", "Export fail!");
			return INPUT;
		}

		return SUCCESS;
	}

	/**
	 * 
	 * @param fileName
	 *            the data xml name
	 * @return file web path
	 * @throws Exception
	 */
	private String getDataPath(String fileName) throws Exception {
		File dir = new File(getExportDir());
		if (!dir.exists()) {
			dir.mkdirs();
		}

		String filepath = getExportDir() + "/" + fileName + ".xml";

		return filepath;
	}

	/**
	 * 文件导出的目录(RealPath)
	 * 
	 * @return directory
	 * @throws Exception
	 */
	private String getExportDir() throws Exception {
		String path = DefaultProperty.getProperty("EXPORT_PATH");
		String dirPath = getEnvironment().getWebcontextRealPath(path);

		return dirPath;
	}

	public ExpObject get_expobj() {
		return _expobj;
	}

	public void set_expobj(ExpObject _expobj) {
		this._expobj = _expobj;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
}

⌨️ 快捷键说明

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