svn-gvsig-desktop / branches / v05 / extensions / extWMS / src / com / iver / cit / gvsig / fmap / layers / TimeDimension.java @ 4187
History | View | Annotate | Download (21.6 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: TimeDimension.java 4187 2006-02-23 10:36:30Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.3.2.5 2006-02-23 10:36:30 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.3.2.4 2006/02/10 13:22:35 jaume
|
50 |
* now analyzes dimensions on demand
|
51 |
*
|
52 |
* Revision 1.3.2.3 2006/01/31 16:25:24 jaume
|
53 |
* correcciones de bugs
|
54 |
*
|
55 |
* Revision 1.4 2006/01/26 16:07:14 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.3.2.1 2006/01/26 12:59:32 jaume
|
59 |
* 0.5
|
60 |
*
|
61 |
* Revision 1.3 2006/01/24 18:01:17 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.2 2006/01/24 14:36:33 jaume
|
65 |
* This is the new version
|
66 |
*
|
67 |
* Revision 1.1.2.11 2006/01/20 15:59:13 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.1.2.10 2006/01/20 15:22:46 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.1.2.9 2006/01/20 08:50:52 jaume
|
74 |
* handles time dimension for the NASA Jet Propulsion Laboratory WMS
|
75 |
*
|
76 |
* Revision 1.1.2.8 2006/01/19 16:09:30 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.1.2.7 2006/01/11 12:20:30 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.1.2.6 2006/01/10 11:33:31 jaume
|
83 |
* Time dimension working against Jet Propulsion Laboratory's WMS server
|
84 |
*
|
85 |
* Revision 1.1.2.5 2006/01/09 18:10:38 jaume
|
86 |
* casi con el time dimension
|
87 |
*
|
88 |
* Revision 1.1.2.4 2006/01/05 23:15:53 jaume
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.1.2.3 2006/01/04 18:09:02 jaume
|
92 |
* Time dimension
|
93 |
*
|
94 |
* Revision 1.1.2.2 2006/01/04 16:49:44 jaume
|
95 |
* Time dimensios
|
96 |
*
|
97 |
* Revision 1.1.2.1 2006/01/03 18:08:40 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
*
|
101 |
*/
|
102 |
/**
|
103 |
*
|
104 |
*/
|
105 |
package com.iver.cit.gvsig.fmap.layers; |
106 |
|
107 |
import java.util.ArrayList; |
108 |
import java.util.GregorianCalendar; |
109 |
|
110 |
/**
|
111 |
* Class for WMS TIME dimension from a WMS. It allows you to handle the correct
|
112 |
* values for this kind of dimension.
|
113 |
* <br>
|
114 |
* <p>
|
115 |
* At the moment this class was written the WMS TIME dimension is defined as the
|
116 |
* ISO8601 standard for expressing times.
|
117 |
* </p>
|
118 |
* <br>
|
119 |
* <p>
|
120 |
* As far as this class implements IFMapWMSDimension it uses the same interface
|
121 |
* and documentation.
|
122 |
* </p>
|
123 |
*
|
124 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
125 |
*/
|
126 |
|
127 |
public class TimeDimension implements IFMapWMSDimension { |
128 |
static private final long millisXsec = 1000; |
129 |
static private final long millisXminute = 60 * millisXsec; |
130 |
static private final long millisXhour = 60 * millisXminute; |
131 |
static private final long millisXday = 24 * millisXhour; |
132 |
static private final long millisXmonth = 30 * millisXday; |
133 |
// according on the Wikipedia (1 year = 365 days 6 hours 9 minutes 9,7 seconds)
|
134 |
static private final long millisXyear = (365*millisXday) + (6*millisXhour) + (9*millisXminute) + 9700; |
135 |
|
136 |
static private final String digit = "[0-9]"; |
137 |
static private final String nonZeroDigit = "[1-9]"; |
138 |
static private final String letter = "[a-zA-Z]"; |
139 |
static private final String seconds = "([0-5]"+digit+"((\\.|,)"+digit+digit+")?)"; |
140 |
static private final String minutes = "([0-5]"+digit+")"; |
141 |
static private final String hours = "(0"+digit+"|1"+digit+"|2[0-3])"; |
142 |
static private final String time = hours+":"+minutes+"(:"+seconds+")?"; |
143 |
static private final String days = "(0?"+nonZeroDigit+"|1"+digit+"|2"+digit+"|30|31)"; |
144 |
static private final String months = "(0?"+nonZeroDigit+"|10|11|12)"; |
145 |
static private final String year = "("+digit+digit+")"; |
146 |
static private final String century = "("+digit+digit+")"; |
147 |
|
148 |
static private final String geologicDatasets = "(K|M|G)"; |
149 |
static private final String floatingPointNumber = "("+digit+"+(\\."+digit+"+)?)"; |
150 |
|
151 |
|
152 |
static private final String regexDateExtendedForBCE1 = "B?"+century+year+"-"; |
153 |
static private final String regexDateExtendedForBCE2 = "B?"+century+year+"-"+months; |
154 |
static private final String regexDateExtendedForBCE3 = "B?"+century+year+"-"+months+"-"+days; |
155 |
static private final String regexDateExtendedForBCE4 = "B?"+century+year+"-"+months+"-"+days+"(T| )"+time+"Z"; |
156 |
// Note: in WMS 1.1.0 the suffix Z is optional
|
157 |
// TODO truncated values not yet allowed
|
158 |
|
159 |
static private final String regexDateExtendedForBCE = |
160 |
"(" + regexDateExtendedForBCE1 + "|" |
161 |
+ regexDateExtendedForBCE2 + "|"
|
162 |
+ regexDateExtendedForBCE3 + "|"
|
163 |
+ regexDateExtendedForBCE4 + ")";
|
164 |
|
165 |
static private final String regexDateForGeologicDatasets = geologicDatasets+floatingPointNumber; |
166 |
|
167 |
static private final String periodMagnitude = "(Y|M|D)"; |
168 |
static private final String p1 = "(("+digit+")+"+periodMagnitude+")"; |
169 |
|
170 |
static private final String timeMagnitude = "(H|M|S)"; |
171 |
static private final String p2 = "("+floatingPointNumber+timeMagnitude+")"; |
172 |
static private final String regexPeriod = "P(("+p1+"+"+"(T"+p2+")*)|("+p1+"*"+"(T"+p2+")+))"; |
173 |
|
174 |
static private final String regexTimeDimension = |
175 |
"("+regexDateExtendedForBCE+"(,"+regexDateExtendedForBCE+")*|("+regexDateExtendedForBCE+")/("+regexDateExtendedForBCE+")/("+regexPeriod+"))"; |
176 |
|
177 |
private String name = "TIME"; |
178 |
private String unit; |
179 |
private String unitSymbol; |
180 |
private String expression; |
181 |
private Object minValue; |
182 |
private Object maxValue; |
183 |
private boolean isGeologic = false; |
184 |
private Integer valueCount; |
185 |
private String period; |
186 |
private long step; // Distance between two points in milliseconds. |
187 |
private int type; |
188 |
private boolean compiled = false; |
189 |
|
190 |
/**
|
191 |
* Creates a new instance of TimeDimension.
|
192 |
* @param units
|
193 |
* @param unitSymbol
|
194 |
* @param expression
|
195 |
*/
|
196 |
public TimeDimension(String _units, String _unitSymbol, String _dimensionExpression) { |
197 |
this.unit = _units;
|
198 |
this.unitSymbol = _unitSymbol;
|
199 |
setExpression(_dimensionExpression); |
200 |
} |
201 |
|
202 |
public String getName() { |
203 |
return name;
|
204 |
} |
205 |
|
206 |
public String getUnit() { |
207 |
return unit;
|
208 |
} |
209 |
|
210 |
public String getUnitSymbol() { |
211 |
return unitSymbol;
|
212 |
} |
213 |
|
214 |
|
215 |
public String getLowLimit() { |
216 |
String separator = (type == INTERVAL) ? "/" : ","; |
217 |
return expression.split(separator)[0]; |
218 |
} |
219 |
|
220 |
public String getHighLimit() { |
221 |
if (type == INTERVAL) {
|
222 |
String[] s = expression.split("/"); |
223 |
return (s.length > 1) ? s[1] : s[0]; |
224 |
} else if (type == MULTIPLE_VALUE) { |
225 |
String[] s = expression.split(","); |
226 |
return s[s.length-1]; |
227 |
} else {
|
228 |
return expression;
|
229 |
} |
230 |
|
231 |
} |
232 |
|
233 |
public String getResolution() { |
234 |
if (type == INTERVAL) {
|
235 |
String[] s = expression.split("/"); |
236 |
return (s.length == 1) ? s[3] : null; |
237 |
} else return null; |
238 |
} |
239 |
|
240 |
public boolean isValidValue(String value) { |
241 |
return (value.matches(regexDateForGeologicDatasets) || value.matches(regexDateExtendedForBCE));
|
242 |
} |
243 |
|
244 |
public Object valueOf(String value) throws IllegalArgumentException { |
245 |
if (compiled) {
|
246 |
// TODO Missing geological dates
|
247 |
String myValue = value.toUpperCase();
|
248 |
if (isValidValue(myValue)) {
|
249 |
Object val = null; |
250 |
if (!isGeologic){
|
251 |
// This is a normal date
|
252 |
int myYear;
|
253 |
int myMonth;
|
254 |
int myDay;
|
255 |
int myHour;
|
256 |
int myMinute;
|
257 |
float mySecond;
|
258 |
String[] s = myValue.split("-"); |
259 |
myYear = (s[0].charAt(0)=='B')? -Integer.parseInt(s[0].substring(1, 5)) : Integer.parseInt(s[0].substring(0, 4)); |
260 |
myMonth = (s.length>1) ? Integer.parseInt(s[1])-1 : 0; |
261 |
if (myValue.matches(regexDateExtendedForBCE4)){
|
262 |
if (s[2].endsWith("Z")) |
263 |
s[2] = s[2].substring(0,s[2].length()-1); |
264 |
s = (s[2].indexOf('T')!=-1) ? s[2].split("T") : s[2].split(" "); |
265 |
myDay = Integer.parseInt(s[0]); |
266 |
|
267 |
// Go with the time
|
268 |
s = s[1].split(":"); |
269 |
myHour = Integer.parseInt(s[0]); |
270 |
myMinute = (s.length>1) ? Integer.parseInt(s[1]) : 0; |
271 |
mySecond = (s.length>2) ? Float.parseFloat(s[2]) : 0; |
272 |
} else {
|
273 |
myDay = (s.length>2) ? Integer.parseInt(s[2]) : 1; |
274 |
|
275 |
myHour = 0;
|
276 |
myMinute = 0;
|
277 |
mySecond = 0;
|
278 |
} |
279 |
GregorianCalendar cal = new GregorianCalendar(myYear, myMonth, myDay, myHour, myMinute, (int)mySecond); |
280 |
val = cal; |
281 |
} else{
|
282 |
// this is a geological date >:-(
|
283 |
} |
284 |
return val;
|
285 |
} else throw new IllegalArgumentException(myValue); |
286 |
} |
287 |
return null; |
288 |
} |
289 |
|
290 |
public String valueAt(int pos) throws ArrayIndexOutOfBoundsException { |
291 |
if (compiled) {
|
292 |
if (pos<0 || pos>valueCount()) |
293 |
throw new ArrayIndexOutOfBoundsException(pos+"(must be >= 0 and <="+valueCount()+")"); |
294 |
|
295 |
if (type == SINGLE_VALUE)
|
296 |
return expression;
|
297 |
|
298 |
if (type == MULTIPLE_VALUE)
|
299 |
return expression.split(",")[pos]; |
300 |
|
301 |
if (!isGeologic){
|
302 |
long newTime = ((GregorianCalendar) minValue).getTimeInMillis(); |
303 |
newTime += (step*pos); |
304 |
GregorianCalendar cal = new GregorianCalendar(); |
305 |
cal.setTimeInMillis(newTime); |
306 |
if (cal.after(maxValue))
|
307 |
return toString((GregorianCalendar) maxValue); |
308 |
else if (cal.before(minValue)) |
309 |
return toString((GregorianCalendar) minValue); |
310 |
else
|
311 |
return toString(cal);
|
312 |
} |
313 |
} |
314 |
return null; |
315 |
} |
316 |
|
317 |
/**
|
318 |
* Prints a GregorianCalendar value in WMS1.1.1 format.
|
319 |
* @param cal
|
320 |
* @return
|
321 |
*/
|
322 |
private String toString(GregorianCalendar cal) { |
323 |
int iYear = cal.get(cal.YEAR);
|
324 |
int iMonth = cal.get(cal.MONTH) + 1; |
325 |
int iDay = cal.get(cal.DAY_OF_MONTH);
|
326 |
int iHour = cal.get(cal.HOUR_OF_DAY);
|
327 |
int iMinute = cal.get(cal.MINUTE);
|
328 |
int iSecond = cal.get(cal.SECOND);
|
329 |
String myYear;
|
330 |
if (iYear<10) |
331 |
myYear = "200"+iYear;
|
332 |
else if (iYear<100) |
333 |
myYear = "20"+iYear;
|
334 |
else if (iYear<1000) |
335 |
myYear = "2"+iYear;
|
336 |
else
|
337 |
myYear = ""+iYear;
|
338 |
String myMonth = (iMonth<10) ? "0"+iMonth : ""+iMonth; |
339 |
String myDay = (iDay<10) ? "0"+iDay : ""+iDay; |
340 |
String myHour = (iHour<10) ? "0"+iHour : ""+iHour; |
341 |
String myMinute = (iMinute<10)? "0"+iMinute : ""+iMinute; |
342 |
String mySecond = (iSecond<10)? "0"+iSecond : ""+iSecond; |
343 |
int myMilliSecond = cal.get(cal.MILLISECOND);
|
344 |
|
345 |
|
346 |
String s = myYear+"-"+myMonth+"-"+myDay+"T"+myHour+":"+myMinute+":"+mySecond+"."+(myMilliSecond/10)+"Z"; |
347 |
if (iYear<0) |
348 |
s = "B"+s;
|
349 |
return s;
|
350 |
} |
351 |
|
352 |
public int valueCount() { |
353 |
if (compiled) {
|
354 |
if (valueCount==null){ |
355 |
if (type == MULTIPLE_VALUE) {
|
356 |
return expression.split(",").length; |
357 |
} else if (type == INTERVAL) { |
358 |
if (period == null) { |
359 |
valueCount = new Integer(0); |
360 |
return valueCount.intValue();
|
361 |
} |
362 |
|
363 |
if (!isGeologic){
|
364 |
|
365 |
long x1 = ((GregorianCalendar) maxValue).getTimeInMillis(); |
366 |
long x0 = ((GregorianCalendar) minValue).getTimeInMillis(); |
367 |
long distance = x1-x0;
|
368 |
step = 0;
|
369 |
|
370 |
boolean isTimeField = false; |
371 |
String val = ""; |
372 |
|
373 |
for (int i = 0; i < period.length(); i++) { |
374 |
if (period.charAt(i) == 'P') |
375 |
continue;
|
376 |
if (period.charAt(i) == 'T'){ |
377 |
isTimeField = true;
|
378 |
continue;
|
379 |
} |
380 |
switch (period.charAt(i)){
|
381 |
case 'Y': |
382 |
step += Integer.parseInt(val) * millisXyear;
|
383 |
val = "";
|
384 |
break;
|
385 |
case 'M': |
386 |
if (isTimeField)
|
387 |
step += Integer.parseInt(val) * millisXminute;
|
388 |
else
|
389 |
step += Integer.parseInt(val) * millisXmonth;
|
390 |
val = "";
|
391 |
break;
|
392 |
case 'D': |
393 |
step += Integer.parseInt(val) * millisXday;
|
394 |
val = "";
|
395 |
break;
|
396 |
case 'H': |
397 |
step += Integer.parseInt(val) * millisXhour;
|
398 |
val = "";
|
399 |
break;
|
400 |
case 'S': |
401 |
step += Integer.parseInt(val) * 1000; |
402 |
val = "";
|
403 |
break;
|
404 |
default:
|
405 |
val += period.charAt(i); |
406 |
break;
|
407 |
} |
408 |
} |
409 |
valueCount = new Integer((int)(distance/step) + 1); // + 1 for the initial point |
410 |
} |
411 |
} else {
|
412 |
// this is a single value expression
|
413 |
valueCount = new Integer(1); |
414 |
return valueCount.intValue();
|
415 |
} |
416 |
} |
417 |
|
418 |
return valueCount.intValue();
|
419 |
} |
420 |
return -1; |
421 |
} |
422 |
|
423 |
public void setExpression(String expr) { |
424 |
expression = expr.toUpperCase(); |
425 |
} |
426 |
|
427 |
public String getExpression() { |
428 |
return expression;
|
429 |
} |
430 |
|
431 |
public int getType() { |
432 |
return type;
|
433 |
} |
434 |
|
435 |
public void compile() { |
436 |
if (expression.matches(regexTimeDimension)){
|
437 |
isGeologic = false;
|
438 |
} else if (expression.matches(regexDateExtendedForBCE)) { |
439 |
isGeologic = false;
|
440 |
} else if (expression.matches(regexDateForGeologicDatasets)){ |
441 |
isGeologic = true;
|
442 |
} else {
|
443 |
throw new IllegalArgumentException(); |
444 |
} |
445 |
String separator;
|
446 |
|
447 |
if (expression.indexOf("/")!=-1) { |
448 |
separator = "/";
|
449 |
type = INTERVAL; |
450 |
} else if (expression.indexOf(",")!=-1) { |
451 |
separator = ",";
|
452 |
type = MULTIPLE_VALUE; |
453 |
} else {
|
454 |
separator = ",";
|
455 |
type = SINGLE_VALUE; |
456 |
} |
457 |
|
458 |
compiled = true;
|
459 |
String[] s = expression.split(separator); |
460 |
minValue = valueOf(s[0]);
|
461 |
if (type == INTERVAL) {
|
462 |
maxValue = (s.length>1) ? valueOf(s[1]) : valueOf(s[0]); |
463 |
period = (s.length>2 && s[2].matches(regexPeriod)) ? s[2] : null; |
464 |
} else if (type == MULTIPLE_VALUE) { |
465 |
maxValue = valueOf(s[s.length-1]);
|
466 |
} else {
|
467 |
maxValue = valueOf(s[0]);
|
468 |
} |
469 |
} |
470 |
} |
471 |
|
472 |
/*
|
473 |
class _TimeDimensionDePrueba implements IFMapWMSDimension {
|
474 |
static private final byte YEAR_FORMAT = -1;
|
475 |
static private final byte YEAR_TO_MONTH_FORMAT = -2;
|
476 |
static private final byte YEAR_TO_DAY_FORMAT = -3;
|
477 |
static private final byte FULL_FORMAT = -4;
|
478 |
|
479 |
static private final long millisXsec = 1000;
|
480 |
static private final long millisXminute = 60 * millisXsec;
|
481 |
static private final long millisXhour = 60 * millisXminute;
|
482 |
static private final long millisXday = 24 * millisXhour;
|
483 |
static private final long millisXmonth = 30 * millisXday;
|
484 |
// according on the Wikipedia (1 year = 365 days 6 hours 9 minutes 9,7 seconds)
|
485 |
static private final long millisXyear = (365*millisXday) + (6*millisXhour) + (9*millisXminute) + 9700;
|
486 |
|
487 |
static private final String digit = "[0-9]";
|
488 |
static private final String nonZeroDigit = "[1-9]";
|
489 |
static private final String letter = "[a-zA-Z]";
|
490 |
static private final String seconds = "([0-5]"+digit+"((\\.|,)"+digit+digit+")?)";
|
491 |
static private final String minutes = "([0-5]"+digit+")";
|
492 |
static private final String hours = "(0"+digit+"|1"+digit+"|2[0-3])";
|
493 |
static private final String time = hours+":"+minutes+"(:"+seconds+")?";
|
494 |
static private final String days = "(0?"+nonZeroDigit+"|1"+digit+"|2"+digit+"|30|31)";
|
495 |
static private final String months = "(0?"+nonZeroDigit+"|10|11|12)";
|
496 |
static private final String year = "("+digit+digit+")";
|
497 |
static private final String century = "("+digit+digit+")";
|
498 |
|
499 |
private String name;
|
500 |
private String unit;
|
501 |
private String unitSymbol;
|
502 |
private ArrayList valueList;
|
503 |
private boolean compiled;
|
504 |
private boolean isGeologic;
|
505 |
private String expression;
|
506 |
private int type;
|
507 |
private byte format = 0;
|
508 |
static private final String regexDateExtendedForBCE1 = "B?"+century+year+"-";
|
509 |
static private final String regexDateExtendedForBCE2 = "B?"+century+year+"-"+months;
|
510 |
static private final String regexDateExtendedForBCE3 = "B?"+century+year+"-"+months+"-"+days;
|
511 |
static private final String regexDateExtendedForBCE4 = "B?"+century+year+"-"+months+"-"+days+"(T| )"+time+"Z";
|
512 |
// Note: in WMS 1.1.0 the suffix Z is optional
|
513 |
// TODO truncated values not yet allowed
|
514 |
|
515 |
static private final String regexDateExtendedForBCE =
|
516 |
"(" + regexDateExtendedForBCE1 + "|"
|
517 |
+ regexDateExtendedForBCE2 + "|"
|
518 |
+ regexDateExtendedForBCE3 + "|"
|
519 |
+ regexDateExtendedForBCE4 + ")";
|
520 |
|
521 |
public String getName() {
|
522 |
return name;
|
523 |
}
|
524 |
|
525 |
public String getUnit() {
|
526 |
return unit;
|
527 |
}
|
528 |
|
529 |
public String getUnitSymbol() {
|
530 |
return unitSymbol;
|
531 |
}
|
532 |
|
533 |
public String getLowLimit() {
|
534 |
return (String) valueList.get(0);
|
535 |
}
|
536 |
|
537 |
public String getHighLimit() {
|
538 |
return (String) valueList.get(valueList.size()-1);
|
539 |
}
|
540 |
|
541 |
|
542 |
public String getResolution() {
|
543 |
return null;
|
544 |
}
|
545 |
|
546 |
public boolean isValidValue(String value) {
|
547 |
// TODO Auto-generated method stub
|
548 |
return false;
|
549 |
}
|
550 |
|
551 |
public Object valueOf(String value) throws IllegalArgumentException {
|
552 |
if (compiled) {
|
553 |
// TODO Missing geological dates
|
554 |
String myValue = value.toUpperCase();
|
555 |
if (isValidValue(myValue)) {
|
556 |
Object val = null;
|
557 |
if (!isGeologic){
|
558 |
// This is a normal date
|
559 |
int myYear;
|
560 |
int myMonth;
|
561 |
int myDay;
|
562 |
int myHour;
|
563 |
int myMinute;
|
564 |
float mySecond;
|
565 |
String[] s = myValue.split("-");
|
566 |
myYear = (s[0].charAt(0)=='B') ? -Integer.parseInt(s[0].substring(1, 5)) : Integer.parseInt(s[0].substring(0, 4));
|
567 |
myMonth = (s.length>1) ? Integer.parseInt(s[1])-1 : 0;
|
568 |
if (myValue.matches(regexDateExtendedForBCE4)){
|
569 |
if (s[2].endsWith("Z"))
|
570 |
s[2] = s[2].substring(0,s[2].length()-1);
|
571 |
s = (s[2].indexOf('T')!=-1) ? s[2].split("T") : s[2].split(" ");
|
572 |
myDay = Integer.parseInt(s[0]);
|
573 |
|
574 |
// Go with the time
|
575 |
s = s[1].split(":");
|
576 |
myHour = Integer.parseInt(s[0]);
|
577 |
myMinute = (s.length>1) ? Integer.parseInt(s[1]) : 0;
|
578 |
mySecond = (s.length>2) ? Float.parseFloat(s[2]) : 0;
|
579 |
} else {
|
580 |
myDay = (s.length>2) ? Integer.parseInt(s[2]) : 1;
|
581 |
|
582 |
myHour = 0;
|
583 |
myMinute = 0;
|
584 |
mySecond = 0;
|
585 |
}
|
586 |
GregorianCalendar cal = new GregorianCalendar(myYear, myMonth, myDay, myHour, myMinute, (int)mySecond);
|
587 |
val = cal;
|
588 |
} else{
|
589 |
// this is a geological date >:-(
|
590 |
}
|
591 |
return val;
|
592 |
} else throw new IllegalArgumentException(myValue);
|
593 |
}
|
594 |
return null;
|
595 |
}
|
596 |
|
597 |
public String valueAt(int pos) throws ArrayIndexOutOfBoundsException {
|
598 |
return (String) valueList.get(pos);
|
599 |
}
|
600 |
|
601 |
public int valueCount() {
|
602 |
return valueList.size();
|
603 |
}
|
604 |
|
605 |
public String getExpression() {
|
606 |
return expression;
|
607 |
}
|
608 |
|
609 |
public void setExpression(String expr) {
|
610 |
this.expression = expr;
|
611 |
}
|
612 |
|
613 |
public int getType() {
|
614 |
return type;
|
615 |
}
|
616 |
|
617 |
public void compile() throws IllegalArgumentException {
|
618 |
String[] items = expression.split(",");
|
619 |
for (int i = 0; i < items.length; i++) {
|
620 |
if (items[i].matches(regexDateExtendedForBCE1)) {
|
621 |
upgradeFormat(YEAR_FORMAT);
|
622 |
if (format == 0)
|
623 |
format = YEAR_FORMAT;
|
624 |
}
|
625 |
else if (items[i].matches(regexDateExtendedForBCE2)) {
|
626 |
if (format >= YEAR_FORMAT)
|
627 |
format = YEAR_TO_MONTH_FORMAT;
|
628 |
}
|
629 |
else if (items[i].matches(regexDateExtendedForBCE3)) {
|
630 |
if (format >= YEAR_TO_MONTH_FORMAT)
|
631 |
format = YEAR_TO_DAY_FORMAT;
|
632 |
}
|
633 |
else if (items[i].matches(regexDateExtendedForBCE4)) {
|
634 |
if (format >= YEAR_TO_DAY_FORMAT)
|
635 |
format = FULL_FORMAT;
|
636 |
}
|
637 |
else
|
638 |
throw new IllegalArgumentException();
|
639 |
}
|
640 |
|
641 |
if (expression.matches(regexTimeDimension)){
|
642 |
isGeologic = false;
|
643 |
} else if (expression.matches(regexDateExtendedForBCE)) {
|
644 |
isGeologic = false;
|
645 |
} else if (expression.matches(regexDateForGeologicDatasets)){
|
646 |
isGeologic = true;
|
647 |
} else {
|
648 |
throw new IllegalArgumentException();
|
649 |
}
|
650 |
String separator;
|
651 |
|
652 |
if (expression.indexOf("/")!=-1) {
|
653 |
separator = "/";
|
654 |
type = INTERVAL;
|
655 |
} else if (expression.indexOf(",")!=-1) {
|
656 |
separator = ",";
|
657 |
type = MULTIPLE_VALUE;
|
658 |
} else {
|
659 |
separator = ",";
|
660 |
type = SINGLE_VALUE;
|
661 |
}
|
662 |
|
663 |
compiled = true;
|
664 |
String[] s = expression.split(separator);
|
665 |
minValue = valueOf(s[0]);
|
666 |
if (type == INTERVAL) {
|
667 |
maxValue = (s.length>1) ? valueOf(s[1]) : valueOf(s[0]);
|
668 |
period = (s.length>2 && s[2].matches(regexPeriod)) ? s[2] : null;
|
669 |
} else if (type == MULTIPLE_VALUE) {
|
670 |
maxValue = valueOf(s[s.length-1]);
|
671 |
} else {
|
672 |
maxValue = valueOf(s[0]);
|
673 |
}
|
674 |
}
|
675 |
|
676 |
private void upgradeFormat(byte sFormat) {
|
677 |
switch (sFormat) {
|
678 |
case YEAR_FORMAT:
|
679 |
break;
|
680 |
case YEAR_TO_MONTH_FORMAT:
|
681 |
break;
|
682 |
case YEAR_TO_DAY_FORMAT:
|
683 |
break;
|
684 |
case FULL_FORMAT:
|
685 |
break;
|
686 |
}
|
687 |
}
|
688 |
}*/
|