Repository: any23 Updated Branches: refs/heads/master 19d85f2fc -> 9d8b1d1e8
Improve handling of external or unrecognized ICAL timezones Project: http://git-wip-us.apache.org/repos/asf/any23/repo Commit: http://git-wip-us.apache.org/repos/asf/any23/commit/9d8b1d1e Tree: http://git-wip-us.apache.org/repos/asf/any23/tree/9d8b1d1e Diff: http://git-wip-us.apache.org/repos/asf/any23/diff/9d8b1d1e Branch: refs/heads/master Commit: 9d8b1d1e8159e7a9bfe174c686022a8ccfb6a3ad Parents: 19d85f2 Author: Hans <[email protected]> Authored: Tue Aug 28 21:28:55 2018 -0500 Committer: Hans <[email protected]> Committed: Tue Aug 28 21:28:55 2018 -0500 ---------------------------------------------------------------------- .../calendar/BaseCalendarExtractor.java | 36 +++++++++---- .../extractor/calendar/ICalExtractorTest.java | 10 ++++ .../example2-bad-timezone-expected.nquads | 55 ++++++++++++++++++++ .../calendar.text/example2-bad-timezone.ics | 34 ++++++++++++ .../example2-external-timezone-expected.nquads | 55 ++++++++++++++++++++ .../example2-external-timezone.ics | 34 ++++++++++++ 6 files changed, 213 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/any23/blob/9d8b1d1e/core/src/main/java/org/apache/any23/extractor/calendar/BaseCalendarExtractor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/any23/extractor/calendar/BaseCalendarExtractor.java b/core/src/main/java/org/apache/any23/extractor/calendar/BaseCalendarExtractor.java index 258006f..32538da 100644 --- a/core/src/main/java/org/apache/any23/extractor/calendar/BaseCalendarExtractor.java +++ b/core/src/main/java/org/apache/any23/extractor/calendar/BaseCalendarExtractor.java @@ -61,7 +61,6 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.math.BigDecimal; import java.math.BigInteger; -import java.time.ZoneOffset; import java.util.Collection; import java.util.List; import java.util.Locale; @@ -383,15 +382,17 @@ abstract class BaseCalendarExtractor implements Extractor.ContentExtractor { return false; } - private static TimeZone getTimeZone(ICalProperty prop, TimezoneInfo info) { - if (info.isFloating(prop)) { - return null; - } - TimezoneAssignment assignment = info.getTimezoneToWriteIn(prop); - if (assignment == null) { - return TimeZone.getTimeZone(ZoneOffset.UTC); - } else { - return assignment.getTimeZone(); + private static TimeZone parseTimeZoneId(String tzId) { + for (;;) { + TimeZone zone = ICalDateFormat.parseTimeZoneId(tzId); + if (zone != null) { + return zone; + } + int ind = tzId.indexOf('/'); + if (ind == -1) { + return null; + } + tzId = tzId.substring(ind + 1); } } @@ -462,7 +463,20 @@ abstract class BaseCalendarExtractor implements Extractor.ContentExtractor { IRI value = f.createIRI("geo:" + str(g.getLatitude()) + "," + str(g.getLongitude())); result.writeTriple(subject, predicate, value); } else { - TimeZone timeZone = getTimeZone(prop, ctx.getTimezoneInfo()); + + String tzId = params.getTimezoneId(); + TimeZone timeZone = null; + if (tzId != null) { + TimezoneInfo tzInfo = ctx.getTimezoneInfo(); + TimezoneAssignment assign = tzInfo.getTimezone(prop); + if (assign != null) { + timeZone = assign.getTimeZone(); + } else { + timeZone = parseTimeZoneId(tzId); + tzInfo.setFloating(prop, true); + } + } + IRI dataTypeIRI = dataType(dataType); JCalValue jsonVal = scribe.writeJson(prop, ctx); http://git-wip-us.apache.org/repos/asf/any23/blob/9d8b1d1e/core/src/test/java/org/apache/any23/extractor/calendar/ICalExtractorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/any23/extractor/calendar/ICalExtractorTest.java b/core/src/test/java/org/apache/any23/extractor/calendar/ICalExtractorTest.java index 9000d64..92120a0 100644 --- a/core/src/test/java/org/apache/any23/extractor/calendar/ICalExtractorTest.java +++ b/core/src/test/java/org/apache/any23/extractor/calendar/ICalExtractorTest.java @@ -45,6 +45,16 @@ public class ICalExtractorTest extends BaseCalendarExtractorTest { } @Test + public void testBadTimezone() throws IOException { + extractAndVerifyAgainstNQuads("example2-bad-timezone.ics", "example2-bad-timezone-expected.nquads"); + } + + @Test + public void testExternalTimezone() throws IOException { + extractAndVerifyAgainstNQuads("example2-external-timezone.ics", "example2-external-timezone-expected.nquads"); + } + + @Test public void testRFC5545example3() throws IOException { extractAndVerifyAgainstNQuads("rfc5545-example3.ics", "rfc5545-example3-expected.nquads"); } http://git-wip-us.apache.org/repos/asf/any23/blob/9d8b1d1e/test-resources/src/test/resources/calendar.text/example2-bad-timezone-expected.nquads ---------------------------------------------------------------------- diff --git a/test-resources/src/test/resources/calendar.text/example2-bad-timezone-expected.nquads b/test-resources/src/test/resources/calendar.text/example2-bad-timezone-expected.nquads new file mode 100644 index 0000000..e55ed53 --- /dev/null +++ b/test-resources/src/test/resources/calendar.text/example2-bad-timezone-expected.nquads @@ -0,0 +1,55 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +_:node1clu1u3ipx2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/12/cal/icaltzd#Vcalendar> <http://bob.example.com/> . +_:node1clu1u3ipx2 <http://www.w3.org/2002/12/cal/icaltzd#prodid> "-//RDU Software//NONSGML HandCal//EN" <http://bob.example.com/> . +_:node1clu1u3ipx2 <http://www.w3.org/2002/12/cal/icaltzd#component> _:node1clu1u3ipx3 <http://bob.example.com/> . +_:node1clu1u3ipx3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/12/cal/icaltzd#Vtimezone> <http://bob.example.com/> . +_:node1clu1u3ipx3 <http://www.w3.org/2002/12/cal/icaltzd#tzid> "America/New_York" <http://bob.example.com/> . +_:node1clu1u3ipx3 <http://www.w3.org/2002/12/cal/icaltzd#standard> _:node1clu1u3ipx4 <http://bob.example.com/> . +_:node1clu1u3ipx4 <http://www.w3.org/2002/12/cal/icaltzd#dtstart> "1998-10-25T02:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx4 <http://www.w3.org/2002/12/cal/icaltzd#tzoffsetfrom> "-04:00" <http://bob.example.com/> . +_:node1clu1u3ipx4 <http://www.w3.org/2002/12/cal/icaltzd#tzoffsetto> "-05:00" <http://bob.example.com/> . +_:node1clu1u3ipx4 <http://www.w3.org/2002/12/cal/icaltzd#tzname> "EST" <http://bob.example.com/> . +_:node1clu1u3ipx3 <http://www.w3.org/2002/12/cal/icaltzd#daylight> _:node1clu1u3ipx5 <http://bob.example.com/> . +_:node1clu1u3ipx5 <http://www.w3.org/2002/12/cal/icaltzd#dtstart> "1999-04-04T02:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx5 <http://www.w3.org/2002/12/cal/icaltzd#tzoffsetfrom> "-05:00" <http://bob.example.com/> . +_:node1clu1u3ipx5 <http://www.w3.org/2002/12/cal/icaltzd#tzoffsetto> "-04:00" <http://bob.example.com/> . +_:node1clu1u3ipx5 <http://www.w3.org/2002/12/cal/icaltzd#tzname> "EDT" <http://bob.example.com/> . +_:node1clu1u3ipx2 <http://www.w3.org/2002/12/cal/icaltzd#component> _:node1clu1u3ipx6 <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/12/cal/icaltzd#Vevent> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#dtstamp> "1998-03-09T23:10:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#uid> "guid-1.example.com" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#organizer> <mailto:[email protected]> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#attendee> _:node1clu1u3ipx7 <http://bob.example.com/> . +_:node1clu1u3ipx7 <http://www.w3.org/2002/12/cal/icaltzd#cutype> "GROUP" <http://bob.example.com/> . +_:node1clu1u3ipx7 <http://www.w3.org/2002/12/cal/icaltzd#rsvp> "TRUE" <http://bob.example.com/> . +_:node1clu1u3ipx7 <http://www.w3.org/2002/12/cal/icaltzd#role> "REQ-PARTICIPANT" <http://bob.example.com/> . +_:node1clu1u3ipx7 <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> <mailto:[email protected]> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#description> "Project XYZ Review Meeting" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#categories> "MEETING" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#class> "PUBLIC" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#created> "1998-03-09T13:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#summary> "XYZ Project Review" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#dtstart> _:node1clu1u3ipx8 <http://bob.example.com/> . +_:node1clu1u3ipx8 <http://www.w3.org/2002/12/cal/icaltzd#tzid> "America/New_Yor" <http://bob.example.com/> . +_:node1clu1u3ipx8 <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> "1998-03-12T08:30:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#dtend> _:node1clu1u3ipx9 <http://bob.example.com/> . +_:node1clu1u3ipx9 <http://www.w3.org/2002/12/cal/icaltzd#tzid> "America/New_Yor" <http://bob.example.com/> . +_:node1clu1u3ipx9 <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> "1998-03-12T09:30:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#location> "1CP Conference Room 4350" <http://bob.example.com/> . + http://git-wip-us.apache.org/repos/asf/any23/blob/9d8b1d1e/test-resources/src/test/resources/calendar.text/example2-bad-timezone.ics ---------------------------------------------------------------------- diff --git a/test-resources/src/test/resources/calendar.text/example2-bad-timezone.ics b/test-resources/src/test/resources/calendar.text/example2-bad-timezone.ics new file mode 100755 index 0000000..2e1e62a --- /dev/null +++ b/test-resources/src/test/resources/calendar.text/example2-bad-timezone.ics @@ -0,0 +1,34 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//RDU Software//NONSGML HandCal//EN +BEGIN:VTIMEZONE +TZID:America/New_York +BEGIN:STANDARD +DTSTART:19981025T020000 +TZOFFSETFROM:-0400 +TZOFFSETTO:-0500 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19990404T020000 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0400 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +DTSTAMP:19980309T231000Z +UID:guid-1.example.com +ORGANIZER:mailto:[email protected] +ATTENDEE;CUTYPE=GROUP;RSVP=TRUE;ROLE=REQ-PARTICIPANT: + mailto:[email protected] +DESCRIPTION:Project XYZ Review Meeting +CATEGORIES:MEETING +CLASS:PUBLIC +CREATED:19980309T130000Z +SUMMARY:XYZ Project Review +DTSTART;TZID=America/New_Yor:19980312T083000 +DTEND;TZID=America/New_Yor:19980312T093000 +LOCATION:1CP Conference Room 4350 +END:VEVENT +END:VCALENDAR http://git-wip-us.apache.org/repos/asf/any23/blob/9d8b1d1e/test-resources/src/test/resources/calendar.text/example2-external-timezone-expected.nquads ---------------------------------------------------------------------- diff --git a/test-resources/src/test/resources/calendar.text/example2-external-timezone-expected.nquads b/test-resources/src/test/resources/calendar.text/example2-external-timezone-expected.nquads new file mode 100644 index 0000000..dee2e4b --- /dev/null +++ b/test-resources/src/test/resources/calendar.text/example2-external-timezone-expected.nquads @@ -0,0 +1,55 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +_:node1clu1u3ipx2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/12/cal/icaltzd#Vcalendar> <http://bob.example.com/> . +_:node1clu1u3ipx2 <http://www.w3.org/2002/12/cal/icaltzd#prodid> "-//RDU Software//NONSGML HandCal//EN" <http://bob.example.com/> . +_:node1clu1u3ipx2 <http://www.w3.org/2002/12/cal/icaltzd#component> _:node1clu1u3ipx3 <http://bob.example.com/> . +_:node1clu1u3ipx3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/12/cal/icaltzd#Vtimezone> <http://bob.example.com/> . +_:node1clu1u3ipx3 <http://www.w3.org/2002/12/cal/icaltzd#tzid> "America/New_York" <http://bob.example.com/> . +_:node1clu1u3ipx3 <http://www.w3.org/2002/12/cal/icaltzd#standard> _:node1clu1u3ipx4 <http://bob.example.com/> . +_:node1clu1u3ipx4 <http://www.w3.org/2002/12/cal/icaltzd#dtstart> "1998-10-25T02:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx4 <http://www.w3.org/2002/12/cal/icaltzd#tzoffsetfrom> "-02:00" <http://bob.example.com/> . +_:node1clu1u3ipx4 <http://www.w3.org/2002/12/cal/icaltzd#tzoffsetto> "-03:00" <http://bob.example.com/> . +_:node1clu1u3ipx4 <http://www.w3.org/2002/12/cal/icaltzd#tzname> "EST" <http://bob.example.com/> . +_:node1clu1u3ipx3 <http://www.w3.org/2002/12/cal/icaltzd#daylight> _:node1clu1u3ipx5 <http://bob.example.com/> . +_:node1clu1u3ipx5 <http://www.w3.org/2002/12/cal/icaltzd#dtstart> "1999-04-04T02:00:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx5 <http://www.w3.org/2002/12/cal/icaltzd#tzoffsetfrom> "-03:00" <http://bob.example.com/> . +_:node1clu1u3ipx5 <http://www.w3.org/2002/12/cal/icaltzd#tzoffsetto> "-02:00" <http://bob.example.com/> . +_:node1clu1u3ipx5 <http://www.w3.org/2002/12/cal/icaltzd#tzname> "EDT" <http://bob.example.com/> . +_:node1clu1u3ipx2 <http://www.w3.org/2002/12/cal/icaltzd#component> _:node1clu1u3ipx6 <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/12/cal/icaltzd#Vevent> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#dtstamp> "1998-03-09T23:10:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#uid> "guid-1.example.com" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#organizer> <mailto:[email protected]> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#attendee> _:node1clu1u3ipx7 <http://bob.example.com/> . +_:node1clu1u3ipx7 <http://www.w3.org/2002/12/cal/icaltzd#cutype> "GROUP" <http://bob.example.com/> . +_:node1clu1u3ipx7 <http://www.w3.org/2002/12/cal/icaltzd#rsvp> "TRUE" <http://bob.example.com/> . +_:node1clu1u3ipx7 <http://www.w3.org/2002/12/cal/icaltzd#role> "REQ-PARTICIPANT" <http://bob.example.com/> . +_:node1clu1u3ipx7 <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> <mailto:[email protected]> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#description> "Project XYZ Review Meeting" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#categories> "MEETING" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#class> "PUBLIC" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#created> "1998-03-09T13:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#summary> "XYZ Project Review" <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#dtstart> _:node1clu1u3ipx8 <http://bob.example.com/> . +_:node1clu1u3ipx8 <http://www.w3.org/2002/12/cal/icaltzd#tzid> "/softwarestudio.org/Olson_20011030_5/America/New_York" <http://bob.example.com/> . +_:node1clu1u3ipx8 <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> "1998-03-12T08:30:00-05:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#dtend> _:node1clu1u3ipx9 <http://bob.example.com/> . +_:node1clu1u3ipx9 <http://www.w3.org/2002/12/cal/icaltzd#tzid> "/America/New_York" <http://bob.example.com/> . +_:node1clu1u3ipx9 <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> "1998-03-12T09:30:00-05:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> <http://bob.example.com/> . +_:node1clu1u3ipx6 <http://www.w3.org/2002/12/cal/icaltzd#location> "1CP Conference Room 4350" <http://bob.example.com/> . + http://git-wip-us.apache.org/repos/asf/any23/blob/9d8b1d1e/test-resources/src/test/resources/calendar.text/example2-external-timezone.ics ---------------------------------------------------------------------- diff --git a/test-resources/src/test/resources/calendar.text/example2-external-timezone.ics b/test-resources/src/test/resources/calendar.text/example2-external-timezone.ics new file mode 100755 index 0000000..73e97c7 --- /dev/null +++ b/test-resources/src/test/resources/calendar.text/example2-external-timezone.ics @@ -0,0 +1,34 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//RDU Software//NONSGML HandCal//EN +BEGIN:VTIMEZONE +TZID:America/New_York +BEGIN:STANDARD +DTSTART:19981025T020000 +TZOFFSETFROM:-0200 +TZOFFSETTO:-0300 +TZNAME:EST +END:STANDARD +BEGIN:DAYLIGHT +DTSTART:19990404T020000 +TZOFFSETFROM:-0300 +TZOFFSETTO:-0200 +TZNAME:EDT +END:DAYLIGHT +END:VTIMEZONE +BEGIN:VEVENT +DTSTAMP:19980309T231000Z +UID:guid-1.example.com +ORGANIZER:mailto:[email protected] +ATTENDEE;CUTYPE=GROUP;RSVP=TRUE;ROLE=REQ-PARTICIPANT: + mailto:[email protected] +DESCRIPTION:Project XYZ Review Meeting +CATEGORIES:MEETING +CLASS:PUBLIC +CREATED:19980309T130000Z +SUMMARY:XYZ Project Review +DTSTART;TZID=/softwarestudio.org/Olson_20011030_5/America/New_York:19980312T083000 +DTEND;TZID=/America/New_York:19980312T093000 +LOCATION:1CP Conference Room 4350 +END:VEVENT +END:VCALENDAR
