简体   繁体   中英

Velocity Removing New Line (Apache Velocity 2.0)

Recently we migrated our application from Velocity 1.7 to 2.0. But after the migration. I see a strange problem, that the output is chomping new lines and merging lines. This happens when we do a parseTemplate() call.

For Example, here is the piece of code that is causing the problem.

#if ($bvoipData && $bvoipConfigType == "TDM")
    call rsvp-sync
    !
    dial-peer cor custom
    !
    #parseTemplate ("IPFlex/VoiceDialPeer.vm")
    sip-ua
    .
    .
    .
    .

#end

With the previous version, the output came in like:

dial-peer hunt 1

!
sip-ua

 retry invite 2

 no cdp run

!

But with Velocity 2.0, I get the output as:

dial-peer hunt 1

!sip-ua

 retry invite 2

 no cdp run

!

I would expect the sip-ua to show up in a new line, rather it just merges it to the previous line.

The line:

dial-peer hunt 1

!

comes from the template IPFlex/VoiceDialPeer.vm .

Not sure if there is some extra configuration that was introduced as a part of the 2.0 release that I probably missed. Any pointers on this would be really helpful.

Velocity 2.0 introduces the notion of space gobbling .

I guess you would need to add

parser.space_gobbling = bc # stands for 'backward-compatible'

to your configuration.

More generally, to maximize backward compatibility with 1.7, you would need to set the following configuration:

# No automatic conversion of methods arguments
introspector.conversion_handler.class = none

# Use backward compatible space gobbling
parser.space_gobbling = bc

# Have #if($foo) only returns false if $foo is false or null
directive.if.empty_check = false

# Allow '-' in identifiers (since 2.1)
parser.allow_hyphen_in_identifiers = true

# Enable backward compatibility mode for Velocimacros
velocimacro.enable_bc_mode = true

# When using an invalid reference handler, also include quiet references (since 2.2)
event_handler.invalid_references.quiet = true

# When using an invalid reference handler, also include null references (since 2.2)
event_handler.invalid_references.null = true

# When using an invalid reference handler, also include tested references (since 2.2)
event_handler.invalid_references.tested = true

as stated on the upgrading page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM