##### Coverage Report - org.melati.template.NoTemplateEngine

Classes in this File | Line Coverage | Branch Coverage | Complexity
NoTemplateEngine |
91% | 22/24
100% | 2/2
| 1.6428571428571428;1.643

1 |  |
     /*
2 |  |
      * $Source: /usr/cvsroot/melati/melati/src/site/resources/withWebmacro/org.melati.template.NoTemplateEngine.html,v $
3 |  |
      * $Revision: 1.1 $
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 |  |
      *     http://paneris.org/
43 |  |
      *     68 Sandbanks Rd, Poole, Dorset. BH14 8BY. UK
44 |  |
      */
45 |  |
46 |  |
     package org.melati.template;
47 |  |
48 |  |
     import java.io.IOException;
49 |  |
     import java.io.PrintWriter;
50 |  |
51 |  |
     import javax.servlet.http.HttpServletResponse;
52 |  |
     import javax.servlet.http.HttpServlet;
53 |  |
54 |  |
     import org.melati.Melati;
55 |  |
     import org.melati.MelatiConfig;
56 |  |
     import org.melati.util.MelatiIOException;
57 |  |
     import org.melati.util.MelatiWriter;
58 |  |
     import org.melati.util.MelatiSimpleWriter;
59 |  |
     import org.melati.util.MelatiStringWriter;
60 |  |
     import org.melati.util.MelatiBufferedWriter;
61 |  |
62 |  |
63 |  |
     /**
64 |  |
      * The <code>null</code> {@link ServletTemplateEngine}.
65 |  |
      *
66 |  |
      * @author Tim Joyce
67 |  |
      */
68 |  |
     public class NoTemplateEngine extends AbstractTemplateEngine implements ServletTemplateEngine {
69 |  |
70 | 170 |
       private String message =
71 |  |
           "No Template engine is Configured, please specify an engine in " +
72 |  |
           "org.melati.MelatiConfig.properties";
73 |  |
74 |  |
       /**
75 |  |
        * Constructor.
76 |  |
        */
77 |  |
       public NoTemplateEngine() {
78 | 170 |
         super();
79 | 170 |
       }
80 |  |
81 |  |
       /**
82 |  |
        * Construct a null Engine.
83 |  |
        *
84 |  |
        * @param config a {@link MelatiConfig}
85 |  |
        */
86 |  |
       public void init(MelatiConfig config) {
87 |  |
         // we don't throw an exception here as it gets hidden away, rather
88 |  |
         // it is better to wait until expandTemplate or getParameters, as
89 |  |
         // that produces a nice
90 |  |
         // exception to the browser
91 | 80 |
       }
92 |  |
93 |  |
       /**
94 |  |
        * Construct a new Engine for use in a servlet environment.
95 |  |
        *
96 |  |
        * @see org.melati.servlet.TemplateServlet
97 |  |
        * @param melatiConfig a {@link MelatiConfig}
98 |  |
        * @param servlet the servlet we are within
99 |  |
        * @throws TemplateEngineException if any problem occurs with the engine
100 |  |
        */
101 |  |
       public void init(MelatiConfig melatiConfig, HttpServlet servlet)
102 |  |
           throws TemplateEngineException {
103 | 2 |
         init(melatiConfig);
104 | 2 |
       }
105 |  |
106 |  |
       /**
107 |  |
        * Throw exception.
108 |  |
        *
109 |  |
        * @param melati the {@link Melati}
110 |  |
        * @throws TemplateEngineException if any problem occurs with the engine
111 |  |
        * @return a {@link TemplateContext}
112 |  |
        */
113 |  |
       public TemplateContext getTemplateContext(Melati melati)
114 |  |
           throws TemplateEngineException {
115 | 96 |
         return melati.getTemplateContext();
116 |  |
       }
117 |  |
118 |  |
       /**
119 |  |
        * Throw exception.
120 |  |
        *
121 |  |
        * @param melati the {@link Melati}
122 |  |
        * @throws TemplateEngineException always
123 |  |
        * @return an exception
124 |  |
        */
125 |  |
       public ServletTemplateContext getServletTemplateContext(Melati melati)
126 |  |
           throws TemplateEngineException {
127 | 2 |
         throw new TemplateEngineException(message);
128 |  |
       }
129 |  |
130 |  |
       /**
131 |  |
        * The name of the template engine (used to find the templets).
132 |  |
        * @return the name of the current configured template engine
133 |  |
        */
134 |  |
       public String getName() {
135 | 24 |
         return "none";
136 |  |
       }
137 |  |
138 |  |
       /**
139 |  |
        * @return the extension of the templates used by this template engine
140 |  |
        */
141 |  |
       public String templateExtension() {
142 | 30 |
         return ".none";
143 |  |
       }
144 |  |
145 |  |
       /**
146 |  |
        * Get a template given its name.
147 |  |
        *
148 |  |
        * @param templateName the name of the template to find
149 |  |
        * @return a template
150 |  |
        */
151 |  |
       public Template template(String templateName) {
152 | 28 |
         throw new TemplateEngineException(
153 |  |
             "The template " +
154 |  |
             templateName + " could not be found because you have not configured a template engine.");
155 |  |
       }
156 |  |
157 |  |
       /**
158 |  |
        * Expand the Template against the context.
159 |  |
        *
160 |  |
        * @param out             a {@link MelatiWriter} to output on
161 |  |
        * @param templateName    the name of the template to expand
162 |  |
        * @param templateContext the {@link ServletTemplateContext} to expand
163 |  |
        *                        the template against
164 |  |
        * @throws TemplateEngineException if invoked
165 |  |
        */
166 |  |
       public void expandTemplate(MelatiWriter out, String templateName,
167 |  |
                                  TemplateContext templateContext)
168 |  |
           throws TemplateEngineException {
169 | 2 |
         throw new TemplateEngineException(message);
170 |  |
       }
171 |  |
172 |  |
173 |  |
       /**
174 |  |
        * Expand the Template against the context.
175 |  |
        *
176 |  |
        * @param out             a {@link MelatiWriter} to output on
177 |  |
        * @param melatiTemplate  the {@link Template} to expand
178 |  |
        * @param templateContext the {@link ServletTemplateContext} to expand
179 |  |
        *                        the template against
180 |  |
        * @throws TemplateEngineException if invoked
181 |  |
        */
182 |  |
       public void expandTemplate(MelatiWriter out, Template melatiTemplate,
183 |  |
                                  TemplateContext templateContext)
184 |  |
           throws TemplateEngineException {
185 | 2 |
         throw new TemplateEngineException(message);
186 |  |
       }
187 |  |
188 |  |
       /**
189 |  |
        * Expand the Template against the context.
190 |  |
        *
191 |  |
        * @param melatiTemplate  the {@link Template} to expand
192 |  |
        * @param templateContext the {@link ServletTemplateContext} to expand
193 |  |
        *                        the template against
194 |  |
        * @throws TemplateEngineException if invoked
195 |  |
        * {@inheritDoc}
196 |  |
        * @see org.melati.template.TemplateEngine#expandedTemplate
197 |  |
        * (org.melati.template.Template, org.melati.template.TemplateContext)
198 |  |
        */
199 |  |
       public String expandedTemplate(Template melatiTemplate,
200 |  |
                                      TemplateContext templateContext)
201 |  |
           throws TemplateEngineException {
202 | 2 |
         throw new TemplateEngineException(message);
203 |  |
       }
204 |  |
205 |  |
       /**
206 |  |
        * @param response the <code>HttpServletResponse</code> that this
207 |  |
        *                 writer will be part of
208 |  |
        * @param buffered whether the writer should be buffered
209 |  |
        * @return a {@link MelatiWriter}
210 |  |
        *         appropriate for this engine.
211 |  |
        */
212 |  |
       public MelatiWriter getServletWriter(HttpServletResponse response,
213 |  |
                                            boolean buffered) {
214 | 4 |
         PrintWriter printWriter = null;
215 |  |
         try {
216 | 4 |
           printWriter = response.getWriter();
217 | 0 |
         } catch (IOException e) {
218 | 0 |
           throw new MelatiIOException(e);
219 | 4 |
         }
220 | 4 |
         if (buffered)
221 | 2 |
           return new MelatiBufferedWriter(printWriter);
222 |  |
         else
223 | 2 |
           return new MelatiSimpleWriter(printWriter);
224 |  |
       }
225 |  |
226 |  |
       /**
227 |  |
        * Return a {@link MelatiStringWriter}.
228 |  |
        * {@inheritDoc}
229 |  |
        * @see org.melati.template.TemplateEngine#getStringWriter()
230 |  |
        * @see Melati#getStringWriter()
231 |  |
        */
232 |  |
       public MelatiStringWriter getStringWriter() {
233 | 42 |
         return new MelatiStringWriter();
234 |  |
       }
235 |  |
236 |  |
       /**
237 |  |
        * Get the underlying engine.
238 |  |
        *
239 |  |
        * @return 'none'
240 |  |
        */
241 |  |
       public Object getEngine() {
242 | 2 |
         return "none";
243 |  |
       }
244 |  |
245 |  |
     }