Coverage Report - org.melati.template.velocity.VelocityServletTemplateContext
 
Classes in this File Line Coverage Branch Coverage Complexity
VelocityServletTemplateContext
57%
4/7
N/A
1.25
 
 1  
 /*    
 2  
  * $Source: /usr/cvsroot/melati/melati/src/main/java/org/melati/template/velocity/VelocityServletTemplateContext.java,v $    
 3  
  * $Revision: 1.5 $    
 4  
  *    
 5  
  * Copyright (C) 2000 Tim Joyce    
 6  
  *    
 7  
  * Part of Melati (http://melati.org), a framework for the rapid    
 8  
  * development of clean, maintainable web applications.    
 9  
  *    
 10  
  * Melati is free software; Permission is granted to copy, distribute
 11  
  * and/or modify this software under the terms either:
 12  
  *
 13  
  * a) the GNU General Public License as published by the Free Software
 14  
  *    Foundation; either version 2 of the License, or (at your option)
 15  
  *    any later version,
 16  
  *
 17  
  *    or
 18  
  *
 19  
  * b) any version of the Melati Software License, as published
 20  
  *    at http://melati.org
 21  
  *
 22  
  * You should have received a copy of the GNU General Public License and
 23  
  * the Melati Software License along with this program;
 24  
  * if not, write to the Free Software Foundation, Inc.,
 25  
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
 26  
  * GNU General Public License and visit http://melati.org to obtain the
 27  
  * Melati Software License.
 28  
  *
 29  
  * Feel free to contact the Developers of Melati (http://melati.org),
 30  
  * if you would like to work out a different arrangement than the options
 31  
  * outlined here.  It is our intention to allow Melati to be used by as
 32  
  * wide an audience as possible.
 33  
  *
 34  
  * This program is distributed in the hope that it will be useful,
 35  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 36  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 37  
  * GNU General Public License for more details.
 38  
  *    
 39  
  * Contact details for copyright holder:    
 40  
  *    
 41  
  *     Tim Joyce <timj At paneris.org>    
 42  
  *    
 43  
  */    
 44  
     
 45  
 package org.melati.template.velocity;    
 46  
     
 47  
 import javax.servlet.http.HttpSession;    
 48  
     
 49  
 import org.melati.template.ServletTemplateContext;    
 50  
 import org.melati.util.MelatiBugMelatiException;
 51  
 import org.melati.servlet.MultipartFormField;    
 52  
 import org.apache.velocity.VelocityContext;    
 53  
     
 54  
 /**    
 55  
  * Implements a template context for Melati with Velocity.
 56  
  * 
 57  
  * The Request and Response are placed in the context 
 58  
  * so that they can be accessed by the Form object. 
 59  
  *     
 60  
  * @author Tim Joyce    
 61  
  */    
 62  
 public class VelocityServletTemplateContext 
 63  
     extends VelocityTemplateContext 
 64  
     implements ServletTemplateContext {    
 65  
     
 66  
  /**    
 67  
   * The HTTP request object context key.    
 68  
   */    
 69  
   public static final String REQUEST = "Request";    
 70  
     
 71  
  /**    
 72  
   * The HTTP response object context key.    
 73  
   */    
 74  
   public static final String RESPONSE = "Response";    
 75  
     
 76  
   /** Mimicking the $Form behaviour of Webmacro. */
 77  
   public static final String FORM = "Form";
 78  
     
 79  
   private Form form;
 80  
   
 81  
   /**
 82  
    * Constructor.
 83  
    * @param vc context containing RESPONSE and REQUEST
 84  
    */
 85  
   public VelocityServletTemplateContext(VelocityContext vc) {
 86  114
     super(vc);
 87  114
     form = new Form((HttpServletRequestWrap)velContext.get(REQUEST));
 88  114
     velContext.put(FORM, form);
 89  114
   }    
 90  
     
 91  
   /**
 92  
    * {@inheritDoc}
 93  
    * @see org.melati.template.ServletTemplateContext#getFormField(java.lang.String)
 94  
    */
 95  
   public String getFormField(String s) {    
 96  0
     return form.get(s);    
 97  
   }    
 98  
     
 99  
   /**
 100  
    * Returns null as this is not a multi part form.
 101  
    * Should perhaps throw an exception.
 102  
    * @see org.melati.template.ServletTemplateContext#getMultipartFormField(java.lang.String)
 103  
    */
 104  
   public MultipartFormField getMultipartFormField(String s) {    
 105  0
     throw new MelatiBugMelatiException("Cannot return a multi-part field from a non-multi-part form");
 106  
   }    
 107  
     
 108  
   /**
 109  
    * {@inheritDoc}
 110  
    * @see org.melati.template.ServletTemplateContext#getSession()
 111  
    */
 112  
   public HttpSession getSession() {    
 113  0
     return ((HttpServletRequestWrap)velContext.get(REQUEST)).getSession(true);    
 114  
   }
 115  
     
 116  
 }    
 117  
     
 118  
     
 119  
     
 120  
     
 121  
     
 122