View Javadoc

1   package org.apache.turbine.modules.screens;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.Iterator;
20  import java.util.Map;
21  
22  import org.apache.ecs.ConcreteElement;
23  import org.apache.ecs.html.B;
24  import org.apache.ecs.html.H3;
25  import org.apache.ecs.html.H4;
26  import org.apache.ecs.html.PRE;
27  import org.apache.ecs.html.TD;
28  import org.apache.ecs.html.TR;
29  import org.apache.ecs.html.Table;
30  import org.apache.turbine.modules.Screen;
31  import org.apache.turbine.util.RunData;
32  
33  /***
34   * This is a sample Error Screen module.
35   *
36   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
37   * @version $Id: Error.java 264148 2005-08-29 14:21:04Z henning $
38   */
39  public class Error extends Screen
40  {
41      /***
42       * Build screen.
43       *
44       * @param data Turbine information.
45       * @return ConcreteElement the page with all the error information.
46       * @throws Exception a generic exception.
47       */
48      public ConcreteElement doBuild(RunData data) throws Exception
49      {
50          data.setTitle("There has been an error!");
51  
52          Table table = new Table().setBorder(0);
53          boolean hasValues = false;
54          for (Iterator it = data.getParameters().keySet().iterator();
55               it.hasNext();)
56          {
57              String key = (String) it.next();
58              String value = data.getParameters().getString(key);
59              TR tr =
60                  new TR().addElement(
61                      new TD().addElement(new B(key))).addElement(
62                      new TD().addElement(" = " + value));
63              table.addElement(tr);
64              hasValues = true;
65          }
66  
67          Table table2 = new Table().setBorder(0);
68          Map varDebug = data.getDebugVariables();
69  
70          boolean hasValues2 = false;
71          for (Iterator i = varDebug.keySet().iterator(); i.hasNext();)
72          {
73              String key = (String) i.next();
74              String value = varDebug.get(key).toString();
75              TR tr =
76                  new TR().addElement(
77                      new TD().addElement(new B(key))).addElement(
78                      new TD().addElement(" = " + value));
79              table2.addElement(tr);
80              hasValues2 = true;
81          }
82  
83          data.getPage().getBody().addElement(
84              new H3(
85                  data.getTitle()
86                      + " Please review the exception below "
87                      + "for more information."));
88  
89          if (hasValues)
90          {
91              data.getPage().getBody().addElement(
92                  new H4().addElement("Get/Post Data:"));
93              data.getPage().getBody().addElement(table);
94          }
95  
96          if (hasValues2)
97          {
98              data.getPage().getBody().addElement(
99                  new H4().addElement("Debugging Data:"));
100             data.getPage().getBody().addElement(table2);
101         }
102 
103         String trace = data.getStackTrace();
104         if (trace != null)
105         {
106             data
107                 .getPage()
108                 .getBody()
109                 .addElement(new H4().addElement("The exception is:"))
110                 .addElement(new PRE(trace))
111                 .addElement(new PRE(data.getStackTraceException().toString()));
112         }
113         return null;
114     }
115 }