Rev 1814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1814 | jmachado | 1 | <%@ page import="jomm.dao.impl.AbstractDao"%><%@ page import="org.apache.commons.net.ftp.FTPClient"%><%@ page import="org.apache.commons.net.ftp.FTPFile"%><%@ page import="org.json.JSONArray"%><%@ page import="org.json.JSONObject"%><%@ page import="pt.estgp.estgweb.utils.Globals"%><%@ page import="pt.estgp.estgweb.domain.CourseUnitImpl"%><%@ page import="pt.estgp.estgweb.domain.dao.DaoFactory"%><%@ page import="pt.estgp.estgweb.web.FtpServer"%><%@ page import="java.io.PrintWriter"%><%@ page contentType="application/json;charset=UTF-8" language="java" %> |
1148 | jmachado | 2 | <% |
3 | String courseUnitId = request.getParameter("courseUnitId"); |
||
4 | AbstractDao.getCurrentSession().beginTransaction(); |
||
5 | CourseUnitImpl cu = (CourseUnitImpl) DaoFactory.getCourseUnitDaoImpl().load(new Long(courseUnitId)); |
||
6 | |||
7 | FtpServer ftpServer = FtpServer.getFtpServerForCurrentUser(Globals.FTP_IONLINE_URL,request); |
||
8 | FTPClient ftpClient = ftpServer.getClient(); |
||
9 | JSONObject json = new JSONObject(); |
||
10 | JSONArray filesJson = new JSONArray(); |
||
11 | |||
1153 | jmachado | 12 | if(ftpClient == null) |
1148 | jmachado | 13 | { |
1153 | jmachado | 14 | AbstractDao.getCurrentSession().getTransaction().commit(); |
15 | out.print(json.toString()); |
||
1148 | jmachado | 16 | |
17 | } |
||
1153 | jmachado | 18 | else |
19 | { |
||
20 | ftpClient.changeWorkingDirectory("/"); |
||
21 | boolean existDirectory = ftpClient.changeWorkingDirectory(cu.getInqueritosPedagogicosPathIntranet()); |
||
22 | |||
23 | if(existDirectory) |
||
24 | { |
||
25 | FTPFile[] files = existDirectory? ftpClient.listFiles(): null; |
||
26 | if(files != null) |
||
27 | for(FTPFile f : files) |
||
28 | { |
||
29 | JSONObject fileJson = new JSONObject(); |
||
30 | fileJson.put("name",f.getName()); |
||
31 | fileJson.put("completePath",cu.getInqueritosPedagogicosPathIntranet() + "/" + f.getName()); |
||
32 | |||
33 | filesJson.put(fileJson); |
||
34 | } |
||
35 | } |
||
36 | json.put("files",filesJson); |
||
37 | ftpClient.logout(); |
||
38 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
39 | out.print(json.toString()); |
||
40 | } |
||
1148 | jmachado | 41 | %> |