Coverage Report - org.melati.template.webmacro.WebmacroServletTemplateEngine
 
Classes in this File Line Coverage Branch Coverage Complexity
WebmacroServletTemplateEngine
75%
9/12
50%
1/2
2
 
 1  
 /*
 2  
  * $Source: /usr/cvsroot/melati/melati/src/main/java/org/melati/template/webmacro/WebmacroServletTemplateEngine.java,v $
 3  
  * $Revision: 1.7 $
 4  
  *
 5  
  * Copyright (C) 2004 Tim Pizey
 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 Pizey <timp@paneris.org>
 42  
  */
 43  
 
 44  
 package org.melati.template.webmacro;
 45  
 
 46  
 import java.io.IOException;
 47  
 
 48  
 import javax.servlet.http.HttpServlet;
 49  
 import javax.servlet.http.HttpServletResponse;
 50  
 
 51  
 import org.melati.Melati;
 52  
 import org.melati.MelatiConfig;
 53  
 import org.melati.template.ServletTemplateContext;
 54  
 import org.melati.template.ServletTemplateEngine;
 55  
 import org.melati.template.TemplateEngineException;
 56  
 import org.melati.util.MelatiWriter;
 57  
 import org.webmacro.InitException;
 58  
 import org.webmacro.WM;
 59  
 import org.webmacro.servlet.WebContext;
 60  
 
 61  
 
 62  
 /**
 63  
  * Wrapper for the WebMacro Template Engine for use in a Servlet context.
 64  
  */
 65  
 public class WebmacroServletTemplateEngine 
 66  
     extends WebmacroTemplateEngine implements ServletTemplateEngine {
 67  
 
 68  
   /**
 69  
    * Constructor.
 70  
    */
 71  
   public WebmacroServletTemplateEngine() {
 72  18
     super();
 73  18
   }
 74  
 
 75  
   /**
 76  
    * Construct a new Engine for use in a servlet environment.
 77  
    *
 78  
    * @see org.melati.servlet.TemplateServlet
 79  
    * @param melatiConfig a {@link MelatiConfig}
 80  
    * @param servlet the servlet we are within
 81  
    * @throws TemplateEngineException if any problem occurs with the engine
 82  
    */
 83  
   public void init(MelatiConfig melatiConfig, HttpServlet servlet) 
 84  
       throws TemplateEngineException {
 85  
     try {
 86  14
       wm = new WM(servlet);
 87  0
     } catch (InitException e) {
 88  0
       throw new TemplateEngineException(e);
 89  14
     }
 90  14
   }
 91  
 
 92  
   /**
 93  
    * Get the generic parameters for WebMacro, 
 94  
    * with servlet objects in the Context.
 95  
    *
 96  
    * @param melati the {@link Melati}
 97  
    * @return a {@link ServletTemplateContext}
 98  
    */
 99  
   public ServletTemplateContext getServletTemplateContext(Melati melati) {
 100  451
     WebContext webContext = new WebContext(wm.getBroker(),
 101  
                                            melati.getRequest(),
 102  
                                            melati.getResponse());
 103  451
     return new WebmacroServletTemplateContext(webContext);
 104  
   }
 105  
   
 106  
   /** 
 107  
    * @param response the <code>HttpServletResponse</code> that this 
 108  
    *                 writer will be part of
 109  
    * @param buffered whether the writer should be buffered
 110  
    * @throws IOException if there is a problem with the filesystem.
 111  
    * @return a {@link MelatiWriter} 
 112  
    *         appropriate for this engine.
 113  
    */
 114  
   public MelatiWriter getServletWriter(HttpServletResponse response, 
 115  
                                        boolean buffered) 
 116  
       throws IOException {
 117  445
     if (buffered) {
 118  
 //      return new MelatiBufferedFastWriter(response);
 119  445
       return new MelatiBufferedFastWriter(wm.getBroker(),response);
 120  
     } else {
 121  
 //      return new MelatiFastWriter(response);
 122  0
       return new MelatiFastWriter(wm.getBroker(),response);
 123  
     }
 124  
   }
 125  
 
 126  
 
 127  
 
 128  
 }