View Javadoc

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