Revision 4187 branches/v05/extensions/extWMS/src/com/iver/cit/gvsig/fmap/layers/TimeDimension.java

View differences:

TimeDimension.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2 2
 *
3 3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4 4
 *
......
20 20
 *
21 21
 *  Generalitat Valenciana
22 22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
23
 *   Av. Blasco Ib��ez, 50
24 24
 *   46010 VALENCIA
25 25
 *   SPAIN
26 26
 *
......
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.3.2.4  2006-02-10 13:22:35  jaume
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
47 50
* now analyzes dimensions on demand
48 51
*
49 52
* Revision 1.3.2.3  2006/01/31 16:25:24  jaume
......
101 104
 */
102 105
package com.iver.cit.gvsig.fmap.layers;
103 106

  
107
import java.util.ArrayList;
104 108
import java.util.GregorianCalendar;
105 109

  
106 110
/**
......
119 123
 * 
120 124
 * @author jaume dominguez faus - jaume.dominguez@iver.es
121 125
 */
126

  
122 127
public class TimeDimension implements IFMapWMSDimension {
123 128
    static private final long millisXsec    = 1000;
124 129
    static private final long millisXminute = 60 * millisXsec;
......
235 240
    public boolean isValidValue(String value) {
236 241
        return (value.matches(regexDateForGeologicDatasets) || value.matches(regexDateExtendedForBCE));
237 242
    }
238

  
243
    
239 244
    public Object valueOf(String value) throws IllegalArgumentException {
240 245
    	if (compiled) {
241 246
    		// TODO Missing geological dates
......
461 466
        } else {
462 467
        	maxValue = valueOf(s[0]);
463 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;	
464 651
        
465
        
466
		
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
		}
467 687
	}
468
}
688
}*/

Also available in: Unified diff