2012-07-18 77 views
0

所有,的FreeMarker联模板(负载从数据库)不解释

我尝试加载从数据库中Freemarker模板Smooks配置文件中,并使用构建插件INTERPRET解析字符串作为模板。但是,输出完全是我存储在数据库中的模板。

以下是Smooks配置文件的一部分:


....

<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> 

.....


我存储在数据库模板就像下面:

<#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> 

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

出于某种原因,输出正好是上面的模板本身。 “$ {TravelerProfile.TravelerOfficeCode}”尚未评估!请帮忙!!!

谢谢!!!

艾格尼丝

回答

0

正弦mytemplate[0].freeMarker_template返回模板源代码本身(或至少我认为),因为你使用的是原始字符串字面量(r"..."),模板的源代码将字面${mytemplate[0].freeMarker_template},然后通过?interpret对模板源代码进行评估。修正后的模板将是:

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

这也可以写成:

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

,或者如果你不需要"myInlineTemplate"模板名称:

<@mytemplate[0].freeMarker_template?interpret />