Hallo Liebe Community,
da ihr mir schon des öfteren aus der Klemme helfen konntet. Hoffe ich, dass Ihr mir auch bei diesem Thema helfen könnt.
Ich versuche über eine DatenbankVorlage (HTML Kanal) eine Datei zu erstellen und als Download zurück zu geben.
Aber irgendwie will es nicht so wie es eigentlich sollte. Das habe ich bisher:
<%@ page contentType="text/calendar;charset=UTF-8" language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.servlet.http.*" %>
<%
try {
$CMS_SET(endDate, #row.EventTime + #row.Duration*60*60*24*1000)$
final StringBuilder vcr = new StringBuilder();
vcr.append("BEGIN:VCALENDAR\n");
vcr.append("METHOD:PUBLISH\n");
vcr.append("BEGIN:VEVENT\n");
vcr.append("SUMMARY:$CMS_VALUE(#row.Title)$\n");
vcr.append("LOCATION:$CMS_VALUE(#row.EventLocation)$\n");
vcr.append("DTSTART:$CMS_VALUE(#row.EventTime)$\n");
vcr.append("DTEND:$CMS_VALUE(endDate.format("dd.MM.yyyy"))$\n");
vcr.append("TRANSP:OPAQUE\n");
vcr.append("SEQUENCE:0\n");
vcr.append("DTSTAMP:20130920T082235Z\n");
vcr.append("DESCRIPTION:$CMS_VALUE(#row.Title)$\n");
vcr.append("PRIORITY:5\n");
vcr.append("X-MICROSOFT-CDO-IMPORTANCE:1\n");
vcr.append("CLASS:PUBLIC\n");
vcr.append("BEGIN:VALARM\n");
vcr.append("TRIGGER:-PT30M\n");
vcr.append("ACTION:DISPLAY\n");
vcr.append("DESCRIPTION:Reminder\n");
vcr.append("END:VALARM\n");
vcr.append("END:VEVENT\n");
vcr.append("END:VCALENDAR\n");
String vcrString = vcr.toString();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
ServletOutputStream os = response.getOutputStream();
response.setCharacterEncoding("UTF-8");
response.setHeader("X-MB-VCRLength", "" + vcrString.length());
response.setHeader("Content-Description", "Outlook vCalender Format File");
response.setHeader("Content-Type", "text/calendar");
response.setHeader("Content-Disposition", "inline; filename=$CMS_VALUE(#row.Title.replace(" ", "_"))$.ics");
InputStream in = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
byte[] outputByte = new byte[4096];
while(in.read(outputByte, 0, 4096) != -1) {
out.write(outputByte, 0, 4096);
}
in.close();
os.flush();
os.close();
} catch (Exception e) {
e.printStackTrace();
}
%>