简体   繁体   English

在描述属性后尝试用换行符解析带有ical4j问题的ical文件

[英]Trying to parse ical file with ical4j problems with newlines after description property

im trying to parse the ical here: http://www.dsek.se/kalender/ical.php?person=&dsek&tlth 我正在尝试在此处解析文档: http ://www.dsek.se/kalender/ical.php?person=&dsek&tlth

with this code: 使用此代码:

URL url=new URL("http://www.dsek.se/kalender/ical.php?person=&dsek&tlth");
calendar=Calendars.load(url);

well, that is basicly the gist of the calendar code. 好吧,这基本上是日历代码的要旨。

But im getting problems, I think somehow the "DEDSCRIPTION: text" gets transformed into "DESCRIPTION: newLine text" before getting parsed and thus the parser wont work I think. 但是在遇到问题时,我认为在解析之前,“ DEDSCRIPTION:文本”会以某种方式转换为“ DESCRIPTION:newLine text”,因此解析器将无法工作。

The problem only appears on the rows where after DESCRIPTION: there is a whitespace, the rows that look like "DESCRIPTION:text" work fine. 该问题仅出现在Description:后有空格的行上,看起来像“ DESCRIPTION:text”的行可以正常工作。 I've also tested another file that don't have these newlines and that file works fine. 我还测试了另一个没有这些换行符的文件,并且该文件运行良好。

So im guessing that maybe it is some kind of character encoding problem? 因此,我猜测这可能是某种字符编码问题? that the URL object changes the encoding of the file? URL对象会更改文件的编码? the character encoding on the file is ISO-8859-15 文件上的字符编码为ISO-8859-15

Or is it just that they have written the file with newlines after "DESCRIPTION:"? 还是仅仅是他们在“ DESCRIPTION:”之后用换行符写了文件? And if that is the case how do I solve this? 如果是这种情况,我该如何解决呢? :S :S

if it matters somehow the the app is running on android :) 如果它以某种方式重要,则该应用程序在android上运行:)

The issue is that the DESCRIPTION field does not follow proper line folding. 问题在于,DESCRIPTION字段未遵循正确的行折叠。 See http://tools.ietf.org/html/rfc5545#section-3.1 参见http://tools.ietf.org/html/rfc5545#section-3.1

So wherever you have something like 所以无论你在哪里

DESCRIPTION:
some text

you should have instead 你应该有

DESCRIPTION:
 some text

(please note the space after the linefeed and before the text) or simply (请注意换行符之后和文本之前的空格)或简单地

DESCRIPTION:some text

You might be able to get away with a simple Regex to fix that. 您可能可以使用简单的Regex来解决此问题。

Then the file is also missing line folding for those DESCRIPTION that have a length greater than 75 characters. 然后,对于长度超过75个字符的那些Description,文件也缺少行折叠。 iCal4j should be fine with that. iCal4j应该可以了。

Finally, regarding the character encoding, UTF-8 is the default (other encoding are actually deprecated. see http://tools.ietf.org/html/rfc5545#section-6 ) so the Calendars.load() method just assumes UTF-8. 最后,关于字符编码,默认为UTF-8(实际上已弃用其他编码。请参见http://tools.ietf.org/html/rfc5545#section-6 ),因此Calendars.load()方法仅假设使用UTF -8。

So, you will have to 因此,您将不得不

Reader r = new InputStreamReader(url.openStream(), "ISO-8859-15");
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = builder.build(r);

Of course, the best solution would be for the authors of those ics files to fix those issues (line folding AND content encoding) on their side. 当然,最好的解决方案是让这些ics文件的作者解决这些问题(行折叠内容编码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM