DBA Data[Home] [Help]

PACKAGE BODY: APPS.WF_CORE

Source


1 PACKAGE BODY wf_core AS
2 /* $Header: wfcoreb.pls 120.12.12010000.2 2008/12/04 00:20:33 alepe ship $ */
3 
4 --
5 -- Token List
6 --
7 TYPE TokenNameTyp IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
8 TYPE TokenValueTyp IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER;
9 TYPE number_array IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
10 
11 token_name_arr     TokenNameTyp;
12 token_value_arr    TokenValueTyp;
13 token_counter      pls_integer := 0;
14 
15 -- State globals for random number generator
16 random_state       number_array;
17 random_length      number;
18 random_tap         number;
19 random_ab_rand     number_array;
20 random_ab_poly     number_array;
21 random_index_next  number;
22 random_modulus     number;
23 random_seeded      boolean;
24 
25  gwf_nls_date_format        varchar2(64) := null;
26  gwf_nls_date_language      varchar2(64) := null;
27  gwf_nls_language           varchar2(64) := null;
28  gwf_nls_territory          varchar2(64) := null;
29  gwf_nls_calendar           varchar2(64) := null;
30  gwf_nls_sort               varchar2(64) := null;
31  gwf_nls_currency           varchar2(64) := null;
32  gwf_nls_numeric_characters varchar2(64) := null;
33 
34 -- HashKey
35 --   Generate the Hash Key for a string
36 FUNCTION HashKey (p_HashString in varchar2) return number is
37 
38  l_hashKey        number;
39 
40 BEGIN
41 
42      return(dbms_utility.get_hash_value(p_HashString, HashBase,
43                                               HashSize));
44 
45 END;
46 
47 --
48 -- Clear
49 --   Clear the error buffers.
50 -- EXCEPTIONS
51 --   none
52 --
53 procedure Clear is
54 begin
55   wf_core.error_name := '';
56   wf_core.error_number := '';
57   wf_core.error_message := '';
58   wf_core.error_stack := '';
59   token_counter := 0;
60 end Clear;
61 
62 --
63 -- Get_Error
64 --   Return current error info and clear error stack.
65 --   Returns null if no current error.
66 --
67 -- IN
68 --   maxErrStackLength - Maximum length of error_stack to return - number
69 --
70 -- OUT
71 --   error_name - error name - varchar2(30)
72 --   error_message - substituted error message - varchar2(2000)
73 --   error_stack - error call stack, truncated if needed  - varchar2(2000)
74 -- EXCEPTIONS
75 --   none
76 --
77 procedure Get_Error(err_name out nocopy varchar2,
78                     err_message out nocopy varchar2,
79                     err_stack out nocopy varchar2,
80                     maxErrStackLength in number )
81 is
82 begin
83   err_name := wf_core.error_name;
84   err_message := wf_core.error_message;
85   err_stack := substrb(wf_core.error_stack, 1, maxErrStackLength);
86   wf_core.clear;
87 end Get_Error;
88 
89 --
90 -- Token
91 --   define error token
92 -- IN
93 --   token_name  - name of token
94 --   token_value - token value
95 -- EXCEPTIONS
96 --   none
97 --
98 procedure Token(token_name  in varchar2,
99                 token_value in varchar2) is
100 begin
101     token_name_arr(token_counter) := token_name;
102     token_value_arr(token_counter) := token_value;
103     token_counter := token_counter + 1;
104     token_name_arr(token_counter) := '';
105     token_value_arr(token_counter) := '';
106 end Token;
107 
108 --
109 -- Substitute
110 --   Return substituted message string, with exception if not found.
111 -- IN
112 --   mtype - message type (WFERR, WFTKN, etc)
113 --   mname - message internal name
114 -- EXCEPTIONS
115 --   Raises an exception if message is not found.
116 --
117 function Substitute(mtype in varchar2, mname in varchar2)
118 return varchar2
119 is
120     mesg_text varchar2(2000);        -- the message text
121     tk varchar2(30);                 -- token name
122     i pls_integer;                   -- the counter for the token table
123 
124 begin
125     -- Get error message and number
126     begin
127       SELECT TEXT INTO mesg_text
128       FROM WF_RESOURCES
129       WHERE TYPE = mtype
130       and NAME = mname
131       and LANGUAGE = userenv('LANG');
132     exception
133       when NO_DATA_FOUND then
134         wf_core.token('NAME', mname);
135         wf_core.token('TYPE', mtype);
136         wf_core.raise('WFCORE_NO_MESSAGE');
137     end;
138 
139     -- Substitute tokens in message
140     i := 0;
141     while (i < token_counter) loop
142 
143       if (instr(mesg_text, '&'||token_name_arr(i), 1, 1) <> 0) then
144         mesg_text := substrb(replace(mesg_text, '&'||token_name_arr(i),
145                              token_value_arr(i)), 1, 2000);
146       end if;
147 
148       i := i + 1;
149     end loop;
150 
151     -- Clear the token table
152     token_counter := 0;
153 
154     return mesg_text;
155 exception
156     when OTHERS then
157       raise;
158 end Substitute;
159 
160 --
161 -- Get_Message (PRIVATE)
162 --   Get a susbstituted message string.
163 -- IN
164 --   msgtype - message type (WFERROR, WFTKN, etc)
165 --   msgname - message name
166 -- RETURNS
167 --   Substituted message string
168 -- EXCEPTIONS
169 --   Never raises an exception.  Return unsusbstituted name if any
170 --   errors.
171 --
172 function Get_Message(
173   msgtype in varchar2,
174   msgname in varchar2)
175 return varchar2
176 is
177   buf varchar2(2000);
178   i pls_integer;
179 begin
180   /* mjc
181   ** WF_VERSION, WF_SYSTEM_GUID, WF_SYSTEM STATUS should
182   ** not vary by language, and should not have been stored
183   ** in wf_resources. If the NLS_LANG is not set to US,
184   ** then these values cannot be retrieved and the Event
185   ** System will error. To makes sure that the Event System
186   ** does not fail, we are including a check here so that
187   ** we always get these values from the US language.
188   ** One day we will move these values somewhere else....
189   ** (I bet you have heard that one before, right?)
190   */
191 
192   -- Get error message and number
193   begin
194       if msgname in ('WF_VERSION','WF_SYSTEM_GUID',
195 	  'WF_SYSTEM_STATUS','WF_SCHEMA','SVC_ENABLED_FLAG',
196           'WFBES_MAX_CACHE_SIZE') then
197 
198         select TEXT
199           into buf
200           from WF_RESOURCES
201          where TYPE = Get_Message.msgtype
202            and NAME = Get_Message.msgname
203            and LANGUAGE = 'US';
204 
205       else
206 
207         select TEXT
208           into buf
209           from WF_RESOURCES
210          where TYPE = Get_Message.msgtype
211            and NAME = Get_Message.msgname
212            and LANGUAGE = userenv('LANG');
213 
214       end if;
215 
216   exception
217       when NO_DATA_FOUND then
218         buf := '[' || msgname || ']';
219   end;
220 
221     -- Substitute tokens in error message
222   i := 0;
223   while (i < token_counter) loop
224 
225     if (instr(buf, '&'||token_name_arr(i), 1, 1) = 0) then
226       -- Token does not appear in message, tack it on to end
227       buf := substrb(buf||' '||token_name_arr(i)||'='||token_value_arr(i),
228                      1, 2000);
229     else
230       buf := substrb(replace(buf, '&'||token_name_arr(i), token_value_arr(i)),
231                      1, 2000);
232     end if;
233     i := i + 1;
234   end loop;
235 
236   -- Clear the token table
237   token_counter := 0;
238 
239   return(buf);
240 exception
241   when others then
242     return(msgname);
243 end Get_Message;
244 
245 --
246 -- Translate
247 --   Translate a string value
248 -- IN
249 --   tkn_name - String token name
250 -- RETURNS
251 --   Translated value of string token
252 --
253 function Translate (tkn_name in varchar2)
254 return varchar2
255 is
256 l_translated_string  VARCHAR2(4000);
257 begin
258 
259   l_translated_string := wf_core.get_message('WFTKN', tkn_name);
260 
261   return (l_translated_string);
262 
263 exception
264   when others then
265     -- Return untranslated token name if any error.
266     return(tkn_name);
267 end Translate;
268 
269 --
270 -- Raise
271 --   Raise an exception to the caller
272 -- IN
273 --   error_name - error name (internal name)
274 -- EXCEPTIONS
275 --   Raises an a user-defined (20002) exception with the error message.
276 --
277 procedure Raise(name in varchar2)
278 is
279 begin
280   -- Set error name
281   wf_core.error_name := name;
282 
283   -- Get substituted message
284   wf_core.error_message := Wf_Core.Get_Message('WFERR', name);
285 
286   -- Select error number
287   begin
288     SELECT ID
289     INTO wf_core.error_number
290     FROM WF_RESOURCES
291     WHERE TYPE = 'WFERR'
292     and NAME = Raise.name
293     and LANGUAGE = userenv('LANG');
294   exception
295     when NO_DATA_FOUND then
296       wf_core.error_number := '';
297   end;
298 
299   -- Prepend error number to message if available
300   if (wf_core.error_number is not null) then
301     wf_core.error_message := substrb(to_char(wf_core.error_number)||
302                                      ': '||wf_core.error_message, 1, 2000);
303   end if;
304 
305   -- Raise the error
306   raise_application_error(-20002, wf_core.error_message);
307 exception
308   when others then
309     raise;
310 end Raise;
311 
312 --
313 -- Context
314 --   set procedure context (for stack trace)
315 -- IN
316 --   pkg_name   - package name
317 --   proc_name  - procedure/function name
318 --   arg1       - first IN argument
319 --   argn       - n'th IN argument
320 -- EXCEPTIONS
321 --   none
322 --
323 procedure Context(pkg_name  in varchar2,
324                   proc_name in varchar2,
325                   arg1      in varchar2 ,
326                   arg2      in varchar2 ,
327                   arg3      in varchar2 ,
328                   arg4      in varchar2 ,
329                   arg5      in varchar2 ,
330                   arg6      in varchar2 ,
331                   arg7      in varchar2 ,
332                   arg8      in varchar2 ,
333                   arg9      in varchar2 ,
334                   arg10     in varchar2 ) is
335 
336     buf varchar2(32000);
337 begin
338     -- Start with package and proc name.
339     buf := wf_core.newline||pkg_name||'.'||proc_name||'(';
340 
341     -- Add all defined args.
342     if (arg1 <> '*none*') then
343       buf := substrb(buf||arg1, 1, 32000);
344     end if;
345     if (arg2 <> '*none*') then
346       buf := substrb(buf||', '||arg2, 1, 32000);
347     end if;
348     if (arg3 <> '*none*') then
349       buf := substrb(buf||', '||arg3, 1, 32000);
350     end if;
351     if (arg4 <> '*none*') then
352       buf := substrb(buf||', '||arg4, 1, 32000);
353     end if;
354     if (arg5 <> '*none*') then
355       buf := substrb(buf||', '||arg5, 1, 32000);
356     end if;
357     if (arg6 <> '*none*') then
358       buf := substrb(buf||',' ||arg6, 1, 32000);
359     end if;
360     if (arg7 <> '*none*') then
361       buf := substrb(buf||', '||arg7, 1, 32000);
362     end if;
363     if (arg8 <> '*none*') then
364       buf := substrb(buf||', '||arg8, 1, 32000);
365     end if;
366     if (arg9 <> '*none*') then
367       buf := substrb(buf||', '||arg9, 1, 32000);
368     end if;
369     if (arg10 <> '*none*') then
370       buf := substrb(buf||', '||arg10, 1, 32000);
371     end if;
372 
373     buf := substrb(buf||')', 1, 32000);
374 
375     -- Concatenate to the error_stack buffer
376     wf_core.error_stack := substrb(wf_core.error_stack||buf, 1, 32000);
377 
378 end Context;
379 
380 -- *** RANDOM ***
381 -- Implements a pseudo-random number generator using the additive linear
382 -- feedback algorithm.  Numbers are generateed according to the rule:
383 --    X[i] = X[i - a] + X[i - b]
384 --    where a and b are constant "taps".
385 
386 --
387 -- Random_init_arrays (PRIVATE)
388 --   Initialize random number generator
389 --
390 procedure random_init_arrays is
391 begin
392     random_ab_rand(1) := 3614090360;
393     random_ab_rand(2) := 3905402710;
394     random_ab_rand(3) := 606105819;
395     random_ab_rand(4) := 3250441966;
396     random_ab_rand(5) := 4118548399;
397     random_ab_rand(6) := 1200080426;
398     random_ab_rand(7) := 2821735955;
399     random_ab_rand(8) := 4249261313;
400     random_ab_rand(9) := 1770035416;
401     random_ab_rand(10) := 2336552879;
402     random_ab_rand(11) := 4294925233;
403     random_ab_rand(12) := 2304563134;
404     random_ab_rand(13) := 1804603682;
405     random_ab_rand(14) := 4254626195;
406     random_ab_rand(15) := 2792965006;
407     random_ab_rand(16) := 1236535329;
408     random_ab_rand(17) := 4129170786;
409     random_ab_rand(18) := 3225465664;
410     random_ab_rand(19) := 643717713;
411     random_ab_rand(20) := 3921069994;
412     random_ab_rand(21) := 3593408605;
413     random_ab_rand(22) := 38016083;
414     random_ab_rand(23) := 3634488961;
415     random_ab_rand(24) := 3889429448;
416     random_ab_rand(25) := 568446438;
417     random_ab_rand(26) := 3275163606;
418     random_ab_rand(27) := 4107603335;
419     random_ab_rand(28) := 1163531501;
420     random_ab_rand(29) := 2850285829;
421     random_ab_rand(30) := 4243563512;
422     random_ab_rand(31) := 1735328473;
423     random_ab_rand(32) := 2368359562;
424     random_ab_rand(33) := 4294588738;
425     random_ab_rand(34) := 2272392833;
426     random_ab_rand(35) := 1839030562;
427     random_ab_rand(36) := 4259657740;
428     random_ab_rand(37) := 2763975236;
429     random_ab_rand(38) := 1272893353;
430     random_ab_rand(39) := 4139469664;
431     random_ab_rand(40) := 3200236656;
432     random_ab_rand(41) := 681279174;
433     random_ab_rand(42) := 3936430074;
434     random_ab_rand(43) := 3572445317;
435     random_ab_rand(44) := 76029189;
436     random_ab_rand(45) := 3654602809;
437     random_ab_rand(46) := 3873151461;
438     random_ab_rand(47) := 530742520;
439     random_ab_rand(48) := 3299628645;
440     random_ab_rand(49) := 4096336452;
441     random_ab_rand(50) := 1126891415;
442     random_ab_rand(51) := 2878612391;
443     random_ab_rand(52) := 4237533241;
444     random_ab_rand(53) := 1700485571;
445     random_ab_rand(54) := 2399980690;
446     random_ab_rand(55) := 4293915773;
447     random_ab_rand(56) := 2240044497;
448     random_ab_rand(57) := 1873313359;
449     random_ab_rand(58) := 4264355552;
450     random_ab_rand(59) := 2734768916;
451     random_ab_rand(60) := 1309151649;
452     random_ab_rand(61) := 4149444226;
453     random_ab_rand(62) := 3174756917;
454     random_ab_rand(63) := 718787259;
455     random_ab_rand(64) := 3951481745;
456 
457     random_ab_poly(1) := 0;
458     random_ab_poly(2) := 0;
459     random_ab_poly(3) := 1;
460     random_ab_poly(4) := 1;
461     random_ab_poly(5) := 1;
462     random_ab_poly(6) := 2;
463     random_ab_poly(7) := 1;
464     random_ab_poly(8) := 1;
465     random_ab_poly(9) := 0;
466     random_ab_poly(10) := 4;
467     random_ab_poly(11) := 3;
468     random_ab_poly(12) := 2;
469     random_ab_poly(13) := 0;
470     random_ab_poly(14) := 0;
471     random_ab_poly(15) := 0;
472     random_ab_poly(16) := 1;
473     random_ab_poly(17) := 0;
474     random_ab_poly(18) := 3;
475     random_ab_poly(19) := 7;
476     random_ab_poly(20) := 0;
477     random_ab_poly(21) := 3;
478     random_ab_poly(22) := 2;
479     random_ab_poly(23) := 1;
480     random_ab_poly(24) := 5;
481     random_ab_poly(25) := 0;
482     random_ab_poly(26) := 3;
483     random_ab_poly(27) := 0;
484     random_ab_poly(28) := 0;
485     random_ab_poly(29) := 3;
486     random_ab_poly(30) := 2;
487     random_ab_poly(31) := 0;
488     random_ab_poly(32) := 3;
489     random_ab_poly(33) := 0;
490     random_ab_poly(34) := 13;
491     random_ab_poly(35) := 0;
492     random_ab_poly(36) := 2;
493     random_ab_poly(37) := 11;
494     random_ab_poly(38) := 0;
495     random_ab_poly(39) := 0;
496     random_ab_poly(40) := 4;
497     random_ab_poly(41) := 0;
498     random_ab_poly(42) := 3;
499     random_ab_poly(43) := 0;
500     random_ab_poly(44) := 0;
501     random_ab_poly(45) := 0;
502     random_ab_poly(46) := 0;
503     random_ab_poly(47) := 0;
504     random_ab_poly(48) := 5;
505     random_ab_poly(49) := 0;
506     random_ab_poly(50) := 9;
507     random_ab_poly(51) := 0;
508     random_ab_poly(52) := 0;
509     random_ab_poly(53) := 3;
510     random_ab_poly(54) := 0;
511     random_ab_poly(55) := 0;
512     random_ab_poly(56) := 24;
513     random_ab_poly(57) := 0;
514     random_ab_poly(58) := 7;
515     random_ab_poly(59) := 19;
516     random_ab_poly(60) := 0;
517     random_ab_poly(61) := 1;
518     random_ab_poly(62) := 0;
519     random_ab_poly(63) := 0;
520     random_ab_poly(64) := 1;
521 end random_init_arrays;
522 
523 --
524 -- Random_Init (PRIVATE)
525 --   Initialize, but don't seed, the generator.  Length refers to the
526 --   amount of state in the generator; longer generators are (somewhat)
527 --   more difficult to predict.
528 --
529 procedure random_init(p_length in number)
530 is
531 begin
532     random_init_arrays;
533 
534     random_length := p_length;
535     random_tap := random_ab_poly(p_length);
536     random_modulus := power(2, 32) - 1;
537 
538     random_init_arrays;
539 
540     random_index_next := 1;
541 end random_init;
542 
543 --
544 -- Random_Seed (PRIVATE)
545 --   Seed the generator with value.  Run it through the specified number of
546 --   cycles, to ensure the seed affects all values produced (10 cycles should
547 --   be sufficient).  If generator has already been seeded, don't do it again.
548 --
549 procedure random_seed(value   in   number,
550                       cycles  in   number)
551 is
552     dummy   number;
553     modval  number;
554 begin
555     for n in 1..random_length loop
556         random_state(n) := random_ab_rand(n);
557     end loop;
558 
559     modval := mod(value, random_modulus);
560     random_state(1) := mod(random_state(1) + modval, random_modulus);
561 
562     for n in 1..(random_length * cycles) loop
563         dummy := to_number(random);
564     end loop;
565 end random_seed;
566 
567 --
568 -- RANDOM (PUBLIC)
569 --   Get the next pseudorandom string
570 -- RETURNS
571 --   Random number as a string (max length 80)
572 --
573 function random return varchar2 is
574     oldestval       number;
575     tapval          number;
576     nextval         number;
577     l_random        varchar2(80);
578 begin
579 
580     if (random_seeded is null) then
581       l_random := wfa_sec.random;
582       if (l_random is not null) then
583         random_seeded := false;
584         return(l_random);
585       end if;
586     elsif (not random_seeded) then
587       return(wfa_sec.random);
588     end if;
589 
590     -- no preferred implementation is picked
591     -- use the default one
592 
593     if NVL(random_seeded, FALSE) <> TRUE then
594         random_init(7);
595         random_seeded := true;
596         random_seed(to_number(to_char(sysdate, 'JSSSSS')), 10);
597     end if;
598 
599     oldestval := random_state(random_index_next);
600     tapval := random_state(
601                   mod(random_index_next+random_length-random_tap-1,
602                       random_length) + 1);
603     nextval := mod(oldestval + tapval, random_modulus);
604 
605     random_state(random_index_next) := nextval;
606     random_index_next := random_index_next + 1;
607     if random_index_next > random_length then
608         random_index_next := 1;
609     end if;
610     return substr(to_char(nextval), 1, 80);
611 
612 exception
613   when others then
614     return('');
615 end random;
616 
617 --
618 -- ACTIVITY_RESULT
619 --      Return the meaning of an activities result_type
620 --      Including standard engine codes
621 -- IN
622 --   LOOKUP_TYPE
623 --   LOOKUP_CODE
624 --
625 -- RETURNS
626 --   MEANING
627 --
628 function activity_result( result_type in varchar2, result_code in varchar2) return varchar2
629 is
630         l_meaning varchar2(80);
631 begin
632         begin
633                 select  meaning
634                 into    l_meaning
635                 from    wf_lookups
636                 where   lookup_type = result_type
637                 and     lookup_code = result_code;
638         exception
639                 when NO_DATA_FOUND then
640                         --
641                         -- If result_code is not in assigned type
642                         -- check standard engine result codes
643                         --
644                         select  meaning
645                         into    l_meaning
646                         from    wf_lookups
647                         where   lookup_type = 'WFENG_RESULT'
648                         and     lookup_code = result_code;
649         end;
650         --
651         return(l_meaning);
652         --
653 exception
654         --
655         -- return lookup_code if any error
656         --
657         when others then
658                 return(result_code);
659 end;
660 --
661 
662 --
663 -- GetResource
664 --   ** OBSOLETE **
665 --   Please use wf_monitor.GetResource instead.
666 --   Called by WFResourceManager.class. Used by the Monitor and Lov Applet.
667 --   fetch A resource from wf_resource table.
668 -- IN
669 -- x_restype
670 -- x_resname
671 
672 procedure GetResource(x_restype varchar2,
673                       x_resname varchar2) is
674 begin
675   null;
676 end GetResource;
677 
678 --
679 -- GetResources
680 --   ** OBSOLETE **
681 --   Please use wf_monitor.GetResources instead.
682 --   Called by WFResourceManager.class. Used by the Monitor and Lov Applet.
683 --   fetch some resources from wf_resource table that match the respattern.
684 -- IN
685 -- x_restype
686 -- x_respattern
687 
688 procedure GetResources(x_restype varchar2,
689                        x_respattern varchar2) is
690 begin
691   null;
692 end GetResources;
693 
694 -- *** Substitue HTML Characters ****
695 -- SubstituteSpecialChars
696    --   Substitutes the occurence of special characters like <, >, \, ', " etc
697    --   with their html codes in any arbitrary string.
698    -- IN
699    --   some_text - text to be substituted
700    -- RETURN
701    --   substituted text
702 
703    function SubstituteSpecialChars(some_text in varchar2)
704    return varchar2 is
705      l_amp     varchar2(1);
706      buf       varchar2(32000);
707      l_amp_flag  boolean;
708      l_lt_flag   boolean;
709      l_gt_flag   boolean;
710      l_bsl_flag  boolean;
711      l_apos_flag boolean;
712      l_quot_flag boolean;
713    begin
714      l_amp := '&';
715 
716      buf := some_text;
717 
718      -- bug 6025162 - This function should substitute only those chars that
719      -- really require substitution. Any valid occurences should be retained.
720      -- No validation should be required for calling this function
721 
722      if (instr(buf, l_amp) > 0) then
723        l_amp_flag  := false;
724        l_lt_flag   := false;
725        l_gt_flag   := false;
726        l_bsl_flag  := false;
727        l_apos_flag := false;
728        l_quot_flag := false;
729 
730        -- mask all valid ampersand containing patterns in the content
731        -- issue is when ntf body already contains of these reserved words...
732        if (instr(buf, l_amp||'amp;') > 0) then
733          buf := replace(buf, l_amp||'amp;', '#AMP#');
734          l_amp_flag := true;
735        end if;
736        if (instr(buf, l_amp||'lt;') > 0) then
737          buf := replace(buf, l_amp||'lt;', '#LT#');
738          l_lt_flag := true;
739        end if;
740        if (instr(buf, l_amp||'gt;') > 0) then
741          buf := replace(buf, l_amp||'gt;', '#GT#');
742          l_gt_flag := true;
743        end if;
744        if (instr(buf, l_amp||'#92;') > 0) then
745          buf := replace(buf, l_amp||'#92;', '#BSL#');
746          l_bsl_flag := true;
747        end if;
748        if (instr(buf, l_amp||'#39;') > 0) then
749          buf := replace(buf, l_amp||'#39;', '#APO#');
750          l_apos_flag := true;
751        end if;
752        if (instr(buf, l_amp||'quot;') > 0) then
753          buf := replace(buf, l_amp||'quot;', '#QUOT#');
754          l_quot_flag := true;
755        end if;
756 
757        buf := replace(buf, l_amp, l_amp||'amp;');
758 
759        -- put the masked valid ampersand containing patterns back
760        if (l_amp_flag) then
761          buf := replace(buf, '#AMP#', l_amp||'amp;');
762        end if;
763        if (l_lt_flag) then
764          buf := replace(buf, '#LT#', l_amp||'lt;');
765        end if;
766        if (l_gt_flag) then
767          buf := replace(buf, '#GT#', l_amp||'gt;');
768        end if;
769        if (l_bsl_flag) then
770          buf := replace(buf, '#BSL#', l_amp||'#92;');
771        end if;
772        if (l_apos_flag) then
773          buf := replace(buf, '#APO#', l_amp||'#39;');
774        end if;
775        if (l_quot_flag) then
776          buf := replace(buf, '#QUOT#', l_amp||'quot;');
777        end if;
778      end if;
779 
780      buf := replace(buf, '<', l_amp||'lt;');
781      buf := replace(buf, '>', l_amp||'gt;');
782      buf := replace(buf, '\', l_amp||'#92;');
783      buf := replace(buf, '''', l_amp||'#39;');
784      buf := replace(buf, '"', l_amp||'quot;');
785      return buf;
786    exception
787      when others then
788        raise;
789 
790    end SubstituteSpecialChars;
791 
792 -- *** Special Char functions ***
793 
794 -- Local_Chr
795 --   Return specified character in current codeset
796 -- IN
797 --   ascii_chr - chr number in US7ASCII
798 function Local_Chr(
799   ascii_chr in number)
800 return varchar2
801 is
802 begin
803 
804   return(wfa_sec.local_chr(ascii_chr));
805 
806 end Local_Chr;
807 
808 -- Newline
809 --   Return newline character in current codeset
810 function Newline
811 return varchar2
812 is
813 begin
814   return(Wf_Core.Local_Chr(10));
815 end Newline;
816 
817 -- Tab
818 --   Return tab character in current codeset
819 function Tab
820 return varchar2
821 is
822 begin
823   return(Wf_Core.Local_Chr(9));
824 end Tab;
825 
826 -- CR - CarriageReturn
827 --   Return CR character in current codeset.
828 function CR
829 return varchar2
830 is
831 begin
832   return(WF_CORE.Local_Chr(13));
833 end CR;
834 
835 --
836 -- CheckIllegalChars (PRIVATE)
837 --
838 function CheckIllegalChars(p_text varchar2, p_raise_exception boolean,p_illegal_charset varchar2)
839 return boolean
840 is
841  l_charset varchar2(20);
842  l_illegal_char varchar2(4);
843 begin
844   if p_illegal_charset is null then
845       l_charset := ';<>()"';
846   else
847       l_charset := p_illegal_charset;
848   end if;
849 
850   for i in 1..length(l_charset)
851   loop
852      l_illegal_char := substr(l_charset,i,1);
853      if (instr(p_text,l_illegal_char)>0) then
854         if (p_raise_exception) then
855            wf_core.token('TEXT', p_text);
856            wf_core.raise('WF_ILLEGAL_CHARS');
857            -- ### Illegal characters found in 'TEXT'
858         end if;
859         return true;
860      end if;
861   end loop;
862   return false;
863 end CheckIllegalChars;
864 
865 procedure InitCache
866 is
867 begin
868 
869    SELECT to_number(substr(version,1, instr(version,'.',1,1) -1))
870    INTO   g_oracle_major_version
871    FROM   v$instance;
872 
873    if (g_oracle_major_version < 10) then
874       if (g_aq_tm_processes is null) then
875          SELECT  value
876          INTO    g_aq_tm_processes
877          FROM    v$parameter
878          WHERE   name = 'aq_tm_processes';
879       end if;
880    end if;
881 
882 end InitCache;
883 
884 --============================================
885 
886 FUNCTION nls_date_format   RETURN varchar2
887 is
888 begin
889 
890   if(gwf_nls_date_format is null) then
891     gwf_nls_date_format := SYS_CONTEXT('USERENV', 'NLS_DATE_FORMAT');
892   end if;
893   RETURN  gwf_nls_date_format ;
894 
895 END nls_date_format;
896 
897 --
898 --
899 --
900 FUNCTION nls_date_language RETURN varchar2
901 is
902 begin
903   if (gwf_nls_date_language is null) then
904     gwf_nls_date_language   := SYS_CONTEXT('USERENV', 'NLS_DATE_LANGUAGE');
905   end if;
906 
907   RETURN gwf_nls_date_language;
908 END nls_date_language;
909 
910 --
911 --
912 --
913 --
914 FUNCTION nls_calendar      RETURN varchar2
915 is
916 begin
917   if(gwf_nls_calendar is null) then
918     gwf_nls_calendar  := SYS_CONTEXT('USERENV', 'NLS_CALENDAR');
919   end if;
920   RETURN gwf_nls_calendar;
921 END nls_calendar;
922 
923 --
924 --
925 --
926 --
927 FUNCTION nls_sort  RETURN varchar2
928 is
929 begin
930   if(gwf_nls_sort is null) then
931     gwf_nls_sort       := SYS_CONTEXT('USERENV', 'NLS_SORT');
932   end if;
933   RETURN gwf_nls_sort;
934 END nls_sort;
935 
936 
937 --
938 --
939 --
940 FUNCTION nls_currency      RETURN varchar2
941 is
942 begin
943 
944    if( gwf_nls_currency is null) then
945       gwf_nls_currency   := SYS_CONTEXT('USERENV', 'NLS_CURRENCY');
946    end if;
947    RETURN gwf_nls_currency;
948 
949 END nls_currency;
950 
951 --
952 --
953 --
954 --
955 FUNCTION nls_numeric_characters RETURN varchar2
956 is
957 begin
958   if (gwf_nls_numeric_characters is null) then
959     select value into gwf_nls_numeric_characters
960     from v$nls_parameters where parameter ='NLS_NUMERIC_CHARACTERS';
961   end if;
962 
963  RETURN gwf_nls_numeric_characters;
964 
965 END nls_numeric_characters;
966 
967   FUNCTION nls_language RETURN varchar2
968   is
969     l_value varchar2(64);
970     l_pos1 number;
971     l_pos2  number;
972   begin
973     if (gwf_nls_language is null) then
974       l_value := SYS_CONTEXT('USERENV', 'LANGUAGE');
975       l_pos1 := instr(l_value, '_');
976       l_pos2 := instr(l_value, '.');
977 
978       gwf_nls_language := substr(l_value, 1, l_pos1-1);
979       gwf_nls_territory := substr(l_value, l_pos1+1, l_pos2-l_pos1-1);
980     end if;
981 
982     RETURN gwf_nls_language;
983 
984   END nls_language;
985 
986   FUNCTION nls_territory RETURN varchar2
987   is
988     l_value varchar2(64);
989   begin
990     if (gwf_nls_territory is null) then
991       l_value := nls_language;  -- in  nls_language we initialize both language and territory
992     end if;
993 
994     RETURN gwf_nls_territory;
995 
996   END nls_territory;
997 
998   procedure initializeNLSDefaults is
999     l_val varchar2(64);
1000   begin
1001     l_val := nls_date_format;
1002     l_val := nls_date_language;
1003     l_val := nls_calendar;
1004     l_val := nls_sort ;
1005     l_val := nls_currency ;
1006     l_val := nls_numeric_characters ;
1007     l_val := nls_language ;
1008     l_val := nls_territory ;
1009   end ;
1010 
1011 
1012 
1013 
1014 
1015 end WF_CORE;