comparison backend/src/main/java/org/dive4elements/river/importer/parsers/AtFileParser.java @ 8200:9d2e69f971f5

sed -i src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:50:33 +0200
parents 82b8bfb47260
children 0a5239a1e46e
comparison
equal deleted inserted replaced
8199:42ac86ec19c7 8200:9d2e69f971f5
32 /** Parse *.at (Abflusstafeln?) files. */ 32 /** Parse *.at (Abflusstafeln?) files. */
33 public class AtFileParser { 33 public class AtFileParser {
34 34
35 public static final String ENCODING = "ISO-8859-1"; 35 public static final String ENCODING = "ISO-8859-1";
36 36
37 private static Logger logger = Logger.getLogger(AtFileParser.class); 37 private static Logger log = Logger.getLogger(AtFileParser.class);
38 38
39 // regular expression from hell to find out time range 39 // regular expression from hell to find out time range
40 public static final Pattern DATE_LINE = Pattern.compile( 40 public static final Pattern DATE_LINE = Pattern.compile(
41 "^\\*\\s*Abflu[^t]+tafel?\\s*([^\\d]+)" + 41 "^\\*\\s*Abflu[^t]+tafel?\\s*([^\\d]+)" +
42 "(\\d{1,2})?\\.?(\\d{1,2})?\\.?(\\d{2,4})\\s*(?:(?:bis)|-)?\\s*" + 42 "(\\d{1,2})?\\.?(\\d{1,2})?\\.?(\\d{2,4})\\s*(?:(?:bis)|-)?\\s*" +
55 String prefix, 55 String prefix,
56 int kind 56 int kind
57 ) 57 )
58 throws IOException { 58 throws IOException {
59 59
60 logger.info("parsing AT file: " + file); 60 log.info("parsing AT file: " + file);
61 61
62 BufferedReader br = null; 62 BufferedReader br = null;
63 63
64 String line = null; 64 String line = null;
65 65
107 } 107 }
108 108
109 String[] splits = tmp.replace(',', '.').split("\\s+"); 109 String[] splits = tmp.replace(',', '.').split("\\s+");
110 110
111 if ((splits.length < 2) || (splits.length > 11)) { 111 if ((splits.length < 2) || (splits.length > 11)) {
112 logger.warn("Found an invalid row in the AT file."); 112 log.warn("Found an invalid row in the AT file.");
113 continue; 113 continue;
114 } 114 }
115 115
116 String strW = splits[0].trim(); 116 String strW = splits[0].trim();
117 double W = Double.parseDouble(strW); 117 double W = Double.parseDouble(strW);
139 139
140 beginning = false; 140 beginning = false;
141 } 141 }
142 } 142 }
143 catch (NumberFormatException pe) { 143 catch (NumberFormatException pe) {
144 logger.warn("AT: invalid number " + pe.getMessage()); 144 log.warn("AT: invalid number " + pe.getMessage());
145 } 145 }
146 catch (FileNotFoundException fnfe) { 146 catch (FileNotFoundException fnfe) {
147 logger.error(fnfe.getMessage()); 147 log.error(fnfe.getMessage());
148 } 148 }
149 finally { 149 finally {
150 if (br != null) { 150 if (br != null) {
151 br.close(); 151 br.close();
152 } 152 }
154 154
155 if (from != null) { 155 if (from != null) {
156 if (to != null && from.compareTo(to) > 0) { 156 if (to != null && from.compareTo(to) > 0) {
157 Date t = from; from = to; to = t; 157 Date t = from; from = to; to = t;
158 } 158 }
159 logger.info("from: " + from + " to: " + to); 159 log.info("from: " + from + " to: " + to);
160 ImportTimeInterval interval = new ImportTimeInterval(from, to); 160 ImportTimeInterval interval = new ImportTimeInterval(from, to);
161 dischargeTable.setTimeInterval(interval); 161 dischargeTable.setTimeInterval(interval);
162 } 162 }
163 163
164 logger.info("Finished parsing AT file: " + file); 164 log.info("Finished parsing AT file: " + file);
165 165
166 return dischargeTable; 166 return dischargeTable;
167 } 167 }
168 168
169 public static Date guessDate(String day, String month, String year) { 169 public static Date guessDate(String day, String month, String year) {
170 // TODO evaluate whether DateGuesser class can do that. 170 // TODO evaluate whether DateGuesser class can do that.
171 if (day == null && month == null && year == null) { 171 if (day == null && month == null && year == null) {
172 return null; 172 return null;
173 } 173 }
174 174
175 logger.debug("day: " + day + " month: " + month + " year: " + year); 175 log.debug("day: " + day + " month: " + month + " year: " + year);
176 176
177 int dayI = 15; 177 int dayI = 15;
178 if (day != null) { 178 if (day != null) {
179 try { 179 try {
180 dayI = Integer.parseInt(day.trim()); 180 dayI = Integer.parseInt(day.trim());
225 try { 225 try {
226 for (String arg: args) { 226 for (String arg: args) {
227 parser.parse(new File(arg)); 227 parser.parse(new File(arg));
228 } 228 }
229 } catch(Exception e) { 229 } catch(Exception e) {
230 logger.error("Exception caught " + e); 230 log.error("Exception caught " + e);
231 } 231 }
232 } 232 }
233 } 233 }
234 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 234 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org