velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Reck <Christoph.R...@dlr.de>
Subject Re: Quotation marks and CR in string literals?
Date Mon, 25 Mar 2002 15:29:06 GMT
Sorry to inform you that the escaping rules apply only to references
and directives. Within strings its another land...

Having newlines within parameter strings has been requested several 
times, but Geir has not yet tackled it (and has not yet loosened
the reins saying "scratch it if it itches you...").

As a workaround use:

#set( $SQ = "'" )
#set( $NL = $someTool.decode("0x0A") )

$foo.bar("${SQ}this${SQ} is quoted${NL}and this is in a new line').

Please don't cry, scream or hang yourself :>   I've seen places when generating
JavaScript with VTL that looked awfully ugly with interpolation...


Make a proposal or send a patch...


I included a complex VTL/JavaScript example at the end of this mail to show
the whole beauty and ugliness of VTL ;)


Daniel Dekany wrote:
> 
> I would like to put quotaton marks and linebreaks into string literals.
> Something like this:
> $foo.bar('\'this\' is quoted\nand this is in a new line').
> How to do it in VTL?
> 
> (If I get the answer that I should do it with string interpolation and some
> object in the context then I will either laugh or cry depending on my
> current mood... (However it would not be a big surprace after the escaping
> rules...))
> 
> --
> To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


I've also done dynamic HTML using JavaScript looking like something like
(variables like $title, $javascript,$bodyAttributes, etc. are rendered by 
a layout.vm template - I can send it to you if you would like to see it.):

#set( $title = "EOLI Applet Page" )
#set( $sessionId = $userSession.getHttpSessionId() )
##
#set( $COLORS.BODY  = "#06066E" )
##
#set( $treeDataURL = "$properties.getServletURL('KeywordSearchServlet')?action=results" )
##
#set( $button = "$properties.getServletPath('button')?fontSize=14&insetH=12" )
##
#set( $javascript = "var bodycolor='$COLORS.BODY'" )
#set( $javascript = "var SessionId='$sessionId';$LF$javascript" )
#set( $javascriptSrc = $properties.getHtmlURL('scriptPath', 'welcome/f_query.js') )
##
#set( $Q = '"' )## the loadAction needs nested VTL string interpolation
#set( $loadAction = "loadCriteria( $res.encodeURL($criteriaURL) )" )
#set( $bodyAttributes = ["onLoad=$Q$loadAction$Q", 'onUnload="closeWindow()"'] )
##
#set( $codebase = $properties.getHtmlURL('welcome/map_applet') )
#set( $appletProperties = $properties.getServletURL('AppletClientPropertiesServlet') )

<SCRIPT LANGUAGE="JavaScript">
  <!--
    // dynamically compute the applet size
    var width  = (document.layers)
      ? window.innerWidth - 4   // for Netscape
      : document.all.tags('body')[0].offsetWidth - 8;   // for MSIE
    var heigth = (document.layers)
      ? window.innerHeight - 4 // for Netscape
      : document.all.tags('body')[0].offsetHeight - 8; // for MSIE
    var html =
      '<applet name="queryApplet"\n' +
      '        codeBase="$codebase"\n' +
      '        archive="eoliApplet.jar"\n' +
      '        code="esa.esrin.muis.client.eoliApplet.EoliApplet.class"\n' +
      '        width="' + width + '" height="' + heigth + '"\n' +
      '        mayscript="mayscript" >\n' +
      '    <param name="sessionID"  value="$sessionId">\n' +
      '    <param name="properties" value="$res.encodeUrl($appletProperties)" >\n' +
      '</applet>\n' +
      '<center>\n' +
      '  <a href="javascript:closeWindow()"\n' +
      '   ><img src="$button&text=Close+Window"\n' +
      '     name="submit" alt="Close Window" border="0"></a>\n' +
      '</center>\n' +
      '\n';\n' +
    document.open();
    document.write(html);
  // -->
</SCRIPT>

-- 
:) Christoph Reck

--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message