Coverage Report - org.melati.template.velocity.VelocityServletTemplateContext
 
Classes in this File Line Coverage Branch Coverage Complexity
VelocityServletTemplateContext
57%
4/7
N/A
1
 
 1  
 /*    
 2  
  * $Source: /usr/cvsroot/melati/melati/src/main/java/org/melati/template/velocity/VelocityServletTemplateContext.java,v $    
 3  
  * $Revision: 1.2 $    
 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.servlet.MultipartFormField;    
 51  
 import org.apache.velocity.VelocityContext;    
 52  
     
 53  
 /**    
 54  
  * Implements a template context for Melati with Velocity.
 55  
  * 
 56  
  * The Request and Response are placed in the context 
 57  
  * so that they can be accessed by the Form object. 
 58  
  *     
 59  
  * @author Tim Joyce    
 60  
  */    
 61  
 public class VelocityServletTemplateContext 
 62  
     extends VelocityTemplateContext 
 63  
     implements ServletTemplateContext {    
 64  
     
 65  
  /**    
 66  
   * The HTTP request object context key.    
 67  
   */    
 68  
   public static final String REQUEST = "Request";    
 69  
     
 70  
  /**    
 71  
   * The HTTP response object context key.    
 72  
   */    
 73  
   public static final String RESPONSE = "Response";    
 74  
     
 75  
   /** Mimicking the $Form behaviour of Webmacro. */
 76  
   public static final String FORM = "Form";
 77  
     
 78  
   private Form form;
 79  
   
 80  
   /**
 81  
    * Constructor.
 82  
    * @param vc context containing RESPONSE and REQUEST
 83  
    */
 84  
   public VelocityServletTemplateContext(VelocityContext vc) {
 85  105
     super(vc);
 86  105
     form = new Form((HttpServletRequestWrap)velContext.get(REQUEST));
 87  105
     velContext.put(FORM, form);
 88  105
   }    
 89  
     
 90  
   /**
 91  
    * {@inheritDoc}
 92  
    * @see org.melati.template.ServletTemplateContext#getForm(java.lang.String)
 93  
    */
 94  
   public String getForm(String s) {    
 95  0
     return form.get(s);    
 96  
   }    
 97  
     
 98  
   /**
 99  
    * Return null, bad smell.
 100  
    * {@inheritDoc}
 101  
    * @see org.melati.template.ServletTemplateContext#getMultipartForm(java.lang.String)
 102  
    */
 103  
   public MultipartFormField getMultipartForm(String s) {    
 104  0
     return null;    
 105  
   }    
 106  
     
 107  
   /**
 108  
    * {@inheritDoc}
 109  
    * @see org.melati.template.ServletTemplateContext#getSession()
 110  
    */
 111  
   public HttpSession getSession() {    
 112  0
     return ((HttpServletRequestWrap)velContext.get(REQUEST)).getSession(true);    
 113  
   }
 114  
     
 115  
 }    
 116  
     
 117  
     
 118  
     
 119  
     
 120  
     
 121