1 16 package org.apache.commons.net.ftp.parser; 17 18 import java.text.ParseException ; 19 20 import org.apache.commons.net.ftp.FTPClientConfig; 21 import org.apache.commons.net.ftp.FTPFile; 22 23 26 27 public class OS400FTPEntryParser extends ConfigurableFTPFileEntryParserImpl 28 { 29 private static final String DEFAULT_DATE_FORMAT 30 = "yy/MM/dd HH:mm:ss"; 32 33 34 private static final String REGEX = 35 "(\\S+)\\s+" + "(\\d+)\\s+" + "(\\S+)\\s+(\\S+)\\s+" + "(\\*\\S+)\\s+" + "(\\S+/?)\\s*"; 41 42 50 public OS400FTPEntryParser() 51 { 52 this(null); 53 } 54 55 67 public OS400FTPEntryParser(FTPClientConfig config) 68 { 69 super(REGEX); 70 configure(config); 71 } 72 73 74 public FTPFile parseFTPEntry(String entry) 75 { 76 77 FTPFile file = new FTPFile(); 78 file.setRawListing(entry); 79 int type; 80 81 if (matches(entry)) 82 { 83 String usr = group(1); 84 String filesize = group(2); 85 String datestr = group(3)+" "+group(4); 86 String typeStr = group(5); 87 String name = group(6); 88 89 try 90 { 91 file.setTimestamp(super.parseTimestamp(datestr)); 92 } 93 catch (ParseException e) 94 { 95 return null; } 97 98 99 if (typeStr.equalsIgnoreCase("*STMF")) 100 { 101 type = FTPFile.FILE_TYPE; 102 } 103 else if (typeStr.equalsIgnoreCase("*DIR")) 104 { 105 type = FTPFile.DIRECTORY_TYPE; 106 } 107 else 108 { 109 type = FTPFile.UNKNOWN_TYPE; 110 } 111 112 file.setType(type); 113 114 file.setUser(usr); 115 116 try 117 { 118 file.setSize(Long.parseLong(filesize)); 119 } 120 catch (NumberFormatException e) 121 { 122 } 124 125 if (name.endsWith("/")) 126 { 127 name = name.substring(0, name.length() - 1); 128 } 129 int pos = name.lastIndexOf('/'); 130 if (pos > -1) 131 { 132 name = name.substring(pos + 1); 133 } 134 135 file.setName(name); 136 137 return file; 138 } 139 return null; 140 } 141 142 148 protected FTPClientConfig getDefaultConfiguration() { 149 return new FTPClientConfig( 150 FTPClientConfig.SYST_OS400, 151 DEFAULT_DATE_FORMAT, 152 null, null, null, null); 153 } 154 155 } 156 | Popular Tags |