1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.net.ftp.parser;
19
20 import java.text.ParseException;
21
22 import org.apache.commons.net.ftp.FTPClientConfig;
23 import org.apache.commons.net.ftp.FTPFile;
24
25
26
27
28
29 public class OS400FTPEntryParser extends ConfigurableFTPFileEntryParserImpl
30 {
31 private static final String DEFAULT_DATE_FORMAT
32 = "yy/MM/dd HH:mm:ss";
33
34
35
36 private static final String REGEX =
37 "(\\S+)\\s+"
38 + "(\\d+)\\s+"
39 + "(\\S+)\\s+(\\S+)\\s+"
40 + "(\\*\\S+)\\s+"
41
42
43
44
45
46
47
48
49
50
51
52 public OS400FTPEntryParser()
53 {
54 this(null);
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public OS400FTPEntryParser(FTPClientConfig config)
70 {
71 super(REGEX);
72 configure(config);
73 }
74
75
76 public FTPFile parseFTPEntry(String entry)
77 {
78
79 FTPFile file = new FTPFile();
80 file.setRawListing(entry);
81 int type;
82
83 if (matches(entry))
84 {
85 String usr = group(1);
86 String filesize = group(2);
87 String datestr = group(3)+" "+group(4);
88 String typeStr = group(5);
89 String name = group(6);
90
91 try
92 {
93 file.setTimestamp(super.parseTimestamp(datestr));
94 }
95 catch (ParseException e)
96 {
97
98 }
99
100
101 if (typeStr.equalsIgnoreCase("*STMF"))
102 {
103 type = FTPFile.FILE_TYPE;
104 }
105 else if (typeStr.equalsIgnoreCase("*DIR"))
106 {
107 type = FTPFile.DIRECTORY_TYPE;
108 }
109 else
110 {
111 type = FTPFile.UNKNOWN_TYPE;
112 }
113
114 file.setType(type);
115
116 file.setUser(usr);
117
118 try
119 {
120 file.setSize(Long.parseLong(filesize));
121 }
122 catch (NumberFormatException e)
123 {
124
125 }
126
127 if (name.endsWith("/"))
128 {
129 name = name.substring(0, name.length() - 1);
130 }
131 int pos = name.lastIndexOf('/');
132 if (pos > -1)
133 {
134 name = name.substring(pos + 1);
135 }
136
137 file.setName(name);
138
139 return file;
140 }
141 return null;
142 }
143
144
145
146
147
148
149
150 @Override
151 protected FTPClientConfig getDefaultConfiguration() {
152 return new FTPClientConfig(
153 FTPClientConfig.SYST_OS400,
154 DEFAULT_DATE_FORMAT,
155 null, null, null, null);
156 }
157
158 }