1 16 package org.apache.commons.net.ftp.parser; 17 import java.text.ParseException ; 18 19 import org.apache.commons.net.ftp.FTPClientConfig; 20 import org.apache.commons.net.ftp.FTPFile; 21 22 30 public class OS2FTPEntryParser extends ConfigurableFTPFileEntryParserImpl 31 32 { 33 34 private static final String DEFAULT_DATE_FORMAT 35 = "MM-dd-yy HH:mm"; 39 private static final String REGEX = 40 "(\\s+|[0-9]+)\\s*" 41 + "(\\s+|[A-Z]+)\\s*" 42 + "(DIR|\\s+)\\s*" 43 + "(\\S+)\\s+(\\S+)\\s+" 44 + "(\\S.*)"; 45 46 54 public OS2FTPEntryParser() 55 { 56 this(null); 57 } 58 59 71 public OS2FTPEntryParser(FTPClientConfig config) 72 { 73 super(REGEX); 74 configure(config); 75 } 76 77 87 public FTPFile parseFTPEntry(String entry) 88 { 89 90 FTPFile f = new FTPFile(); 91 if (matches(entry)) 92 { 93 String size = group(1); 94 String attrib = group(2); 95 String dirString = group(3); 96 String datestr = group(4)+" "+group(5); 97 String name = group(6); 98 try 99 { 100 f.setTimestamp(super.parseTimestamp(datestr)); 101 } 102 catch (ParseException e) 103 { 104 return null; } 106 107 108 if (dirString.trim().equals("DIR") || attrib.trim().equals("DIR")) 110 { 111 f.setType(FTPFile.DIRECTORY_TYPE); 112 } 113 else 114 { 115 f.setType(FTPFile.FILE_TYPE); 116 } 117 118 119 f.setName(name.trim()); 121 122 f.setSize(Long.parseLong(size.trim())); 124 125 return (f); 126 } 127 return null; 128 129 } 130 131 137 protected FTPClientConfig getDefaultConfiguration() { 138 return new FTPClientConfig( 139 FTPClientConfig.SYST_OS2, 140 DEFAULT_DATE_FORMAT, 141 null, null, null, null); 142 } 143 144 } 145 | Popular Tags |