##### Coverage Report - org.webmacro.servlet.ErrorHandler

Classes in this File | Line Coverage | Branch Coverage | Complexity
ErrorHandler |
0% | 0/15
N/A | N/A
| 1.5;1.5

1 |  |
     /*
2 |  |
      * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
3 |  |
      *
4 |  |
      * Redistribution and use in source and binary forms, with or without
5 |  |
      * modification, are permitted under the terms of either of the following
6 |  |
      * Open Source licenses:
7 |  |
      *
8 |  |
      * The GNU General Public License, version 2, or any later version, as
9 |  |
      * published by the Free Software Foundation
10 |  |
      * (http://www.fsf.org/copyleft/gpl.html);
11 |  |
      *
12 |  |
      *  or
13 |  |
      *
14 |  |
      * The Semiotek Public License (http://webmacro.org/LICENSE.)
15 |  |
      *
16 |  |
      * This software is provided "as is", with NO WARRANTY, not even the
17 |  |
      * implied warranties of fitness to purpose, or merchantability. You
18 |  |
      * assume all risks and liabilities associated with its use.
19 |  |
      *
20 |  |
      * See www.webmacro.org for more information on the WebMacro project.
21 |  |
      */
22 |  |
23 |  |
24 |  |
     package org.webmacro.servlet;
25 |  |
26 |  |
     import org.webmacro.Broker;
27 |  |
     import org.webmacro.ResourceException;
28 |  |
     import org.webmacro.Template;
29 |  |
     import org.webmacro.engine.StringTemplate;
30 |  |
31 |  |
     /**
32 |  |
      * This handler gets called if a normal handler could not
33 |  |
      * be constructed--it writes out an error message
34 |  |
      * explaining what went wrong.
35 |  |
      */
36 | 0 |
     final class ErrorHandler implements Handler
37 |  |
     {
38 |  |
39 |  |
         private static final String DEFAULT_ERROR_TEXT =
40 |  |
                 "<HTML><HEAD><TITLE>Error</TITLE></HEAD>\n"
41 |  |
                 + "#set $Response.ContentType = \"text/html\"\n"
42 |  |
                 + "<BODY><H1>Error</H1>"
43 |  |
                 + "<HR>$error</BODY></HTML>";
44 |  |
45 | 0 |
         private Template _errorTemplate = null;
46 |  |
47 |  |
         /**
48 |  |
          * The default error handler simply returns its template
49 |  |
          * @see TemplateStore
50 |  |
          * @exception HandlerException if you don't want to handle the connect
51 |  |
          * @return A Template which can be used to interpret the connection
52 |  |
          */
53 |  |
         public Template accept (WebContext c)
54 |  |
                 throws HandlerException
55 |  |
         {
56 | 0 |
             Broker broker = c.getBroker();
57 |  |
             String templateName;
58 |  |
59 |  |
             try
60 |  |
             {
61 | 0 |
                 templateName = (String) broker.get("config", WMServlet.ERROR_TEMPLATE);
62 |  |
             }
63 | 0 |
             catch (ResourceException e)
64 |  |
             {
65 | 0 |
                 templateName = WMServlet.ERROR_TEMPLATE_DEFAULT;
66 | 0 |
             }
67 |  |
68 |  |
             try
69 |  |
             {
70 | 0 |
                 _errorTemplate = (Template) broker.get("template", templateName);
71 |  |
             }
72 | 0 |
             catch (ResourceException e)
73 |  |
             {
74 | 0 |
                 _errorTemplate = new StringTemplate(broker, DEFAULT_ERROR_TEXT,
75 |  |
                         "WebMacro default error template");
76 | 0 |
             }
77 |  |
78 | 0 |
             return _errorTemplate;
79 |  |
         }
80 |  |
81 |  |
         /**
82 |  |
          * Does nothing
83 |  |
          */
84 |  |
         public void destroy ()
85 |  |
         {
86 | 0 |
         }
87 |  |
88 |  |
         /**
89 |  |
          * Does nothing
90 |  |
          */
91 |  |
         public void init ()
92 |  |
         {
93 | 0 |
         }
94 |  |
95 |  |
96 |  |
         /**
97 |  |
          * Return the name of this handler
98 |  |
          */
99 |  |
         final public String toString ()
100 |  |
         {
101 | 0 |
             return "WebMacro ErrorHandler";
102 |  |
         }
103 |  |
     }
104 |  |
105 |  |