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 package fr.paris.lutece.plugins.folderlisting.business;
35
36 import fr.paris.lutece.portal.service.util.AppPathService;
37 import fr.paris.lutece.portal.service.util.AppPropertiesService;
38 import fr.paris.lutece.util.filesystem.DirectoryNotFoundException;
39 import fr.paris.lutece.util.filesystem.FileSystemUtil;
40
41 import java.io.File;
42
43 import java.text.DateFormat;
44 import java.text.SimpleDateFormat;
45
46 import java.util.ArrayList;
47 import java.util.Collection;
48 import java.util.Date;
49
50
51
52
53
54 public class FolderListingHome
55 {
56
57
58 private static final String PROPERTY_DATE_FORMAT = "folderlisting.format.date";
59
60
61
62
63
64
65 public static Collection<FolderListingFile> getFiles( String strPath )
66 throws DirectoryNotFoundException
67 {
68 Collection listFiles = new ArrayList( );
69
70 for ( File file : FileSystemUtil.getFiles( AppPathService.getWebAppPath( ), strPath ) )
71 {
72 FolderListingFile f = new FolderListingFile( );
73
74
75 String strExtension = null;
76 int nPos = file.getName( ).lastIndexOf( "." );
77
78 if ( nPos != -1 )
79 {
80 strExtension = file.getName( ).substring( nPos + 1 );
81 }
82
83
84 String strDateFormat = AppPropertiesService.getProperty( PROPERTY_DATE_FORMAT );
85 DateFormat formatter = new SimpleDateFormat( strDateFormat );
86 Date date = new Date( file.lastModified( ) );
87 String strDate = formatter.format( date );
88
89
90 f.setName( file.getName( ) );
91 f.setSize( "" + ( ( file.length( ) / 1024L ) + 1 ) );
92 f.setPath( strPath );
93 f.setDate( strDate );
94 f.setExtension( strExtension );
95
96 listFiles.add( f );
97 }
98
99 return listFiles;
100 }
101
102
103
104
105
106
107 public static Collection<FolderListingDirectory> getSubDirectories( String strPath )
108 throws DirectoryNotFoundException
109 {
110 Collection listDirs = new ArrayList( );
111
112 for ( File file : FileSystemUtil.getSubDirectories( AppPathService.getWebAppPath( ), strPath ) )
113 {
114 FolderListingDirectory dir = new FolderListingDirectory( );
115
116
117 String strDateFormat = AppPropertiesService.getProperty( PROPERTY_DATE_FORMAT );
118 DateFormat formatter = new SimpleDateFormat( strDateFormat );
119 Date date = new Date( file.lastModified( ) );
120 String strDate = formatter.format( date );
121
122
123 dir.setName( file.getName( ) );
124 dir.setPath( strPath );
125 dir.setDate( strDate );
126
127 listDirs.add( dir );
128 }
129
130 return listDirs;
131 }
132 }