<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" isErrorPage="true" session="true"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="java.io.*"
%><%@page import="java.util.Enumeration"
%><%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    boolean showTraceButton = false;
    String message;
    if (exception != null) {
        message = exception.toString();
    } else {
        message = "Unknown Exception -- The exception message was lost before generating this page.";
    }
    String requestedUrl = request.getRequestURL().toString();
    String userName = (String)session.getAttribute("userName");
    if (userName == null) {
        userName = "Unknown-User";
    }
    String exNewWindow = (String)session.getAttribute("ExInNewWindow");
    boolean showHeader = true;
    if(exNewWindow != null && exNewWindow.equalsIgnoreCase("true"))
    {
		showHeader = false;
		session.removeAttribute("ExInNewWindow");
    }
    String timeOfException = (new java.util.Date()).toString();

%>
</a></td></tr></table></table></p>
<!-- ======================== EXCEPTION NOTE ====================== -->
<!-- <% QuickForm.writeHtml(out, message); %> -->
<html>
<head><title>Interstage Business Process Manager | Error report</title>
<jsp:include page="StyleSheet.jsp"/>
<script>
function showTrace(wform)
{
    settings=
    "toolbar=no,location=no,directories=no,"+
    "status=no,menubar=no,scrollbars=yes,"+
    "resizable=yes,width=400,height=300";

    MyNewWindow=window.open("","Error",settings);
    MyNewWindow.document.write(wform.exc.value);
}
</script>
</head>
<body class="bodyClass">
<table class="tableClass" cellspacing="0" cellpadding="0" border="0" width="100%">
  <tr align="left">
    <td width="164"><img src="images/interstage_logo.gif" width="164" height="36"/></td>
  </tr>
<tr>
        <td><img src="images/clear.gif" width="1" height="27"></td>
</tr>
<%
 if(showHeader)
{
%>
<tr><td>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><td>
        <table border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="5"><div align="right"><img src="images/tab/inactive_left.gif" width="5" height="25"></div></td>
          <td width="125" nowrap background="images/tab/other_tab_bg.gif">
            <div align="center"><a href="WorkList.jsp">
              <font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Work List</strong>
              </font></a></div></td>
          <td width="7"><img src="images/tab/inactive_right.gif" width="7" height="25"></td>

          <td width="5"><div align="right"><img src="images/tab/inactive_left.gif" width="5" height="25"></div></td>
          <td width="125" nowrap background="images/tab/other_tab_bg.gif">
            <div align="center"><a href="ProcessList.jsp">
              <font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Process Instances</strong>
              </font></a></div></td>
          <td width="7"><img src="images/tab/inactive_right.gif" width="7" height="25"></td>

          <td width="5"><div align="right"><img src="images/tab/inactive_left.gif" width="5" height="25"></div></td>
          <td width="125" nowrap background="images/tab/other_tab_bg.gif">
            <div align="center"><a href="TemplateList.jsp">
              <font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Process Definition</strong>
              </font></a></div></td>
          <td width="7"><img src="images/tab/inactive_right.gif" width="7" height="25"></td>
    <%
        String transPortType = (String)session.getAttribute("TransportType");
        if(transPortType!= null && !transPortType.equalsIgnoreCase("LE"))        
        {
    %>
          <td width="5"><div align="right"><img src="images/tab/inactive_left.gif" width="5" height="25"></div></td>
          <td width="125" nowrap background="images/tab/other_tab_bg.gif">
            <div align="center"><a href="Dashboard.jsp">
              <font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong>Dashboard</strong>
              </font></a></div></td>
          <td width="7"><img src="images/tab/inactive_right.gif" width="7" height="25"></td>
    <%
        }
    %>
        </tr>
        </table>
</td></tr>
<%
}
%>
<tr>
<td colspan="3" align="right">
</td>
</tr>
</table>

<center><br/><br/>
<form name="temp" method="post" action="Login.jsp">
<table cellpadding="10" width="80%" border="0">
<tr>

  <td> <table border="0" width="600" cellspacing="0" bgcolor="#CCCCCC" height="106" cellpadding="1" align="center">
      <tr>
        <td><table border="0" width="600" cellspacing="0" bgcolor="#FFFFFF" height="106" cellpadding="20" bordercolor="#CCCCCC" align="center">
            <tr>
              <td> <font color="#333333" size="1" face="verdana"><img src="images/icons/exception.gif" border="0" align="left">I'm
                sorry.&nbsp; The system has generated an exception, which means
                that for some reason it is unable to process your request.&nbsp;&nbsp;
                The information below may help in determining what went wrong.&nbsp;&nbsp;
                </font> <p><font color="#333333" size="1" face="verdana">In some
                  cases you can go back to the last page, fix the problem, and
                  resubmit. In other cases your system administrator will need
                  to be involved to correct something on the system server.</font>
              </td>
            </tr>
          </table>

        </td>
      </tr>
    </table>
    <br>
    <table width="600" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
      <tr bgcolor="#eeeeee">
        <td>
          <div align="right"><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Time
            of occurrence</font></strong></div></td>
        <td width="317"><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><%= timeOfException %></font></strong></td>
      </tr>
      <tr bgcolor="#FFFFFF">
        <td><div align="right"><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Logged
            in as</font></strong></div></td>
        <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><%= userName %></font></strong></td>
      </tr>
      <tr bgcolor="#FFFFFF">
        <td><div align="right"><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif">Accessing
            Page</font></strong></div></td>
        <td><strong><font color="#000000" size="1" face="Verdana, Arial, Helvetica, sans-serif"><%= requestedUrl %></font></strong></td>
      </tr>
      <tr bgcolor="#eeeeee">
        <td colspan="2"><font color="#FF0000" size="1" face="Verdana, Arial, Helvetica, sans-serif">
          <% 
          message = message.replaceAll(",",", "); //to format the message shown
          deparenthesize(out, message); %>
          </font></td>
      </tr>
    </table>
    <br>
    <div align="center"><font color="#999999" size="1" face="Verdana, Arial, Helvetica, sans-serif">
      </font> </div>
    <table border="0" width="600" cellspacing="0" bgcolor="#CCCCCC" height="106" cellpadding="1" align="center">
      <tr>
        <td><table width="600" border="0" align="center" cellpadding="20" cellspacing="1" bordercolor="#CCCCCC" bgcolor="#FFFFFF">
            <tr>
              <td width="100%"><p><font face="Arial" color="#008080"> <font color="#333333" size="1" face="Verdana, Arial, Helvetica, sans-serif">
              <img src="images/icons/info_excep.gif" border="0" align="left">If you need to report this problem, use the details button below,
                  and include the contents of the pop-up window in any correspondence.</font></font></p>
                <p align="right">
                  <input name="button" type="button" onclick="showTrace(this.form)" value="Details" class="core-button">
                </p></td>
            </tr>
          </table>

        </td>
      </tr>
    </table>


<%
    out.flush();
    StringWriter sw = new StringWriter();
    PrintWriter w = new PrintWriter(sw);
    sw.write("<ul>");
    if (exception.getClass() != null) {
        sw.write("<li>The exception object was of class <b>");
        QuickForm.writeHtml(sw, exception.getClass().getName());
        sw.write("</b><br>");
    }
    sw.write("<li>The exception's message is <B>");
    QuickForm.writeHtmlWithLineBreaks(sw, exception.toString());
    sw.write("</b><br><li>Time: <b>");
    sw.write(           timeOfException);
    sw.write("</b>\n<li>user: <b>");
    sw.write(           userName);
    sw.write("</b>\n<li>url: <b>");
    sw.write(           requestedUrl);
    sw.write("</b>\n<li>The stack trace is as follows:");
    sw.write("</ul><pre>");
    exception.printStackTrace(w);  //note, if the stack trace contains left or right angle brackets this will cause garbage in the final window
    sw.write("</pre><br>");
%>
    <input type="hidden" name="exc" value="<% QuickForm.writeHtml(out, sw.toString()); %>">
<%
    w.close();
    out.flush();
%>
    </td>
</tr>
</table>

</form>
</center>
</body>
</html>
<%!
    // converts a string with multiple nested parenthises into
    // a nested hierarchy of lists ... much easier to read
    public void deparenthesize(JspWriter out, String input)
        throws Exception
    {
        try {
            // now print it as a set of ul statements
            int pos = 0;
            int leftover=1;
            int last = input.length();
            out.write("\n<ul>");
            while (pos < last) {
                int spos = input.indexOf('{', pos);
                int epos = input.indexOf('}', pos);
                int jpos = input.indexOf("nested exception is:", pos);
                int kpos = input.indexOf("because:", pos);
                int npos = last;
                int option = 0;
                int skip = 0;
                if (spos >= 0 && spos < npos) {
                    npos = spos;
                    option = 1;
                    skip = 1;
                }
                if (epos >= 0 && epos < npos) {
                    npos = epos;
                    option = 2;
                    skip = 1;
                }
                if (jpos >= 0 && jpos < npos) {
                    npos = jpos;
                    option = 3;
                    skip = 20;
                }
                if (kpos >= 0 && kpos < npos) {
                    npos = kpos;
                    option = 3;
                    skip = 8;
                }

                // if the character at the position is the searched char,
                // then both pos and npos will be the same
                if (npos > pos) {
                    out.write("<li>");
                    QuickForm.writeHtmlWithLineBreaks(out, input.substring(pos, npos));
                }
                pos = npos + skip;
                switch (option) {
                case 3:
                    leftover++;
                    // continue to next block
                case 1:
                    out.write("\n<ul>");
                    break;
                case 2:
                    out.write("\n</ul>");
                    break;
                case 0:
                    break;
                }

                // skip any following white space to avoid empty outline entries
                while (pos < last && input.charAt(pos) == ' ') {
                    pos++;
                }
            }
            while (leftover > 0) {
                out.write("\n</ul>");
                leftover--;
            }
        }
        catch (Exception ee) {
            out.write("<!-- deparenthesize got this error:");
            out.write(ee.toString());
            out.write("-->");
        }
    }
%>
