1 16 package org.apache.commons.net.ftp.parser; 17 18 import org.apache.commons.net.ftp.Configurable; 19 import org.apache.commons.net.ftp.FTPClientConfig; 20 import org.apache.commons.net.ftp.FTPFileEntryParser; 21 22 23 33 public class DefaultFTPFileEntryParserFactory 34 implements FTPFileEntryParserFactory 35 { 36 private FTPClientConfig config = null; 37 38 76 public FTPFileEntryParser createFileEntryParser(String key) 77 { 78 Class parserClass = null; 79 FTPFileEntryParser parser = null; 80 try 81 { 82 parserClass = Class.forName(key); 83 parser = (FTPFileEntryParser) parserClass.newInstance(); 84 } 85 catch (ClassNotFoundException e) 86 { 87 String ukey = null; 88 if (null != key) 89 { 90 ukey = key.toUpperCase(); 91 } 92 if (ukey.indexOf(FTPClientConfig.SYST_UNIX) >= 0) 93 { 94 parser = createUnixFTPEntryParser(); 95 } 96 else if (ukey.indexOf(FTPClientConfig.SYST_VMS) >= 0) 97 { 98 parser = createVMSVersioningFTPEntryParser(); 99 } 100 else if (ukey.indexOf(FTPClientConfig.SYST_NT) >= 0) 101 { 102 parser = createNTFTPEntryParser(); 103 } 104 else if (ukey.indexOf(FTPClientConfig.SYST_OS2) >= 0) 105 { 106 parser = createOS2FTPEntryParser(); 107 } 108 else if (ukey.indexOf(FTPClientConfig.SYST_OS400) >= 0) 109 { 110 parser = createOS400FTPEntryParser(); 111 } 112 else if (ukey.indexOf(FTPClientConfig.SYST_MVS) >= 0) 113 { 114 parser = createMVSEntryParser(); 115 } 116 else 117 { 118 throw new ParserInitializationException("Unknown parser type: " + key); 119 } 120 } 121 catch (ClassCastException e) 122 { 123 throw new ParserInitializationException(parserClass.getName() 124 + " does not implement the interface " 125 + "org.apache.commons.net.ftp.FTPFileEntryParser.", e); 126 } 127 catch (Throwable e) 128 { 129 throw new ParserInitializationException("Error initializing parser", e); 130 } 131 132 if (parser instanceof Configurable) { 133 ((Configurable)parser).configure(this.config); 134 } 135 return parser; 136 } 137 138 158 public FTPFileEntryParser createFileEntryParser(FTPClientConfig config) 159 throws ParserInitializationException 160 { 161 this.config = config; 162 String key = config.getServerSystemKey(); 163 return createFileEntryParser(key); 164 } 165 166 167 public FTPFileEntryParser createUnixFTPEntryParser() 168 { 169 return (FTPFileEntryParser) new UnixFTPEntryParser(); 170 } 171 172 public FTPFileEntryParser createVMSVersioningFTPEntryParser() 173 { 174 return (FTPFileEntryParser) new VMSVersioningFTPEntryParser(); 175 } 176 177 public FTPFileEntryParser createNTFTPEntryParser() 178 { 179 if (config != null && FTPClientConfig.SYST_NT.equals( 180 config.getServerSystemKey())) 181 { 182 return new NTFTPEntryParser(); 183 } else { 184 return new CompositeFileEntryParser(new FTPFileEntryParser[] 185 { 186 new NTFTPEntryParser(), 187 new UnixFTPEntryParser() 188 }); 189 } 190 } 191 192 public FTPFileEntryParser createOS2FTPEntryParser() 193 { 194 return (FTPFileEntryParser) new OS2FTPEntryParser(); 195 } 196 197 public FTPFileEntryParser createOS400FTPEntryParser() 198 { 199 if (config != null && 200 FTPClientConfig.SYST_OS400.equals(config.getServerSystemKey())) 201 { 202 return new OS400FTPEntryParser(); 203 } else { 204 return new CompositeFileEntryParser(new FTPFileEntryParser[] 205 { 206 new OS400FTPEntryParser(), 207 new UnixFTPEntryParser() 208 }); 209 } 210 } 211 212 public FTPFileEntryParser createMVSEntryParser() 213 { 214 return new MVSFTPEntryParser(); 215 } 216 217 218 219 } 220 221 | Popular Tags |