70 constructor = ElephantContext.getConstructor(request, response);
71 if(!request.getParameter(
"down_path").matches(
"\\@\\-?[0-9\\-]+") &&
76 response.setHeader(
"pragma",
"no-cache");
77 response.setHeader(
"Cache-control",
"no-cache, no-store, must-revalidate");
78 response.setHeader(
"Expires",
"01 Apr 1995 01:10:10 GMT");
82 path = request.getParameter(
"down_path");
83 if(file ==
null) file = (String) constructor.
findAttribute(
"xp_down_file");
84 if(path !=
null && path.startsWith(
"@")) {
89 String root = (String) constructor.
findAttribute(
"xp_down_path");
90 path = (root ==
null ?
"" : root) + (path ==
null ?
"" : path);
94 int p = path.lastIndexOf(
'/');
96 file = path.substring(p + 1);
97 path = path.substring(0, p);
111 path = path.replaceAll(
"\\@root", ElephantContext.getRealPath(
"/"));
112 if(constructor.
getUser() !=
null) {
113 path = path.replaceAll(
"\\@user", constructor.
getUser().
getId());
118 if(file.startsWith(
"/") || file.startsWith(
"\\")) {
119 file = file.substring(1);
123 new File(ElephantContext.getRealPath(
"/WEB-INF/logs")).mkdirs();
124 File record =
new File(ElephantContext.getRealPath(
"/WEB-INF/logs/downloads.txt"));
125 BufferedWriter bw =
new BufferedWriter(
new FileWriter(record, record.exists()));
128 ObjectString.formatNativeObject(
new java.util.Date(),
true) +
129 " - " + path +
"/" + file +
133 response.setContentType(
new MimetypesFileTypeMap().getContentType(path +
"/" + file));
134 response.setContentLength((
int)
new File(path +
"/" + file).length());
135 String onlyFile = file;
136 int p = file.lastIndexOf(
"/");
138 onlyFile = onlyFile.substring(p + 1);
140 response.setHeader(
"Content-Disposition",
"attachment;filename=\"" + onlyFile.replaceAll(
",",
"_") +
"\"");
141 OutputStream out = response.getOutputStream();
142 FileInputStream fis =
new FileInputStream(path +
"/" + file);
144 byte buffer[] =
new byte[10240];
146 while((count = fis.read(buffer)) > -1) {
147 out.write(buffer, 0, count);
152 bw =
new BufferedWriter(
new FileWriter(record, record.exists()));
153 bw.write(
" >>>>>>>>>>>>>> Complete\n");
Object findAttribute(String key)
String getParameter(String param)
boolean isInRole(String role)