Skip to content

Commit

Permalink
解压缩 到指定目录 over
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangkaitao committed Jun 15, 2013
1 parent 2a92405 commit 313e46a
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 24 deletions.
12 changes: 12 additions & 0 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,17 @@
<artifactId>commons-compress</artifactId>
<version>${common.compress.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>${ant.version}</version>
<exclusions>
<exclusion>
<artifactId>ant-launcher</artifactId>
<groupId>org.apache.ant</groupId>
</exclusion>
</exclusions>
</dependency>

<!-- data source 相关jar包-->
<dependency>
Expand Down Expand Up @@ -684,6 +695,7 @@
<guava.version>13.0.1</guava.version>
<common.fileupload.version>1.2.2</common.fileupload.version>
<common.compress.version>1.5</common.compress.version>
<ant.version>1.9.1</ant.version>

<junit.version>4.11</junit.version>
<mockito.version>1.9.5</mockito.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public String tree(Model model) throws UnsupportedEncodingException {
@ResponseBody
public Object ajaxLoad(
@RequestParam("id") long parentId,
@RequestParam(value = "paths", required = false) String[] excludePaths,
@RequestParam("path") String parentPath) throws UnsupportedEncodingException {

parentPath = URLDecoder.decode(parentPath, Constants.ENCODING);
Expand All @@ -127,6 +128,10 @@ public Object ajaxLoad(
if(!subFile.isDirectory()) {
continue;
}
String path = URLEncoder.encode(subFile.getAbsolutePath().replace(rootPath, ""), Constants.ENCODING);
if(isExclude(excludePaths, path)) {
continue;
}
id++;
trees.add(extractFileInfoMap(subFile, rootPath, id, parentId));
}
Expand Down Expand Up @@ -173,6 +178,53 @@ public String listFile(
return viewName("list");
}

@RequestMapping("select")
public String showSelectForm(
@RequestParam("paths") String[] excludePaths,
Model model) throws UnsupportedEncodingException {

String rootPath = sc.getRealPath(ROOT_DIR);

List<Map> trees = Lists.newArrayList();

long id = 0L;
File rootDirectory = new File(rootPath);

Map<Object, Object> root= extractFileInfoMap(rootDirectory, rootPath, id, -1);

trees.add(root);

for(File subFile : rootDirectory.listFiles()) {
if(!subFile.isDirectory()) {
continue;
}
String path = URLEncoder.encode(subFile.getAbsolutePath().replace(rootPath, ""), Constants.ENCODING);
if(isExclude(excludePaths, path)) {
continue;
}
id++;
trees.add(extractFileInfoMap(subFile, rootPath, id, (Long)root.get("id")));
}

model.addAttribute("trees", trees);
model.addAttribute("excludePaths", excludePaths);

return viewName("selectForm");
}

private boolean isExclude(String[] excludePaths, String path) {
if (excludePaths == null) {
return false;
}
for (int i = 0; i < excludePaths.length; i++) {
String excludePath = excludePaths[i];
if(path.equals(excludePath)) {
return true;
}
}
return false;
}

@RequestMapping(value = "edit", method = RequestMethod.GET)
public String showEditForm(
@RequestParam(value = "path", required = false, defaultValue = "") String path,
Expand Down Expand Up @@ -472,13 +524,15 @@ public String compress(
@RequestMapping("uncompress")
public String uncompress(
@RequestParam(value = "parentPath") String parentPath,
@RequestParam(value = "descPath") String descPath,
@RequestParam(value = "paths") String[] paths,
@RequestParam(value = "conflict") String conflict,
RedirectAttributes redirectAttributes) throws IOException {


String rootPath = sc.getRealPath(ROOT_DIR);
parentPath = URLDecoder.decode(parentPath, Constants.ENCODING);
descPath = URLDecoder.decode(descPath, Constants.ENCODING);

for(int i = 0, l = paths.length; i < l; i++) {
String path = paths[i];
Expand All @@ -491,16 +545,17 @@ public String uncompress(
}

try {
String descPath = rootPath + File.separator + parentPath;

String descAbsolutePath = rootPath + File.separator + descPath;
for(String path : paths) {
CompressUtils.unzip(path, descPath, "override".equals(conflict));
CompressUtils.unzip(path, descAbsolutePath, "override".equals(conflict));
}
redirectAttributes.addFlashAttribute(Constants.MESSAGE, "解压成功!");
} catch (Exception e) {
redirectAttributes.addFlashAttribute(Constants.ERROR, e.getMessage());
}

redirectAttributes.addAttribute("path", URLEncoder.encode(parentPath, Constants.ENCODING));
redirectAttributes.addAttribute("path", URLEncoder.encode(descPath, Constants.ENCODING));
return redirectToUrl(viewName("list"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static final void zip(String compressPath, String[] needCompressPaths) {
try {
zaos = new ZipArchiveOutputStream(compressFile);
zaos.setUseZip64(Zip64Mode.AsNeeded);
zaos.setEncoding("GBK");

for (File file : files) {
addFilesToCompression(zaos, file, "");
Expand Down Expand Up @@ -98,7 +99,7 @@ private static void unzipFolder(File uncompressFile, File descPathFile, boolean

ZipFile zipFile = null;
try {
zipFile = new ZipFile(uncompressFile);
zipFile = new ZipFile(uncompressFile, "GBK");

Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
while (entries.hasMoreElements()) {
Expand Down
24 changes: 18 additions & 6 deletions web/src/main/webapp/WEB-INF/jsp/admin/maintain/editor/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@
return;
}
var canUncompress = true;
$(checkbox).each(function() {
if(decodeURIComponent($(this).val()).toLowerCase().indexOf(".zip") == -1) {
canUncompress = false;
}
});
// $(checkbox).each(function() {
// if(decodeURIComponent($(this).val()).toLowerCase().indexOf(".zip") == -1) {
// canUncompress = false;
// }
// });
if(!canUncompress) {
$.app.alert({
message : "目前只支持zip文件的解压缩,请只选择zip文件"
Expand All @@ -223,7 +223,19 @@
$.app.alert({message: "请输入<strong>ok</strong>确认执行操作!"});
return;
}
window.location.href = ctx + "/admin/maintain/editor/uncompress?parentPath=${current.path}&conflict=" + conflict + "&" + checkbox.serialize();
$.app.modalDialog(
"选择移动到的目录",
"${ctx}/admin/maintain/editor/select?" + checkbox.serialize(),
{
height:300,
width:300,
ok : function(modal) {
var ztree = $.fn.zTree.getZTreeObj(modal.find("#selectTree .ztree").attr("id"));
var selectedNode = ztree.getSelectedNodes()[0];
var descPath = selectedNode.path;
window.location.href = ctx + "/admin/maintain/editor/uncompress?parentPath=${current.path}&descPath=" + descPath + "&conflict=" + conflict + "&" + checkbox.serialize();
}
});
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jspf"%>
<%@include file="/WEB-INF/jsp/common/import-zTree-css.jspf"%>

<div id="selectTree"></div>

<%@include file="/WEB-INF/jsp/common/import-zTree-js.jspf"%>
<script type="text/javascript">
$(function() {
var zNodes =[
<c:forEach items="${trees}" var="m">
{ id:${m.id}, pId:${m.pId}, name:"${m.name}", path : "${m.path}", iconSkin:"${m.iconSkin}", open: ${m.open}, root : ${m.root},isParent:${m.isParent}},
</c:forEach>
];
var excludePaths = [];
<c:forEach items="${excludePaths}" var="path">
excludePaths.push('${path}');
</c:forEach>
$.zTree.initMovableTree({
containerId : "selectTree",
zNodes : zNodes,
urlPrefix : "${ctx}/admin/maintain/editor",
async : true,
setting : {
async : {
type: "get",
autoParam : ["id", "path"],
otherParam : ["paths", excludePaths.join(",")]
}
}
});
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
<i class="icon-refresh" title="点击刷新"></i>
</a>
</li>

</ul>

<es:contentFooter/>
<%@include file="/WEB-INF/jsp/common/import-zTree-js.jspf"%>
<script type="text/javascript">
var async = ${not empty param.async and param.async eq true};
$(function() {
var zNodes =[
<c:forEach items="${trees}" var="m">
Expand All @@ -29,7 +27,7 @@
$.zTree.initMovableTree({
zNodes : zNodes,
urlPrefix : "${ctx}/admin/maintain/editor",
async : async,
async : true,
setting : {
async : {
type: "get",
Expand Down
2 changes: 1 addition & 1 deletion web/src/main/webapp/WEB-INF/jsp/common/import-js.jspf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
<script src="${ctx}/static/comp/nicescroll/jquery.nicescroll.min.js?3"></script>
<script src="${ctx}/static/comp/nicescroll/jquery.nicescroll.plus.js?3"></script>

<script src="${ctx}/static/js/application.js?10" type="text/javascript"></script>
<script src="${ctx}/static/js/application.js?11" type="text/javascript"></script>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script src="${ctx}/static/comp/zTree/js/jquery.ztree.all-3.5.js?3"></script>
<script src="${ctx}/static/comp/zTree/js/tree.common.js?4"></script>
<script src="${ctx}/static/comp/zTree/js/tree.common.js?5"></script>


Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
{
width:600,
height:450,
okBtn:false,
callback : function() {
$("[name='category.name']").validationEngine('validate');
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
"参照",
"${ctx}/showcase/product/category/select/multiple;domId=searchCategoryId",
{
height : 400,
okBtn : false
height : 400
}
);
});
Expand Down
11 changes: 9 additions & 2 deletions web/src/main/webapp/WEB-INF/static/css/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ iframe[tabs="true"] {

#menu li a {
color: #0088cc;
font-weight: bold;
text-decoration: none;
}

Expand Down Expand Up @@ -593,9 +594,15 @@ iframe[tabs="true"] {
text-align: center;
}

.table > tbody > tr.active {
color: #bd362f;
.table > tbody > tr.active, .table > tbody > tr.active > td{
background: #0088cc;

}
.table > tbody > tr.active * {
color: #fff!important;
font-weight: bold;
}


.popover {
color: #333;
Expand Down
4 changes: 1 addition & 3 deletions web/src/main/webapp/WEB-INF/static/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ $.app = {
modalDialog : function(title, url, settings) {

$.app.waiting();
console.info(settings.ok);
var defaultSettings = {
title : title,
closeText : "关闭",
Expand All @@ -161,7 +160,6 @@ $.app = {
width:600,
modal:true,
noTitle : false,
okBtn : true,
close: function() {
$(this).closest(".ui-dialog").remove();
},
Expand Down Expand Up @@ -197,7 +195,7 @@ $.app = {
}
settings = $.extend(true, {}, defaultSettings, settings);

if(!settings.okBtn) {
if(!settings.ok) {
delete settings.buttons['确定'];
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/main/webapp/WEB-INF/tags/maintain/showFileInfo.tag
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<input type="hidden" name="names" value="${fileInfo.name}">
</c:if>
</td>
<td>
<td style="word-break: break-all;">
<c:choose>
<c:when test="${fileInfo.isDirectory}">
<a href="${ctx}/admin/maintain/editor/list?path=${fileInfo.path}">
Expand Down
Binary file not shown.

0 comments on commit 313e46a

Please sign in to comment.