AEM 6 - Create .ics file dynamically and store on page | Community
Skip to main content
Har_Khandelwal
Level 2
October 16, 2015
Solved

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

  • October 16, 2015
  • 5 replies
  • 3990 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

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

5 replies

smacdonald2008
Level 10
October 16, 2015

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. 

Adobe Employee
October 16, 2015

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();

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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

Har_Khandelwal
Level 2
October 16, 2015

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. 

Sham_HC
Level 10
October 16, 2015

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-useFoldingWriter.html

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