setup-global.jspf 3.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<%--
  -	$RCSfile$
  -	$Revision$
  -	$Date$
--%>

<%@ page import="java.lang.reflect.Method,
                 java.beans.PropertyDescriptor,
                 java.sql.Connection,
                 org.jivesoftware.database.DbConnectionManager,
                 java.io.File,
                 java.sql.Statement,
                 java.sql.SQLException,
                 java.util.Map,
15
                 org.jivesoftware.util.ClassUtils"
16
%>
17

18 19
<jsp:useBean id="admin" class="org.jivesoftware.util.WebManager"  />
<% admin.init(request, response, session, application, out ); %>
20

21 22
<%  // Figure out if we've already run setup:
	if (!admin.isSetupMode()) {
23 24 25 26
        response.sendRedirect("setup-completed.jsp");
        return;
    }

27 28 29 30 31 32
    // Is a restart required?
    if ("true".equals(session.getAttribute("jive.setup.requireRestart"))) {
        response.sendRedirect("setup-completed.jsp");
        return;
    }

33 34 35
    // embedded mode?
    boolean embeddedMode = false;
    try {
Matt Tucker's avatar
Matt Tucker committed
36
        ClassUtils.forName("org.jivesoftware.messenger.starter.ServerStarter");
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        embeddedMode = true;
    }
    catch (Exception ignored) {}

    // sidebar var for sidebar page - it has to be global.
    boolean showSidebar = true;
%>

<%! // Trys to load a class 3 different ways.
    Class loadClass(String className) throws ClassNotFoundException {
        Class theClass = null;
        try {
            theClass = Class.forName(className);
        }
        catch (ClassNotFoundException e1) {
            try {
                theClass = Thread.currentThread().getContextClassLoader().loadClass(className);
            }
            catch (ClassNotFoundException e2) {
                theClass = getClass().getClassLoader().loadClass(className);
            }
        }
        return theClass;
    }

    final PropertyDescriptor getPropertyDescriptor(PropertyDescriptor[] pd, String name) {
        for (int i=0; i<pd.length; i++) {
            if (name.equals(pd[i].getName())) {
                return pd[i];
            }
        }
        return null;
    }

    boolean testConnection(Map errors) {
        boolean success = true;
        Connection con = null;
        try {
            con = DbConnectionManager.getConnection();
            if (con == null) {
                success = false;
                errors.put("general","A connection to the database could not be "
                    + "made. View the error message by opening the "
Matt Tucker's avatar
Matt Tucker committed
80
                    + "\"" + File.separator + "logs" + File.separator + "error.log\" log "
81 82 83 84 85 86 87 88 89 90 91 92
                    + "file, then go back to fix the problem.");
            }
            else {
            	// See if the Jive db schema is installed.
            	try {
            		Statement stmt = con.createStatement();
            		// Pick an arbitrary table to see if it's there.
            		stmt.executeQuery("SELECT * FROM jiveID");
            		stmt.close();
            	}
            	catch (SQLException sqle) {
                    success = false;
93
                    sqle.printStackTrace();
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
                    errors.put("general","The Jive Messenger database schema does not "
                        + "appear to be installed. Follow the installation guide to "
                        + "fix this error.");
            	}
            }
        }
        catch (Exception ignored) {}
        finally {
            try {
        	    con.close();
            } catch (Exception ignored) {}
        }
        return success;
    }
%>