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

📄 templateact.java

📁 JEECMS是JavaEE版网站管理系统(Java Enterprise Edition Content Manage System)的简称。 基于java技术开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

	public String exportTplSubmit() {
		if (solSet == null || solSet.isEmpty()) {
			addActionError("请选择要导出的模板");
			return exportTpl();
		}
		String path = contextPvd.getAppRealPath(getWeb().getTplRoot()
				.toString());
		// 模板 系统目录集
		File[] sysDirs = new File(path).listFiles(ComUtils.DIR_FILE_FILTER);
		List<FileEntry> fileEntrys = new ArrayList<FileEntry>();
		String prefix = null;
		for (File sysDir : sysDirs) {
			for (File solDir : sysDir.listFiles(ComUtils.DIR_FILE_FILTER)) {
				if (solSet.contains(solDir.getName())) {
					prefix = sysDir.getName() + "-";
					fileEntrys.add(new FileEntry("", prefix, solDir));
				}
			}
		}
		solMap = getWeb().getSolutions();
		path = contextPvd.getAppRealPath(getWeb().getResRootBuf().toString());
		File[] solDirs = new File(path).listFiles(ComUtils.DIR_FILE_FILTER);
		for (File solDir : solDirs) {
			if (!solSet.contains(solDir.getName())) {
				continue;
			}
			for (File sysDir : solDir.listFiles()) {
				fileEntrys.add(new FileEntry(solDir.getName() + SPT + "${root}"
						+ SPT + solDir.getName(), sysDir));
			}

		}
		HttpServletResponse response = contextPvd.getResponse();
		response.setContentType("application/zip");
		response.addHeader("Content-disposition", "filename=template.zip");
		try {
			Zipper.zip(response.getOutputStream(), fileEntrys);
		} catch (IOException e) {
			log.error("导出模板失败!", e);
		}
		return null;
	}

	public String importTpl() {
		return "importTpl";
	}

	@SuppressWarnings("unchecked")
	public String importTplSubmit() {
		if (tplsFile == null) {
			addActionError("请上传模板文件!");
			return "import";
		}
		if (!tplsFileFileName.toLowerCase().endsWith(".zip")) {
			addActionError("请使用zip格式的模板压缩包!");
		}
		String tplPath = contextPvd.getAppRealPath(getWeb().getTplRoot()
				.toString());
		String resPath = contextPvd.getAppRealPath(getWeb().getResRootBuf()
				.toString());
		try {
			ZipFile zip = new ZipFile(tplsFile);
			Enumeration<ZipEntry> en = zip.getEntries();
			ZipEntry entry = null;
			String name = null;
			String fileName = null;
			File outFile = null;
			File pfile = null;
			byte[] buf = new byte[1024];
			int len = 0;
			InputStream is = null;
			OutputStream os = null;
			int index = -1;
			int findex = -1;
			int mindex = -1;
			while (en.hasMoreElements()) {
				entry = en.nextElement();
				if (!entry.isDirectory()) {
					name = entry.getName();
					log.debug("解压zip文件:{}", name);
					// 模板还是资源
					if ((index = name.indexOf("${root}")) != -1) {
						fileName = resPath + name.substring(index + 7);
					} else {
						findex = name.indexOf(SPT);
						index = name.lastIndexOf(SPT);
						mindex = name.indexOf('-', index);
						// 系统/方案/文件
						fileName = tplPath + name.substring(index, mindex)
								+ FILE_SPT + name.substring(0, findex + 1)
								+ name.substring(mindex + 1);
					}
					fileName = fileName.replace(SPT, FILE_SPT);
					log.debug("解压地址:{}", fileName);
					outFile = new File(fileName);
					pfile = outFile.getParentFile();
					if (!pfile.exists()) {
						pfile.mkdirs();
					}
					try {
						is = zip.getInputStream(entry);
						os = new FileOutputStream(outFile);
						while ((len = is.read(buf)) != -1) {
							os.write(buf, 0, len);
						}
					} finally {
						if (is != null) {
							is.close();
							is = null;
						}
						if (os != null) {
							os.close();
							os = null;
						}
					}
				}
			}
			addActionMessage("导入模板成功");
		} catch (IOException e) {
			log.error("导入模板时IO错误!", e);
			addActionError("导入模板时IO错误!");
		}
		return "import";
	}

	private void addUploadRule() {
		// 设置上传规则
		UploadRule rule = new UploadRule(getWeb().getResRoot(), "", false,
				false, false);
		uploadRuleId = rule.hashCode();
		contextPvd.setSessionAttr(UploadRule.KEY + uploadRuleId, rule);
	}

	private void removeUploadRule() {
		// 清除上传规则
		contextPvd.removeAttribute(UploadRule.KEY + uploadRuleId);
	}

	private Map<String, Object> jsonRoot = new HashMap<String, Object>();
	private FileWrap treeRoot;
	private FileWrap resRoot;
	private String relPath;
	private String parentPath;
	private String tplContent;
	private String tplName;
	private String dirName;
	private String origName;
	private List<FileWrap> subDir;

	private File[] resFile;
	private String[] resFileContentType;
	private String[] resFileFileName;

	private File tplsFile;
	private String tplsFileContentType;
	private String tplsFileFileName;

	private Map<String, String[]> dirMap;
	private Map<String, String> solMap;
	private Set<String> solSet;
	private InputStream inputStream;

	private int uploadRuleId;

	public FileWrap getTreeRoot() {
		return treeRoot;
	}

	public void setTreeRoot(FileWrap treeRoot) {
		this.treeRoot = treeRoot;
	}

	public String getTplContent() {
		return tplContent;
	}

	public void setTplContent(String tplContent) {
		this.tplContent = tplContent;
	}

	public String getTplName() {
		return tplName;
	}

	public void setTplName(String tplName) {
		this.tplName = tplName;
	}

	public String getRelPath() {
		return relPath;
	}

	public void setRelPath(String relPath) {
		this.relPath = relPath;
	}

	public Map<String, Object> getJsonRoot() {
		return jsonRoot;
	}

	public void setJsonRoot(Map<String, Object> jsonRoot) {
		this.jsonRoot = jsonRoot;
	}

	public List<FileWrap> getSubDir() {
		return subDir;
	}

	public void setSubDir(List<FileWrap> subDir) {
		this.subDir = subDir;
	}

	public String getOrigName() {
		return origName;
	}

	public void setOrigName(String origName) {
		this.origName = origName;
	}

	public String getDirName() {
		return dirName;
	}

	public void setDirName(String dirName) {
		this.dirName = dirName;
	}

	public String getParentPath() {
		return parentPath;
	}

	public void setParentPath(String parentPath) {
		this.parentPath = parentPath;
	}

	public FileWrap getResRoot() {
		return resRoot;
	}

	public void setResRoot(FileWrap resRoot) {
		this.resRoot = resRoot;
	}

	public java.io.File[] getResFile() {
		return resFile;
	}

	public void setResFile(java.io.File[] resFile) {
		this.resFile = resFile;
	}

	public String[] getResFileContentType() {
		return resFileContentType;
	}

	public void setResFileContentType(String[] resFileContentType) {
		this.resFileContentType = resFileContentType;
	}

	public String[] getResFileFileName() {
		return resFileFileName;
	}

	public void setResFileFileName(String[] resFileFileName) {
		this.resFileFileName = resFileFileName;
	}

	public Map<String, String[]> getDirMap() {
		return dirMap;
	}

	public void setDirMap(Map<String, String[]> dirMap) {
		this.dirMap = dirMap;
	}

	public Map<String, String> getSolMap() {
		return solMap;
	}

	public void setSolMap(Map<String, String> solMap) {
		this.solMap = solMap;
	}

	public Set<String> getSolSet() {
		return solSet;
	}

	public void setSolSet(Set<String> solSet) {
		this.solSet = solSet;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public File getTplsFile() {
		return tplsFile;
	}

	public void setTplsFile(File tplsFile) {
		this.tplsFile = tplsFile;
	}

	public String getTplsFileContentType() {
		return tplsFileContentType;
	}

	public void setTplsFileContentType(String tplsFileContentType) {
		this.tplsFileContentType = tplsFileContentType;
	}

	public String getTplsFileFileName() {
		return tplsFileFileName;
	}

	public void setTplsFileFileName(String tplsFileFileName) {
		this.tplsFileFileName = tplsFileFileName;
	}

	public int getUploadRuleId() {
		return uploadRuleId;
	}

	public void setUploadRuleId(int uploadRuleId) {
		this.uploadRuleId = uploadRuleId;
	}
}

⌨️ 快捷键说明

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