Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM 6 - Create .ics file dynamically and store on page

Avatar

Level 3

I am trying to create an ICS file everytime my page loads and store it under jcr:content of the same page.

I am using iCal4j API for creation of the ics file. 

How do I save this file under my page?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

I wouldn't do this activity on page load, but rather use sling eventing to determine any change to the page, and then recompute the ICS file. Storing it on the page node itself is likely the best, as then you don't to take care of a separate activation/deactivation/deletion.

kind regards,
Jörg

View solution in original post

5 Replies

Avatar

Level 10

You can store data anywhere in the JCR - it does not need to be under the page to access it. In your page, use JQuery $( document ).ready(). When the page loads, call a backend servlet to get this data from the JCR, return the data to the page and set the data. 

Avatar

Employee

If you are looking for code snippet, it goes like this. But keep in mind that your approach of storing a file on load(GET method) violates REST principles.

 Node folder = myResource.adaptTo(Node.class);

JcrUtils.putFile(folder, "myfile.ics", "text/plain", instream);

folder.getSession().save();

Avatar

Correct answer by
Employee Advisor

Hi,

I wouldn't do this activity on page load, but rather use sling eventing to determine any change to the page, and then recompute the ICS file. Storing it on the page node itself is likely the best, as then you don't to take care of a separate activation/deactivation/deletion.

kind regards,
Jörg

Avatar

Level 3

Thank you for the help. 

I implemented the code using a servlet. Every time the "download ics" button is clicked, the request goes to the servlet which creates the file and sends it back. I have set the following properties to the servlet response :

response.setContentType("text/calendar");
response.setHeader("Content-Disposition", "attachment; filename=event.ics");
response.setContentLength(cal.toString().length());
response.getWriter().print(cal.toString());

 

and i get the following output when i check the response in chrome/mozilla developer mode: 

BEGIN:VCALENDAR
PRODID:-//Event Calendar V1.1//EN
VERSION:2.0
CALSCALE:GREGORIAN
DESCRIPTION: Event Description
BEGIN:VEVENT
DTSTAMP:20150323T143849Z
DTSTART:20150422T093000
DTEND:20150423T190000
SUMMARY:Event Title
TZID:America/New_York
UID:20150323T143849Z-uidGen@fe80:0:0:0:0:ffff:ffff:fffe%11
END:VEVENT
END:VCALENDAR

 

But I still it does not download the ics file. 

Avatar

Level 10

I could not understand your use case why you want to store, because you might have some events not every one subscribed Or applicable to few users. So far with  implementations generally created on fly & pass in response using FoldingWriter of ical.

http://build.mnode.org/projects/ical4j/apidocs/index.html?net/fortuna/ical4j/data//class-useFoldingW...

FoldingWriter foldingWriter = new FoldingWriter(response.getWriter(),....;