##### Coverage Report - org.melati.test.WebmacroMelatiServletTest

Classes in this File | Line Coverage | Branch Coverage | Complexity
WebmacroMelatiServletTest |
100% | 16/16
75% | 3/4
| 2.0;2

1 |  |
     /*
2 |  |
      * $Source: /usr/cvsroot/melati/melati/src/site/resources/withWebmacro/org.melati.test.WebmacroMelatiServletTest.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@paneris.org>
42 |  |
      *     http://paneris.org/
43 |  |
      *     68 Sandbanks Rd, Poole, Dorset. BH14 8BY. UK
44 |  |
      */
45 |  |
46 |  |
     package org.melati.test;
47 |  |
48 |  |
     import java.io.ByteArrayOutputStream;
49 |  |
50 |  |
     import org.melati.template.ServletTemplateContext;
51 |  |
     import org.melati.Melati;
52 |  |
     import org.melati.MelatiConfig;
53 |  |
     import org.melati.servlet.PathInfoException;
54 |  |
     import org.melati.servlet.TemplateServlet;
55 |  |
     import org.melati.PoemContext;
56 |  |
     import org.melati.template.webmacro.MelatiFastWriter;
57 |  |
58 |  |
     import org.webmacro.WebMacro;
59 |  |
     import org.webmacro.WM;
60 |  |
     import org.webmacro.Context;
61 |  |
     import org.webmacro.Template;
62 |  |
63 |  |
     /**
64 |  |
      * Test WebMacro in standalone mode (outside the servlet API) by expanding a
65 |  |
      * template to a string and then including it within a template.
66 |  |
      *
67 |  |
      * You would not normally do this this way, a much better approach would be to
68 |  |
      * use templets.
69 |  |
      *
70 |  |
      * @author Tim Joyce $Revision: 1.1 $
71 |  |
      */
72 | 2 |
     public class WebmacroMelatiServletTest extends TemplateServlet {
73 |  |
74 |  |
       private static final long serialVersionUID = 8747414296960744530L;
75 |  |
76 |  |
       protected String doTemplateRequest(Melati melati,
77 |  |
           ServletTemplateContext templateContext) throws Exception {
78 |  |
79 | 4 |
         if (melati.getMethod() != null && melati.getMethod().equals("StandAlone")) {
80 |  |
           // construct a Melati with a StringWriter instead of a servlet
81 |  |
           // request and response
82 | 2 |
           WebMacro wm = new WM();
83 | 2 |
           ByteArrayOutputStream sw = new ByteArrayOutputStream();
84 | 2 |
           MelatiFastWriter fmw = new MelatiFastWriter(wm.getBroker(), sw, melati
85 |  |
               .getEncoding());
86 | 2 |
           Melati m = new Melati(new MelatiConfig(), fmw);
87 | 2 |
           Context context2 = wm.getContext();
88 | 2 |
           context2.put("melati", m);
89 | 2 |
           context2.put("ml", m.getMarkupLanguage());
90 | 2 |
           Template template = wm.getTemplate("org/melati/test/StandAlone.wm");
91 | 2 |
           template.write(fmw.getFastWriter().getOutputStream(), context2);
92 | 2 |
           fmw.flush();
93 |  |
           // write to the StringWriter
94 | 2 |
           String out = sw.toString();
95 |  |
           // finally, put what we have into the original templateContext
96 | 2 |
           templateContext.put("StandAlone", out);
97 |  |
         }
98 | 4 |
         return "org/melati/test/WebmacroMelatiServletTest";
99 |  |
       }
100 |  |
101 |  |
       /**
102 |  |
        * Set up the melati context so we don't have to specify the logicaldatabase
103 |  |
        * on the pathinfo.
104 |  |
        *
105 |  |
        * This is a very good idea when writing your appications where you are
106 |  |
        * typically only accessing a single database
107 |  |
        */
108 |  |
       protected PoemContext poemContext(Melati melati) throws PathInfoException {
109 | 4 |
         return poemContextWithLDB(melati, "melatitest");
110 |  |
       }
111 |  |
112 |  |
113 |  |
     }