Enhancements to web_util_pkg
This commit is contained in:
parent
a1afda54bc
commit
1b4c1cb0ab
@ -40,7 +40,8 @@ begin
|
||||
end get_email_domain;
|
||||
|
||||
|
||||
function get_escaped_str_with_breaks (p_string in varchar2) return varchar2
|
||||
function get_escaped_str_with_breaks (p_string in varchar2,
|
||||
p_escape_text_if_markup in boolean := true) return varchar2
|
||||
as
|
||||
l_returnvalue string_util_pkg.t_max_pl_varchar2;
|
||||
begin
|
||||
@ -54,16 +55,68 @@ begin
|
||||
Who Date Description
|
||||
------ ---------- --------------------------------
|
||||
MBR 22.02.2012 Created
|
||||
MBR 21.05.2015 Option to skip escaping if text already contains markup
|
||||
|
||||
*/
|
||||
|
||||
l_returnvalue := replace (htf.escape_sc(p_string), string_util_pkg.g_line_feed, '<br>');
|
||||
if (not p_escape_text_if_markup) and (text_contains_markup (p_string)) then
|
||||
l_returnvalue := p_string;
|
||||
else
|
||||
l_returnvalue := replace (htf.escape_sc(p_string), string_util_pkg.g_line_feed, '<br>');
|
||||
end if;
|
||||
|
||||
return l_returnvalue;
|
||||
|
||||
end get_escaped_str_with_breaks;
|
||||
|
||||
|
||||
function get_escaped_str_with_paragraph (p_string in varchar2,
|
||||
p_escape_text_if_markup in boolean := true,
|
||||
p_encode_asterisks in boolean := false,
|
||||
p_linkify_text in boolean := false) return varchar2
|
||||
as
|
||||
l_returnvalue string_util_pkg.t_max_pl_varchar2;
|
||||
begin
|
||||
|
||||
/*
|
||||
|
||||
Purpose: get escaped string with HTML paragraphs
|
||||
|
||||
Remarks:
|
||||
|
||||
Who Date Description
|
||||
------ ---------- --------------------------------
|
||||
MBR 27.10.2013 Created
|
||||
MBR 14.12.2014 Option to encode asterisks with HTML entity
|
||||
MBR 21.05.2015 Option to skip escaping if text already contains markup
|
||||
MBR 29.05.2016 Option to linkify text
|
||||
MBR 13.06.2016 Linkify: Fix for links at the end of line/paragraph
|
||||
|
||||
*/
|
||||
|
||||
if (not p_escape_text_if_markup) and (text_contains_markup (p_string)) then
|
||||
l_returnvalue := p_string;
|
||||
else
|
||||
l_returnvalue := replace (p_string, string_util_pkg.g_carriage_return, '');
|
||||
l_returnvalue := replace (htf.escape_sc (l_returnvalue), string_util_pkg.g_line_feed, '</p><p>');
|
||||
l_returnvalue := '<p>' || l_returnvalue || '</p>';
|
||||
-- remove empty paragraphs
|
||||
l_returnvalue := replace (l_returnvalue, '<p></p>', '');
|
||||
end if;
|
||||
|
||||
if p_encode_asterisks then
|
||||
l_returnvalue := replace (l_returnvalue, '*', chr(38) || 'bull;');
|
||||
end if;
|
||||
|
||||
if p_linkify_text then
|
||||
l_returnvalue := linkify_text (replace(l_returnvalue, '</p>', ' </p>'), p_attributes => 'target="_blank"');
|
||||
end if;
|
||||
|
||||
return l_returnvalue;
|
||||
|
||||
end get_escaped_str_with_paragraph;
|
||||
|
||||
|
||||
function get_local_file_url (p_file_path in varchar2) return varchar2
|
||||
as
|
||||
l_returnvalue string_util_pkg.t_max_pl_varchar2;
|
||||
@ -96,6 +149,107 @@ begin
|
||||
end get_local_file_url;
|
||||
|
||||
|
||||
function get_absolute_url (p_url in varchar2,
|
||||
p_base_url in varchar2) return varchar2
|
||||
as
|
||||
l_returnvalue string_util_pkg.t_max_pl_varchar2;
|
||||
begin
|
||||
|
||||
/*
|
||||
|
||||
Purpose: get absolute URL
|
||||
|
||||
Remarks:
|
||||
|
||||
Who Date Description
|
||||
------ ---------- --------------------------------
|
||||
MBR 17.11.2013 Created
|
||||
|
||||
*/
|
||||
|
||||
if instr(p_url, '://') > 0 then
|
||||
-- the URL already contains a protocol
|
||||
l_returnvalue := p_url;
|
||||
elsif substr(p_url, 1, 1) = '/' then
|
||||
l_returnvalue := p_base_url || p_url;
|
||||
else
|
||||
l_returnvalue := p_base_url || '/' || p_url;
|
||||
end if;
|
||||
|
||||
return l_returnvalue;
|
||||
|
||||
end get_absolute_url;
|
||||
|
||||
|
||||
function text_contains_markup (p_text in varchar2) return boolean
|
||||
as
|
||||
l_returnvalue boolean;
|
||||
begin
|
||||
|
||||
/*
|
||||
|
||||
Purpose: returns true if text contains (HTML) markup
|
||||
|
||||
Remarks:
|
||||
|
||||
Who Date Description
|
||||
------ ---------- --------------------------------
|
||||
MBR 26.02.2015 Created
|
||||
|
||||
*/
|
||||
|
||||
if p_text is null then
|
||||
l_returnvalue := false;
|
||||
else
|
||||
l_returnvalue := instr(p_text, '<') > 0;
|
||||
end if;
|
||||
|
||||
return l_returnvalue;
|
||||
|
||||
end text_contains_markup;
|
||||
|
||||
|
||||
function linkify_text (p_text in varchar2,
|
||||
p_attributes in varchar2 := null) return varchar2
|
||||
is
|
||||
l_begin_http number := 1;
|
||||
l_http_idx number := 1;
|
||||
l_http_length number := 0;
|
||||
l_returnvalue string_util_pkg.t_max_pl_varchar2;
|
||||
begin
|
||||
|
||||
/*
|
||||
|
||||
Purpose: change links in regular text into clickable links
|
||||
|
||||
Remarks: based on "wwv_flow_hot_http_links" in Apex 4.1, enhanced to handle both http and https
|
||||
|
||||
Who Date Description
|
||||
------ ---------- --------------------------------
|
||||
MBR 30.05.2013 Created
|
||||
|
||||
*/
|
||||
|
||||
loop
|
||||
|
||||
l_begin_http := regexp_instr(p_text || ' ', 'http://|https://', l_http_idx, 1, 0, 'i');
|
||||
|
||||
exit when l_begin_http = 0;
|
||||
|
||||
l_returnvalue := l_returnvalue || substr(p_text || ' ', l_http_idx, l_begin_http - l_http_idx);
|
||||
l_http_length := instr(replace(p_text,chr(10),' ') || ' ', ' ', l_begin_http) - l_begin_http;
|
||||
l_returnvalue := l_returnvalue || '<a ' || p_attributes || ' href="' || rtrim(substr(p_text || ' ', l_begin_http, l_http_length), '.') || '">' || substr(p_text || ' ', l_begin_http, l_http_length) || '</a>';
|
||||
l_http_idx := l_begin_http + l_http_length;
|
||||
|
||||
end loop;
|
||||
|
||||
l_returnvalue := l_returnvalue || substr(p_text || ' ', l_http_idx);
|
||||
|
||||
return l_returnvalue;
|
||||
|
||||
end linkify_text;
|
||||
|
||||
|
||||
end web_util_pkg;
|
||||
/
|
||||
|
||||
|
||||
@ -18,11 +18,29 @@ as
|
||||
function get_email_domain (p_email in varchar2) return varchar2;
|
||||
|
||||
-- get escaped string with HTML line breaks
|
||||
function get_escaped_str_with_breaks (p_string in varchar2) return varchar2;
|
||||
function get_escaped_str_with_breaks (p_string in varchar2,
|
||||
p_escape_text_if_markup in boolean := true) return varchar2;
|
||||
|
||||
-- get escaped string with HTML paragraphs
|
||||
function get_escaped_str_with_paragraph (p_string in varchar2,
|
||||
p_escape_text_if_markup in boolean := true,
|
||||
p_encode_asterisks in boolean := false,
|
||||
p_linkify_text in boolean := false) return varchar2;
|
||||
|
||||
-- get local file URL
|
||||
function get_local_file_url (p_file_path in varchar2) return varchar2;
|
||||
|
||||
-- get absolute URL
|
||||
function get_absolute_url (p_url in varchar2,
|
||||
p_base_url in varchar2) return varchar2;
|
||||
|
||||
-- returns true if text contains (HTML) markup
|
||||
function text_contains_markup (p_text in varchar2) return boolean;
|
||||
|
||||
-- linkify text
|
||||
function linkify_text (p_text in varchar2,
|
||||
p_attributes in varchar2 := null) return varchar2;
|
||||
|
||||
end web_util_pkg;
|
||||
/
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user