DBA Data[Home] [Help]

PACKAGE BODY: APPS.ECX_PRINT_LOCAL

Source


1 package body ecx_print_local as
2 -- $Header: ECXLXMLB.pls 120.4.12010000.2 2008/08/22 20:00:06 cpeixoto ship $
3 
4 l_procedure          PLS_INTEGER := ecx_debug.g_procedure;
5 l_statement          PLS_INTEGER := ecx_debug.g_statement;
6 l_unexpected         PLS_INTEGER := ecx_debug.g_unexpected;
7 l_procedureEnabled   boolean     := ecx_debug.g_procedureEnabled;
8 l_statementEnabled   boolean     := ecx_debug.g_statementEnabled;
9 l_unexpectedEnabled  boolean     := ecx_debug.g_unexpectedEnabled;
10 
11 
12 -- fix for bug 6900831: max number of loops before we consider infinite loop
13 l_loop_max           PLS_INTEGER := 5;
14 
15 -- Pointer to keep track of last printed node, used for supressing empty node.
16 last_node_printed	PLS_INTEGER := 0;
17 -- Boolean value to hold profile value ECX_SUPPRESS_EMPTY_TAGS
18 suppress_profile	Boolean := false;
19 
20 /**
21 As per XML 1.0 Spec.
22 **/
23 i_amp 	varchar2(1) := '&';
24 i_lt 	varchar2(1) := '<';
25 i_gt 	varchar2(1) := '>';
26 i_apos 	varchar2(1) := '''';
27 i_quot 	varchar2(1) := '"';
28 i_xmldoc CLOB;
29 i_var_pos pls_integer;
30 /** Change required for Clob Support -- 2263729 ***/
31 g_split_threshold pls_integer := 4000;
32 
33 function  has_fragment(var_pos IN pls_integer) return boolean;
34 function has_fragment_value (var_pos IN pls_integer) return boolean;
35 procedure print_xml_fragment (var_pos IN pls_integer,
36                               print_tag IN boolean);
37 procedure append_clob is
38 
39    i_method_name   varchar2(2000) := 'ecx_print_local.append_clob';
40    i_writeamount           number;
41    i_length                number;
42    i_temp                  varchar2(32767);
43 
44 begin
45    if (l_procedureEnabled) then
46      ecx_debug.push(i_method_name);
47    end if;
48 
49    i_writeamount :=0;
50    i_length :=0;
51    i_temp:='';
52 
53    if i_xmldoc is null then
54       dbms_lob.createtemporary(i_xmldoc,TRUE,DBMS_LOB.SESSION);
55    end if;
56 
57    for i in 1..i_tmpxml.COUNT loop
58       -- check for the element length
59       i_writeamount := length(i_tmpxml(i));
60       -- set append status to true
61       -- check if temp buffer is full
62       if(i_writeamount+i_length > 10000) then
63          if(l_statementEnabled) then
64            ecx_debug.log(l_statement,'Buffer Length', to_char(i_length),i_method_name);
65 	 end if;
66          dbms_lob.writeappend(i_xmldoc,i_length, i_temp);
67          if(l_statementEnabled) then
68            ecx_debug.log(l_statement, i_temp,i_method_name);
69 	 end if;
70          i_temp:='';
71          i_length:=i_writeamount;
72          i_temp:=i_tmpxml(i);
73       else
74          i_length:=i_length+i_writeamount;
75          -- add new entry
76          i_temp:=concat(i_temp, i_tmpxml(i));
77       end if;
78    end loop;
79 
80    if(i_tmpxml.COUNT > 0)
81    then
82      dbms_lob.writeappend(i_xmldoc,i_length, i_temp);
83      if(l_statementEnabled) then
84         ecx_debug.log(l_statement, i_temp,i_method_name);
85      end if;
86   end if;
87    i_tmpxml.DELETE;
88 
89  if (l_procedureEnabled) then
90     ecx_debug.pop(i_method_name);
91   end if;
92 exception
93    when value_error then
94 	ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
95         if(l_unexpectedEnabled) then
96            ecx_debug.log(l_unexpected, ecx_utils.i_errbuf,i_method_name);
97         end if;
98 	raise ECX_UTILS.PROGRAM_EXIT;
99 
100    when ecx_utils.program_exit then
101 	raise ECX_UTILS.PROGRAM_EXIT;
102 
103    when others then
104 	ecx_debug.setErrorInfo(2, 30, SQLERRM || '- ECX_PRINT_LOCAL.APPEND_CLOB');
105 	if(l_unexpectedEnabled) then
106            ecx_debug.log(l_unexpected, 'ECX', SQLERRM || '- ECX_PRINT_LOCAL.APPEND_CLOB',i_method_name);
107 	end if;
108 	raise ECX_UTILS.PROGRAM_EXIT;
109 end append_clob;
110 
111 
112 procedure element_value
113 	(
114         clob_value          IN      clob,
115 	value		    IN	varchar2
116 	)
117 is
118 
119 i_method_name   varchar2(2000) := 'ecx_print_local.element_value';
120 
121 begin
122 
123        If clob_value is not null Then
124                get_chunks(clob_value);
125        elsif value is not null Then
126                get_chunks(value);
127        End if;
128 
129 exception
130 when value_error then
131 	ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
132         if(l_unexpectedEnabled) then
133            ecx_debug.log(l_unexpected, ecx_utils.i_errbuf,i_method_name);
134 	end if;
135 	raise ECX_UTILS.PROGRAM_EXIT;
136 when ecx_utils.program_exit then
137 	raise ECX_UTILS.PROGRAM_EXIT;
138 when others then
139 	ecx_debug.setErrorInfo(2, 30, SQLERRM || '- ECX_PRINT_LOCAL.ELEMENT_VALUE');
140 	if(l_unexpectedEnabled) then
141            ecx_debug.log(l_unexpected,'ECX', SQLERRM || '- ECX_PRINT_LOCAL.ELEMENT_VALUE',i_method_name);
142 	end if;
143 	raise ECX_UTILS.PROGRAM_EXIT;
144 end element_value;
145 
146 
147 
148 procedure cdata_element_value
149         (
150         clob_value      IN      clob,
151         value           IN      varchar2
152         )
153 is
154 
155 i_method_name   varchar2(2000) := 'ecx_print_local.cdata_element_value';
156 
157 begin
158 
159 if (clob_value is not null) or
160    (value is not null ) Then
161        i_tmpxml(i_tmpxml.COUNT +1) := i_cdatastarttag;
162        If clob_value is not null Then
163                get_chunks(clob_value,true);
164        elsif value is not null Then
165                get_chunks(value,true);
166        End if;
167        -- close CDATA tag
168 	i_tmpxml(i_tmpxml.COUNT + 1) := i_cdataendtag;
169 End if;
170 
171 exception
172 when value_error then
173         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
174         if(l_unexpectedEnabled) then
175            ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
176 	end if;
177         raise ECX_UTILS.PROGRAM_EXIT;
178 when ecx_utils.program_exit then
179 	raise ECX_UTILS.PROGRAM_EXIT;
180 when others then
181         ecx_debug.setErrorInfo(2, 30, SQLERRM || '- ECX_PRINT_LOCAL.CDATA_ELEMENT_VALUE');
182         if(l_unexpectedEnabled) then
183                ecx_debug.log(l_unexpected, 'ECX', SQLERRM || '- ECX_PRINT_LOCAL.CDATA_ELEMENT_VALUE',
184 	                    i_method_name);
185 	end if;
186         raise ECX_UTILS.PROGRAM_EXIT;
187 end cdata_element_value;
188 
189 procedure print_node_stack
190 is
191 
192 i_method_name   varchar2(2000) := 'ecx_print_local.print_node_stack';
193 
194 begin
195 
196 if (l_node_stack.COUNT > 0)
197 then
198    if (l_node_stack.count <> 0)
199    then
200       for i in l_node_stack.first..l_node_stack.last
201       loop
202 	 if(l_statementEnabled) then
203             ecx_debug.log(l_statement,'Counter'||i,l_node_stack(i),i_method_name);
204 	 end if;
205       end loop;
206    end if;
207 end if;
208 end print_node_stack;
209 
210 
211 /*
212   This procedure will pop elements from l_node_stack until the element that was
213   last on the stack before print_discont_elements was called (represented by
214   i_last_stack_id) is restored.
215 */
216 
217 procedure pop_discont_elements
218         (
219         i_last_stack_id         IN      pls_integer
220         )
221 is
222 
223 i_method_name   varchar2(2000) := 'ecx_print_local.pop_discont_elements';
224 
225 
226 begin
227 
228 if (l_procedureEnabled) then
229   ecx_debug.push(i_method_name);
230 end if;
231 
232 if(l_statementEnabled) then
233   ecx_debug.log(l_statement, 'i_last_stack_id', i_last_stack_id,i_method_name);
234   ecx_debug.log(l_statement, 'l_node_stack.LAST', l_node_stack(l_node_stack.LAST),i_method_name);
235 end if;
236 
237 if (i_last_stack_id <> l_node_stack(l_node_stack.LAST))
238 then
239 loop
240 exit when (l_node_stack(l_node_stack.LAST) <= i_last_stack_id);
241 
242 	if(last_node_printed = l_node_stack.LAST)
243 	then
244 		/** Change required for Clob Support -- 2263729 ***/
245 		if ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).is_clob is not null Then
246         		cdata_element_node_close
247 	                (
248 		        ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).attribute_name,
249 			ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).value,
250 	                ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).clob_value
251 		        );
252 		else
253 			element_node_close
254         		(
255 	        	ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).attribute_name
256 			);
257 		end if;
258 
259 		if(l_statementEnabled) then
260 		         ecx_debug.log(l_statement,'</'|| ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).attribute_name||'>',i_method_name);
261 		end if;
262 	end if;
263         xmlPOP;
264 end loop;
265 end if;
266 
267 if (l_procedureEnabled) then
268     ecx_debug.pop(i_method_name);
269 end if;
270 
271 exception
272 when ecx_utils.program_exit then
273         if (l_procedureEnabled) then
274          ecx_debug.pop(i_method_name);
275         end if;
276 	raise ECX_UTILS.PROGRAM_EXIT;
277 when others then
278 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' -  ECX_PRINT_LOCAL.POP_DISCONT_ELEMENTS');
279 	if(l_unexpectedEnabled) then
280          ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' -  ECX_PRINT_LOCAL.POP_DISCONT_ELEMENTS',i_method_name);
281 	end if;
282         if (l_procedureEnabled) then
283            ecx_debug.pop(i_method_name);
284         end if;
285         raise ECX_UTILS.PROGRAM_EXIT;
286 end pop_discont_elements;
287 
288 
289 /*
290   This procedure prints the discontinuous elements for an element (if any).
291   It will go through g_target starting from i_start_pos till i_end_pos looking
292   for elements that are children of this element and that belong to the same level
293   as this element. When it encounters first such discontinuous element, it will note
294   the attribute id and then invoke print_new_level with this atribute_id and the level#.
295   This call to print_new_level will print all the elements starting from the supplied
296   attribute id till it encounters elements that do not belong to the level
297 */
298 
299 procedure print_discont_elements
300         (
301         i_start_pos             IN      pls_integer,
302         i_end_pos               IN      pls_integer,
303         i_parent_attr_id        IN      pls_integer,
304         i_ext_level             IN      pls_integer
305         )
306 is
307 
308 i_method_name   varchar2(2000) := 'ecx_print_local.print_discont_elements';
309 
310 curr_parent_id  pls_integer;
311 curr_id         pls_integer;
312 curr_level      pls_integer;
313 print_id        pls_integer;
314 k               pls_integer;
315 elements_found  boolean := false;
316 descendant_found boolean := false;
317 
318 begin
319 if (l_procedureEnabled) then
320      ecx_debug.push(i_method_name);
321 end if;
322 
323 if(l_statementEnabled) then
324   ecx_debug.log(l_statement, 'i_start_pos', i_start_pos,i_method_name);
325   ecx_debug.log(l_statement, 'i_end_pos', i_end_pos,i_method_name);
326   ecx_debug.log(l_statement, 'i_parent_attr_id', i_parent_attr_id,i_method_name);
327   ecx_debug.log(l_statement, 'i_ext_level', i_ext_level,i_method_name);
328 end if;
329 
330 for k in i_start_pos..i_end_pos
331 loop
332         -- get element details
333         curr_parent_id := ecx_utils.g_target(k).parent_attribute_id;
334         curr_id := ecx_utils.g_target(k).attribute_id;
335         curr_level := ecx_utils.g_target(k).external_level;
336 
337         descendant_found := is_descendant(i_parent_attr_id, curr_id);
338         if (descendant_found AND curr_level = i_ext_level)
339         then
340                 -- elements belong to this parent so need to be printed
341                 if (not elements_found)
342                 then
343                         print_id := curr_id;
344                         if(l_statementEnabled) then
345                           ecx_debug.log(l_statement, 'print_id', print_id,i_method_name);
346 			end if;
347                         elements_found := true;
348                 end if;
349         end if;
350 
351         if( (not descendant_found) OR (curr_level <> i_ext_level) OR (k = i_end_pos))
352         then
353                 -- elements belong to a new level under ext_level.
354                 -- Print any discontinuous_elements that were found. These elements
355                 -- probably were not printed as their data never arrived
356                 if (elements_found)
357                 then
358                         print_new_level(i_ext_level, print_id);
359                         elements_found := false;
360                 end if;
361         end if;
362         exit when not descendant_found;
363 end loop;
364 
365 if (l_procedureEnabled) then
366   ecx_debug.pop(i_method_name);
367 end if;
368 
369 exception
370 when ecx_utils.program_exit then
371         if (l_procedureEnabled) then
372            ecx_debug.pop(i_method_name);
373         end if;
374 	raise ECX_UTILS.PROGRAM_EXIT;
375 when others then
376 	ecx_debug.setErrorInfo(2, 30, SQLERRM ||' - ECX_PRINT_LOCAL.PRINT_DISCONT_ELEMENTS');
377 	if(l_unexpectedEnabled) then
378             ecx_debug.log(l_unexpected,'ECX', SQLERRM ||' - ECX_PRINT_LOCAL.PRINT_DISCONT_ELEMENTS',i_method_name);
379 	end if;
380         if (l_procedureEnabled) then
381            ecx_debug.pop(i_method_name);
382         end if;
383         raise ECX_UTILS.PROGRAM_EXIT;
384 end print_discont_elements;
385 
386 
387 /*
388   evaluates if i_element_id is a descendant of i_parent_id
389 */
390 function is_descendant (
391 	i_parent_id	IN	pls_integer,
392 	i_element_id	IN	pls_integer
393 	) return 		boolean
394 is
395 
396         i_method_name   varchar2(2000) := 'ecx_print_local.is_descendant';
397 	curr_pid	pls_integer;
398 begin
399         if (l_procedureEnabled) then
400           ecx_debug.push(i_method_name);
401         end if;
402 
403 	curr_pid := ecx_utils.g_target(i_element_id).parent_attribute_id;
404 	loop
405 		if (curr_pid = i_parent_id)
406 		then
407 			if(l_statementEnabled) then
408                           ecx_debug.log(l_statement,'Returning true',i_method_name);
409 			end if;
410 		        if (l_procedureEnabled) then
411                          ecx_debug.pop(i_method_name);
412                         end if;
413 			return (true);
414 		elsif (curr_pid < i_parent_id)
415 		then
416 			if(l_statementEnabled) then
417                           ecx_debug.log(l_statement,'Returning false',i_method_name);
418 			end if;
419 		        if (l_procedureEnabled) then
420                          ecx_debug.pop(i_method_name);
421                         end if;
422 			return (false);
423 		else
424 			curr_pid := ecx_utils.g_target(curr_pid).parent_attribute_id;
425 		end if;
426 	exit when curr_pid = 0;
427 	end loop;
428 
429         -- for the special case where 0 is the ancestor
430         if (curr_pid = 0 AND curr_pid = i_parent_id)
431         then
432         	if(l_statementEnabled) then
433                 	ecx_debug.log(l_statement,'Returning true: 0 is the ancestor',i_method_name);
434                 end if;
435                 if (l_procedureEnabled) then
436                 	ecx_debug.pop(i_method_name);
437                 end if;
438                 return (true);
439 	end if;
440 
441 	if(l_statementEnabled) then
442            ecx_debug.log(l_statement,'Returning false',i_method_name);
443 	end if;
444         return (false);
445         if (l_procedureEnabled) then
446           ecx_debug.pop(i_method_name);
447         end if;
448 exception
449 when ecx_utils.program_exit then
450         if (l_procedureEnabled) then
451           ecx_debug.pop(i_method_name);
452         end if;
453 	raise ECX_UTILS.PROGRAM_EXIT;
454 when others then
455         ecx_debug.setErrorInfo(2, 30, SQLERRM ||' - ECX_PRINT_LOCAL.IS_DESCENDANT');
456         if(l_unexpectedEnabled) then
457            ecx_debug.log(l_unexpected,'ECX', SQLERRM ||' - ECX_PRINT_LOCAL.IS_DESCENDANT',i_method_name);
458 	end if;
459         if (l_procedureEnabled) then
460           ecx_debug.pop(i_method_name);
461         end if;
462         raise ECX_UTILS.PROGRAM_EXIT;
463 end is_descendant;
464 
465 
466 procedure xmlPOPALL(
467    x_xmldoc OUT NOCOPY  clob)
468 is
469 
470 i_method_name   varchar2(2000) := 'ecx_print_local.xmlPOPALL';
471 
472 last_stack_id   pls_integer;
473 
474 begin
475 	if(l_statementEnabled) then
476 		print_node_stack;
477 	end if;
478 
479 	while (l_node_stack.COUNT > 0)
480 	loop
481                 /*
482                   before closing the current element print its discontinuous elements, if any
483                   Since we don't have current_position, we need to find the end position
484                   of the the level to which this element belongs and look for discont elements
485                   from last_printed to the element level's file_end_pos
486                 */
487                 last_stack_id := l_node_stack(l_node_stack.LAST);
488 
489                 print_discont_elements (last_printed + 1,
490                                         ecx_utils.g_target_levels(ecx_utils.g_target
491                                         (l_node_stack(l_node_stack.LAST)).external_level).file_end_pos,
492                                         l_node_stack(l_node_stack.LAST),
493                                         ecx_utils.g_target(l_node_stack
494                                         (l_node_stack.LAST)).external_level);
495 		/*
496                   if at all any discontinuous elements were printed we need to once again
497                   ensure if the last element on the stack is the one which we were trying to close
498                   so keep popping the discont elements till you reach this element
499 		*/
500                 pop_discont_elements(last_stack_id);
501 
502 		-- close this element only if it was opened
503 		if(last_node_printed = l_node_stack.LAST)
504 		then
505        	        	/** Change required for Clob Support -- 2263729 ***/
506 			if  ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).is_clob is not null  Then
507 				cdata_element_node_close
508 				(
509 				 ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).attribute_name,
510 				 ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).value,
511 				 ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).clob_value
512 				);
513 			else
514 				element_node_close
515 				(
516 				ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).attribute_name
517 				);
518 			end if;
519 			if(l_statementEnabled) then
520         			ecx_debug.log(l_statement,'</'||ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).attribute_name||'>', i_method_name);
521 		        end if;
522 		end if;
523 	xmlPOP;
524 	end loop;
525         append_clob;
526         ecx_utils.g_xml_frag.delete;
527         x_xmldoc := i_xmldoc;
528 
529         if dbms_lob.istemporary(i_xmldoc) = 1 then
530            dbms_lob.freetemporary(i_xmldoc);
531            i_xmldoc := null;
532         end if;
533 
534 exception
535    when ecx_utils.program_exit then
536         if dbms_lob.istemporary(i_xmldoc) = 1 then
537            dbms_lob.freetemporary(i_xmldoc);
538            i_xmldoc := null;
539         end if;
540 	raise ECX_UTILS.PROGRAM_EXIT;
541 
542    when others then
543 	ecx_debug.setErrorInfo(2, 30, SQLERRM || '- ECX_PRINT_LOCAL.xmlPOPALL');
544 	if(l_unexpectedEnabled) then
545            ecx_debug.log(l_unexpected,'ECX', SQLERRM || '- ECX_PRINT_LOCAL.xmlPOPALL',i_method_name);
546 	end if;
547         if dbms_lob.istemporary(i_xmldoc) = 1 then
548            dbms_lob.freetemporary(i_xmldoc);
549            i_xmldoc := null;
550         end if;
551 	raise ECX_UTILS.PROGRAM_EXIT;
552 end xmlPOPALL;
553 
554 procedure xmlPUSH
555 	(
556 	i	pls_integer
557 	)
558 	is
559 
560 begin
561 	l_node_stack(l_node_stack.COUNT) := i;
562 end xmlPUSH;
563 
564 procedure xmlPOP
565 is
566 begin
567 	if l_node_stack.COUNT > 0
568 	then
569 		-- if last_node_printed is pointing to the last node we need to reset it
570 		if(last_node_printed = l_node_stack.LAST)
571 		then
572 			last_node_printed := l_node_stack.LAST - 1;
573 		end if;
574 		l_node_stack.delete(l_node_stack.LAST);
575 	end if;
576 end xmlPOP;
577 
578 procedure element_open
579 	(
580 	tag_name        IN      varchar2
581 	)
582 is
583 i_method_name   varchar2(2000) := 'ecx_print_local.element_open';
584 begin
585 	i_tmpxml(i_tmpxml.COUNT+1) := i_elestarttag||tag_name||' ';
586 exception
587 when value_error then
588         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
589         if(l_unexpectedEnabled) then
590             ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
591 	end if;
592         raise ECX_UTILS.PROGRAM_EXIT;
593 when ecx_utils.program_exit then
594 	raise ECX_UTILS.PROGRAM_EXIT;
595 when others then
596 	ecx_debug.setErrorInfo(2, 30, SQLERRM || '- ECX_PRINT_LOCAL.ELEMENT_OPEN');
597 	if(l_unexpectedEnabled) then
598             ecx_debug.log(l_unexpected,'ECX', SQLERRM || '- ECX_PRINT_LOCAL.ELEMENT_OPEN',i_method_name);
599 	end if;
600 	raise ECX_UTILS.PROGRAM_EXIT;
601 end;
602 
603 procedure element_close
604 is
605 
606 i_method_name   varchar2(2000) := 'ecx_print_local.element_close';
607 begin
608 	i_tmpxml(i_tmpxml.COUNT+1) := i_eleendtag;
609 exception
610 when value_error then
611         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
612 	if(l_unexpectedEnabled) then
613             ecx_debug.log(l_unexpected, ecx_utils.i_errbuf, i_method_name);
614 	 end if;
615         raise ECX_UTILS.PROGRAM_EXIT;
616 when ecx_utils.program_exit then
617 	raise ECX_UTILS.PROGRAM_EXIT;
618 when others then
619 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.ELEMENT_CLOSE');
620 	if(l_unexpectedEnabled) then
621             ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.ELEMENT_CLOSE',i_method_name);
622 	end if;
623 	raise ECX_UTILS.PROGRAM_EXIT;
624 end element_close;
625 
626 procedure element_node_open
627 	(
628 	tag_name	IN	varchar2,
629 	value		IN	varchar2,
630         clob_value	IN	clob
631 	)
632 is
633 
634 i_method_name   varchar2(2000) := 'ecx_print_local.element_node_open';
635 
636 begin
637      if (clob_value is not null) or
638            (value is not null ) Then
639         	i_tmpxml(i_tmpxml.COUNT +1) := i_elestarttag||tag_name||i_eleendtag;
640               	If clob_value is not null Then
641                 	get_chunks(clob_value);
642               	elsif value is not null Then
643                 	get_chunks(value);
644               	End if;
645         else
646 		i_tmpxml(i_tmpxml.COUNT+1) := i_elestarttag||tag_name||i_eleendtag;
647 	End if;
648 
649 exception
650 when value_error then
651         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
652         if(l_unexpectedEnabled) then
653           ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
654 	end if;
655         raise ECX_UTILS.PROGRAM_EXIT;
656 when ecx_utils.program_exit then
657 	raise ECX_UTILS.PROGRAM_EXIT;
658 when others then
659 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.ELEMENT_NODE_OPEN');
660 	if(l_unexpectedEnabled) then
661           ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.ELEMENT_NODE_OPEN',i_method_name);
662 	end if;
663 	raise ECX_UTILS.PROGRAM_EXIT;
664 end element_node_open;
665 
666 
667 procedure element_node_close
668 	(
669 	tag_name	IN	varchar2
670 	)
671 	is
672 i_method_name   varchar2(2000) := 'ecx_print_local.element_node_close';
673 
674 begin
675 	i_tmpxml(i_tmpxml.COUNT+1) := i_eleclosetag||tag_name||i_eleendtag;
676 exception
677 when value_error then
678         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
679         if(l_unexpectedEnabled) then
680             ecx_debug.log(l_unexpected, ecx_utils.i_errbuf,i_method_name);
681 	end if;
682         raise ECX_UTILS.PROGRAM_EXIT;
683 when ecx_utils.program_exit then
684 	raise ECX_UTILS.PROGRAM_EXIT;
685 when others then
686 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.ELEMENT_NODE_CLOSE');
687 	if(l_unexpectedEnabled) then
688             ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.ELEMENT_NODE_CLOSE',i_method_name);
689 	end if;
690 	raise ECX_UTILS.PROGRAM_EXIT;
691 end element_node_close;
692 
693 /**  Change required for Clob Support -- 2263729 ***/
694 procedure cdata_element_node_open
695 	(
696 	tag_name	IN	varchar2,
697         value           IN      varchar2,
698 	clob_value	IN	clob
699 	)
700 is
701 i_method_name   varchar2(2000) := 'ecx_print_local.cdata_element_node_open';
702 
703 i      pls_integer:=1;
704 begin
705         if (clob_value is not null) or
706            (value is not null ) Then
707         	i_tmpxml(i_tmpxml.COUNT +1) := i_elestarttag||tag_name||i_eleendtag||i_cdatastarttag;
708               	If clob_value is not null Then
709                 	get_chunks(clob_value,true);
710               	elsif value is not null Then
711                 	get_chunks(value,true);
712               	End if;
713           -- close CDATA tag
714 	   i_tmpxml(i_tmpxml.COUNT + 1) := i_cdataendtag;
715         else
716 		i_tmpxml(i_tmpxml.COUNT+1) := i_elestarttag||tag_name||i_eleendtag;
717 	End if;
718 exception
719 when ecx_utils.program_exit then
720 	raise ECX_UTILS.PROGRAM_EXIT;
721 when others then
722 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.CDATA_ELEMENT_NODE_OPEN');
723 	if(l_unexpectedEnabled) then
724          ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.CDATA_ELEMENT_NODE_OPEN',
725 	              i_method_name);
726         end if;
727 	raise ECX_UTILS.PROGRAM_EXIT;
728 end;
729 
730 /** Change required for Clob Support -- 2263729 ***/
731 procedure cdata_element_node_close
732 	(
733 	tag_name	IN	varchar2,
734         value           IN      varchar2,
735 	clob_value	IN	clob
736 	)
737 is
738 i_method_name   varchar2(2000) := 'ecx_print_local.cdata_element_node_close';
739 
740 begin
741 	i_tmpxml(i_tmpxml.COUNT+1) := i_eleclosetag||tag_name||i_eleendtag;
742 
743 exception
744 when ecx_utils.program_exit then
745 	raise ECX_UTILS.PROGRAM_EXIT;
746 when others then
747 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.CDATA_ELEMENT_NODE_CLOSE');
748 	if(l_unexpectedEnabled) then
749             ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.CDATA_ELEMENT_NODE_CLOSE',
750 	                 i_method_name);
751 	end if;
752 	raise ECX_UTILS.PROGRAM_EXIT;
753 end;
754 
755 
756 procedure element_node
757 	(
758 	tag_name	IN	varchar2,
759 	value		IN	varchar2
760 	)
761 	is
762 
763 i_method_name   varchar2(2000) := 'ecx_print_local.element_node';
764 i_temp		varchar2(32767);
765 
766 begin
767 i_temp	:= value;
768 i_tmpxml(i_tmpxml.COUNT+1) := i_elestarttag||tag_name||i_eleendtag;
769 if value is not null
770 then
771 	/*
772 	Changed as per XML 1.0 spec.
773 	*/
774         escape_spec_char(value, i_temp);
775 
776         if (length(i_tmpxml(i_tmpxml.COUNT)) + length(i_temp) > ecx_utils.G_VARCHAR_LEN)
777         then
778            i_tmpxml(i_tmpxml.COUNT + 1) := i_temp;
779         else
780            i_tmpxml(i_tmpxml.COUNT) := i_tmpxml(i_tmpxml.COUNT) || i_temp;
781         end if;
782 end if;
783 	i_tmpxml(i_tmpxml.COUNT+1) := i_eleclosetag||tag_name||i_eleendtag;
784 exception
785 when value_error then
786         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
787         if(l_unexpectedEnabled) then
788           ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
789 	end if;
790         raise ECX_UTILS.PROGRAM_EXIT;
791 when ecx_utils.program_exit then
792 	raise ECX_UTILS.PROGRAM_EXIT;
793 when others then
794 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.ELEMENT_NODE');
795 	if(l_unexpectedEnabled) then
796            ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.ELEMENT_NODE',
797 	                i_method_name);
798 	end if;
799 	raise ECX_UTILS.PROGRAM_EXIT;
800 end element_node;
801 
802 procedure attribute_node
803 	(
804 	attribute_name	IN	varchar2,
805 	attribute_value	IN	varchar2
806 	)
807 is
808 i_method_name   varchar2(2000) := 'ecx_print_local.attribute_node';
809 i_temp	varchar2(32767);
810 begin
811 	i_temp	:= attribute_value;
812 	/**
813 	Changed as per XML 1.0 spec.
814 	**/
815 	if i_temp is null
816 	then
817 		return;
818 	end if;
819         escape_spec_char(attribute_value, i_temp);
820 
821  	i_tmpxml(i_tmpxml.COUNT + 1) := ' ' || attribute_name || ' = "';
822 
823         if(length(i_tmpxml(i_tmpxml.COUNT)) + length(i_temp) < ecx_utils.G_VARCHAR_LEN)
824         then
825            i_tmpxml(i_tmpxml.COUNT) := i_tmpxml(i_tmpxml.COUNT) || i_temp || '"';
826         else -- > or =
827            i_tmpxml(i_tmpxml.COUNT + 1) := i_temp;
828            i_tmpxml(i_tmpxml.COUNT + 1) := '"';
829         end if;
830 exception
831 when value_error then
832         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
833         if(l_unexpectedEnabled) then
834            ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
835 	end if;
836         raise ECX_UTILS.PROGRAM_EXIT;
837 when ecx_utils.program_exit then
838 	raise ECX_UTILS.PROGRAM_EXIT;
839 when others then
840 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.ATTRIBUTE_NODE');
841 	if(l_unexpectedEnabled) then
842          ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.ATTRIBUTE_NODE',i_method_name);
843         end if;
844 	raise ECX_UTILS.PROGRAM_EXIT;
845 end;
846 
847 procedure attribute_node_close
848 	(
849 	attribute_name	IN	varchar2,
850 	attribute_value	IN	varchar2
851 	)
852 is
853 i_method_name   varchar2(2000) := 'ecx_print_local.attribute_node_close';
854 i_temp	varchar2(32767);
855 
856 begin
857 	i_temp := attribute_value;
858 	/**
859 	Changed as per XML 1.0 spec.
860 	**/
861 if i_temp is not null
862 then
863         escape_spec_char(attribute_value, i_temp);
864 
865         i_tmpxml(i_tmpxml.COUNT + 1) := ' ' || attribute_name || ' = "';
866 
867         if(length(i_tmpxml(i_tmpxml.COUNT)) + length(i_temp) < ecx_utils.G_VARCHAR_LEN)
868         then
869            i_tmpxml(i_tmpxml.COUNT) := i_tmpxml(i_tmpxml.COUNT) || i_temp || '">';
870         elsif(length(i_temp) < ecx_utils.G_VARCHAR_LEN)
871         then
872            i_tmpxml(i_tmpxml.COUNT + 1) :=  i_temp || '">';
873         else
874            i_tmpxml(i_tmpxml.COUNT + 1) :=  i_temp;
875 	   i_tmpxml(i_tmpxml.COUNT + 1) := '">';
876         end if;
877 else
878 	i_tmpxml(i_tmpxml.COUNT+1) := '>';
879 end if;
880 exception
881 when value_error then
882         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
883         if(l_unexpectedEnabled) then
884            ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
885 	end if;
886         raise ECX_UTILS.PROGRAM_EXIT;
887 when ecx_utils.program_exit then
888 	raise ECX_UTILS.PROGRAM_EXIT;
889 when others then
890 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.ATTRIBUTE_NODE_CLOSE');
891 	if(l_unexpectedEnabled) then
892            ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.ATTRIBUTE_NODE_CLOSE',
893 	                i_method_name);
894 	end if;
895 	raise ECX_UTILS.PROGRAM_EXIT;
896 end;
897 
898 procedure pi_node
899 	(
900 	pi			IN	varchar2,
901 	attribute_string	in	varchar2 :=NULL
902 	)
903 	is
904 
905 i_method_name   varchar2(2000) := 'ecx_print_local.pi_node';
906 begin
907 	i_tmpxml(i_tmpxml.COUNT+1) := i_pistart||pi||' '||attribute_string||' '||i_piend;
908 exception
909 when ecx_utils.program_exit then
910 	raise ECX_UTILS.PROGRAM_EXIT;
911 when others then
912 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.PI_NODE');
913 	if(l_unexpectedEnabled) then
914            ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.PI_NODE',i_method_name);
915 	end if;
916 	raise ECX_UTILS.PROGRAM_EXIT;
917 end pi_node;
918 
919 procedure document_node
920 	(
921 	root_element	in	varchar2,
922 	filename	IN	varchar2,
923 	dtd_url		IN	varchar2
924 	)
925 is
926 i_method_name   varchar2(2000) := 'ecx_print_local.document_node';
927 begin
928 	if filename is not null
929 	then
930 		i_tmpxml(i_tmpxml.COUNT+1) := '<!DOCTYPE  '||root_element;
931 
932 		if dtd_url is null
933 		then
934 			if filename is null
935 			then
936 				i_tmpxml(i_tmpxml.COUNT) := i_tmpxml(i_tmpxml.COUNT)|| ' >';
937 			else
938 				i_tmpxml(i_tmpxml.COUNT) := i_tmpxml(i_tmpxml.COUNT)||' SYSTEM ' ||i_quot||filename||i_quot||' >';
939 			end if;
940 		else
941 			i_tmpxml(i_tmpxml.COUNT) := i_tmpxml(i_tmpxml.COUNT)||' SYSTEM ' ||i_quot||dtd_url||filename||i_quot||' >';
942 		end if;
943 	end if;
944 exception
945 when ecx_utils.program_exit then
946 	raise ECX_UTILS.PROGRAM_EXIT;
947 when others then
948 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.DOCUMENT_NODE');
949 	if(l_unexpectedEnabled) then
950             ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.DOCUMENT_NODE',i_method_name);
951 	end if;
952 	raise ECX_UTILS.PROGRAM_EXIT;
953 end document_node;
954 
955 procedure comment_node
956 	(
957 	value	IN	varchar2
958 	)
959 is
960 i_method_name   varchar2(2000) := 'ecx_print_local.comment_node';
961 begin
962 	i_tmpxml(i_tmpxml.COUNT+1) := i_commstart||' '||value||' '||i_commend;
963 exception
964 when ecx_utils.program_exit then
965 	raise ECX_UTILS.PROGRAM_EXIT;
966 when others then
967 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.COMMENT_NODE');
968 	if(l_unexpectedEnabled) then
969             ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.COMMENT_NODE',i_method_name);
970 	end if;
971 	raise ECX_UTILS.PROGRAM_EXIT;
972 end comment_node;
973 
974 
975 -- This procedure prints any nodes waiting to be printed on l_node_stack
976 procedure print_waiting_nodes
977 is
978 i_method_name   varchar2(2000) := 'ecx_print_local.print_waiting_nodes';
979 i_last_node_printed  pls_integer;
980 begin
981 if(l_procedureEnabled) then
982   ecx_debug.PUSH(i_method_name);
983 end if;
984 
985 i_last_node_printed := last_node_printed + 1;
986 
987 if(l_node_stack.COUNT > 0)
988 then
989   for i in i_last_node_printed..l_node_stack.LAST
990   loop
991       if  ecx_utils.g_target(l_node_stack(i)).is_clob is not null
992       Then
993         cdata_element_node_open
994         (
995   	  ecx_utils.g_target(l_node_stack(i)).attribute_name,
996 	  ecx_utils.g_target(l_node_stack(i)).value,
997           ecx_utils.g_target(l_node_stack(i)).clob_value
998 	);
999       else
1000         i_var_pos := l_node_stack(i);
1001         if (has_fragment(i_var_pos)) then
1002          print_xml_fragment(i_var_pos,true);
1003         else
1004 	element_node_open
1005 	(
1006   	  ecx_utils.g_target(l_node_stack(i)).attribute_name,
1007 	  ecx_utils.g_target(l_node_stack(i)).value,
1008           ecx_utils.g_target(l_node_stack(i)).clob_value
1009 	);
1010         end if;
1011       end if;
1012   end loop;
1013 end if;
1014 last_node_printed := l_node_stack.LAST;
1015 
1016 if(l_procedureEnabled) then
1017   ecx_debug.POP(i_method_name);
1018 end if;
1019 
1020 exception
1021 when ecx_utils.program_exit
1022 then
1023   if (l_procedureEnabled) then
1024     ecx_debug.pop(i_method_name);
1025   end if;
1026   raise ECX_UTILS.PROGRAM_EXIT;
1027 when others then
1028   ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.PRINT_WAITING_NODES');
1029   if(l_statementEnabled) then
1030     ecx_debug.log(l_statement, 'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.PRINT_WAITING_NODES',
1031      i_method_name);
1032     ecx_debug.log(l_statement, 'resetting first_time',i_method_name);
1033   end if;
1034   ecx_print_local.first_time_printing := true;
1035   if (l_procedureEnabled)
1036   then
1037     ecx_debug.pop(i_method_name);
1038   end if;
1039   raise ECX_UTILS.PROGRAM_EXIT;
1040 end print_waiting_nodes;
1041 
1042 -- This procedure prints any nodes waiting to be printed on l_node_stack. This procedure is called by an attribute.
1043 procedure print_waiting_nodes_attr
1044 is
1045 i_method_name   varchar2(2000) := 'ecx_print_local.print_waiting_nodes_attr';
1046 i_last_node_printed  pls_integer;
1047 begin
1048 if(l_procedureEnabled) then
1049   ecx_debug.PUSH(i_method_name);
1050 end if;
1051 
1052 i_last_node_printed := last_node_printed + 1;
1053 
1054 if(l_node_stack.COUNT > 0)
1055 then
1056   for i in i_last_node_printed..l_node_stack.LAST
1057   loop
1058     if(i = l_node_stack.LAST)
1059     then
1060       element_open(ecx_utils.g_target(l_node_stack(i)).attribute_name);
1061     else
1062       if  ecx_utils.g_target(l_node_stack(i)).is_clob is not null
1063       Then
1064         cdata_element_node_open
1065         (
1066   	  ecx_utils.g_target(l_node_stack(i)).attribute_name,
1067 	  ecx_utils.g_target(l_node_stack(i)).value,
1068           ecx_utils.g_target(l_node_stack(i)).clob_value
1069 	);
1070       else
1071         i_var_pos := l_node_stack(i);
1072         if (has_fragment(i_var_pos)) then
1073          print_xml_fragment(i_var_pos,true);
1074         else
1075 	element_node_open
1076 	(
1077   	  ecx_utils.g_target(l_node_stack(i)).attribute_name,
1078 	  ecx_utils.g_target(l_node_stack(i)).value,
1079           ecx_utils.g_target(l_node_stack(i)).clob_value
1080 	);
1081         end if;
1082       end if;
1083     end if;
1084   end loop;
1085 end if;
1086 last_node_printed := l_node_stack.LAST;
1087 
1088 if(l_procedureEnabled) then
1089   ecx_debug.POP(i_method_name);
1090 end if;
1091 
1092 exception
1093 when ecx_utils.program_exit
1094 then
1095   if (l_procedureEnabled) then
1096     ecx_debug.pop(i_method_name);
1097   end if;
1098   raise ECX_UTILS.PROGRAM_EXIT;
1099 when others then
1100   ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.PRINT_WAITING_NODES_ATTR');
1101   if(l_statementEnabled) then
1102     ecx_debug.log(l_statement, 'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.PRINT_WAITING_NODES_ATTR',
1103      i_method_name);
1104     ecx_debug.log(l_statement, 'resetting first_time',i_method_name);
1105   end if;
1106   ecx_print_local.first_time_printing := true;
1107   if (l_procedureEnabled)
1108   then
1109     ecx_debug.pop(i_method_name);
1110   end if;
1111   raise ECX_UTILS.PROGRAM_EXIT;
1112 end print_waiting_nodes_attr;
1113 
1114 Function get_suppress_profile return boolean is
1115 
1116 i_string   varchar2(2000);
1117 l_suppress varchar2(1) := 'N';
1118 i_method_name   varchar2(2000) := 'ecx_print_local.get_suppress_profile';
1119 begin
1120 if (l_procedureEnabled) then
1121 	ecx_debug.push(i_method_name);
1122 end if;
1123 if (ecx_utils.g_install_mode is null) then
1124   ecx_utils.g_install_mode := wf_core.translate('WF_INSTALL');
1125 end if;
1126 
1127 if ecx_utils.g_install_mode = 'EMBEDDED'
1128 then
1129   i_string := 'begin fnd_profile.get('||'''ECX_SUPPRESS_EMPTY_TAGS'''||',
1130     :l_suppress);end;';
1131   execute immediate i_string USING OUT l_suppress;
1132 else
1133   l_suppress := wf_core.translate('ECX_SUPPRESS_EMPTY_TAGS');
1134 end if;
1135 
1136 if(l_statementEnabled) then
1137   ecx_debug.log(l_statement, 'ECX_SUPPRESS_EMPTY_TAGS',l_suppress,i_method_name);
1138 end if;
1139 /* if profile option is not set assume empty tags should not be suppressed */
1140 if (l_suppress is null) then
1141   return false;
1142 end if;
1143 
1144 if(l_procedureEnabled) then
1145   ecx_debug.POP(i_method_name);
1146 end if;
1147 
1148 return (l_suppress = 'Y') OR (l_suppress = 'y');
1149 
1150 exception
1151 when ecx_utils.program_exit
1152 then
1153   if (l_procedureEnabled)
1154   then
1155     ecx_debug.pop(i_method_name);
1156   end if;
1157   raise ECX_UTILS.PROGRAM_EXIT;
1158 when others
1159 then
1160   ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.GET_SUPPRESS_PROFILE');
1161   if(l_unexpectedEnabled)
1162   then
1163     ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.GET_SUPPRESS_PROFILE',
1164       i_method_name);
1165     ecx_debug.log(l_unexpected, 'resetting first_time',i_method_name);
1166   end if;
1167   ecx_print_local.first_time_printing := true;
1168   if (l_procedureEnabled)
1169   then
1170     ecx_debug.pop(i_method_name);
1171   end if;
1172   raise ECX_UTILS.PROGRAM_EXIT;
1173 
1174 end get_suppress_profile;
1175 
1176 procedure print_new_level
1177 	(
1178 	i_level		IN	pls_integer,
1179 	i_index		IN	pls_integer
1180 	)
1181 is
1182 i_method_name   varchar2(2000) := 'ecx_print_local.print_new_level';
1183 i		pls_integer := i_index;
1184 j		pls_integer :=1;
1185 k		pls_integer :=0;
1186 do_printing 	Boolean	    := false;
1187 current_position        pls_integer;
1188 last_stack_id           pls_integer;
1189 start_pos               pls_integer;
1190 end_pos                 pls_integer;
1191 
1192 -- fix for bug 6900831
1193 loop_count         pls_integer :=  0;
1194 w_note_stack_last  pls_integer := -1;
1195 w_i                pls_integer := -1;
1196 w_start_pos        pls_integer := -1;
1197 w_current_position pls_integer := -1;
1198 
1199 begin
1200 if (l_procedureEnabled) then
1201   ecx_debug.push(i_method_name);
1202 end if;
1203 if(l_statementEnabled) then
1204   ecx_debug.log(l_statement,'i_level',i_level,i_method_name);
1205   ecx_debug.log(l_statement,'i_index',i_index,i_method_name);
1206 end if;
1207 if(l_statementEnabled) then
1208   ecx_debug.log(l_statement,'count',ecx_utils.g_xml_frag.count,i_method_name);
1209 end if;
1210 if (ecx_utils.g_xml_frag.count >0)  then
1211 for i in ecx_utils.g_xml_frag.FIRST .. ecx_utils.g_xml_frag.LAST
1212    loop
1213 if(l_statementEnabled) then
1214   ecx_debug.log(l_statement,'var_pos',ecx_utils.g_xml_frag(i).variable_pos,i_method_name);
1215   ecx_debug.log(l_statement,'value',ecx_utils.g_xml_frag(i).value,i_method_name);
1216 end if;
1217 end loop;
1218 end if;
1219 
1220 if (ecx_utils.g_target(i).external_level <> i_level)
1221 then
1222 	return;
1223 end if;
1224 
1225 loop
1226 	exit when i = ecx_utils.g_target.COUNT;
1227 	if(l_statementEnabled) then
1228           ecx_debug.log(l_statement,'Current DTD Node=>'||i,ecx_utils.g_target(i).attribute_name,i_method_name);
1229 	  print_node_stack;
1230 	end if;
1231 
1232         current_position := i;
1233         if(l_statementEnabled) then
1234           ecx_debug.log(l_statement,'Set current position to', current_position,i_method_name);
1235 	end if;
1236 
1237 	if ecx_utils.g_target(i).attribute_type = 2
1238 	then
1239 		begin
1240 		if(ecx_utils.g_target(i).value is not null)
1241 		then
1242 			if(l_statementEnabled) then
1243 			       ecx_debug.log(l_statement,'Attribute Value is not null',i_method_name);
1244 			end if;
1245 
1246 			print_waiting_nodes_attr;
1247 
1248 			if ecx_utils.g_target(i+1).attribute_type = 1
1249 			then
1250 				attribute_node_close
1251 					(
1252 					ecx_utils.g_target(i).attribute_name,
1253 					ecx_utils.g_target(i).value
1254 					);
1255 				 if(l_statementEnabled) then
1256                                     ecx_debug.log(l_statement,ecx_utils.g_target(i).value,i_method_name);
1257 				    ecx_debug.log(l_statement,ecx_utils.g_target(i).attribute_name||'="">',
1258 				                 i_method_name);
1259 			         end if;
1260                                 if  ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).is_clob is not null Then
1261                                     cdata_element_value(
1262                                      ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).clob_value,
1263                                      ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).value);
1264                                 else
1265                                     if (has_fragment(ecx_utils.g_target(i).parent_attribute_id)) then
1266                                           print_xml_fragment(ecx_utils.g_target(i).parent_attribute_id,false);
1267                                     else
1268 				    element_value(ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).clob_value,
1269                                           ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).value);
1270                                     end if;
1271                                      if(l_statementEnabled) then
1272                                          ecx_debug.log(l_statement,ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).value,
1273 					              i_method_name);
1274 				     end if;
1275                                 end if;
1276 
1277 			elsif ecx_utils.g_target(i+1).attribute_type = 2
1278 			then
1279 				attribute_node
1280 					(
1281 					ecx_utils.g_target(i).attribute_name,
1282 					ecx_utils.g_target(i).value
1283 					);
1284 				if(l_statementEnabled) then
1285                                     ecx_debug.log(l_statement,ecx_utils.g_target(i).attribute_name||'=""',i_method_name);
1286 		        	    ecx_debug.log(l_statement,ecx_utils.g_target(i).value,i_method_name);
1287 				end if;
1288 			end if;
1289 		else -- to close the parent if none of the attributes are to be printed.
1290 			if(last_node_printed = l_node_stack.LAST) -- if parent is on top stack and has been printed
1291 			then
1292 				if( i = ecx_utils.g_target.LAST  OR ecx_utils.g_target(i+1).attribute_type = 1)
1293 				then
1294 					element_close;
1295 					if  ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).is_clob is not null
1296 					Then
1297 						cdata_element_value(
1298 		                                ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).clob_value,
1299 				                ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).value);
1300 					else
1301                                                 if (has_fragment(ecx_utils.g_target(i).parent_attribute_id)) then
1302                                                 print_xml_fragment(ecx_utils.g_target(i).parent_attribute_id,false);
1303                                                 else
1304 						element_value(ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).clob_value,
1305 	                                        ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).value);
1306                                                 end if;
1307 			                        if(l_statementEnabled)
1308 						then
1309 							ecx_debug.log(l_statement,ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).value,i_method_name);
1310 						end if;
1311 					end if;
1312 				end if;
1313 			end if;
1314 		end if;
1315 		exception
1316 		when no_data_found
1317 		then
1318 			attribute_node_close
1319 				(
1320 				ecx_utils.g_target(i).attribute_name,
1321 				ecx_utils.g_target(i).value
1322 				);
1323 			if(l_unexpectedEnabled) then
1324                              ecx_debug.log(l_unexpected,ecx_utils.g_target(i).value,i_method_name);
1325 			     ecx_debug.log(l_unexpected,ecx_utils.g_target(i).attribute_name||'="">',i_method_name);
1326 			end if;
1327                         if  ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).is_clob is not null Then
1328                         	cdata_element_value(
1329                                 ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).clob_value,
1330                                 ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).value);
1331                      	else
1332                                 if (has_fragment(ecx_utils.g_target(i).parent_attribute_id)) then
1333                                     print_xml_fragment(ecx_utils.g_target(i).parent_attribute_id,false);
1334                                 else
1335                         	element_value(ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).clob_value,
1336                                             ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).value);
1337                                 end if;
1338                                 if(l_statementEnabled) then
1339                                   ecx_debug.log(l_statement,ecx_utils.g_target(ecx_utils.g_target(i).parent_attribute_id).value,
1340 				               i_method_name);
1341 			        end if;
1342                     	end if;
1343 
1344 		end;
1345 
1346                 last_printed := ecx_utils.g_target(i).attribute_id;
1347                 if(l_statementEnabled) then
1348                     ecx_debug.log(l_statement, 'last_printed 1', last_printed,i_method_name);
1349 		end if;
1350 
1351 	elsif ecx_utils.g_target(i).attribute_type = 1
1352 	then
1353                 if (ecx_print_local.first_time_printing)
1354 		then
1355 		   do_printing := true;
1356 		   ecx_print_local.first_time_printing := false;
1357 		   suppress_profile := get_suppress_profile;
1358 		   /* Reinitialize the clob, so that it would not have left over
1359                       data from previous run */
1360                    if dbms_lob.istemporary(i_xmldoc) = 1 then
1361                       dbms_lob.freetemporary(i_xmldoc);
1362                    end if;
1363                    i_xmldoc := null;
1364 		else
1365 		   if ecx_utils.g_target(i).parent_attribute_id =
1366 		      l_node_stack(l_node_stack.LAST)
1367 		   then
1368       		      if(l_statementEnabled) then
1369                         ecx_debug.log(l_statement,  'condition true',i_method_name);
1370 	              end if;
1371 		      do_printing := true;
1372 		   else
1373 		      do_printing := false;
1374 		      if(l_statementEnabled) then
1375                         ecx_debug.log(l_statement,  'condition false',i_method_name);
1376 	              end if;
1377 		   end if;
1378 		end if;
1379 		if (do_printing)
1380 		then
1381                         /*
1382                           before we put the current element on the stack, if this element's parent has
1383                           any discontinuous elements that were not printed we need to print these
1384                         */
1385 
1386                         if (l_node_stack.COUNT <> 0)
1387                         then
1388                         	print_discont_elements(last_printed + 1, current_position - 1,
1389                                 	               l_node_stack(l_node_stack.LAST),
1390                                         	       ecx_utils.g_target(l_node_stack
1391                                                        (l_node_stack.LAST)).external_level);
1392 				/*
1393 	                          if at all any discontinuous elements were printed we need to once
1394                                   again ensure if the last element on the stack is the current
1395                                   element's parent. if not we need to pop till this condition is
1396                                   satisfied
1397 				*/
1398 	                        pop_discont_elements(ecx_utils.g_target(i).parent_attribute_id);
1399                         end if;
1400 					if(l_statementEnabled) then
1401 						ecx_debug.log(l_statement,'value:',ecx_utils.g_target(i).value,
1402 				                 i_method_name);
1403 						ecx_debug.log(l_statement,'flag:',ecx_utils.g_target(i).required_flag,
1404 				                 i_method_name);
1405 						ecx_debug.log(l_statement,'attribute name:',ecx_utils.g_target(i).attribute_name,
1406 				                 i_method_name);
1407 					end if;
1408 
1409 			-- if suppress profile is true and node is optional and does not have a value then push it on the stack .
1410 			-- Do not print it.
1411 			if (suppress_profile AND
1412 			    ecx_utils.g_target(i).value is null AND
1413                             ecx_utils.g_target(i).required_flag = 'N' AND NOT has_fragment_value(i))
1414 			then
1415                                 xmlPUSH(ecx_utils.g_target(i).attribute_id);
1416 			else
1417 
1418 			 	-- This means that either the node has a value or attributes or
1419                                 -- that it was required. In this case we need to both print and push
1420 				-- it.Also we will advance our the last_node_printed pointer
1421 
1422 				print_waiting_nodes;
1423 
1424 			  	if ecx_utils.g_target(i).has_attributes > 0
1425 				then
1426 					element_open(ecx_utils.g_target(i).attribute_name);
1427 					if(l_statementEnabled) then
1428 						ecx_debug.log(l_statement,'<'||ecx_utils.g_target(i).attribute_name,
1429 				                 i_method_name);
1430 					end if;
1431 				else
1432  					/** Change required for Clob Support -- 2263729 ***/
1433                 		       	if  ecx_utils.g_target(i).is_clob is not null Then
1434                         	        	cdata_element_node_open
1435                                		        (
1436 						ecx_utils.g_target(i).attribute_name,
1437 						ecx_utils.g_target(i).value,
1438                 	                       	ecx_utils.g_target(i).clob_value
1439                         	               	);
1440                         		else
1441                                                 if (has_fragment(i)) then
1442                                                   print_xml_fragment(i,true);
1443                                                 else
1444 						element_node_open
1445 						(
1446 						ecx_utils.g_target(i).attribute_name,
1447 						ecx_utils.g_target(i).value,
1448 	                	                ecx_utils.g_target(i).clob_value
1449 						);
1450                                                 end if;
1451                	 	        	end if;
1452 		    			if(l_statementEnabled) then
1453 	                                    ecx_debug.log(l_statement,'<'||ecx_utils.g_target(i).attribute_name||'>',
1454 					                 i_method_name);
1455 					end if;
1456 				end if;
1457 			  	xmlPUSH(ecx_utils.g_target(i).attribute_id);
1458 				last_node_printed := l_node_stack.LAST;
1459 			    	if(l_statementEnabled) then
1460                                 	ecx_debug.log(l_statement,'last_node_printed = ', last_node_printed, i_method_name);
1461 				end if;
1462 			end if;
1463         	        ecx_print_local.last_printed := ecx_utils.g_target(i).attribute_id;
1464                         if(l_statementEnabled) then
1465                            ecx_debug.log(l_statement,'last_printed ', last_printed,i_method_name);
1466 			end if;
1467 
1468 		elsif ecx_utils.g_target(i).parent_attribute_id <> l_node_stack(l_node_stack.LAST)
1469 		then
1470                         loop_count := 0;
1471 			loop
1472 				exit when l_node_stack(l_node_stack.LAST) =
1473 					ecx_utils.g_target(i).parent_attribute_id;
1474                                 --     or loop_count >= l_loop_max;
1475                                 if loop_count >= l_loop_max then
1476                                     ecx_debug.log(l_statement,'Abnormal Termination, Node Stack:','stack',i_method_name);
1477                                     print_node_stack;
1478                                     ecx_debug.log(l_statement,'Value for i: ',i,i_method_name);
1479                                     ecx_debug.log(l_statement,'Start position: ',start_pos,i_method_name);
1480                                     ecx_debug.log(l_statement,'Current position: ',current_position,i_method_name);
1481                                     ecx_debug.log(l_statement,'Current target element: ',ecx_utils.g_target(i).attribute_name,i_method_name);
1482                                     raise_application_error(-20000,'Abnormal condition encountered, infinite loop detected');
1483                                 end if;
1484 
1485                         	/*
1486                           	before we close the current element if this element has any discontinuous
1487                           	elements that were not printed we need to print these
1488                           	since we are closing this elment we know need to look for discont elements
1489                          	only till the file_end_pos of this element's level and not the current_pos
1490                         	*/
1491                         	start_pos := last_printed + 1;
1492 
1493                                 if (is_descendant(l_node_stack(l_node_stack.LAST), i))
1494                                 then
1495                                         if ( l_node_stack.LAST = w_note_stack_last and
1496                                              i                 = w_i and
1497                                              start_pos         = w_start_pos and
1498                                              current_position  = w_current_position)
1499                                         then
1500                                              loop_count := loop_count + 1;
1501                                         else
1502                                              loop_count := 0;
1503                                              w_note_stack_last := l_node_stack.LAST;
1504                                              w_i := i;
1505                                              w_start_pos := start_pos;
1506                                              w_current_position := current_position;
1507                                         end if;
1508 
1509                                         end_pos := current_position;
1510                                         print_discont_elements (start_pos, end_pos,
1511                                                  l_node_stack(l_node_stack.LAST),
1512                                                  ecx_utils.g_target(l_node_stack
1513                                                  (l_node_stack.LAST)).external_level);
1514 				else
1515                                         loop_count := 0;
1516                         		end_pos := ecx_utils.g_target_levels(ecx_utils.g_target(l_node_stack
1517                                 	   (l_node_stack.LAST)).external_level).file_end_pos;
1518 
1519        	                		print_discont_elements (start_pos, end_pos,
1520                	                        	l_node_stack(l_node_stack.LAST),
1521                         	               	ecx_utils.g_target(l_node_stack
1522                                                	(l_node_stack.LAST)).external_level);
1523 
1524                                         if (not (is_descendant(l_node_stack(l_node_stack.LAST), i)))
1525                                         then
1526 
1527 						-- check if an element needs to be closed.
1528 						-- element will need to be closed only if it was opened.
1529 						-- if it were opened then the last_node_printed id should be set to the last
1530 						-- on stack
1531 						if(last_node_printed = l_node_stack.LAST)
1532 						then
1533   					    		/** Change required for Clob Support -- 2263729 ***/
1534                         		    		if ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).is_clob is not null Then
1535 								cdata_element_node_close
1536                                 				(
1537 								ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).attribute_name,
1538 								ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).value,
1539 								ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).clob_value
1540                         	        			);
1541                         			    	else
1542 			   					element_node_close
1543 								(
1544 								ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).attribute_name
1545 								);
1546                 	        		    	end if;
1547 
1548 						    	if(l_statementEnabled) then
1549                                 	              		ecx_debug.log(l_statement,'</'||ecx_utils.g_target(l_node_stack(l_node_stack.LAST)).attribute_name||'>',
1550 						               i_method_name);
1551 					    		end if;
1552 						end if;
1553 						xmlPOP;
1554 					end if;
1555 				end if;  -- NOT an ancestor
1556 			end loop;
1557                         if ( loop_count >= l_loop_max )
1558                         then
1559 				if(l_statementEnabled)
1560 				then
1561                                         ecx_debug.log(l_statement,'l_loop_max reached: '||l_loop_max, i_method_name);
1562 				end if;
1563                         end if;
1564 
1565                 	/*
1566                   	before we push the current element if this element's parent has any
1567                   	discontinuous elements that were not printed we need to print these
1568                 	*/
1569 
1570                 	print_discont_elements (last_printed + 1, current_position - 1,
1571                                                l_node_stack(l_node_stack.LAST),
1572                                                ecx_utils.g_target(l_node_stack
1573                                                (l_node_stack.LAST)).external_level);
1574 			/*
1575                           if at all any discontinuous elements were printed we need to once again
1576                           ensure if the last element on the stack is the current element's parent
1577                           if not we need to pop till this condition is satisfied
1578 			*/
1579                         pop_discont_elements(ecx_utils.g_target(i).parent_attribute_id);
1580 
1581 			-- Move this one on the Stack.
1582 			-- Check for the next Node whether it is Attribute Node or not
1583 
1584 			-- if suppress profile is true and node is optional and does not have a value
1585 			-- just push it on the stack . do not print it
1586 			if (suppress_profile AND
1587 			    ecx_utils.g_target(i).value is null AND
1588 			    ecx_utils.g_target(i).required_flag = 'N')
1589 			then
1590 				  xmlPUSH(ecx_utils.g_target(i).attribute_id);
1591 			else
1592 
1593 			 	-- Either the node has a value or attributes or that
1594 				-- it was required. in this case we need to both print and push it.
1595 				-- Also we will advance our the last_node_printed pointer print_waiting_nodes;
1596 				print_waiting_nodes;
1597 
1598 			  	if ecx_utils.g_target(i).has_attributes > 0
1599 			  	then
1600 		  			element_open(ecx_utils.g_target(i).attribute_name);
1601 					if(l_statementEnabled)
1602 					then
1603 	                                        ecx_debug.log(l_statement,'<'||ecx_utils.g_target(i).attribute_name, i_method_name);
1604 					end if;
1605 			  	else
1606  					/** Change required for Clob Support -- 2263729 ***/
1607                         		if ecx_utils.g_target(i).is_clob is not null Then
1608 	                               		cdata_element_node_open
1609                                        		(
1610 						ecx_utils.g_target(i).attribute_name,
1611 						ecx_utils.g_target(i).value,
1612                 	                       	ecx_utils.g_target(i).clob_value
1613         	                               	);
1614                         		else
1615                                                 if (has_fragment(i)) then
1616                                                   print_xml_fragment(i,true);
1617                                                 else
1618 						element_node_open
1619 						(
1620 						ecx_utils.g_target(i).attribute_name,
1621 						ecx_utils.g_target(i).value,
1622 	                        	        ecx_utils.g_target(i).clob_value
1623 						);
1624                                                 end if;
1625 	                        	end if;
1626 					if(l_statementEnabled) then
1627                                     		ecx_debug.log(l_statement,'<'||ecx_utils.g_target(i).attribute_name||'>',
1628 				                 i_method_name);
1629 					end if;
1630 				end if;
1631 				xmlPUSH(ecx_utils.g_target(i).attribute_id);
1632                                 last_node_printed := l_node_stack.LAST;
1633 				if(l_statementEnabled) then
1634 	                           ecx_debug.log(l_statement, 'last_node_printed = ', last_node_printed,i_method_name);
1635 				end if;
1636 			end if;
1637 	                ecx_print_local.last_printed := ecx_utils.g_target(i).attribute_id;
1638                 	if(l_statementEnabled) then
1639                            ecx_debug.log(l_statement, 'last_printed', last_printed,i_method_name);
1640 			end if;
1641                  end if;
1642 	end if;
1643 	exit when ecx_utils.g_target.LAST = i;
1644 	i := ecx_utils.g_target.NEXT(i);
1645 	exit when ecx_utils.g_target(i).external_level <> i_level;
1646 end loop;
1647 
1648 append_clob;
1649 
1650 if (l_procedureEnabled) then
1651   ecx_debug.pop(i_method_name);
1652 end if;
1653 
1654 exception
1655 when ecx_utils.program_exit then
1656         if (l_procedureEnabled) then
1657            ecx_debug.pop(i_method_name);
1658         end if;
1659 	ecx_print_local.suppress_profile := false;
1660 	raise ECX_UTILS.PROGRAM_EXIT;
1661 when others then
1662 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.PRINT_NEW_LEVEL');
1663 	if(l_unexpectedEnabled) then
1664             ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.PRINT_NEW_LEVEL',
1665 	                 i_method_name);
1666 	    ecx_debug.log(l_unexpected, 'resetting first_time',i_method_name);
1667 	end if;
1668 	ecx_print_local.first_time_printing := true;
1669 	ecx_print_local.suppress_profile := false;
1670 	if (l_procedureEnabled) then
1671            ecx_debug.pop(i_method_name);
1672         end if;
1673 	raise ECX_UTILS.PROGRAM_EXIT;
1674 end print_new_level;
1675 
1676 
1677 procedure escape_spec_char(
1678    p_value     IN          Varchar2,
1679    x_value     OUT  NOCOPY Varchar2
1680    ) is
1681 
1682 i_method_name   varchar2(2000) := 'ecx_print_local.escape_spec_char';
1683 
1684 begin
1685    if (p_value is null) then
1686       return;
1687    end if;
1688    x_value := p_value;
1689    x_value := replace(x_value,i_amp, i_amp||'amp;');
1690    x_value := replace(x_value,i_lt, i_amp||'lt;');
1691    x_value := replace(x_value,i_gt, i_amp||'gt;');
1692    x_value := replace(x_value,i_apos, i_amp||'apos;');
1693    x_value := replace(x_value,i_quot, i_amp||'quot;');
1694 exception
1695 when value_error then
1696         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
1697         if(l_unexpectedEnabled) then
1698           ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
1699 	end if;
1700         raise ECX_UTILS.PROGRAM_EXIT;
1701 when ecx_utils.program_exit then
1702 	raise ECX_UTILS.PROGRAM_EXIT;
1703 when others then
1704       ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.escape_spec_char');
1705       if(l_unexpectedEnabled) then
1706           ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.escape_spec_char',i_method_name);
1707       end if;
1708       raise ecx_utils.program_exit;
1709 end escape_spec_char;
1710 
1711 procedure replace_spec_char(
1712    p_value     IN          Varchar2,
1713    x_value     OUT  NOCOPY Varchar2
1714    ) is
1715 
1716 i_method_name   varchar2(2000) := 'ecx_print_local.replace_spec_char';
1717 
1718 begin
1719    if(l_statementEnabled) then
1720      ecx_debug.log(l_statement, 'p_value',  p_value,i_method_name);
1721    end if;
1722    if (p_value is null) then
1723       return;
1724    end if;
1725    x_value := p_value;
1726    x_value := replace(x_value,i_amp||'amp;', i_amp);
1727    x_value := replace(x_value,i_amp||'lt;', i_lt);
1728    x_value := replace(x_value,i_amp||'gt;', i_gt);
1729    x_value := replace(x_value,i_amp||'apos;', i_apos);
1730    x_value := replace(x_value,i_amp||'quot;', i_quot);
1731 
1732    x_value := replace(x_value,i_amp||'#38;', i_amp);
1733    x_value := replace(x_value,i_amp||'#60;', i_lt);
1734    x_value := replace(x_value,i_amp||'#62;', i_gt);
1735    x_value := replace(x_value,i_amp||'#39;', i_apos);
1736    x_value := replace(x_value,i_amp||'#34;', i_quot);
1737 
1738    x_value := replace(x_value,i_amp||'#x26;', i_amp);
1739    x_value := replace(x_value,i_amp||'#x3c;', i_lt);
1740    x_value := replace(x_value,i_amp||'#x3e;', i_gt);
1741    x_value := replace(x_value,i_amp||'#x27;', i_apos);
1742    x_value := replace(x_value,i_amp||'#x22;', i_quot);
1743 
1744    if(l_statementEnabled) then
1745      ecx_debug.log(l_statement,'x_value',  x_value,i_method_name);
1746    end if;
1747 exception
1748    when others then
1749       ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_PRINT_LOCAL.replace_spec_char');
1750       if(l_unexpectedEnabled) then
1751         ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_PRINT_LOCAL.replace_spec_char',i_method_name);
1752       end if;
1753       raise ecx_utils.program_exit;
1754 end replace_spec_char;
1755 procedure get_chunks
1756         (
1757          clob_value    IN clob,
1758          is_cdata      IN boolean
1759         )
1760 is
1761 
1762 i_method_name   varchar2(2000) := 'ecx_print_local.get_chunks';
1763 
1764 i       pls_integer:=1;
1765 clength pls_integer:=0;
1766 i_temp varchar2(32767);
1767 --i_temp1 varchar2(32767);
1768 Begin
1769 	clength := dbms_lob.getlength(clob_value);
1770         while clength >= i loop
1771         	i_temp := dbms_lob.substr(clob_value,g_split_threshold,i);
1772 /*
1773                 if (not is_cdata) then
1774                     escape_spec_char(i_temp, i_temp1);
1775                 else
1776                     i_temp1 := i_temp;
1777                 end if;
1778                 i_tmpxml(i_tmpxml.COUNT+1) := i_temp1;
1779 */
1780 		get_chunks(i_temp, is_cdata);
1781                 i := i+ g_split_threshold;
1782  	end loop;
1783 Exception
1784 when value_error then
1785         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
1786         if(l_unexpectedEnabled) then
1787           ecx_debug.log(l_unexpected, ecx_utils.i_errbuf,i_method_name);
1788 	end if;
1789         raise ECX_UTILS.PROGRAM_EXIT;
1790 when ecx_utils.program_exit then
1791 	raise ECX_UTILS.PROGRAM_EXIT;
1792 When Others Then
1793 	ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' - ECX_PRINT_LOCAL.GET_CHUNKS');
1794 	if(l_unexpectedEnabled) then
1795           ecx_debug.log(l_unexpected, 'ECX', ecx_utils.i_errbuf || SQLERRM || ' - ECX_PRINT_LOCAL.GET_CHUNKS',
1796 	               i_method_Name);
1797 	end if;
1798         raise ecx_utils.program_exit;
1799 End;
1800 
1801 
1802 
1803 procedure get_chunks
1804         (
1805           value    IN varchar2,
1806           is_cdata      IN boolean
1807         )
1808 is
1809 
1810 i_method_name   varchar2(2000) := 'ecx_print_local.get_chunks';
1811 
1812 i       pls_integer:=1;
1813 clength pls_integer:=0;
1814 i_temp  varchar2(32767);
1815 i_temp1 varchar2(4000);
1816 Begin
1817 	if (not is_cdata) then
1818 	    escape_spec_char(value, i_temp);
1819 	else
1820 	    i_temp := value;
1821 	end if;
1822 	clength := lengthb(i_temp);
1823         while clength >= i loop
1824 		i_temp1 := substrb(i_temp,i,g_split_threshold);
1825                 i_tmpxml(i_tmpxml.COUNT+1) := i_temp1;
1826                 i := i+ g_split_threshold;
1827 	end loop;
1828 Exception
1829 when value_error then
1830         ecx_debug.setErrorInfo(1, 30, 'ECX_INVALID_VARCHAR2_LEN');
1831         if(l_unexpectedEnabled) then
1832           ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
1833 	end if;
1834         raise ECX_UTILS.PROGRAM_EXIT;
1835 when ecx_utils.program_exit then
1836 	raise ECX_UTILS.PROGRAM_EXIT;
1837 When Others Then
1838 	ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' - ECX_PRINT_LOCAL.GET_CHUNKS');
1839 	if(l_unexpectedEnabled) then
1840           ecx_debug.log(l_unexpected,'ECX', ecx_utils.i_errbuf || SQLERRM || ' - ECX_PRINT_LOCAL.GET_CHUNKS',
1841 	               i_method_name);
1842 	end if;
1843         raise ecx_utils.program_exit;
1844 End;
1845 
1846 
1847 FUNCTION has_fragment (var_pos IN pls_integer) return boolean
1848 is
1849   i_method_name   varchar2(2000) := 'ecx_print_local.has_fragment';
1850   flag varchar2(1):= 'N';
1851 BEGIN
1852 
1853   if (ecx_utils.g_xml_frag.count >0 and ecx_utils.g_target(var_pos).value is
1854        null and ecx_utils.g_target(var_pos).clob_value is null) then
1855 
1856    for i in ecx_utils.g_xml_frag.FIRST .. ecx_utils.g_xml_frag.LAST
1857    loop
1858       if (var_pos = ecx_utils.g_xml_frag(i).variable_pos) then
1859 
1860       flag := 'Y';
1861       exit;
1862       end if;
1863    end loop;
1864   else
1865      return FALSE;
1866   end if;
1867 
1868   if  (flag = 'Y') then
1869    return TRUE;
1870   else
1871     return FALSE;
1872   end if;
1873 exception
1874  When Others Then
1875         ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' - ECX_PRINT_LOCAL.HAS_FRAGMENT');
1876         if(l_unexpectedEnabled) then
1877           ecx_debug.log(l_unexpected,'ECX', ecx_utils.i_errbuf || SQLERRM || ' - ECX_PRINT_LOCAL.HAS_FRAGMENT',
1878                        i_method_name);
1879         end if;
1880         raise ecx_utils.program_exit;
1881 
1882 end;
1883 
1884 FUNCTION has_fragment_value (var_pos IN pls_integer) return boolean
1885 is
1886  i_method_name   varchar2(2000) := 'ecx_print_local.has_fragment_value';
1887  flag varchar2(1):= 'N';
1888 BEGIN
1889   if (ecx_utils.g_xml_frag.count >0 and ecx_utils.g_target(var_pos).value is
1890   null and ecx_utils.g_target(var_pos).clob_value is null) then
1891 
1892    for i in ecx_utils.g_xml_frag.FIRST .. ecx_utils.g_xml_frag.LAST
1893    loop
1894      if (var_pos = ecx_utils.g_xml_frag(i).variable_pos and
1895           ecx_utils.g_xml_frag(i).value is not null) then
1896      flag := 'Y';
1897      exit;
1898      end if;
1899    end loop;
1900   else
1901      return FALSE;
1902   end if;
1903   if  (flag = 'Y') then
1904    return TRUE;
1905   else
1906     return FALSE;
1907   end if;
1908 EXCEPTION
1909  When Others Then
1910         ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' -
1911                                 ECX_PRINT_LOCAL.HAS_FRAGMENT_VALUE');
1912         if(l_unexpectedEnabled) then
1913           ecx_debug.log(l_unexpected,'ECX', ecx_utils.i_errbuf || SQLERRM || ' -
1914                                   ECX_PRINT_LOCAL.HAS_FRAGMENT_VALUE',
1915                                    i_method_name);
1916         end if;
1917         raise ecx_utils.program_exit;
1918 
1919 end;
1920 
1921 PROCEDURE print_xml_fragment (var_pos IN pls_integer,
1922                               print_tag IN boolean)
1923 is
1924 i_method_name   varchar2(2000) := 'ecx_print_local.print_xml_fragment';
1925 begin
1926  if (l_procedureEnabled) then
1927      ecx_debug.push(i_method_name);
1928  end if;
1929 
1930  if(l_statementEnabled) then
1931      ecx_debug.log(l_statement,'attribute_name',
1932        ecx_utils.g_target(var_pos).attribute_name,i_method_name);
1933  end if;
1934 
1935   if (print_tag) then
1936     i_tmpxml(i_tmpxml.COUNT+1) :=
1937              i_elestarttag||ecx_utils.g_target(var_pos).attribute_name ||i_eleendtag;
1938   end if;
1939   if (ecx_utils.g_xml_frag.count > 0) then
1940    for i in ecx_utils.g_xml_frag.FIRST .. ecx_utils.g_xml_frag.LAST
1941    loop
1942      if (var_pos = ecx_utils.g_xml_frag(i).variable_pos) then
1943       if (ecx_utils.g_xml_frag(i).value is not null) then
1944          get_chunks(ecx_utils.g_xml_frag(i).value,true);
1945       end if;
1946       exit;
1947      end if;
1948    end loop;
1949   end if;
1950   if (l_procedureEnabled) then
1951     ecx_debug.pop(i_method_name);
1952   end if;
1953 EXCEPTION
1954  When Others Then
1955         ecx_debug.setErrorInfo(2, 30, ecx_utils.i_errbuf || SQLERRM || ' - ECX_PRINT_LOCAL.PRINT_XML_FRAGMENT');
1956         if(l_unexpectedEnabled) then
1957           ecx_debug.log(l_unexpected,'ECX', ecx_utils.i_errbuf || SQLERRM || ' - ECX_PRINT_LOCAL.PRINT_XML_FRAGMENT',
1958                        i_method_name);
1959         end if;
1960         raise ecx_utils.program_exit;
1961 end;
1962 
1963 end ecx_print_local;