1 package ch
.cyberduck
.core
.ftp
;
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
20 import ch
.cyberduck
.core
.ftp
.parser
.CompositeFileEntryParser
;
21 import ch
.cyberduck
.core
.ftp
.parser
.EPLFFTPEntryParser
;
22 import ch
.cyberduck
.core
.ftp
.parser
.LaxUnixFTPEntryParser
;
23 import ch
.cyberduck
.core
.ftp
.parser
.RumpusFTPEntryParser
;
24 import ch
.cyberduck
.core
.ftp
.parser
.TrellixFTPEntryParser
;
25 import ch
.cyberduck
.core
.ftp
.parser
.UnitreeFTPEntryParser
;
27 import org
.apache
.commons
.net
.ftp
.FTPClientConfig
;
28 import org
.apache
.commons
.net
.ftp
.parser
.FTPFileEntryParserFactory
;
29 import org
.apache
.commons
.net
.ftp
.parser
.MVSFTPEntryParser
;
30 import org
.apache
.commons
.net
.ftp
.parser
.NTFTPEntryParser
;
31 import org
.apache
.commons
.net
.ftp
.parser
.NetwareFTPEntryParser
;
32 import org
.apache
.commons
.net
.ftp
.parser
.OS2FTPEntryParser
;
33 import org
.apache
.commons
.net
.ftp
.parser
.OS400FTPEntryParser
;
34 import org
.apache
.commons
.net
.ftp
.parser
.ParserInitializationException
;
36 import java
.util
.Arrays
;
37 import java
.util
.Locale
;
38 import java
.util
.TimeZone
;
43 public class FTPParserFactory
implements FTPFileEntryParserFactory
{
45 public CompositeFileEntryParser
createFileEntryParser(final FTPClientConfig config
) throws ParserInitializationException
{
46 return this.createFileEntryParser(config
.getServerSystemKey(), TimeZone
.getTimeZone(config
.getServerTimeZoneId()));
49 public CompositeFileEntryParser
createFileEntryParser(final String system
) throws ParserInitializationException
{
50 return this.createFileEntryParser(system
, TimeZone
.getDefault());
53 public CompositeFileEntryParser
createFileEntryParser(final String system
, final TimeZone timezone
) throws ParserInitializationException
{
55 String ukey
= system
.toUpperCase(Locale
.ROOT
);
56 if(ukey
.contains(FTPClientConfig
.SYST_UNIX
)) {
57 return this.createUnixFTPEntryParser(timezone
);
59 else if(ukey
.contains(FTPClientConfig
.SYST_VMS
)) {
60 throw new ParserInitializationException(String
.format("\"%s\" is not currently a supported system.", system
));
62 else if(ukey
.contains(FTPClientConfig
.SYST_NETWARE
)) {
63 return this.createNetwareFTPEntryParser(timezone
);
65 else if(ukey
.contains(FTPClientConfig
.SYST_NT
)) {
66 return this.createNTFTPEntryParser(timezone
);
68 else if(ukey
.contains(FTPClientConfig
.SYST_OS2
)) {
69 return this.createOS2FTPEntryParser(timezone
);
71 else if(ukey
.contains(FTPClientConfig
.SYST_OS400
)) {
72 return this.createOS400FTPEntryParser(timezone
);
74 else if(ukey
.contains(FTPClientConfig
.SYST_MVS
)) {
75 return this.createUnixFTPEntryParser(timezone
);
78 // Defaulting to UNIX parser
79 return this.createUnixFTPEntryParser(timezone
);
82 private CompositeFileEntryParser
createUnixFTPEntryParser(final TimeZone timezone
) {
83 return new CompositeFileEntryParser(Arrays
.asList(
84 new LaxUnixFTPEntryParser() {
86 protected FTPClientConfig
getDefaultConfiguration() {
87 final FTPClientConfig config
= super.getDefaultConfiguration();
88 config
.setServerTimeZoneId(timezone
.getID());
92 new EPLFFTPEntryParser(),
93 new RumpusFTPEntryParser() {
95 protected FTPClientConfig
getDefaultConfiguration() {
96 final FTPClientConfig config
= super.getDefaultConfiguration();
97 config
.setServerTimeZoneId(timezone
.getID());
101 new TrellixFTPEntryParser() {
103 protected FTPClientConfig
getDefaultConfiguration() {
104 final FTPClientConfig config
= super.getDefaultConfiguration();
105 config
.setServerTimeZoneId(timezone
.getID());
109 new UnitreeFTPEntryParser() {
111 protected FTPClientConfig
getDefaultConfiguration() {
112 final FTPClientConfig config
= super.getDefaultConfiguration();
113 config
.setServerTimeZoneId(timezone
.getID());
120 private CompositeFileEntryParser
createNetwareFTPEntryParser(final TimeZone timezone
) {
121 return new CompositeFileEntryParser(Arrays
.asList(
122 new NetwareFTPEntryParser() {
124 protected FTPClientConfig
getDefaultConfiguration() {
125 final FTPClientConfig config
= super.getDefaultConfiguration();
126 config
.setServerTimeZoneId(timezone
.getID());
130 this.createUnixFTPEntryParser(timezone
)
134 private CompositeFileEntryParser
createNTFTPEntryParser(final TimeZone timezone
) {
135 return new CompositeFileEntryParser(Arrays
.asList(
136 new NTFTPEntryParser() {
138 public FTPClientConfig
getDefaultConfiguration() {
139 final FTPClientConfig config
= super.getDefaultConfiguration();
140 config
.setServerTimeZoneId(timezone
.getID());
144 this.createUnixFTPEntryParser(timezone
)
148 private CompositeFileEntryParser
createOS2FTPEntryParser(final TimeZone timezone
) {
149 return new CompositeFileEntryParser(Arrays
.asList(
150 new OS2FTPEntryParser() {
152 protected FTPClientConfig
getDefaultConfiguration() {
153 final FTPClientConfig config
= super.getDefaultConfiguration();
154 config
.setServerTimeZoneId(timezone
.getID());
161 private CompositeFileEntryParser
createOS400FTPEntryParser(final TimeZone timezone
) {
162 return new CompositeFileEntryParser(Arrays
.asList(
163 new OS400FTPEntryParser() {
165 protected FTPClientConfig
getDefaultConfiguration() {
166 final FTPClientConfig config
= super.getDefaultConfiguration();
167 config
.setServerTimeZoneId(timezone
.getID());
171 this.createUnixFTPEntryParser(timezone
)
175 private CompositeFileEntryParser
createMVSEntryParser(final TimeZone timezone
) {
176 return new CompositeFileEntryParser(Arrays
.asList(
177 new MVSFTPEntryParser() {
179 protected FTPClientConfig
getDefaultConfiguration() {
180 final FTPClientConfig config
= super.getDefaultConfiguration();
181 config
.setServerTimeZoneId(timezone
.getID());