ListManager.java
2.7 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
76
77
78
79
80
81
82
83
84
package it.softecspa.fileproxy.proxyservices.manager;
import it.softecspa.fileproxy.proxyservices.request.ListRequestType;
import it.softecspa.fileproxy.proxyservices.response.ListResponseType;
import it.softecspa.fileproxy.proxyservices.xml.output.list.FileElement;
import it.softecspa.fileproxy.proxyservices.xml.output.list.ResponseROOT;
import it.softecspa.fileproxy.services.common.CheckerException;
import it.softecspa.fileproxy.services.common.ManagerException;
import it.softecspa.fileproxy.services.common.ResponseOutcome;
import it.softecspa.fileproxy.services.common.core.response.body.BodyXML;
import it.softecspa.kahuna.io.File;
import it.softecspa.kahuna.util.calendar.EnterpriseCalendar;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class ListManager extends AbstractHttpFileProxyManager<ListRequestType, ListResponseType> {
private String path;
@Override
protected void validateRequest() throws CheckerException, ManagerException {
checkRequestIfNullSetDefault("onlyFile", Boolean.FALSE);
checkRequestIfNullSetDefault("showHidden", Boolean.FALSE);
path = normalizePath(request.getPath());
}
@Override
protected void doService(ListRequestType request, ListResponseType response) throws ManagerException {
log.info("Request LIST of folder '"+path+"' (onlyFile="+request.getOnlyFile().booleanValue()+")");
List<File> files = File.dir(path, request.getOnlyFile().booleanValue());
if (files==null) {
throw new ManagerException(new CheckerException(ResponseOutcome.PATH_NOT_VALID));
}
ResponseROOT xml_response = new ResponseROOT();
// PATH
xml_response.setPath(request.getPath());
// FILES
for (File file : files) {
if (file.isHidden()) {
if (!request.getShowHidden().booleanValue()) continue;
}
FileElement fe = new FileElement();
if (file.isDirectory()) fe.setDirectory(true);
if (file.isFile()) fe.setFile(true);
if (file.isHidden()) fe.setHidden(true);
fe.setSize(file.length());
//
EnterpriseCalendar modify = EnterpriseCalendar.newInstance(file.lastModified());
if (modify!=null) fe.setModify(modify.formatISO8601zulu());
//
fe.setEntityValue(file.getName());
xml_response.addFile(fe);
}
// NUMBER
xml_response.setNumber(xml_response.getFiles().size());
xml_response.applyCData();
// Converto XmlElement in un byte[]
byte[] xml;
try {
xml = xml_response.generateXML("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new ManagerException(e);
}
response.addBody(new BodyXML(xml));
// Risposta POSITIVA
new ResponseBuilder(response).setReturn(ResponseOutcome.OK);
}
}