1
1
/*
2
- * Copyright (c) 2012, 2019 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2012, 2020 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
25
25
26
26
package build .tools .cldrconverter ;
27
27
28
- import static build .tools .cldrconverter .Bundle .jreTimeZoneNames ;
29
28
import build .tools .cldrconverter .BundleGenerator .BundleType ;
30
29
import java .io .File ;
31
30
import java .io .IOException ;
@@ -87,7 +86,9 @@ public class CLDRConverter {
87
86
static final String ZONE_NAME_PREFIX = "timezone.displayname." ;
88
87
static final String METAZONE_ID_PREFIX = "metazone.id." ;
89
88
static final String PARENT_LOCALE_PREFIX = "parentLocale." ;
89
+ static final String META_EMPTY_ZONE_NAME = "EMPTY_ZONE" ;
90
90
static final String [] EMPTY_ZONE = {"" , "" , "" , "" , "" , "" };
91
+ static final String META_ETCUTC_ZONE_NAME = "ETC_UTC" ;
91
92
92
93
private static SupplementDataParseHandler handlerSuppl ;
93
94
private static LikelySubtagsParseHandler handlerLikelySubtags ;
@@ -666,68 +667,21 @@ private static Map<String, Object> extractCurrencyNames(Map<String, Object> map,
666
667
private static Map <String , Object > extractZoneNames (Map <String , Object > map , String id ) {
667
668
Map <String , Object > names = new HashMap <>();
668
669
669
- // Copy over missing time zone ids from JRE for English locale
670
- if (id .equals ("en" )) {
671
- Map <String [], String > jreMetaMap = new HashMap <>();
672
- jreTimeZoneNames .stream ().forEach (e -> {
673
- String tzid = (String )e [0 ];
674
- String [] data = (String [])e [1 ];
675
-
676
- if (map .get (TIMEZONE_ID_PREFIX + tzid ) == null &&
677
- handlerMetaZones .get (tzid ) == null ||
678
- handlerMetaZones .get (tzid ) != null &&
679
- map .get (METAZONE_ID_PREFIX + handlerMetaZones .get (tzid )) == null ) {
680
-
681
- // First, check the alias
682
- String canonID = canonicalTZMap .get (tzid );
683
- if (canonID != null && !tzid .equals (canonID )) {
684
- Object value = map .get (TIMEZONE_ID_PREFIX + canonID );
685
- if (value != null ) {
686
- names .put (tzid , value );
687
- return ;
688
- } else {
689
- String meta = handlerMetaZones .get (canonID );
690
- if (meta != null ) {
691
- value = map .get (METAZONE_ID_PREFIX + meta );
692
- if (value != null ) {
693
- names .put (tzid , meta );
694
- return ;
695
- }
696
- }
697
- }
698
- }
699
-
700
- // Check the CLDR meta key
701
- Optional <Map .Entry <String , String >> cldrMeta =
702
- handlerMetaZones .getData ().entrySet ().stream ()
703
- .filter (me ->
704
- Arrays .deepEquals (data ,
705
- (String [])map .get (METAZONE_ID_PREFIX + me .getValue ())))
706
- .findAny ();
707
- cldrMeta .ifPresentOrElse (meta -> names .put (tzid , meta .getValue ()), () -> {
708
- // Check the JRE meta key, add if there is not.
709
- Optional <Map .Entry <String [], String >> jreMeta =
710
- jreMetaMap .entrySet ().stream ()
711
- .filter (jm -> Arrays .deepEquals (data , jm .getKey ()))
712
- .findAny ();
713
- jreMeta .ifPresentOrElse (meta -> names .put (tzid , meta .getValue ()), () -> {
714
- String metaName = "JRE_" + tzid .replaceAll ("[/-]" , "_" );
715
- names .put (METAZONE_ID_PREFIX + metaName , data );
716
- names .put (tzid , metaName );
717
- });
718
- });
719
- }
720
- });
721
- }
722
-
723
670
getAvailableZoneIds ().stream ().forEach (tzid -> {
724
671
// If the tzid is deprecated, get the data for the replacement id
725
672
String tzKey = Optional .ofNullable ((String )handlerSupplMeta .get (tzid ))
726
673
.orElse (tzid );
727
674
Object data = map .get (TIMEZONE_ID_PREFIX + tzKey );
728
675
729
676
if (data instanceof String []) {
730
- names .put (tzid , data );
677
+ // Hack for UTC. UTC is an alias to Etc/UTC in CLDR
678
+ if (tzid .equals ("Etc/UTC" ) && !map .containsKey (TIMEZONE_ID_PREFIX + "UTC" )) {
679
+ names .put (METAZONE_ID_PREFIX + META_ETCUTC_ZONE_NAME , data );
680
+ names .put (tzid , META_ETCUTC_ZONE_NAME );
681
+ names .put ("UTC" , META_ETCUTC_ZONE_NAME );
682
+ } else {
683
+ names .put (tzid , data );
684
+ }
731
685
} else {
732
686
String meta = handlerMetaZones .get (tzKey );
733
687
if (meta != null ) {
@@ -744,24 +698,23 @@ private static Map<String, Object> extractZoneNames(Map<String, Object> map, Str
744
698
745
699
// exemplar cities.
746
700
Map <String , Object > exCities = map .entrySet ().stream ()
747
- .filter (e -> e .getKey ().startsWith (CLDRConverter .EXEMPLAR_CITY_PREFIX ))
748
- .collect (Collectors
749
- .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
701
+ .filter (e -> e .getKey ().startsWith (CLDRConverter .EXEMPLAR_CITY_PREFIX ))
702
+ .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
750
703
names .putAll (exCities );
751
704
752
- if (!id .equals ("en" ) &&
753
- !names .isEmpty ()) {
754
- // CLDR does not have UTC entry, so add it here.
755
- names .put ("UTC" , EMPTY_ZONE );
756
-
757
- // no metazone zones
758
- Arrays .asList (handlerMetaZones .get (MetaZonesParseHandler .NO_METAZONE_KEY )
759
- .split ("\\ s" )).stream ()
760
- .forEach (tz -> {
761
- names .put (tz , EMPTY_ZONE );
762
- });
705
+ // If there's no UTC entry at this point, add an empty one
706
+ if (!names .isEmpty () && !names .containsKey ("UTC" )) {
707
+ names .putIfAbsent (METAZONE_ID_PREFIX + META_EMPTY_ZONE_NAME , EMPTY_ZONE );
708
+ names .put ("UTC" , META_EMPTY_ZONE_NAME );
763
709
}
764
710
711
+ // Finally some compatibility stuff
712
+ ZoneId .SHORT_IDS .entrySet ().stream ()
713
+ .filter (e -> !names .containsKey (e .getKey ()) && names .containsKey (e .getValue ()))
714
+ .forEach (e -> {
715
+ names .put (e .getKey (), names .get (e .getValue ()));
716
+ });
717
+
765
718
return names ;
766
719
}
767
720
0 commit comments