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.pipeline.PipelineData;
035 import org.apache.turbine.util.RunData;
036
037 /**
038 * This is a sample Error Screen module.
039 *
040 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
041 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
042 * @version $Id: Error.java 938645 2010-04-27 20:57:51Z tv $
043 */
044 public class Error extends Screen
045 {
046 /**
047 * Build screen.
048 *
049 * @deprecated Use PipelineData version instead.
050 * @param data Turbine information.
051 * @return ConcreteElement the page with all the error information.
052 * @throws Exception a generic exception.
053 */
054 public ConcreteElement doBuild(RunData data) throws Exception
055 {
056 data.setTitle("There has been an error!");
057
058 Table table = new Table().setBorder(0);
059 boolean hasValues = false;
060 for (Iterator it = data.getParameters().keySet().iterator();
061 it.hasNext();)
062 {
063 String key = (String) it.next();
064 String value = data.getParameters().getString(key);
065 TR tr =
066 new TR().addElement(
067 new TD().addElement(new B(key))).addElement(
068 new TD().addElement(" = " + value));
069 table.addElement(tr);
070 hasValues = true;
071 }
072
073 Table table2 = new Table().setBorder(0);
074 Map varDebug = data.getDebugVariables();
075
076 boolean hasValues2 = false;
077 for (Iterator i = varDebug.keySet().iterator(); i.hasNext();)
078 {
079 String key = (String) i.next();
080 String value = varDebug.get(key).toString();
081 TR tr =
082 new TR().addElement(
083 new TD().addElement(new B(key))).addElement(
084 new TD().addElement(" = " + value));
085 table2.addElement(tr);
086 hasValues2 = true;
087 }
088
089 data.getPage().getBody().addElement(
090 new H3(
091 data.getTitle()
092 + " Please review the exception below "
093 + "for more information."));
094
095 if (hasValues)
096 {
097 data.getPage().getBody().addElement(
098 new H4().addElement("Get/Post Data:"));
099 data.getPage().getBody().addElement(table);
100 }
101
102 if (hasValues2)
103 {
104 data.getPage().getBody().addElement(
105 new H4().addElement("Debugging Data:"));
106 data.getPage().getBody().addElement(table2);
107 }
108
109 String trace = data.getStackTrace();
110 if (trace != null)
111 {
112 data
113 .getPage()
114 .getBody()
115 .addElement(new H4().addElement("The exception is:"))
116 .addElement(new PRE(trace))
117 .addElement(new PRE(data.getStackTraceException().toString()));
118 }
119 return null;
120 }
121
122
123 /**
124 * Build screen.
125 *
126 * @param data Turbine information.
127 * @return ConcreteElement the page with all the error information.
128 * @throws Exception a generic exception.
129 */
130 public ConcreteElement doBuild(PipelineData pipelineData) throws Exception
131 {
132 RunData data = getRunData(pipelineData);
133 return doBuild(data);
134 }
135 }