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
77 public FTPFile parseFTPEntry(String entry)
78 {
79
80 FTPFile file = new FTPFile();
81 file.setRawListing(entry);
82 int type;
83
84 if (matches(entry))
85 {
86 String usr = group(1);
87 String filesize = group(2);
88 String datestr = group(3)+" "+group(4);
89 String typeStr = group(5);
90 String name = group(6);
91
92 try
93 {
94 file.setTimestamp(super.parseTimestamp(datestr));
95 }
96 catch (ParseException e)
97 {
98
99 }
100
101
102 if (typeStr.equalsIgnoreCase("*STMF"))
103 {
104 type = FTPFile.FILE_TYPE;
105 }
106 else if (typeStr.equalsIgnoreCase("*DIR"))
107 {
108 type = FTPFile.DIRECTORY_TYPE;
109 }
110 else
111 {
112 type = FTPFile.UNKNOWN_TYPE;
113 }
114
115 file.setType(type);
116
117 file.setUser(usr);
118
119 try
120 {
121 file.setSize(Long.parseLong(filesize));
122 }
123 catch (NumberFormatException e)
124 {
125
126 }
127
128 if (name.endsWith("/"))
129 {
130 name = name.substring(0, name.length() - 1);
131 }
132 int pos = name.lastIndexOf('/');
133 if (pos > -1)
134 {
135 name = name.substring(pos + 1);
136 }
137
138 file.setName(name);
139
140 return file;
141 }
142 return null;
143 }
144
145
146
147
148
149
150
151 @Override
152 protected FTPClientConfig getDefaultConfiguration() {
153 return new FTPClientConfig(
154 FTPClientConfig.SYST_OS400,
155 DEFAULT_DATE_FORMAT,
156 null, null, null, null);
157 }
158
159 }