0

All,

I try to load the FreeMarker template from database in the Smooks configuration file and use the build-ins INTERPRET to parse the string as template. However, the output is exactly the template I stored in the database.

The following is part of the Smooks configuration file:


....

<resource-config selector="hs:TravelerProfile">
    <resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<db:executor executeOnElement="hs:TravelerProfile" datasource="StagingDS">
          <db:statement>select freeMarker_template from template_lookup where agencyid='111'; 
          </db:statement>
          <db:resultSet name="mytemplate" />
    </db:executor>

<ftl:freemarker applyOnElementNS="www.travel.com" applyOnElement="TravelerProfile">

    <ftl:template>
    < !--       
    <#assign templateSource = r"${mytemplate[0].freeMarker_template}">
    <#assign inlineTemplate = [templateSource, "myInlineTemplate"]?interpret>
    <@inlineTemplate/> 
    -- >
    </ftl:template>
</ftl:freemarker>

.....


The template I stored in the database is like following:

<#ftl ns_prefixes={"D":"www.hhs.gov/travel"}>
<?xml version="1.0" encoding="UTF-8"?>
<po:PoHeadersInterfaceCollection xmlns:po="https://www.travel.com/xmlns/financial/po112007.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.travel.com/xmlns/financial/po112007.xsd">
  <po:PoHeadersInterface>
    <po:interfaceSourceCode>VendorName</po:interfaceSourceCode>
    <po:poLinesInterfaceCollection>
      <po:PoLinesInterface>
        <po:PoDistributionsInterfaceCollection>
          <po:PoDistributionsInterface>
            <po:destinationOrganizationId>${TravelerProfile.TravelerOfficeCode}
            </po:destinationOrganizationId>
          </po:PoDistributionsInterface>
        </po:PoDistributionsInterfaceCollection>
      </po:PoLinesInterface>
    </po:poLinesInterfaceCollection>
  </po:PoHeadersInterface>
</po:PoHeadersInterfaceCollection>

====================================

For some reason, the output is exactly the above template itself. "${TravelerProfile.TravelerOfficeCode}" has not been evaluated! Please help!!!

Thank you!!!

Agnes

1 Answers1

0

Sine mytemplate[0].freeMarker_template returns the template source code itself (or at least I assume that), and since you are using a raw string literal (r"..."), the source code of your template will be literally ${mytemplate[0].freeMarker_template}, which is then evaluated by ?interpret to the template source code. The corrected template would be:

<#assign inlineTemplate = [mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret>
<@inlineTemplate/>

which can be also written as:

<@([mytemplate[0].freeMarker_template, "myInlineTemplate"]?interpret) />

or if you don't need the "myInlineTemplate" template name:

<@mytemplate[0].freeMarker_template?interpret />
ddekany
  • 29,656
  • 4
  • 57
  • 64