jqueryFileTree.jsp
3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page
import="java.math.BigDecimal,java.util.Date,java.io.File,java.io.FilenameFilter,java.util.Arrays,weaver.general.Util,weaver.general.TimeUtil"%>
<%
/**
* jQuery File Tree JSP Connector
* Version 1.0
* Copyright 2008 Joshua Gould
* 21 April 2008
*/
String dir = request.getParameter("dir");
//System.out.println("dir==="+dir);
String dir_copy = dir;
if(dir!=null){
dir_copy = java.net.URLDecoder.decode(dir_copy);
}
if (dir_copy == null||!dir_copy.startsWith("/page/resource/userfile") || dir_copy.indexOf("..")!=-1) {
return;
}
if (dir.charAt(dir.length()-1) == '\\') {
dir = dir.substring(0, dir.length()-1) + "/";
} else if (dir.charAt(dir.length()-1) != '/') {
dir += "/";
}
String dirAbs="";
dirAbs =application.getRealPath("/")+dir;
dirAbs = Util.StringReplace(dirAbs,"\\","/");
String fileInfo ="[";
if (new File(dirAbs).exists()) {
String[] files = new File(dirAbs).list(new FilenameFilter() {
public boolean accept(File dirAbs, String name) {
return name.charAt(0) != '.';
}
});
Arrays.sort(files, String.CASE_INSENSITIVE_ORDER);
if(files.length>0){
out.print("<ul class=\"jqueryFileTree\" style=\"display: none;\">");
// All dirs
for (int i=0; i<files.length;i++) {
String file = files[i];
File _file = new File(dirAbs, file);
if (_file.isDirectory()) {
out.print("<li class=\"directory collapsed\" onmouseover=\"operateShow('oprate_div_"+file+"');\" onmouseout=\"operateHide('oprate_div_"+file+"');\">"+
"<a href=\"#\" rel=\"" + dir + file + "/\">"
+ file + "</a><div id='oprate_div_"+file+"' style='margin-left:86px;display:none;' class='hoverDiv'> "+
"<a onclick=\"addDir('"+dir + file+"','"+file+"');\" title='新建目录'><span class='operHoverSpan operHover_hand operHoverSpan_hover'> 新建 </span></a>"+
"<a onclick=\"editDir('"+dir + file+"','"+file+"');\" title='重命名目录'><span class='operHoverSpan operHover_hand operHoverSpan_hover'> 重命名 </span></a>"+
"<a onclick=\"delDir('"+dir + file+"','"+file+"');\" title='删除目录'><span class='operHoverSpan operHover_hand operHoverSpan_hover'> 删除 </span></a></div></li>");
}else{
fileInfo+="['"+file+"','"+new BigDecimal((_file.length()/1000)).setScale(0, BigDecimal.ROUND_HALF_UP)+"K','"+TimeUtil.getDateString(new Date(_file.lastModified()))+"'],";
}
}
// All files
/*for (int i=0; i<files.length;i++) {
String file = files[i];
File _file = new File(dirAbs, file);
if (!_file.isDirectory()) {
int dotIndex = file.lastIndexOf('.');
String ext = dotIndex > 0 ? file.substring(dotIndex + 1) : "";
out.print("<li class=\"file ext_" + ext + "\"><a href=\"#\" rel=\"" + dir + file + "\">"
+ file + "</a></li>");
}
}*/
out.print("</ul>");
}
if(!fileInfo.equals("[")){
fileInfo = fileInfo.substring(0,fileInfo.length()-1);
}
fileInfo +="]";
out.println("$%^&"+fileInfo);
}
%>