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.pipeline.PipelineData;
    35  import org.apache.turbine.util.RunData;
    36
    37  /**
    38   * This is a sample Error Screen module.
    39   *
    40   * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
    41   * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
    42   * @version $Id: Error.java 938645 2010-04-27 20:57:51Z tv $
    43   */
    44  public class Error extends Screen
    45  {
    46      /**
    47       * Build screen.
    48       *
    49       * @deprecated Use PipelineData version instead.
    50       * @param data Turbine information.
    51       * @return ConcreteElement the page with all the error information.
    52       * @throws Exception a generic exception.
    53       */
    54      public ConcreteElement doBuild(RunData data) throws Exception
    55      {
    56          data.setTitle("There has been an error!");
    57
    58          Table table = new Table().setBorder(0);
    59          boolean hasValues = false;
    60          for (Iterator it = data.getParameters().keySet().iterator();
    61               it.hasNext();)
    62          {
    63              String key = (String) it.next();
    64              String value = data.getParameters().getString(key);
    65              TR tr =
    66                  new TR().addElement(
    67                      new TD().addElement(new B(key))).addElement(
    68                      new TD().addElement(" = " + value));
    69              table.addElement(tr);
    70              hasValues = true;
    71          }
    72
    73          Table table2 = new Table().setBorder(0);
    74          Map varDebug = data.getDebugVariables();
    75
    76          boolean hasValues2 = false;
    77          for (Iterator i = varDebug.keySet().iterator(); i.hasNext();)
    78          {
    79              String key = (String) i.next();
    80              String value = varDebug.get(key).toString();
    81              TR tr =
    82                  new TR().addElement(
    83                      new TD().addElement(new B(key))).addElement(
    84                      new TD().addElement(" = " + value));
    85              table2.addElement(tr);
    86              hasValues2 = true;
    87          }
    88
    89          data.getPage().getBody().addElement(
    90              new H3(
    91                  data.getTitle()
    92                      + " Please review the exception below "
    93                      + "for more information."));
    94
    95          if (hasValues)
    96          {
    97              data.getPage().getBody().addElement(
    98                  new H4().addElement("Get/Post Data:"));
    99              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 }