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 NTFTPEntryParser extends ConfigurableFTPFileEntryParserImpl 31 { 32 33 private static final String DEFAULT_DATE_FORMAT 34 = "MM-dd-yy hh:mma"; 36 37 40 private static final String REGEX = 41 "(\\S+)\\s+(\\S+)\\s+" 42 + "(<DIR>)?\\s*" 43 + "([0-9]+)?\\s+" 44 + "(\\S.*)"; 45 46 54 public NTFTPEntryParser() 55 { 56 this(null); 57 } 58 59 71 public NTFTPEntryParser(FTPClientConfig config) 72 { 73 super(REGEX); 74 configure(config); 75 } 76 77 87 public FTPFile parseFTPEntry(String entry) 88 { 89 FTPFile f = new FTPFile(); 90 f.setRawListing(entry); 91 92 if (matches(entry)) 93 { 94 String datestr = group(1)+" "+group(2); 95 String dirString = group(3); 96 String size = group(4); 97 String name = group(5); 98 try 99 { 100 f.setTimestamp(super.parseTimestamp(datestr)); 101 } 102 catch (ParseException e) 103 { 104 return null; } 106 107 if (null == name || name.equals(".") || name.equals("..")) 108 { 109 return (null); 110 } 111 f.setName(name); 112 113 114 if ("<DIR>".equals(dirString)) 115 { 116 f.setType(FTPFile.DIRECTORY_TYPE); 117 f.setSize(0); 118 } 119 else 120 { 121 f.setType(FTPFile.FILE_TYPE); 122 if (null != size) 123 { 124 f.setSize(Long.parseLong(size)); 125 } 126 } 127 return (f); 128 } 129 return null; 130 } 131 132 138 public FTPClientConfig getDefaultConfiguration() { 139 return new FTPClientConfig( 140 FTPClientConfig.SYST_NT, 141 DEFAULT_DATE_FORMAT, 142 null, null, null, null); 143 } 144 145 } 146 | Popular Tags |