1 16 package org.apache.commons.net.ftp.parser; 17 import java.util.Calendar ; 18 19 import org.apache.commons.net.ftp.FTPFile; 20 21 35 public class EnterpriseUnixFTPEntryParser extends RegexFTPFileEntryParserImpl 36 { 37 38 42 private static final String MONTHS = 43 "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"; 44 45 48 private static final String REGEX = 49 "(([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])" 50 + "([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z]))" 51 + "(\\S*)\\s*" 52 + "(\\S+)\\s*" 53 + "(\\S*)\\s*" 54 + "(\\d*)\\s*" 55 + "(\\d*)\\s*" 56 + MONTHS 57 + "\\s*" 58 + "((?:[012]\\d*)|(?:3[01]))\\s*" 59 + "((\\d\\d\\d\\d)|((?:[01]\\d)|(?:2[0123])):([012345]\\d))\\s" 60 + "(\\S*)(\\s*.*)"; 61 62 66 public EnterpriseUnixFTPEntryParser() 67 { 68 super(REGEX); 69 } 70 71 81 public FTPFile parseFTPEntry(String entry) 82 { 83 84 FTPFile file = new FTPFile(); 85 file.setRawListing(entry); 86 87 if (matches(entry)) 88 { 89 String usr = group(14); 90 String grp = group(15); 91 String filesize = group(16); 92 String mo = group(17); 93 String da = group(18); 94 String yr = group(20); 95 String hr = group(21); 96 String min = group(22); 97 String name = group(23); 98 99 file.setType(FTPFile.FILE_TYPE); 100 file.setUser(usr); 101 file.setGroup(grp); 102 try 103 { 104 file.setSize(Long.parseLong(filesize)); 105 } 106 catch (NumberFormatException e) 107 { 108 } 110 111 Calendar cal = Calendar.getInstance(); 112 cal.set(Calendar.MILLISECOND, 0); 113 cal.set(Calendar.SECOND, 114 0); 115 cal.set(Calendar.MINUTE, 116 0); 117 cal.set(Calendar.HOUR_OF_DAY, 118 0); 119 try 120 { 121 122 int pos = MONTHS.indexOf(mo); 123 int month = pos / 4; 124 if (yr != null) 125 { 126 cal.set(Calendar.YEAR, 128 Integer.parseInt(yr)); 129 } 130 else 131 { 132 int year = cal.get(Calendar.YEAR); 134 135 if (cal.get(Calendar.MONTH) < month) 138 { 139 year--; 140 } 141 cal.set(Calendar.YEAR, 142 year); 143 cal.set(Calendar.HOUR_OF_DAY, 144 Integer.parseInt(hr)); 145 cal.set(Calendar.MINUTE, 146 Integer.parseInt(min)); 147 } 148 cal.set(Calendar.MONTH, 149 month); 150 cal.set(Calendar.DATE, 151 Integer.parseInt(da)); 152 file.setTimestamp(cal); 153 } 154 catch (NumberFormatException e) 155 { 156 } 158 file.setName(name); 159 160 return file; 161 } 162 return null; 163 } 164 } 165 | Popular Tags |