I am working on contract module for my project.
The contract templates are stored as RTF template with many placeholders with syntax as @placeholder_name@
.
Each campaign entry is associated with a particular contract template at any given time.
When the contract for the campaign is requested/downloaded:
- the RTF template is read as a variable.
- placeholders within the file variable are replaced with the values from the query objects for the campaign.
- the variable is then send to the browser for download using
cfcontent
.
Problem
I need to remove the whole section in the rtf file, if the value for a particular placeholder is empty. For example: the Additional Information section here:
I was able to find out the following rtf block inside the file, which is the whole section of Additional Information above including the rtf table styling.
\par \ltrrow}\trowd \irow0\irowband0\lastrow \ltrrow\ts78\trgaph108\trleft-
810\trbrdrt\brdrdot\brdrw10 \trbrdrl\brdrdot\brdrw10 \trbrdrb\brdrdot\brdrw10 \trbrdrr\brdrdot\brdrw10 \trbrdrh\brdrdot\brdrw10 \trbrdrv\brdrdot\brdrw10 \trftsWidth3\trwWidth11520\trftsWidthB3\trftsWidthA3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid12942116\tbllkhdrrows\tbllkhdrcols\tbllknocolband\tblind-702\tblindtype3 \clvertalt\clbrdrt\brdrdot\brdrw10 \clbrdrl \brdrdot\brdrw10 \clbrdrb\brdrdot\brdrw10 \clbrdrr\brdrdot\brdrw10 \cltxlrtb\clftsWidth3\clwWidth3510\clshdrawnil \cellx2700\clvertalt\clbrdrt\brdrdot\brdrw10 \clbrdrl\brdrdot\brdrw10 \clbrdrb\brdrdot\brdrw10 \clbrdrr\brdrdot\brdrw10
\cltxlrtb\clftsWidth3\clwWidth8010\clshdrawnil \cellx10710\pard \ltrpar\ql \li0\ri0\sa200\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\pararsid4544034 {\rtlch\fcs1 \af1 \ltrch\fcs0 \insrsid3568873 Additional Information}{
\rtlch\fcs1 \af1 \ltrch\fcs0 \insrsid4544034 \cell }\pard \ltrpar\ql \li0\ri0\sa200\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0 {\rtlch\fcs1 \af1 \ltrch\fcs0 \insrsid3568873\charrsid4544034 @additional_contract_info@}{
\rtlch\fcs1 \af1 \ltrch\fcs0 \insrsid4544034 \cell }\pard \ltrpar\ql \li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0 {\rtlch\fcs1 \af1 \ltrch\fcs0 \insrsid4544034 \trowd \irow0\irowband0\lastrow \ltrrow
\ts78\trgaph108\trleft-810\trbrdrt\brdrdot\brdrw10 \trbrdrl\brdrdot\brdrw10 \trbrdrb\brdrdot\brdrw10 \trbrdrr\brdrdot\brdrw10 \trbrdrh\brdrdot\brdrw10 \trbrdrv\brdrdot\brdrw10
\trftsWidth3\trwWidth11520\trftsWidthB3\trftsWidthA3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid12942116\tbllkhdrrows\tbllkhdrcols\tbllknocolband\tblind-702\tblindtype3 \clvertalt\clbrdrt\brdrdot\brdrw10 \clbrdrl
\brdrdot\brdrw10 \clbrdrb\brdrdot\brdrw10 \clbrdrr\brdrdot\brdrw10 \cltxlrtb\clftsWidth3\clwWidth3510\clshdrawnil \cellx2700\clvertalt\clbrdrt\brdrdot\brdrw10 \clbrdrl\brdrdot\brdrw10 \clbrdrb\brdrdot\brdrw10 \clbrdrr\brdrdot\brdrw10
\cltxlrtb\clftsWidth3\clwWidth8010\clshdrawnil \cellx10710\row }\pard \ltrpar\ql \li0\ri0\sa200\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 {\rtlch\fcs1 \af1 \ltrch\fcs0 \insrsid4544034
\par }
I have been working on it to find a solution for days now. What I need is a regular expression statement in ColdFusion to find the block of \par
control word wrapped around the placeholder @additional_contract_info@
i.e Only the parent para for the placeholder:
the portion: "\par ...@additional_contract_info@ ...." until the ending \par
Assuming the paras are not nested.
I am not very proficient with Regular expression and I tried googling and searching SO for all types of related questions but couldn't solve it. I need help with it!