⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiaconfigurationwizard.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        // force objects to garbage collector...        istream = null;        url     = null;    }    // end tryHostURL()    /**     * Try to establish a connection with the host url indicates by the user     * on the server settings page, and check some error(s) (like HTTP-403, etc).     * @author  Serge Huber     *     * @exception   Exception       an exception occured during the process.     */    private void tryWebAppsDeployBaseURL()    throws Exception    {        URL          url      = null;        InputStream  istream  = null;        try        {            url      = new URL( ((String)values.get("webapps_deploybaseurl")) );            istream  = url.openStream();            istream.close();        } catch (Exception e) {            throw new Exception( "Cannot connect to the web applications deployment base URL." );        }        // force objects to garbage collector...        istream = null;        url     = null;    }    // end tryHostURL()    /**     * Try to create the path to jahia files indicates by the user on the     * server settings page, and check some error(s) (like permissions, etc).     * @author  Alexandre Kraft     *     * @exception   Exception       an exception occured during the process.     */    private void tryJahiaFilesPath()    throws Exception    {        String jahiaFiles = null;        try        {            // transform context-relative path in filesystem if needed...            if( ((String)values.get("server_jahiafiles")).substring(0,9).equals("$context/") ) {                jahiaFiles = context.getRealPath(                                 ((String)values.get("server_jahiafiles")).substring(                                     8, ((String)values.get("server_jahiafiles")).length() ) );            } else {                throw new StringIndexOutOfBoundsException();            }        } catch (StringIndexOutOfBoundsException sioobe) {            jahiaFiles = (String)values.get("server_jahiafiles");        }        // a filepath must contain at least one file separator...        if( jahiaFiles.indexOf(File.separator) == -1 ) {            throw new Exception( "Jahia Files must be a valid filesystem or context-relative path." );        }        // create the File object...        File jf     = new File( jahiaFiles );        File parent = null;        // check if the location exists... or not.        if( jf.exists() )        {            if( jf.isFile() ) {                                                             // check if it's a file ?!                throw new Exception( "Jahia Files must be a directory, and not a file." );            }            if( !jf.canRead() ) {                                                           // check if i have permissions to read on it...                throw new Exception( "Can't read in Jahia Files directory. Please verify permissions." );            }            if( !jf.canWrite() ) {                                                          // check if i have permissions to write on it...                throw new Exception( "Can't write in Jahia Files directory. Please verify permissions." );            }        } else {            // get parent directory...            parent = jf.getParentFile();            // check if the parent exists... or not.            if( parent.exists() ) {                if( !parent.canWrite() ) {                                                  // check if i have permissions to write on parent...                    throw new Exception( "Jahia can't create your directory (write permissions)." );                }            } else {                if( !parent.mkdirs() ) {                                                    // the parent don't exists... create it if possible.                    throw new Exception( "Jahia can't create your directory (write permissions)." );                }            }        }        // force objects to garbage collector...        parent     = null;        jf         = null;        jahiaFiles = null;    }    // end tryJahiaFilesPath()    /**     * Read the database script requested by the user, get the test table line and     * execute the self-test in the databaseconnection static object of jahia     * administration.     * @author  Alexandre Kraft     *     * @return  HashMap containing the results of the database test.     */    private HashMap testDBConnection()    {        String line;        // get script runtime...        try {            BufferedReader inBuffer = new BufferedReader(                                      new FileReader(dbScriptsPath + File.separator +                                                     values.get("database_script")));            while ((line = inBuffer.readLine()) != null) {                if (line.indexOf("jahia_db_test", 13) >= 0) {                    break;                }            }        } catch (IOException ioe) {            line = "unknown";        }        // test database...        return db.databaseTest( (String)values.get("database_script"), (String)values.get("database_driver"),                                (String)values.get("database_url"), (String)values.get("database_user"),                                (String)values.get("database_pwd"), line,                                "true".equals(values.get("utf8Encoding")) );    }    /**     * Insert the database tables described in the database script. Before the     * insertion, since you're sure that the user want overwrite his database,     * each table is dropped, table after table.     * @author  Alexandre Kraft     *     * @exception   Exception       an exception occured during the process.     */    private void createDBTables()    throws Exception    {        File         object   = null;        Enumeration  runtime  = null;        String       line     = null;        // construct script path...        StringBuffer script = new StringBuffer( dbScriptsPath );        script.append( File.separator );        script.append( (String)values.get("database_script") );        // get script runtime...        try {            object  = new File( script.toString() );            runtime = scripts.getDatabaseScriptsRuntime( object );        } catch (Exception e) {            throw new Exception( "Jahia can't read the appropriate database script." );        }        // drop each tables (if present) and (re-)create it after...        while( runtime.hasMoreElements() ) {            line = (String) runtime.nextElement();            try {                db.query( "DROP TABLE " + line.substring( line.indexOf("jahia_"), line.indexOf("(")).trim() );            } catch (Exception e) {                // nothing to do...... i don't care if the drop doesn't work.            }            db.query( line );        }        // force objects to garbage collector...        object  = null;        script  = null;        runtime = null;        line    = null;    }    // end createDBTables()    /**     * Insert database custom data, like root user and properties.     * @author  Alexandre Kraft     * @author  Khue Nguyen     *     * @exception   Exception       an exception occured during the process.     */    private void insertDBCustomContent()    throws Exception    {        // get two keys...        String rootName = (String)values.get("root_user");        int siteID0 = 0;        int siteID1 = 1;        String rootKey = rootName + ":" + siteID0;        String grpKey0 = JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME + ":" + siteID0;        String grpKey1 = JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME + ":" + siteID1;        // query insert root user...        StringBuffer sqlRootUser = new StringBuffer();        sqlRootUser.append( "INSERT INTO jahia_users(id_jahia_users, name_jahia_users, password_jahia_users, key_jahia_users, siteid_jahia_users) VALUES(0, '" );        sqlRootUser.append( rootName + "', '");        sqlRootUser.append( JahiaUserManagerService.encryptPassword( (String)values.get("root_pwd") ) );        sqlRootUser.append( "','" + rootKey + "', " + siteID0 + ")" );            db.query( sqlRootUser.toString() );        // query insert root first name...        sqlRootUser = new StringBuffer();        sqlRootUser.append( "INSERT INTO jahia_user_prop(id_jahia_users, name_jahia_user_prop, value_jahia_user_prop) VALUES(0, 'firstname', '" );        sqlRootUser.append( JahiaTools.replacePattern((String)values.get("root_firstname"), "'", "''") + "')" );            db.query( sqlRootUser.toString() );        // query insert root last name...        sqlRootUser = new StringBuffer();        sqlRootUser.append( "INSERT INTO jahia_user_prop(id_jahia_users, name_jahia_user_prop, value_jahia_user_prop) VALUES(0, 'lastname', '" );        sqlRootUser.append( JahiaTools.replacePattern((String)values.get("root_lastname"), "'", "''") + "')" );            db.query( sqlRootUser.toString() );        // query insert root e-mail address...        sqlRootUser = new StringBuffer();        sqlRootUser.append( "INSERT INTO jahia_user_prop(id_jahia_users, name_jahia_user_prop, value_jahia_user_prop) VALUES(0, 'email', '" );        sqlRootUser.append( (String)values.get("root_mail") + "')" );            db.query( sqlRootUser.toString() );        // query insert administrators group...        sqlRootUser = new StringBuffer();        sqlRootUser.append( "INSERT INTO jahia_grps(id_jahia_grps, name_jahia_grps, key_jahia_grps, siteid_jahia_grps) VALUES(");        sqlRootUser.append( siteID0 + ", '");        sqlRootUser.append( JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME + "','" );        sqlRootUser.append( grpKey0 + "', " + siteID0 + ")" );            db.query( sqlRootUser.toString() );        // query insert administrators group access...        sqlRootUser = new StringBuffer();        sqlRootUser.append( "INSERT INTO jahia_grp_access(id_jahia_member, id_jahia_grps, membertype_grp_access) VALUES('" );        sqlRootUser.append( rootKey + "', '" + grpKey0 + "', 1)" ); // 1 = user type            db.query( sqlRootUser.toString() );        // query insert group access for the root user with initial site admin group        sqlRootUser = new StringBuffer();        sqlRootUser.append( "INSERT INTO jahia_grp_access(id_jahia_member, id_jahia_grps, membertype_grp_access) VALUES('" );        sqlRootUser.append( rootKey + "','" + grpKey1 + "', 1)" ); // 1 = user type        db.query( sqlRootUser.toString() );        // query insert site user...        sqlRootUser = new StringBuffer();        sqlRootUser.append( "INSERT INTO jahia_sites_users(username_sites_users, siteid_sites_users, userid_sites_users) VALUES('" );        sqlRootUser.append( rootName + "', " + siteID1 + ", '" + rootKey + "')" );        db.query( sqlRootUser.toString() );    }    // end insertDBCustomContent()    /**     * Insert database default data, like default users, default users properties,     * default groups, templates, etc. It also set auto-incrementors id... it's     * very important, be careful about this.     * @author  Alexandre Kraft     * @author  Khue Nguyen     *     * @exception   Exception       an exception occured during the process.     */    private void insertDBDefaultContent()    throws Exception    {        // read from the file...        File         object   = null;        Enumeration  runtime  = null;        String       line     = null;        // construct script path...        StringBuffer script = new StringBuffer( dbScriptsPath );        script.append( File.separator );        if ( values.get("templates") != null ){            script.append( "default_"+JahiaTools.removeFileExtension((String)values.get("templates"),".jar")+".values" );        }        // get script runtime...        try {            object  = new File( script.toString() );            runtime = scripts.getDatabaseScriptsRuntime( object );        } catch (Exception e) {         

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -