2012-07-18 75 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 />