You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by nb...@apache.org on 2003/05/28 01:15:40 UTC

cvs commit: jakarta-velocity-tools/examples/layout/layout CSS.vm Default.vm Printable.vm TableBased.vm layout.css

nbubna      2003/05/27 16:15:40

  Added:       examples/layout Error.vm VM_global_library.vm build.xml
                        index.vm
               examples/layout/META-INF MANIFEST.MF
               examples/layout/WEB-INF toolbox.xml velocity.properties
                        web.xml
               examples/layout/WEB-INF/lib README.txt
               examples/layout/WEB-INF/src LayoutLinkTool.java
               examples/layout/layout CSS.vm Default.vm Printable.vm
                        TableBased.vm layout.css
  Log:
  Initial revision of layout example app by Tim Colson
  
  Revision  Changes    Path
  1.1                  jakarta-velocity-tools/examples/layout/Error.vm
  
  Index: Error.vm
  ===================================================================
  #*
   * $Id: Error.vm,v 1.1 2003/05/27 23:15:39 nbubna Exp $
   *#
  ##Force use of default layout (so req params don't override it)
  #set( $layout = "Default.vm" )
  #title( "Error - $!cause.class.name" )
  
  <div align="center">
  <h1>There has been an error!</h1>
  <br>
  <b style="color: #FF0000;">
  #if( $invocation_exception )
    $!invocation_exception.message
  #else
    $!cause.message
  #end
  </b>
  <br><br><br>
  ##Let's hide this highly useful but highly ugly info from the users
  <!--
  
  #if( $invocation_exception )
  oh joy! it's a MethodInvocationException!
  
  Reference name: $invocation_exception.referenceName
  Method name: $invocation_exception.methodName
  #end
  
  Alright, here's the stack.  Good luck.
  
  $stack_trace
  
  -->
  <h3>Sorry about that!</h3>
  </div>
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/VM_global_library.vm
  
  Index: VM_global_library.vm
  ===================================================================
  ##$Id: VM_global_library.vm,v 1.1 2003/05/27 23:15:39 nbubna Exp $  
  
  #**
   * Sets the $page_title key, so if it ever changes,
   * it need only be changed here.
   *#
  #macro( title $string )
  #set( $page_title = $string )#end
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/build.xml
  
  Index: build.xml
  ===================================================================
  <!-- $Id: build.xml,v 1.1 2003/05/27 23:15:39 nbubna Exp $ -->
  <project name="VelocityTools- Example Layout Application" default="war" basedir=".">
  
    <property name="SRC"      value="${basedir}/WEB-INF/src"/>
    <property name="CLASSES"  value="${basedir}/WEB-INF/classes"/>
    <property name="LIB"      value="${basedir}/WEB-INF/lib"/>
  
    <!-- Construct compile and javadoc classpath -->
    <path id="classpath">
      <fileset dir="${LIB}">
        <include name="*.jar"/>
      </fileset>
    </path>
  
    <!-- ================================================================== -->
    <!-- C O M P I L E                                                      -->
    <!-- ================================================================== -->
    <target name="compile">
      <mkdir dir="${basedir}/WEB-INF/classes"/>
      <!-- Compile the java code from ${SRC} into ${CLASSES} -->
      <javac srcdir="${SRC}"
             includes="*/**"
             destdir="${CLASSES}">
         <classpath refid="classpath"/>
      </javac>
    </target>
  
    <!-- ================================================================== -->
    <!-- W A R                                                              -->
    <!-- ================================================================== -->
    <target name="war" depends="compile">
      <jar jarfile="${basedir}/../layout.war" 
           basedir="${basedir}"
           excludes="**/MANIFEST.MF"/>
  
      <echo>                                                  </echo>
      <echo>  A WAR file (Web ARchive) was created for you in </echo>
      <echo>  the directory above. (/examples)  It is called  </echo>
      <echo>                                                  </echo>
      <echo>      layout.war                                  </echo>
      <echo>                                                  </echo>
      <echo>  To use it with Tomcat, copy the .war file to    </echo>
      <echo>  the webapps directory in the Tomcat tree        </echo>
      <echo>  (assuming a standard Tomcat installation)  and  </echo>
      <echo>  then restart Tomcat.  To access the page        </echo>
      <echo>  point you browser to                            </echo>
      <echo>                                                  </echo>
      <echo>     http://localhost:8080/layout/index.vm        </echo>
      <echo>                                                  </echo>
      <echo>  If you have any questions, don't hesitate to    </echo>
      <echo>  ask on the Velocity user list.                  </echo>
  
    </target>
  
    <!-- ================================================================== -->
    <!-- C L E A N                                                          -->
    <!-- ================================================================== -->
    <target name="clean">
      <!-- remove old class files -->
      <delete dir="${CLASSES}"/>
    </target>
  
  </project>
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/index.vm
  
  Index: index.vm
  ===================================================================
  #*
   * $Id: index.vm,v 1.1 2003/05/27 23:15:39 nbubna Exp $  
   *#
  <TABLE BORDER=1>
  <TR>
  <TD BGCOLOR="#FFFFCC"><H2> Main Screen Content </H2>
  I'm a Velocity template using a layout file!
  <P>
  
  
  #if( !$layout )
  <H3>Example Layouts</H3>
  <A HREF="$link.setLayout('Printable.vm')">Printable layout</A>: same as adding &quot;?layout=Printable.vm&quot; to the URL
  <BR>
  <A HREF="$link.setLayout('TableBased.vm')">Table based layout</A>: same as adding &quot;?layout=TableBased.vm&quot; to the URL
  <BR>
  <A HREF="$link.setLayout('CSS.vm')">CSS based layout</A>: same as adding &quot;?layout=CSS.vm&quot; to the URL
  
  #title( "Default" )
  
  #else 
  
  #if( $layout == "CSS.vm" ) 
   #title( "CSS 3 Column" )
  #elseif( $layout == "TableBased.vm" )
   #title( "Table Based" )
  #elseif( $layout == "Printable.vm" )
   #title( "Printable" )
  #end
  
  <P>
  <B>Currently using: $page_title layout </B><BR>
  Notice how the web page title (\$page_title) is set from within the main content, but displayed by the layout in the web page "title".</P>
  
  
  
  <B>Return to <A HREF="$link.setRelative('index.vm')">Default layout</A></B>
  
  #end
  </P>
  
  <H3>Some sample template content</H3>
  This page request was made from: $request.remoteAddr
  <BR>
  Lets count : #foreach( $i in [1..5] )$i #end
  <BR>
  The author of this example was $author
  </TD>
  </TR>
  </TABLE>
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/META-INF/MANIFEST.MF
  
  Index: MANIFEST.MF
  ===================================================================
  Manifest-Version: 1.0
  Created-By: Ant 1.4.1
  
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/WEB-INF/toolbox.xml
  
  Index: toolbox.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- $Id: toolbox.xml,v 1.1 2003/05/27 23:15:39 nbubna Exp $ -->
  <toolbox>
  
    <data type="string">
      <key>author</key>
      <value>Tim Colson</value>
    </data>
  
    <tool>
      <key>link</key>
      <scope>request</scope>
      <class>LayoutLinkTool</class>
    </tool>
  
  </toolbox>
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/WEB-INF/velocity.properties
  
  Index: velocity.properties
  ===================================================================
  # $Id: velocity.properties,v 1.1 2003/05/27 23:15:39 nbubna Exp $
  #
  # These are the default properties.  So, this file is essentially
  # unnecessary here, but is included just to demonstrate that these
  # can be changed.
  #
  
  # Filepath for error template, relative to web application root directory
  tools.view.servlet.error.template = Error.vm
  
  # Directory for layout templates, relative to web application root directory
  tools.view.servlet.layout.directory = layout/
  
  # Filepath of the default layout template 
  # relative to the layout directory 
  # NOT relative to the root directory of the webapp!
  tools.view.servlet.layout.default.template =  Default.vm
  
  
  1.1                  jakarta-velocity-tools/examples/layout/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
  
  <!-- $Id: web.xml,v 1.1 2003/05/27 23:15:39 nbubna Exp $ -->
  <web-app>
  
    <!-- Define Velocity template rendererr -->
    <servlet>
      <servlet-name>velocity</servlet-name>
      <servlet-class>org.apache.velocity.tools.view.servlet.VelocityLayoutServlet</servlet-class>
      <init-param>
        <param-name>org.apache.velocity.toolbox</param-name>
        <param-value>/WEB-INF/toolbox.xml</param-value>
      </init-param>
      <init-param>
        <param-name>org.apache.velocity.properties</param-name>
        <param-value>/WEB-INF/velocity.properties</param-value>
      </init-param>
      <load-on-startup>10</load-on-startup>
    </servlet>
  
    <!-- Map *.vm files to Velocity -->
    <servlet-mapping>
      <servlet-name>velocity</servlet-name>
      <url-pattern>*.vm</url-pattern>
    </servlet-mapping>
  
  	<welcome-file-list>
  		<welcome-file>index.vm</welcome-file>
  	</welcome-file-list>
  
  </web-app>
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/WEB-INF/lib/README.txt
  
  Index: README.txt
  ===================================================================
  R E A D M E
  ===========
  
  Library files will be copies here during the build process
  to avoid having many copies of the same library checked in.
  
  
  1.1                  jakarta-velocity-tools/examples/layout/WEB-INF/src/LayoutLinkTool.java
  
  Index: LayoutLinkTool.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Velocity", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.velocity.tools.view.tools.LinkTool;
  import org.apache.velocity.tools.view.servlet.VelocityLayoutServlet;
  
  /**
   * This is meant to demonstrate how to extend the LinkTool to
   * avoid the manual use of "magic" or common query parameters.
   *
   * @author <a href="mailto:nathan@esha.com">Nathan Bubna</a>
   * @version $Id: LayoutLinkTool.java,v 1.1 2003/05/27 23:15:39 nbubna Exp $
   */
  public class LayoutLinkTool extends LinkTool
  {
  	public LayoutLinkTool setLayout(String layout)
  	{
          return (LayoutLinkTool)addQueryData(VelocityLayoutServlet.KEY_LAYOUT, layout);
  	}
  }
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/layout/CSS.vm
  
  Index: CSS.vm
  ===================================================================
  #*
   * $Id: CSS.vm,v 1.1 2003/05/27 23:15:39 nbubna Exp $ 
   *#
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
  
  <html>
  <head>
  	<title>LAYOUT = $!page_title</title>
  	<style type="text/css" media="screen">@import "$link.setRelative('/layout/layout.css')";</style>
  	
  </head>
  <body>
  
  <div class="content">
  	<h1>CSS Layout</h1>
  	<p>$screen_content</p>
  </div>
  
  <div class="content">
  	<h2>Known Issues</h2>
  	<p>This layout fails in IE4.5/Mac. That browser has poor support for CSS absolute positioning, yet it recognizes and executes the CSS @import statement used to hide CSS from broken browsers. Currently, there is no known solution.</p>
  </div>
  
  
  <div id="navAlpha">
  	<h2>Links</h2>
  	<p>
  		<a href="http://jakarta.apache.org/velocity/" title="Velocity Template Engine">Velocity</a><br>
  		<a href="$link.setRelative('index.vm')">Default Layout</a><br>
  		<a href="$link.setRelative('index.vm').setLayout('Printable.vm')">Printable Layout</a><br>
  	</p>
  	
  	<h2>Rollover via CSS</h2>
  	
  	<p>
  	<div id="button">
  	<ul>
  		<li><a href="#">Home</a></li>
  		<li><a href="#">Velocity Manual</a></li>
  		<li><a href="#">Jakarta</a></li>
  		<li><a href="http://www.alistapart.com/stories/taminglists/">A List Apart CSS</a></li>
  		
  	</ul>
  	</div>
  
  	</p>
  </div>
  
  <div id="navBeta">
  	<h2>Nifty Layout Techniques</h2>
  	<p>All sorts of nifty layout can be accomplished using cascading style sheets (CSS). Check out <a href="http://www.bluerobot.com" title="BlueRobot layout Resource">bluerobot.com</a> and the <a href="http://www.bluerobot.com/web/layouts/">Layout Reservoir</A> </p>
  </div>
  
  <!-- BlueRobot was here. -->
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/layout/Default.vm
  
  Index: Default.vm
  ===================================================================
  #*
   * $Id: Default.vm,v 1.1 2003/05/27 23:15:39 nbubna Exp $ 
   *#
  <html>
  <head>
    <title>LAYOUT= $!page_title</title>
  </head>
  <body>
  <B>DEFAULT LAYOUT - HEADER</B><BR>
  
  <P>
  $screen_content
  </P>
  
  <B>DEFAULT LAYOUT - FOOTER</B><BR>
  </body>
  </html>
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/layout/Printable.vm
  
  Index: Printable.vm
  ===================================================================
  #*
   * $Id: Printable.vm,v 1.1 2003/05/27 23:15:39 nbubna Exp $  
   *#
  <html>
  <head>
    <title>LAYOUT= $!page_title</title>
  </head>
  <body>
  <B>PRINTABLE LAYOUT - HEADER</B><BR>
  
  <P>
  $screen_content
  </P>
  
  <B>PRINTABLE LAYOUT - FOOTER</B><BR>
  </body>
  </html>
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/layout/TableBased.vm
  
  Index: TableBased.vm
  ===================================================================
  #*
   * $Id: TableBased.vm,v 1.1 2003/05/27 23:15:39 nbubna Exp $ 
   *#
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
  
  <html>
  <head>
  	<title>LAYOUT = $!page_title</title>
  	
  </head>
  
  <body>
  
  <TABLE CELLPADDING="10"> 
   
  <TR>
  <!-- left nav -->
  <TD BGCOLOR="#66EEFF" VALIGN="TOP" >
  	<ul>
  		<li><a href="#">Home</a></li>
  		<li><a href="#">Velocity Manual</a></li>
  		<li><a href="#">Jakarta</a></li>
  	</ul>
  </TD>
  <TD>
  	<p>$screen_content</p>
  </TD>
  
  </body>
  </html>
  
  
  
  1.1                  jakarta-velocity-tools/examples/layout/layout/layout.css
  
  Index: layout.css
  ===================================================================
  /* $Id: layout.css,v 1.1 2003/05/27 23:15:39 nbubna Exp $ */
  
  body {
  	color:#333;
  	background-color:white;
  	margin:20px;
  	padding:0px;
  	font:11px verdana, arial, helvetica, sans-serif;
  	}
  h1 {
  	margin:0px 0px 15px 0px;
  	padding:0px;
  	font-size:28px;
  	font-weight:900;
  	color:#ccc;
  	}
  h2 {
  	font:bold 12px/14px verdana, arial, helvetica, sans-serif;
  	margin:0px 0px 5px 0px;
  	padding:0px;
  	}
  p {
  	font:11px/20px verdana, arial, helvetica, sans-serif;
  	margin:0px 0px 16px 0px;
  	padding:0px;
  	}
  .Content>p {margin:0px;}
  .Content>p+p {text-indent:30px;}
  
  a {
  	color:#09c;
  	font-size:11px;
  	font-family:verdana, arial, helvetica, sans-serif;
  	font-weight:600;
  	text-decoration:none;
  	}
  a:link {color:#09c;}
  a:visited {color:#07a;}
  a:hover {background-color:#eee;}
    
  
  /* All the content boxes belong to the content class. */
  .content {
  	position:relative; /* Position is declared "relative" to gain control of stacking order (z-index). */
  	width:auto;
  	min-width:120px;
  	margin:0px 210px 20px 170px;
  	border:1px solid black;
  	background-color:white;
  	padding:10px;
  	z-index:3; /* This allows the content to overlap the right menu in narrow windows in good browsers. */
  	}
  
  #navAlpha {
  	position:absolute;
  	width:150px;
  	top:20px;
  	left:20px;
  	border:1px dashed black;
  	background-color:#eee;
  	padding:10px;
  	z-index:2;
  
  /* Here is the ugly brilliant hack that protects IE5/Win from its own stupidity. 
  Thanks to Tantek Celik for the hack and to Eric Costello for publicizing it. 
  IE5/Win incorrectly parses the "\"}"" value, prematurely closing the style 
  declaration. The incorrect IE5/Win value is above, while the correct value is 
  below. See http://glish.com/css/hacks.asp for details. */
  	voice-family: "\"}\"";
  	voice-family:inherit;
  	width:128px;
  	}
  /* I've heard this called the "be nice to Opera 5" rule. Basically, it feeds correct 
  length values to user agents that exhibit the parsing error exploited above yet get 
  the CSS box model right and understand the CSS2 parent-child selector. ALWAYS include
  a "be nice to Opera 5" rule every time you use the Tantek Celik hack (above). */
  body>#navAlpha {width:128px;}
  		
  #navBeta {
  	position:absolute;
  	width:190px;
  	top:20px;
  	right:20px;
  	border:1px dashed black;
  	background-color:#eee;
  	padding:10px;
  	z-index:1;
  /* Again, the ugly brilliant hack. */
  	voice-family: "\"}\"";
  	voice-family:inherit;
  	width:168px;
  	}
  /* Again, "be nice to Opera 5". */
  body>#navBeta {width:168px;}
  
  
  /* Rollover Menu CSS from http://www.alistapart.com/stories/taminglists/ */
  
  #button {
  	width: 9em;
  	border-right: 1px solid #000;
  	padding: 0 0 1em 0;
  	margin-bottom: 1em;
  	font-family: 'Trebuchet MS', 'Lucida Grande',
  	  Verdana, Lucida, Geneva, Helvetica, 
  	  Arial, sans-serif;
  	background-color: #90bade;
  	color: #333;
  	}
  
  	#button ul {
  		list-style: none;
  		margin: 0;
  		padding: 0;
  		border: none;
  		}
  		
  	#button li {
  		border-bottom: 1px solid #90bade;
  		margin: 0;
  		}
  
  	#button li a {
  		display: block;
  		padding: 5px 5px 5px 0.5em;
  		border-left: 10px solid #1958b7;
  		border-right: 10px solid #508fc4;
  		background-color: #2175bc;
  		color: #fff;
  		text-decoration: none;
  		width: 100%;
  		}
  
  	html>body #button li a {
  		width: auto;
  		}
  
  	#button li a:hover {
  		border-left: 10px solid #1c64d1;
  		border-right: 10px solid #5ba3e0;
  		background-color: #2586d7;
  		color: #fff;
  		}
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org