setup-global.jsp 3.07 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<%--
  -	$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,
                 org.jivesoftware.util.ClassUtils" %>

<%  // Figure out if we've already run setup:

	boolean doSetup = false;

    if (!doSetup) {
        response.sendRedirect("setup-completed.jsp");
        return;
    }

    // embedded mode?
    boolean embeddedMode = false;
    try {
Matt Tucker's avatar
Matt Tucker committed
29
        ClassUtils.forName("org.jivesoftware.messenger.starter.ServerStarter");
Matt Tucker's avatar
Matt Tucker committed
30 31 32 33 34 35 36 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
        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
73
                    + "\"" + File.separator + "logs" + File.separator + "error.log\" log "
Matt Tucker's avatar
Matt Tucker committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
                    + "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;
                    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;
    }
%>