You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Alexandre Martin <am...@istop.com> on 2002/11/26 18:02:56 UTC

Formatting Issue (Whitespace)

I have the following two macros. The content output is fine but the formatting is not how I want it. 

How can I modify my macros to output the content in the desired format (see below)?


#macro(button $index)
    #if($menu.size() > $index)
        #set($buttontext = $menu.elementAt($index).alttext)
 <A HREF="${menu.elementAt($index).link}"><IMG SRC="${req.contextPath}/button_factory?textColor=FFFFFF&bgColor=${accentcolor}&text=${utils.escapeForURL($buttontext)}"></A>
    #else
 &nbsp;<!-- empty button -->
    #end
#end
#macro(imenu $startindex)
    #if($menu.size() > $startindex)
        <TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="600" BORDER="0">
                <TR>
                    <TD>#button($startindex)</TD>
      #set($startindex = $startindex + 1)
                    <TD>#button($startindex)</TD>
                    #set($startindex = $startindex + 1)
                    <TD>#button($startindex)</TD>
                    #set($startindex = $startindex + 1)
                    <TD>#button($startindex)</TD>
                    #set($startindex = $startindex + 1)
                    <TD>#button($startindex)</TD>    
                </TR>
        </TABLE>
    #end
#end


Current Output:

    <TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="600" BORDER="0">
 <TR>
     <TD WIDTH="89" BGCOLOR="#990000">            <A HREF="menu0link"><IMG SRC="/button_factory?textColor=FFFFFF&BGCOLOR=990000&text=Search"></A>
</TD>
    <TD WIDTH="89" BGCOLOR="#990000">            <!-- empty button -->
</TD>
    <TD WIDTH="89" BGCOLOR="#990000">            <!-- empty button -->
</TD>
    <TD WIDTH="89" BGCOLOR="#990000">            <!-- empty button -->
</TD>
    <TD WIDTH="90" BGCOLOR="#990000">            <!-- empty button -->
</TD>    
 </TR>
</TABLE>
        

Desired Output:

<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="600" BORDER="0">
<TR>
    <TD WIDTH="89" BGCOLOR="#990000"><A HREF="menu0link"><IMG SRC="/button_factory?textColor=FFFFFF&BGCOLOR=990000&text=Search"></A></TD>
    <TD WIDTH="89" BGCOLOR="#990000"><!-- empty button --></TD>
    <TD WIDTH="89" BGCOLOR="#990000"><!-- empty button --></TD>
    <TD WIDTH="89" BGCOLOR="#990000"><!-- empty button --></TD>
    <TD WIDTH="90" BGCOLOR="#990000"><!-- empty button --></TD>    
</TR>
/TABLE>

Re: button factory

Posted by Ch...@dlr.de.
t b dinesh wrote:
> What is this button factory servlet?
> Where can I find it?
> 
> 
>>       *#<IMG SRC="${req.contextPath}/button_factory?#*
>>          *#textColor=FFFFFF&bgColor=${accentcolor}#*
>>          *#&text=${utils.escapeForURL($buttontext)}">#*
> 
> 
>>P.S. I see that you are using a button factory, is this based on my code? Cheers!
>>      As I've stated somewhere in some list the past (turbine, velocity,other?),
>>      it is intended to be published, can someone take a lead on this to get it
>>      into jakarta or sourceforge? I could also do this if someone points me in
>>      the right direction (jakarta account?).
>>

See the attachment.

In the webapp and web.xml I mapped the servlet to a simple name
     <servlet>
         <servlet-name>button</servlet-name>
         <servlet-class>de.dlr.dfd.muiswww.servlets.ButtonFactory</servlet-class>
     </servlet>

And use it out of velocity, e.g.:
...
#set( $button = "/button?fontSize=16&width=110&height=26&insetH=0&insetV=0&fgColor=0xFFFFFF&buttonColor=0x333333&borderColor=0x404040" )

...
         <img src="$button&text=Home" alt="Home" border="0"></a>


Please give feedback if you think this should go into Jakarta or sourceforge...


You can try it out live at:
   http://piglet.esrin.esa.it:8080/eoweb/servlets/button?text=Hello%20World!
PLEASE NO LIVE LINKS TO THIS SITE. I HAVE PROVIDED THE SOURCE IN THE
ATTACHMENT SO YOU CAN INSTALL IT ON YOUR SITE.

If you use something prior to JDK 1.4, you will need to start the servlet
container (Tomcat) with a proper DISPLAY environment set, for example:
    setenv DISPLAY localhost:1
with a virtual X frame buffer (xvfb in the XFree X11r6 delivery), to be able
to use the headless Swing clases.

-- 
:) Christoph Reck

Re: Formatting Issue (Whitespace)

Posted by Ch...@dlr.de.
Hi Alexandre,

the workaround to omit stray whitespaces in the output is to use
comments spanning the EOL and whitespaces:

#macro( button $index )#*
   *##if( $menu.size() > $index )#*
     *##set( $buttontext = $menu.elementAt($index).alttext )#*
     *#<A HREF="${menu.elementAt($index).link}">#*
       *#<IMG SRC="${req.contextPath}/button_factory?#*
          *#textColor=FFFFFF&bgColor=${accentcolor}#*
          *#&text=${utils.escapeForURL($buttontext)}">#*
     *#</A>#*
   *##else#*
     *#&nbsp;<!-- empty button -->#*
   *##end#*
*##end

I know this is not vey pretty, but it works. I have posted a proposal
to fix this in velocity, but it has not reached a consensus (will it ever?).

P.S. I see that you are using a button factory, is this based on my code? Cheers!
      As I've stated somewhere in some list the past (turbine, velocity, other?),
      it is intended to be published, can someone take a lead on this to get it
      into jakarta or sourceforge? I could also do this if someone points me in
      the right direction (jakarta account?).

--
:) Christoph

Alexandre Martin wrote:
> I have the following two macros. The content output is fine but the formatting is not how I want it. 
> 
> How can I modify my macros to output the content in the desired format (see below)?
> 
> 
> #macro(button $index)
>     #if($menu.size() > $index)
>         #set($buttontext = $menu.elementAt($index).alttext)
>  <A HREF="${menu.elementAt($index).link}"><IMG SRC="${req.contextPath}/button_factory?textColor=FFFFFF&bgColor=${accentcolor}&text=${utils.escapeForURL($buttontext)}"></A>
>     #else
>  &nbsp;<!-- empty button -->
>     #end
> #end
> #macro(imenu $startindex)
>     #if($menu.size() > $startindex)
>         <TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="600" BORDER="0">
>                 <TR>
>                     <TD>#button($startindex)</TD>
>       #set($startindex = $startindex + 1)
>                     <TD>#button($startindex)</TD>
>                     #set($startindex = $startindex + 1)
>                     <TD>#button($startindex)</TD>
>                     #set($startindex = $startindex + 1)
>                     <TD>#button($startindex)</TD>
>                     #set($startindex = $startindex + 1)
>                     <TD>#button($startindex)</TD>    
>                 </TR>
>         </TABLE>
>     #end
> #end
> 
> 
> Current Output:
> 
>     <TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="600" BORDER="0">
>  <TR>
>      <TD WIDTH="89" BGCOLOR="#990000">            <A HREF="menu0link"><IMG SRC="/button_factory?textColor=FFFFFF&BGCOLOR=990000&text=Search"></A>
> </TD>
>     <TD WIDTH="89" BGCOLOR="#990000">            <!-- empty button -->
> </TD>
>     <TD WIDTH="89" BGCOLOR="#990000">            <!-- empty button -->
> </TD>
>     <TD WIDTH="89" BGCOLOR="#990000">            <!-- empty button -->
> </TD>
>     <TD WIDTH="90" BGCOLOR="#990000">            <!-- empty button -->
> </TD>    
>  </TR>
> </TABLE>
>         
> 
> Desired Output:
> 
> <TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="600" BORDER="0">
> <TR>
>     <TD WIDTH="89" BGCOLOR="#990000"><A HREF="menu0link"><IMG SRC="/button_factory?textColor=FFFFFF&BGCOLOR=990000&text=Search"></A></TD>
>     <TD WIDTH="89" BGCOLOR="#990000"><!-- empty button --></TD>
>     <TD WIDTH="89" BGCOLOR="#990000"><!-- empty button --></TD>
>     <TD WIDTH="89" BGCOLOR="#990000"><!-- empty button --></TD>
>     <TD WIDTH="90" BGCOLOR="#990000"><!-- empty button --></TD>    
> </TR>
> /TABLE>
> 

-- 
:) Christoph Reck


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>