{-- ** -- ** -- ** -- ** I M P O R T A N T N O T E !!! -- ** -- ** -- ** this is an old script! - since build 247 of -- ** FormsAPI Master a ReportsAPI is included that -- ** makes this script redundant! -- ** -- ** Stefan Mueller, ORCL Toolbox - 19/Feb/03 -- ** -- ** -- ** -- ** -- ** -- ** -- ** } PROGRAM ReportsAPI_BoilerPlates; {-- *************************************************************************** -- ** Descr. : Oracle Reports has no real API like Forms does. It has some -- ** functionality to merge rdf with definitions of objects/properties -- ** in XML, however - modyfing existing properties (like sourcecode) -- ** is not currently supported. The workarround is to convert the -- ** RDF to a readable REX version and then parse the source yourself. -- ** -- ** This script will do this, showing how to parse a REX file, and -- ** extract and change boilerplate texts. This tutorial script -- ** changes the prompt by adding a 'Hello:' at the beginning and a -- ** ':End' at the end of the text. It also shows some techniques how -- ** to parse hex-coded strings (like boilertexts are, because of multi- -- ** byte language supports!). -- ** -- ** IMPORTANT: Oracle doesn't document and support the REX fileformat -- ** for doing such changes, tests have shown that it works, -- ** but please always test carefully! -- ** -- ** MINVERS: requires FormsAPI Master 1.0 Build 236 and up -- *************************************************************************** -- ** 17/03/02 1.001.00 Initial Creation, muellers@orcl-toolbox.com -- ***************************************************************************} VAR ps : TParamScreen; pb : tparamboard; l_dest,l_dest2 : string; i,i2 : integer; s : string; rexsource : string; rexdest : string; filename : string; function ConvertToRawRex(txt : varchar2) : string; var x,y : integer; lText : varchar2; begin result := ' len = ' + to_char(Length(txt))+C_CR; result := result + ' str = (BINARY)'+C_CR; result := result + '<<"'+C_CR; //Build up hex lines For x := 1 To Length(txt) do begin lText := lText + IntToHex(Ascii(txt[x])); If (x Mod 32) = 0 Then begin result := result + lText+C_CR; lText := ''; end else if (x Mod 4) = 0 then begin lText := lText + ' '; End; end; //At at end we right pad 00 to end of next string Y := (4 - (Length(txt) Mod 4)) * 2; If Y = 8 then lText := lText + ' 00000000' else lText := lText + substr('000000000000',1,y); result := result + lText+C_CR; end; procedure ConvertReport(srcfile : varchar2); var rexlist : tstringlist; k,x,d : number; lStartCapture : boolean; lStartHex : boolean; lHexString : varchar2; lOldPhrase : varchar2; lNewPhrase : varchar2; lhex : number; InputBuffer : varchar2; s : string; begin //create a list item to hold the lines of our rex-source file rexlist := tstringlist.create; //now load the rex source file rexlist.text := LoadString(srcfile); lStartCapture := false; lStartHex := false; k := 0; //loop through the source lines until we reach the end while k < rexlist.count do begin InputBuffer := rexlist.strings[k]; //search for the ROS-token that stands for boilerplate text if InputBuffer = 'DEFINE ROSSTRINGS' then begin //if found then start capture mode! lStartCapture := True; end; //if in capture mode then process the properties If lStartCapture Then begin //len and str tokens need to be rewritten, so remove them from the list! If (LeftString(InputBuffer, 8) = ' len =') or (LeftString(InputBuffer, 8) = ' str =') then begin // Ignore lines that are re-written when we rewrite phrase rexlist.delete(k); end else If InputBuffer = '<<"' Then begin //Recognised start of hex version of text lStartHex := True; lHexString := ''; rexlist.delete(k); end else If InputBuffer = '">>' Then begin //Recognise at end of hex and process as registration or translation accordingly lStartHex := False; lStartCapture := False; lOldPhrase := ''; lHexstring := upper(actrim(DeleteChar(lHexString, ' '))); //Convert HEX to Ascii For x := 1 to ((Length(lHexString)-1) div 2) do begin lhex := HexToInt(substr(lHexString, (x*2)-1, 2)); if lhex=0 then break else lOldPhrase := lOldPhrase + Chr(lhex); end; logadd(' => orig: '+lOldPhrase); lNewPhrase := 'Hello:'+lOldPhrase+':End'; rexlist.insert(k,ConvertToRawRex(lNewPhrase)); end else if lStartHex then //If currently reading in hex, then append to hex string and delete begin lHexString := lHexString + inputbuffer; rexlist.delete(k); end else begin inc(k); end; end else begin inc(k); end; end; //overwrite the modified rex-source with the new one SaveString(rexlist.text,srcfile); //free the list of our rex-source memory rexlist.free; end; //Start Main Program BEGIN //build the parameterscreen ps := TParamScreen.create; pb := ps.AddBoard('Reports Labelchanger Tutorial',picOptions); pb.addparam(parLabel,'MYLABEL','Please select the Reports file to change the label:','',''); pb.addparam(parFileName,'MYFILE','Source','','Reports (*.rdf)|*.rdf|All Files *.*|*.*'); //show parameterscreen if ps.ShowParamScreen then begin filename := ps.paramvalue('MYFILE'); logadd('Processing '+filename); host('rwcon60.exe stype=rdffile source='+filename+' dtype=rexfile batch=yes overwrite=yes',true); rexsource := ChangeFileExt(filename,'.rex'); if FileExists(rexsource)=false then RaiseException('Error converting reports rdf-file to rex-file!'); ConvertReport(rexsource); //now rename it to new_xxx.rex rexdest := extractfilepath(rexsource)+'new_'+extractfilename(rexsource); CopyFile(rexsource,rexdest); filename := ChangeFileExt(rexdest,'.rex'); //..and convert it host('rwcon60.exe stype=rexfile source='+rexdest+' dtype=rdffile batch=yes overwrite=yes',true); if FileExists(filename)=false then RaiseException(' => Error converting reports rex-file to rdf-file!'); end else begin logadd('pressed cancelbutton on parameterscreen!'); end; ps.free; END.