forked from mortenbra/alexandria-plsql-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuri_template_util_pkg.pkb
More file actions
executable file
·134 lines (84 loc) · 2.93 KB
/
Copy pathuri_template_util_pkg.pkb
File metadata and controls
executable file
·134 lines (84 loc) · 2.93 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
create or replace package body uri_template_util_pkg
as
/*
Purpose: Package handles URI templates
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 30.07.2012 Created
*/
function expand (p_template in varchar2,
p_values in t_str_array) return varchar2
as
l_returnvalue string_util_pkg.t_max_db_varchar2;
begin
/*
Purpose: expand URI based on template
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 30.07.2012 Created
*/
l_returnvalue := p_template;
if p_values.count > 0 then
for i in p_values.first .. p_values.last loop
l_returnvalue := regexp_replace (l_returnvalue, regexp_util_pkg.g_exp_curly_brackets, p_values(i), 1, 1);
end loop;
end if;
return l_returnvalue;
end expand;
function match (p_uri in varchar2,
p_templates in t_str_array) return varchar2
as
l_template string_util_pkg.t_max_db_varchar2;
l_returnvalue string_util_pkg.t_max_db_varchar2;
begin
/*
Purpose: matches actual URI with list of templates
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 30.07.2012 Created
*/
if p_templates.count > 0 then
for i in p_templates.first .. p_templates.last loop
l_template := regexp_replace(p_templates(i), regexp_util_pkg.g_exp_curly_brackets, '(.*)');
if regexp_substr(p_uri, l_template) = p_uri then
l_returnvalue := p_templates(i);
exit;
end if;
end loop;
end if;
return l_returnvalue;
end match;
function parse (p_template in varchar2,
p_uri in varchar2) return t_dictionary
as
l_template string_util_pkg.t_max_db_varchar2;
l_from pls_integer;
l_to pls_integer;
l_value string_util_pkg.t_max_db_varchar2;
l_returnvalue t_dictionary;
begin
/*
Purpose: get actual names and values
Remarks:
Who Date Description
------ ---------- --------------------------------
MBR 30.07.2012 Created
*/
l_template := p_template;
for l_rec in (select column_value as key_name from table(regexp_util_pkg.match (l_template, regexp_util_pkg.g_exp_curly_brackets))) loop
l_from := instr(l_template, l_rec.key_name);
l_to := instr(p_uri, '/', l_from + 1);
if l_to = 0 then
l_to := length(p_uri) + 1;
end if;
l_value := substr(p_uri, l_from, l_to - l_from);
l_template := replace(l_template, l_rec.key_name, l_value);
l_returnvalue(substr(l_rec.key_name, 2, length(l_rec.key_name) - 2)) := l_value;
end loop;
return l_returnvalue;
end parse;
end uri_template_util_pkg;
/