?? templateact.java
字號:
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 "importTpl";
}
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 "importTpl";
}
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 + -