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?
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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();
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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.
FoldingWriter foldingWriter = new FoldingWriter(response.getWriter(),....;
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies