001: package org.apache.turbine.modules.screens;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.util.Iterator;
023: import java.util.Map;
024:
025: import org.apache.ecs.ConcreteElement;
026: import org.apache.ecs.html.B;
027: import org.apache.ecs.html.H3;
028: import org.apache.ecs.html.H4;
029: import org.apache.ecs.html.PRE;
030: import org.apache.ecs.html.TD;
031: import org.apache.ecs.html.TR;
032: import org.apache.ecs.html.Table;
033: import org.apache.turbine.modules.Screen;
034: import org.apache.turbine.util.RunData;
035:
036: /**
037: * This is a sample Error Screen module.
038: *
039: * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
040: * @version $Id: Error.java 534527 2007-05-02 16:10:59Z tv $
041: */
042: public class Error extends Screen {
043: /**
044: * Build screen.
045: *
046: * @param data Turbine information.
047: * @return ConcreteElement the page with all the error information.
048: * @throws Exception a generic exception.
049: */
050: public ConcreteElement doBuild(RunData data) throws Exception {
051: data.setTitle("There has been an error!");
052:
053: Table table = new Table().setBorder(0);
054: boolean hasValues = false;
055: for (Iterator it = data.getParameters().keySet().iterator(); it
056: .hasNext();) {
057: String key = (String) it.next();
058: String value = data.getParameters().getString(key);
059: TR tr = new TR()
060: .addElement(new TD().addElement(new B(key)))
061: .addElement(new TD().addElement(" = " + value));
062: table.addElement(tr);
063: hasValues = true;
064: }
065:
066: Table table2 = new Table().setBorder(0);
067: Map varDebug = data.getDebugVariables();
068:
069: boolean hasValues2 = false;
070: for (Iterator i = varDebug.keySet().iterator(); i.hasNext();) {
071: String key = (String) i.next();
072: String value = varDebug.get(key).toString();
073: TR tr = new TR()
074: .addElement(new TD().addElement(new B(key)))
075: .addElement(new TD().addElement(" = " + value));
076: table2.addElement(tr);
077: hasValues2 = true;
078: }
079:
080: data.getPage().getBody().addElement(
081: new H3(data.getTitle()
082: + " Please review the exception below "
083: + "for more information."));
084:
085: if (hasValues) {
086: data.getPage().getBody().addElement(
087: new H4().addElement("Get/Post Data:"));
088: data.getPage().getBody().addElement(table);
089: }
090:
091: if (hasValues2) {
092: data.getPage().getBody().addElement(
093: new H4().addElement("Debugging Data:"));
094: data.getPage().getBody().addElement(table2);
095: }
096:
097: String trace = data.getStackTrace();
098: if (trace != null) {
099: data.getPage().getBody().addElement(
100: new H4().addElement("The exception is:"))
101: .addElement(new PRE(trace)).addElement(
102: new PRE(data.getStackTraceException()
103: .toString()));
104: }
105: return null;
106: }
107: }
|