forked from mortenbra/alexandria-plsql-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicalendar_util_pkg.pkb
More file actions
executable file
·279 lines (176 loc) · 6.71 KB
/
Copy pathicalendar_util_pkg.pkb
File metadata and controls
executable file
·279 lines (176 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
create or replace package body icalendar_util_pkg
as
/*
Purpose: Package handles the iCalendar protocol (RFC 5545)
Remarks: see http://en.wikipedia.org/wiki/ICalendar and http://tools.ietf.org/html/rfc5545
Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
*/
m_protocol_version constant varchar2(3) := '2.0';
m_date_format constant varchar2(30) := 'YYYYMMDD"T"HH24MISS';
m_line_delimiter constant varchar2(2) := chr(13) || chr(10);
m_prodid varchar2(2000);
procedure set_prodid (p_prodid in varchar2)
as
begin
/*
Purpose: set prodid (company/product name)
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 07.03.2018 Created
*/
m_prodid := substr(p_prodid, 1, 2000);
end set_prodid;
function fmt_date (p_date in date) return varchar2
as
l_returnvalue string_util_pkg.t_max_db_varchar2;
begin
/*
Purpose: format date
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
*/
l_returnvalue := to_char(p_date, m_date_format);
return l_returnvalue;
end fmt_date;
function fmt_organizer (p_organizer_name in varchar2,
p_organizer_email in varchar2) return varchar2
as
l_returnvalue string_util_pkg.t_max_db_varchar2;
begin
/*
Purpose: format date
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
*/
l_returnvalue := 'CN="' || p_organizer_name || '":MAILTO:' || p_organizer_email;
return l_returnvalue;
end fmt_organizer;
function fmt_text (p_text in varchar2) return varchar2
as
l_returnvalue string_util_pkg.t_max_db_varchar2;
begin
/*
Purpose: format text
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
*/
-- TODO: "Actual line feeds in data items are encoded as a backslash followed by the letter N (the bytes 5C 6E or 5C 4E in UTF-8). "
-- TODO: Encode text according to https://tools.ietf.org/html/rfc5545#section-3.3.11
l_returnvalue := p_text;
return l_returnvalue;
end fmt_text;
function add_core_object (p_ical_body in varchar2) return varchar2
as
l_returnvalue string_util_pkg.t_max_pl_varchar2;
begin
/*
Purpose: wrap core object around iCalendar body
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
*/
l_returnvalue := 'BEGIN:VCALENDAR' || m_line_delimiter ||
'VERSION:' || m_protocol_version || m_line_delimiter ||
'PRODID:' || nvl(m_prodid, '-//My Company//NONSGML My Product//EN') || m_line_delimiter ||
p_ical_body || m_line_delimiter ||
'END:VCALENDAR';
return l_returnvalue;
end add_core_object;
function get_event_str (p_event in t_event) return varchar2
as
l_returnvalue string_util_pkg.t_max_pl_varchar2;
begin
/*
Purpose: get event string
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
*/
l_returnvalue := 'BEGIN:VEVENT' || m_line_delimiter ||
'SUMMARY:' || fmt_text(p_event.summary) || m_line_delimiter ||
'DESCRIPTION:' || fmt_text(p_event.description) || m_line_delimiter ||
'LOCATION:' || fmt_text(p_event.location) || m_line_delimiter ||
'ORGANIZER;' || fmt_organizer (p_event.organizer_name, p_event.organizer_email) || m_line_delimiter ||
'DTSTART:' || fmt_date(p_event.start_date) || m_line_delimiter ||
'DTEND:' || fmt_date(nvl(p_event.end_date, p_event.start_date)) || m_line_delimiter ||
'DTSTAMP:' || fmt_date(sysdate) || m_line_delimiter ||
'UID:' || nvl(p_event.uid, rawtohex(sys_guid()) || chr(64) || 'domain.example') || m_line_delimiter ||
'STATUS:' || nvl(p_event.status, 'CONFIRMED') || m_line_delimiter ||
'END:VEVENT';
l_returnvalue := add_core_object (l_returnvalue);
return l_returnvalue;
end get_event_str;
procedure download_event_str (p_event_str in varchar2,
p_filename in varchar2 := null)
as
l_event_str string_util_pkg.t_max_pl_varchar2;
begin
/*
Purpose: download event string
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 07.03.2018 Created
*/
owa_util.mime_header('text/calendar', false);
htp.p('Content-length: ' || length(p_event_str));
htp.p('Content-Disposition: attachment; filename="' || nvl(p_filename, 'event.ics') || '"');
owa_util.http_header_close;
htp.prn (p_event_str);
end download_event_str;
procedure download_event (p_event in t_event)
as
begin
/*
Purpose: download event
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
MBR 07.03.2018 Refactored
*/
download_event_str (p_event_str => get_event_str (p_event), p_filename => file_util_pkg.get_filename_str(p_event.summary, 'ics'));
end download_event;
function create_event (p_start_date in date,
p_end_date in date,
p_summary in varchar2,
p_description in varchar2 := null,
p_location in varchar2 := null,
p_organizer_name in varchar2 := null,
p_organizer_email in varchar2 := null,
p_status in varchar2 := null,
p_uid in varchar2 := null) return t_event
as
l_returnvalue t_event;
begin
/*
Purpose: create event
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 26.10.2012 Created
*/
l_returnvalue.start_date := p_start_date;
l_returnvalue.end_date := p_end_date;
l_returnvalue.summary := p_summary;
l_returnvalue.description := p_description;
l_returnvalue.location := p_location;
l_returnvalue.organizer_name := p_organizer_name;
l_returnvalue.organizer_email := p_organizer_email;
l_returnvalue.status := p_status;
l_returnvalue.uid := p_uid;
return l_returnvalue;
end create_event;
end icalendar_util_pkg;
/