How to set / get the content of the Java HTML Editor in Oracle Forms from a CLOB field including all images as base64 encoded strings

NOTE: If you want to retrieve the Java HTML Editor content including all document images embedded inside the document  encoded as strings you should use the following method:

public void setEmbedAllImagesInsideTheDocument(boolean embed)

public boolean isEmbedAllImagesInsideTheDocument()

like this:

hArgs:=FBEAN.CREATE_ARGLIST;
FBEAN.ADD_ARG(hArgs,true);
FBean.Invoke('HTMLEDITOR_AREA',1, 'setEmbedAllImagesInsideTheDocument',hArgs);

After that by simply retrieving the document content using getContent() or getBodyContent() you will get also all images embedded inside the document as strings and you can save them easily into a CLOB field. See below how to save/retrieve the HTMLEditor content from a CLOB field.

In the downloadable demo in the folder "examples/oracle forms" there is an example which contains the whole code and illustrates how this works.

INSERT INTO EDITOR FROM CLOB

For this example the database contains the table EPM_CONTRACT_CONS
and the structure of this table is as follows:

EPM_CONTRACT_CONS
==============================
EMP_NO                                  NUMBER
ASSUMPTION_DESC               CLOB
 

insert some text into ASSUMPTION_DESC, and set EMP_NO to 1. Here below is the code for inserting the CLOB field content inside the HTMLEditor.


DECLARE
  bean varchar2(200):='HTMLEDITOR_AREA';
  t_id number(20):=1;
  hArgs FBEAN.ARGLIST;
  parts number(20);
  part varchar2(32500);
  part_size number(20) := 1000;
  body_length number(20);
BEGIN

  hArgs := FBEAN.CREATE_ARGLIST;

       -- Init the editor buffer
      FBean.Invoke(bean,1,'openContentBuffer');
    
     
-- Get CLOB content length
          
     select nvl(dbms_lob.getlength(ASSUMPTION_DESC),0) into body_length from EPM_CONTRACT_CONS where EMP_NO = t_id;
    
     if body_length > 0 then
       
-- Get length and number of the parts
        select trunc(dbms_lob.getlength(ASSUMPTION_DESC)/ part_size) +1 into parts from EPM_CONTRACT_CONS where EMP_NO = t_id;
      
        for i in 1..parts loop
            select dbms_lob.substr(ASSUMPTION_DESC,part_size,((i-1)*part_size)+1) into part from EPM_CONTRACT_CONS where EMP_NO = t_id;
            hArgs := FBEAN.CREATE_ARGLIST;
            FBEAN.ADD_ARG(hArgs,part);

            -- Append each part to the content buffer

            FBean.Invoke(bean,1,'appendContentToContentBuffer',hArgs);
        end loop;
     
     end if;

     
-- Populate Editor
      FBean.Invoke(bean,1,'closeBufferAndInsert');

 
END;

 

SAVE INTO CLOB FROM EDITOR

This code is used to illustrate how to transfer the editor content to a CLOB field in the database.


For this example the database contains the table EPM_CONTRACT_CONS
and the structure of this table is as follows:

EPM_CONTRACT_CONS
==============================
EMP_NO                                  NUMBER
ASSUMPTION_DESC               CLOB
 

insert some text into ASSUMPTION_DESC, and set EMP_NO to 1. Here below is the code for inserting the CLOB field content inside the HTMLEditor.

DECLARE

  bean varchar2(200):='HTMLEDITOR_AREA';
  t_id number(20):=1;
  hArgs FBEAN.ARGLIST;
  parts number(20);
  part varchar2(32500);
  body_length number(20);
  r_hd clob := null;
  res_hd clob;
  part_size binary_integer := 4000;
  pos number(20);
  old_length number(20);
  last_part_size binary_integer;
BEGIN

  hArgs := FBEAN.CREATE_ARGLIST;
 

     body_length := FBean.Invoke_num(bean,1,'getBodyContentLenght');
      parts := trunc(body_length / part_size);
      DBMS_LOB.CREATETEMPORARY(r_hd,TRUE);

     
-- Complete parts
      if parts > 0 then
    
          for i in 1..parts loop
          hArgs := FBEAN.CREATE_ARGLIST;
          pos := ((i-1)*part_size);
            fbean.add_arg(hargs,pos);
            fbean.add_arg(hargs,part_size);
          part := fbean.invoke_char(bean,1,'getBodyContentPortion',hargs);
          dbms_lob.write(r_hd,part_size,pos+1,part);
          end loop;
        
       
-- Last part
        hArgs := FBEAN.CREATE_ARGLIST;
        pos := pos + part_size;
        last_part_size := body_length - (parts) * part_size;
          fbean.add_arg(hargs,pos);

          fbean.add_arg(hargs,last_part_size);
        part := fbean.invoke_char(bean,1,'getBodyContentPortion',hargs);
        dbms_lob.write(r_hd,last_part_size,pos+1,part);
      else
        hArgs := FBEAN.CREATE_ARGLIST;
          fbean.add_arg(hargs,0);
          fbean.add_arg(hargs,body_length);
        part := fbean.invoke_char(bean,1,'getBodyContentPortion',hargs);
        dbms_lob.write(r_hd,length(part),1,part);
      end if;

      update EPM_CONTRACT_CONS set ASSUMPTION_DESC = r_hd where EMP_NO = t_id;
      DBMS_LOB.FREETEMPORARY(r_hd);

 
END;