Complete porting of ical4j to post getContextClassLoader() Android era,

Tue, 10 Feb 2015 21:32:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 21:32:00 +0100
changeset 5
e0e108e77052
parent 4
45d57ecba757
child 6
952493b9f497

Complete porting of ical4j to post getContextClassLoader() Android era,
correcting critical flaws reported by users on the upstream bugtracker
including https://github.com/gggard/AndroidCaldavSyncAdapater/issues/224/

src/ical4j.properties file | annotate | diff | comparison | revisions
src/net/fortuna/ical4j/model/TimeZoneRegistryImpl.java file | annotate | diff | comparison | revisions
src/net/fortuna/ical4j/util/ResourceLoader.java file | annotate | diff | comparison | revisions
src/tz.alias file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/ical4j.properties	Tue Feb 10 21:32:00 2015 +0100
     1.3 @@ -0,0 +1,81 @@
     1.4 +#
     1.5 +# Copyright (c) 2011, Ben Fortuna
     1.6 +# All rights reserved.
     1.7 +#
     1.8 +# Redistribution and use in source and binary forms, with or without
     1.9 +# modification, are permitted provided that the following conditions
    1.10 +# are met:
    1.11 +#
    1.12 +#  o Redistributions of source code must retain the above copyright
    1.13 +# notice, this list of conditions and the following disclaimer.
    1.14 +#
    1.15 +#  o Redistributions in binary form must reproduce the above copyright
    1.16 +# notice, this list of conditions and the following disclaimer in the
    1.17 +# documentation and/or other materials provided with the distribution.
    1.18 +#
    1.19 +#  o Neither the name of Ben Fortuna nor the names of any other contributors
    1.20 +# may be used to endorse or promote products derived from this software
    1.21 +# without specific prior written permission.
    1.22 +#
    1.23 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.25 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.26 +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    1.27 +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.28 +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.29 +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.30 +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    1.31 +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    1.32 +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    1.33 +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.34 +#
    1.35 +# Redistribution and use in source and binary forms, with or without
    1.36 +# modification, are permitted provided that the following conditions
    1.37 +# are met:
    1.38 +#
    1.39 +#  o Redistributions of source code must retain the above copyright
    1.40 +# notice, this list of conditions and the following disclaimer.
    1.41 +#
    1.42 +#  o Redistributions in binary form must reproduce the above copyright
    1.43 +# notice, this list of conditions and the following disclaimer in the
    1.44 +# documentation and/or other materials provided with the distribution.
    1.45 +#
    1.46 +#  o Neither the name of Ben Fortuna nor the names of any other contributors
    1.47 +# may be used to endorse or promote products derived from this software
    1.48 +# without specific prior written permission.
    1.49 +#
    1.50 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.51 +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.52 +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.53 +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    1.54 +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.55 +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.56 +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.57 +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    1.58 +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    1.59 +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    1.60 +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.61 +#
    1.62 +#net.fortuna.ical4j.parser=net.fortuna.ical4j.data.HCalendarParserFactory
    1.63 +
    1.64 +#net.fortuna.ical4j.timezone.registry=net.fortuna.ical4j.model.DefaultTimeZoneRegistryFactory
    1.65 +
    1.66 +#net.fortuna.ical4j.timezone.update.enabled={true|false}
    1.67 +
    1.68 +#net.fortuna.ical4j.timezone.date.floating={true|false}
    1.69 +
    1.70 +#net.fortuna.ical4j.factory.decoder=net.fortuna.ical4j.util.DefaultDecoderFactory
    1.71 +
    1.72 +#net.fortuna.ical4j.factory.encoder=net.fortuna.ical4j.util.DefaultEncoderFactory
    1.73 +
    1.74 +#net.fortuna.ical4j.recur.maxincrementcount=1000
    1.75 +
    1.76 +#ical4j.unfolding.relaxed={true|false}
    1.77 +
    1.78 +ical4j.parsing.relaxed=true
    1.79 +
    1.80 +ical4j.validation.relaxed=true
    1.81 +
    1.82 +#ical4j.compatibility.outlook={true|false}
    1.83 +
    1.84 +#ical4j.compatibility.notes={true|false}
     2.1 --- a/src/net/fortuna/ical4j/model/TimeZoneRegistryImpl.java	Tue Feb 10 19:58:00 2015 +0100
     2.2 +++ b/src/net/fortuna/ical4j/model/TimeZoneRegistryImpl.java	Tue Feb 10 21:32:00 2015 +0100
     2.3 @@ -73,14 +73,14 @@
     2.4      private static final Properties ALIASES = new Properties();
     2.5      static {
     2.6          try {
     2.7 -            ALIASES.load(ResourceLoader.getResourceAsStream("net/fortuna/ical4j/model/tz.alias"));
     2.8 +            ALIASES.load(ResourceLoader.getResourceAsStream("tz.alias"));
     2.9          }
    2.10          catch (IOException ioe) {
    2.11              LogFactory.getLog(TimeZoneRegistryImpl.class).warn(
    2.12                      "Error loading timezone aliases: " + ioe.getMessage());
    2.13          }
    2.14          try {
    2.15 -        	ALIASES.load(ResourceLoader.getResourceAsStream("tz.alias"));
    2.16 +        	ALIASES.load(ResourceLoader.getResourceAsStream("/tz.alias"));
    2.17          }
    2.18          catch (Exception e) {
    2.19          	LogFactory.getLog(TimeZoneRegistryImpl.class).debug(
     3.1 --- a/src/net/fortuna/ical4j/util/ResourceLoader.java	Tue Feb 10 19:58:00 2015 +0100
     3.2 +++ b/src/net/fortuna/ical4j/util/ResourceLoader.java	Tue Feb 10 21:32:00 2015 +0100
     3.3 @@ -54,11 +54,20 @@
     3.4  	public static URL getResource(String name) {
     3.5  		URL resource = null;
     3.6  		try {
     3.7 +			// Hack to bootstrap a multithreaded class loader context
     3.8 +			if (Thread.currentThread().getContextClassLoader() == null)
     3.9 +				Thread.currentThread().setContextClassLoader(ResourceLoader.class.getClassLoader());
    3.10  			resource = Thread.currentThread().getContextClassLoader().getResource(name);
    3.11 +
    3.12 +			if (resource == null) // Flawed build path for assets, try again
    3.13 +				resource = Thread.currentThread().getContextClassLoader().getResource("/" + name);
    3.14  		}
    3.15  		catch (SecurityException e) {
    3.16  			LOG.info("Unable to access context classloader, using default. " + e.getMessage());
    3.17  		}
    3.18 +		catch (Exception e) {
    3.19 +			LOG.info("General context classloader error, using default. " + e.getMessage());
    3.20 +		}
    3.21  		if (resource == null) {
    3.22  			resource = ResourceLoader.class.getResource("/" + name);
    3.23  		}
    3.24 @@ -74,11 +83,19 @@
    3.25  	public static InputStream getResourceAsStream(String name) {
    3.26  		InputStream stream = null;
    3.27  		try {
    3.28 +			// Hack to bootstrap a multithreaded class loader context
    3.29 +			if (Thread.currentThread().getContextClassLoader() == null)
    3.30 +				Thread.currentThread().setContextClassLoader(ResourceLoader.class.getClassLoader());
    3.31  			stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
    3.32 +			if (stream == null)
    3.33 +				stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("/" + name);
    3.34  		}
    3.35  		catch (SecurityException e) {
    3.36  			LOG.info("Unable to access context classloader, using default. " + e.getMessage());
    3.37  		}
    3.38 +		catch (Exception e) {
    3.39 +			LOG.info("General context classloader error, using default. " + e.getMessage());
    3.40 +		}
    3.41  		if (stream == null) {
    3.42  			stream = ResourceLoader.class.getResourceAsStream("/" + name);
    3.43  		}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/tz.alias	Tue Feb 10 21:32:00 2015 +0100
     4.3 @@ -0,0 +1,131 @@
     4.4 +## Unsupported timezone identifiers..
     4.5 +Etc/GMT+0=Etc/GMT
     4.6 +Etc/GMT-0=Etc/GMT
     4.7 +Etc/GMT0=Etc/GMT
     4.8 +GMT=Etc/GMT
     4.9 +
    4.10 +### Temporary hack to support above timezones..
    4.11 +Etc/GMT=Europe/London
    4.12 +Etc/Greenwich=Etc/GMT
    4.13 +Etc/UCT=Europe/London
    4.14 +Etc/UTC=Europe/London
    4.15 +Etc/Universal=Etc/UTC
    4.16 +
    4.17 +Etc/Zulu=Etc/UTC
    4.18 +
    4.19 +## Non-Oslon aliases:
    4.20 +#
    4.21 +US/Pacific-New=America/Los_Angeles
    4.22 +
    4.23 +## Update Olson backward compatibility here:
    4.24 +#
    4.25 +Africa/Asmera = Africa/Asmara
    4.26 +Africa/Timbuktu = Africa/Bamako
    4.27 +America/Argentina/ComodRivadavia = America/Argentina/Catamarca
    4.28 +America/Atka = America/Adak
    4.29 +America/Buenos_Aires = America/Argentina/Buenos_Aires
    4.30 +America/Catamarca = America/Argentina/Catamarca
    4.31 +America/Coral_Harbour = America/Atikokan
    4.32 +America/Cordoba = America/Argentina/Cordoba
    4.33 +America/Ensenada = America/Tijuana
    4.34 +America/Fort_Wayne = America/Indiana/Indianapolis
    4.35 +America/Indianapolis = America/Indiana/Indianapolis
    4.36 +America/Jujuy = America/Argentina/Jujuy
    4.37 +America/Knox_IN = America/Indiana/Knox
    4.38 +America/Louisville = America/Kentucky/Louisville
    4.39 +America/Mendoza = America/Argentina/Mendoza
    4.40 +America/Porto_Acre = America/Rio_Branco
    4.41 +America/Rosario = America/Argentina/Cordoba
    4.42 +America/Virgin = America/St_Thomas
    4.43 +Asia/Ashkhabad = Asia/Ashgabat
    4.44 +Asia/Chungking = Asia/Chongqing
    4.45 +Asia/Dacca = Asia/Dhaka
    4.46 +Asia/Katmandu = Asia/Kathmandu
    4.47 +Asia/Calcutta = Asia/Kolkata
    4.48 +Asia/Macao = Asia/Macau
    4.49 +Asia/Tel_Aviv = Asia/Jerusalem
    4.50 +Asia/Saigon = Asia/Ho_Chi_Minh
    4.51 +Asia/Thimbu = Asia/Thimphu
    4.52 +Asia/Ujung_Pandang = Asia/Makassar
    4.53 +Asia/Ulan_Bator = Asia/Ulaanbaatar
    4.54 +Atlantic/Faeroe = Atlantic/Faroe
    4.55 +Atlantic/Jan_Mayen = Europe/Oslo
    4.56 +Australia/ACT = Australia/Sydney
    4.57 +Australia/Canberra = Australia/Sydney
    4.58 +Australia/LHI = Australia/Lord_Howe
    4.59 +Australia/NSW = Australia/Sydney
    4.60 +Australia/North = Australia/Darwin
    4.61 +Australia/Queensland = Australia/Brisbane
    4.62 +Australia/South = Australia/Adelaide
    4.63 +Australia/Tasmania = Australia/Hobart
    4.64 +Australia/Victoria = Australia/Melbourne
    4.65 +Australia/West = Australia/Perth
    4.66 +Australia/Yancowinna = Australia/Broken_Hill
    4.67 +Brazil/Acre = America/Rio_Branco
    4.68 +Brazil/DeNoronha = America/Noronha
    4.69 +Brazil/East = America/Sao_Paulo
    4.70 +Brazil/West = America/Manaus
    4.71 +Canada/Atlantic = America/Halifax
    4.72 +Canada/Central = America/Winnipeg
    4.73 +Canada/East-Saskatchewan = America/Regina
    4.74 +Canada/Eastern = America/Toronto
    4.75 +Canada/Mountain = America/Edmonton
    4.76 +Canada/Newfoundland = America/St_Johns
    4.77 +Canada/Pacific = America/Vancouver
    4.78 +Canada/Saskatchewan = America/Regina
    4.79 +Canada/Yukon = America/Whitehorse
    4.80 +Chile/Continental = America/Santiago
    4.81 +Chile/EasterIsland = Pacific/Easter
    4.82 +Cuba = America/Havana
    4.83 +Egypt = Africa/Cairo
    4.84 +Eire = Europe/Dublin
    4.85 +Europe/Belfast = Europe/London
    4.86 +Europe/Tiraspol = Europe/Chisinau
    4.87 +GB = Europe/London
    4.88 +GB-Eire = Europe/London
    4.89 +GMT+0 = Etc/GMT
    4.90 +GMT-0 = Etc/GMT
    4.91 +GMT0 = Etc/GMT
    4.92 +Greenwich = Etc/GMT
    4.93 +Hongkong = Asia/Hong_Kong
    4.94 +Iceland = Atlantic/Reykjavik
    4.95 +Iran = Asia/Tehran
    4.96 +Israel = Asia/Jerusalem
    4.97 +Jamaica = America/Jamaica
    4.98 +Japan = Asia/Tokyo
    4.99 +Kwajalein = Pacific/Kwajalein
   4.100 +Libya = Africa/Tripoli
   4.101 +Mexico/BajaNorte = America/Tijuana
   4.102 +Mexico/BajaSur = America/Mazatlan
   4.103 +Mexico/General = America/Mexico_City
   4.104 +NZ = Pacific/Auckland
   4.105 +NZ-CHAT = Pacific/Chatham
   4.106 +Navajo = America/Denver
   4.107 +PRC = Asia/Shanghai
   4.108 +Pacific/Samoa = Pacific/Pago_Pago
   4.109 +Pacific/Yap = Pacific/Chuuk
   4.110 +Pacific/Truk = Pacific/Chuuk
   4.111 +Pacific/Ponape = Pacific/Pohnpei
   4.112 +Poland = Europe/Warsaw
   4.113 +Portugal = Europe/Lisbon
   4.114 +ROC = Asia/Taipei
   4.115 +ROK = Asia/Seoul
   4.116 +Singapore = Asia/Singapore
   4.117 +Turkey = Europe/Istanbul
   4.118 +UCT = Etc/UCT
   4.119 +US/Alaska = America/Anchorage
   4.120 +US/Aleutian = America/Adak
   4.121 +US/Arizona = America/Phoenix
   4.122 +US/Central = America/Chicago
   4.123 +US/East-Indiana = America/Indiana/Indianapolis
   4.124 +US/Eastern = America/New_York
   4.125 +US/Hawaii = Pacific/Honolulu
   4.126 +US/Indiana-Starke = America/Indiana/Knox
   4.127 +US/Michigan = America/Detroit
   4.128 +US/Mountain = America/Denver
   4.129 +US/Pacific = America/Los_Angeles
   4.130 +US/Samoa = Pacific/Pago_Pago
   4.131 +UTC = Etc/UTC
   4.132 +Universal = Etc/UTC
   4.133 +W-SU = Europe/Moscow
   4.134 +Zulu = Etc/UTC

mercurial