Встроенный шаблон FreeMarker (загрузка из базы данных) в Smooks не интерпретируется

Все,

Я пытаюсь загрузить шаблон 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}" не оценивался! Пожалуйста помоги!!!

Спасибо!!!

Агнес


person user1535552    schedule 18.07.2012    source источник


Ответы (1)


Sine 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 />
person ddekany    schedule 19.07.2012