DBA Data[Home] [Help]

PACKAGE BODY: APPS.WF_RENDER

Source


1 package body WF_RENDER as
2 /* $Header: wfrenb.pls 115.3 2004/01/30 08:03:19 vshanmug noship $ */
3 
4 -- Bug 2580807 Moved Render from Wf_Event to here and rename it to
5 -- xml_style_sheet
6 -- Original Bug 2376197
7 /*
8 ** DefaultRender (PRIVATE)
9 ** Replaces < and > symbols within a XML document with lt; and gt; to be
10 ** displayed within html pages.
11 */
12 PROCEDURE DefaultRender(l_data  in out nocopy clob)
13 is
14   l_amp     varchar2(1) := '&';
15   l_lt      varchar2(1) := '<';
16   l_gt      varchar2(1) := '>';
17   tmp       clob;
18   buf       varchar2(32767);
19   amt       number;
20   chunksize number := 16000;
21   offset    number := 1;
22 
23 begin
24   amt := DBMS_LOB.GetLength(l_data);
25   DBMS_LOB.CreateTemporary(tmp, TRUE, DBMS_LOB.session);
26   -- display XML content in a pre formatted way if the
27   dbms_lob.writeappend(tmp, 5, '<PRE>');
28   loop
29     if amt > chunksize then
30       dbms_lob.read(l_data, chunksize, offset, buf);
31       buf := replace(buf, l_amp, l_amp||'amp;');
32       buf := replace(buf, l_gt, l_amp||'gt;');
33       buf := replace(buf, l_lt, l_amp||'lt;');
34       dbms_lob.WriteAppend(tmp, length(buf), buf);
35       amt := amt - chunksize;
36       offset := offset + chunksize;
37     else
38       dbms_lob.read(l_data, amt, offset, buf);
39       buf := replace(buf, l_amp, l_amp||'amp;');
40       buf := replace(buf, l_gt, l_amp||'gt;');
41       buf := replace(buf, l_lt, l_amp||'lt;');
42       dbms_lob.WriteAppend(tmp, length(buf), buf);
43       exit;
44     end if;
45   end loop;
46   dbms_lob.writeappend(tmp, 6, '</PRE>');
47 
48   amt := dbms_lob.GetLength(tmp);
49   dbms_lob.copy(l_data, tmp, amt, 1, 1);
50 
51 exception
52   when others then
53     -- don't do anything, give back what you have processed
54     null;
55 end DefaultRender;
56 ---------------------------------------------------------------------------
57 /*
58 ** Standard PLSQLCLOB API to render the CLOB event data of an event in a
59 ** notification message.
60 */
61 PROCEDURE XML_Style_Sheet (document_id   in     varchar2,
62                   display_type  in     varchar2,
63                   document      in out nocopy clob,
64                   document_type in out nocopy varchar2)
65 is
66   l_sig_text    varchar2(1);
67   l_event       wf_event_t;
68   l_attr        varchar2(100);
69   l_evt_attr    varchar2(30);
70   l_nid         number;
71   l_txslt_name  varchar2(256);
72   l_hxslt_name  varchar2(256);
73   l_txslt_ver   varchar2(20);
74   l_hxslt_ver   varchar2(20);
75   l_tapp_code   varchar2(256);
76   l_happ_code   varchar2(256);
77   l_retcode     pls_integer;
78   l_retmsg      varchar2(2000);
79   slash         number;
80   next_slash    number;
81   l_parser      xmlparser.parser;
82   l_amount      number;
83   l_data        clob;
84   l_temp        clob;
85 begin
86   -- parser instance to parse XML CLOB document
87   l_parser := xmlParser.NewParser;
88 
89   -- parse document id to get the parameters
90   slash := instr(document_id, '/', 1);
91   l_attr := substr(document_id, 1, slash-1);
92   next_slash := instr(document_id, '/', slash+1);
93   l_txslt_name := substr(document_id, slash+1, next_slash-slash-1);
94   slash := next_slash;
95   next_slash := instr(document_id, '/', slash+1);
96   l_txslt_ver := substr(document_id, slash+1, next_slash-slash-1);
97   slash := next_slash;
98   next_slash := instr(document_id, '/', slash+1);
99   l_tapp_code := substr(document_id, slash+1, next_slash-slash-1);
100   slash := next_slash;
101   next_slash := instr(document_id, '/', slash+1);
102   l_hxslt_name := substr(document_id, slash+1, next_slash-slash-1);
103   slash := next_slash;
104   next_slash := instr(document_id, '/', slash+1);
105   l_hxslt_ver := substr(document_id, slash+1, next_slash-slash-1);
106   slash := next_slash;
107   l_happ_code := substr(document_id, slash+1);
108 
109   -- parse for event attribute name and notification id from the
110   -- first parameter
111   l_evt_attr := substr(l_attr, 1, instr(document_id, ':', 1)-1);
112   l_nid := to_number(substr(l_attr, instr(document_id, ':', 1)+1));
113 
114   -- get profile value for WF_SIG_TEXT_ONLY
115   l_sig_text := fnd_profile.value('WF_SIG_TEXT_ONLY');
116 
117   -- get the event from wf_notification_attributes
118   dbms_lob.createtemporary(l_data, TRUE, DBMS_LOB.Session);
119   l_event := Wf_Notification_Util.GetAttrEvent(l_nid, l_evt_attr);
120   l_temp := l_event.GetEventData();
121   l_amount := dbms_lob.getLength(l_temp);
122   dbms_lob.copy(l_data, l_temp, l_amount, 1, 1);
123 
124   -- if no XML document do nothing
125   if (l_data is NULL) then
126      return;
127   end if;
128 
129   -- for text only profile
130   if (l_sig_text = 'Y') then
131      if (l_txslt_name is NULL) then
132         -- render XML content without transformation
133         wf_core.raise('WFE_DEFAULT_RENDER');
134      end if;
135      ecx_standard.perform_xslt_transformation
136                        (I_XML_FILE       => l_data,
137                         I_XSLT_FILE_NAME => l_txslt_name,
138                         I_XSLT_FILE_VER  => l_txslt_ver,
139                         I_XSLT_APPLICATION_CODE => l_tapp_code,
140                         I_RETCODE        => l_retcode,
141                         I_RETMSG         => l_retmsg);
142      if (l_retcode > 0) then
143         -- render XML content without transformation
144         wf_core.raise('WFE_DEFAULT_RENDER');
145      end if;
146      dbms_lob.append(document, l_data);
147      return;
148   end if;
149   if (display_type = WF_NOTIFICATION.doc_text) then
150      if (l_txslt_name is NULL) then
151         if (l_hxslt_name is NULL) then
152            -- render XML content without transformation
153            wf_core.raise('WFE_DEFAULT_RENDER');
154         else
155            -- use html stylesheet if no text style sheet available
156            l_txslt_name := l_hxslt_name;
157            l_txslt_ver := l_hxslt_ver;
158            l_tapp_code := l_happ_code;
159         end if;
160      end if;
161      -- apply style sheet
162      ecx_standard.perform_xslt_transformation
163                        (I_XML_FILE       => l_data,
164                         I_XSLT_FILE_NAME => l_txslt_name,
165                         I_XSLT_FILE_VER  => l_txslt_ver,
166                         I_XSLT_APPLICATION_CODE => l_tapp_code,
167                         I_RETCODE        => l_retcode,
168                         I_RETMSG         => l_retmsg);
169      if (l_retcode > 0) then
170         -- render XML content without transformation
171         wf_core.raise('WFE_DEFAULT_RENDER');
172      end if;
173      dbms_lob.append(document, l_data);
174      return;
175   end if;
176 
177   if (display_type = WF_NOTIFICATION.doc_html) then
178      if (l_hxslt_name is NULL) then
179         if( l_txslt_name is NULL) then
180            -- render XML content without transformation
181            wf_core.raise('WFE_DEFAULT_RENDER');
182         else
183            -- use text stylesheet if no html style sheet available
184            l_hxslt_name := l_txslt_name;
185            l_hxslt_ver := l_txslt_ver;
186            l_happ_code := l_tapp_code;
187         end if;
188      end if;
189      -- apply style sheet
190      ecx_standard.perform_xslt_transformation
191                        (I_XML_FILE       => l_data,
192                         I_XSLT_FILE_NAME => l_hxslt_name,
193                         I_XSLT_FILE_VER  => l_hxslt_ver,
194                         I_XSLT_APPLICATION_CODE => l_happ_code,
195                         I_RETCODE        => l_retcode,
196                         I_RETMSG         => l_retmsg);
197      if (l_retcode > 0) then
198         -- render XML content without transformation
199         wf_core.raise('WFE_DEFAULT_RENDER');
200      end if;
201      dbms_lob.append(document, l_data);
202      return;
203   end if;
204 exception
205   when others then
206      -- parse the XML and display the content after replaing < and > with
207      -- appropriate references
208      if (l_data IS NOT NULL) then
209         xmlparser.parseClob(l_parser, l_data);
210         if (display_type = Wf_Notification.doc_html) then
211            DefaultRender(l_data);
212         end if;
213         dbms_lob.append(document, l_data);
214      end if;
215 end XML_Style_Sheet;
216 ---------------------------------------------------------------------------
217 end WF_RENDER;