<%--
  -	$RCSfile$
  -	$Revision: 1217 $
  -	$Date: 2005-04-11 14:11:06 -0700 (Mon, 11 Apr 2005) $
--%>

<%@ page import="java.lang.reflect.Method,
                 java.io.File,
                 org.jivesoftware.util.LocaleUtils" %>

<%-- note, the loadClass method is defined in setup-global.jspf --%>

<%  // Check the user's environment for minimum requirements.

    boolean jdk13Installed = false;
    boolean servlet22Installed = false;
    boolean jsp11Installed = false;
    boolean jiveJarsInstalled = false;
    boolean messengerHomeExists = false;
    File messengerHome = null;

    // Check for JDK 1.5
    try {
        loadClass("java.util.concurrent.ConcurrentHashMap");
        jdk13Installed = true;
    }
    catch (ClassNotFoundException cnfe) {}
    // Check for Servlet 2.3:
    try {
        Class c = loadClass("javax.servlet.http.HttpSession");
        Method m = c.getMethod("getAttribute",new Class[]{String.class});
        servlet22Installed = true;
    }
    catch (ClassNotFoundException cnfe) {}
    // Check for JSP 1.1:
    try {
        loadClass("javax.servlet.jsp.tagext.Tag");
        jsp11Installed = true;
    }
    catch (ClassNotFoundException cnfe) {}
    // Check that the Messenger jar are installed:
    try {
        loadClass("org.jivesoftware.messenger.XMPPServer");
        jiveJarsInstalled = true;
    }
    catch (ClassNotFoundException cnfe) {}

    // Try to determine what the jiveHome directory is:
    try {
        Class jiveGlobalsClass = loadClass("org.jivesoftware.util.JiveGlobals");
        Method getMessengerHomeMethod = jiveGlobalsClass.getMethod("getHomeDirectory", (Class[])null);
        String messengerHomeProp = (String)getMessengerHomeMethod.invoke(jiveGlobalsClass, (Object[])null);
        if (messengerHomeProp != null) {
            messengerHome = new File(messengerHomeProp);
            if (messengerHome.exists()) {
                messengerHomeExists = true;
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    // If there were no errors, redirect to the main setup page
    if (!jdk13Installed || !servlet22Installed || !jsp11Installed || !jiveJarsInstalled
            || !messengerHomeExists)
    {
%>
        <html>
        <head>
            <title><fmt:message key="title" /> <fmt:message key="setup.title" /></title>
            <link rel="stylesheet" type="text/css" href="style.css">
        </head>
        <body>

        <p class="jive-setup-page-header">
        <fmt:message key="title" /> <fmt:message key="setup.title" />
        </p>

        <p class="jive-setup-error-text">
        <fmt:message key="setup.env.check.error" /> <fmt:message key="title" /> <fmt:message key="setup.title" />.
        </p>

        <p>
        <fmt:message key="setup.env.check.error_info">
            <fmt:param value="<%= LocaleUtils.getLocalizedString("title") %>" />
        </fmt:message>
        </p>

        <ul>
        <table cellpadding="3" cellspacing="2" border="0">
        <%  if (jdk13Installed) { %>

            <tr>
                <td><img src="../images/check.gif" width="13" height="13" border="0"></td>
                <td>
                    <fmt:message key="setup.env.check.jdk" />
                </td>
            </tr>

        <%  } else { %>

            <tr>
                <td><img src="../images/x.gif" width="13" height="13" border="0"></td>
                <td>
                    <span class="jive-setup-error-text">
                    <fmt:message key="setup.env.check.jdk" />
                    </span>
                </td>
            </tr>

        <%  }
            if (servlet22Installed) {
        %>
            <tr>
                <td><img src="../images/check.gif" width="13" height="13" border="0"></td>
                <td>
                    <fmt:message key="setup.env.check.servlet" />
                </td>
            </tr>

        <%  } else { %>

            <tr>
                <td><img src="../images/x.gif" width="13" height="13" border="0"></td>
                <td>
                    <span class="jive-setup-error-text">
                    <fmt:message key="setup.env.check.servlet" />
                    </span>
                </td>
            </tr>

        <%  }
            if (jsp11Installed) {
        %>
            <tr>
                <td><img src="../images/check.gif" width="13" height="13" border="0"></td>
                <td>
                    <fmt:message key="setup.env.check.jsp" />
                </td>
            </tr>

        <%  } else { %>

            <tr>
                <td><img src="../images/x.gif" width="13" height="13" border="0"></td>
                <td>
                    <span class="jive-setup-error-text">
                    <fmt:message key="setup.env.check.jsp" />
                    </span>
                </td>
            </tr>

        <%  }
            if (jiveJarsInstalled) {
        %>
            <tr>
                <td><img src="../images/check.gif" width="13" height="13" border="0"></td>
                <td>
                    <fmt:message key="title" /> <fmt:message key="setup.env.check.class" />
                </td>
            </tr>

        <%  } else { %>

            <tr>
                <td><img src="../images/x.gif" width="13" height="13" border="0"></td>
                <td>
                    <span class="jive-setup-error-text">
                    <fmt:message key="title" /> <fmt:message key="setup.env.check.class" />
                    </span>
                </td>
            </tr>

        <%  }
            if (messengerHomeExists) {
        %>
            <tr>
                <td><img src="../images/x.gif" width="13" height="13" border="0"></td>
                <td>
                    <span class="jive-setup-error-text">
                    <fmt:message key="setup.env.check.jive" /> (<%= messengerHome.toString() %>)
                    </span>
                </td>
            </tr>

        <%  } else { %>

            <tr>
                <td><img src="../images/x.gif" width="13" height="13" border="0"></td>
                <td>
                    <span class="jive-setup-error-text">
                    <fmt:message key="setup.env.check.not_home" />
                    </span>
                </td>
            </tr>

        <%  } %>
        </table>
        </ul>

        <p>
        <fmt:message key="setup.env.check.doc" />
        </p>

        </body>
        </html>

<%      // return so we stop showing the page:
        return;
    }
%>