source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/com/gs3/testGXT/server/ListDirectoryServiceImpl.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 1.4 KB
Line 
1package com.gs3.testGXT.server;
2
3import java.io.File;
4import java.util.LinkedList;
5
6import com.google.gwt.user.server.rpc.RemoteServiceServlet;
7import com.gs3.testGXT.client.services.ListDirectoryService;
8
9@SuppressWarnings("serial")
10public class ListDirectoryServiceImpl extends RemoteServiceServlet implements ListDirectoryService {
11
12 @Override
13 public LinkedList<String[]> getDirectoryContents(String path) {
14 LinkedList<String[]> ret = new LinkedList<String[]>();
15 try {
16 //only try first symbol
17 File folder = new File(path);
18 File[] listOfFiles = folder.listFiles();
19
20 if(listOfFiles == null) { //there are no files because this is not a directory!
21 return ret; // if we return an empty list, the client will understand - we could potentially return null too
22 }
23
24 //I know this isn't proper JSON: I can fix this a little bit later
25 for (int i = 0; i < listOfFiles.length; i++) {
26 String LA = "INVALID";
27 String LB;
28 String LC;
29
30 LB = listOfFiles[i].getName();
31 LC = listOfFiles[i].getCanonicalPath();
32 if (listOfFiles[i].isFile()) {
33 LA = "File";
34 } else if (listOfFiles[i].isDirectory()) {
35 LA = "Folder";
36 }
37 else { //I'm not sure if this should even be possible...
38 continue;
39 }
40 String[] tmp = new String[] {LA, LB, LC};
41 ret.add(tmp);
42 }
43 } catch (Exception e) {
44 System.err.println(e);
45 }
46 return ret;
47 }
48
49}
Note: See TracBrowser for help on using the repository browser.