Announcement Announcement Module
Collapse
No announcement yet.
Velocity db resource encoding Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Velocity db resource encoding

    I use velocity for both email and view(SpringMVC).
    And the velocityEngine is set to be multi-resource loader
    as followings.

    Everything seems work fine except that when I move the
    file template into dabatase, the rendering characters get
    garbled.

    Any advice will be appriciated!
    Thanks

    Code:
    <!-- Part of ApplicationContext-velocity.xml -->
    <bean id="velocityLayoutViewResolver"
      class="....VelocityLayoutViewResolver">
      <property name="viewClass">
          <value>...VelocityLayoutView</value>
      </property>
      <property name="toolboxConfigLocation">
          <value>/WEB-INF/toolbox.xml</value>
      </property>
      <property name="contentType">
          <value>text/html;charset=UTF-8</value>
      </property>        
    </bean>
    
    <bean id="velocityConfigurer"
      class="...VelocityConfigurer">
      <property name="velocityEngine">
          <ref bean="velocityEngine"/>
      </property>
    </bean>  
    
    <bean id="velocityEngine" class="...VelocityEngineFactoryBean"> 
      <property name="velocityPropertiesMap">
          <map>
              <entry key="resource.loader"><value>file, ds</value></entry>
              <entry key="ds.resource.loader.instance">
                  <ref bean="dbLoader"/>
              </entry>
              <entry key="ds.resource.loader.resource.table">
                  <value>velocity_template_table</value>
              </entry>
              <entry key="ds.resource.loader.resource.keycolumn">
                   <value>template_name</value>
              </entry>
              <entry key="ds.resource.loader.resource.templatecolumn">
                   <value>template_content</value>
               </entry>
              <entry key="ds.resource.loader.resource.timestampcolumn">
                   <value>template_timestamp</value>
               </entry>
              <entry key="file.resource.loader.class">
                  <value>org.apache.velocity.runtime.resource.loader.FileResourceLoader</value>
              </entry>
              <entry key="file.resource.loader.path">
                  <value>${myweb.root}/WEB-INF/velocity</value>
               </entry>
              <entry key="input.encoding">
                   <value>UTF-8</value>
              </entry>
            </map>
        </property>
    </bean>
    
    <bean id="dbLoader"  class="org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader">
        <property name="dataSource"><ref bean="dataSource"/></property>
    </bean>
    oracle10g characterset
    Code:
    >SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER='NLS_CHARACTERSET'
    UTF8
    velocity-1.5
    velocity-tools-view-1.3

  • #2
    It might be a problem that Velocity(1.5) DataSourceResourceLoader#getResourceStream uses ResultSet.getAsciiStream method to get data from database.
    After fixing it,everything seems to be working fine.

    Comment

    Working...
    X