org.opencms.setup
Class CmsSetupBean

java.lang.Object
  extended byorg.opencms.setup.CmsSetupBean
All Implemented Interfaces:
Cloneable, I_CmsShellCommands, Serializable

public class CmsSetupBean
extends Object
implements Serializable, Cloneable, I_CmsShellCommands

A java bean as a controller for the OpenCms setup wizard.

It is not allowed to customize this bean with methods for a specific database server setup!

Database server specific settings should be set/read using get/setDbProperty, as for example like:

 setDbProperty("oracle.defaultTablespace", value);
 

Since:
6.0.0
Version:
$Revision: 1.39 $
Author:
Thomas Weckert, Carsten Weinholz, Alexander Kandzior
See Also:
Serialized Form

Field Summary
static String GENERIC_PROVIDER
          DB provider constant.
static String HTML_MESSAGE_FILE
          Name of the property file containing HTML fragments for setup wizard and error dialog.
static String MYSQL_PROVIDER
          DB provider constant.
static String ORACLE_PROVIDER
          DB provider constant.
static String POSTGRESQL_PROVIDER
          DB provider constant.
static String[] REQUIRED_DB_SETUP_FILES
          Required files per database server setup.
 
Constructor Summary
CmsSetupBean()
          Default constructor.
 
Method Summary
 void backupConfiguration(String filename, String originalFilename)
          Restores the opencms.xml either to or from a backup file, depending whether the setup wizard is executed the first time (the backup does not exist) or not (the backup exists).
 void checkEthernetAddress()
          Checks the ethernet address value and generates a dummy address, if necessary.
 void copyFile(String source, String target)
          Copies a given file.
 Map getAvailableModules()
          Returns a map with all available modules.
 String getConfigRfsPath()
          Returns the "config" path in the OpenCms web application.
 String getDatabase()
          Returns the key of the selected database server (e.g.
 String getDatabaseConfigPage(String key)
          Returns the URI of a database config page (in step 3) for a specified database key.
 String getDatabaseName(String databaseKey)
          Returns the clear text name for a database server setup specified by a database key (e.g.
 Map getDatabaseProperties()
          Returns a map with the database properties of *all* available database configurations keyed by their database keys (e.g.
 List getDatabases()
          Returns a list with they keys (e.g.
 String getDb()
          Returns the database name.
 String getDbConStrParams()
          Returns the JDBC connect URL parameters.
 String getDbCreateConStr()
          Returns the database create statement.
 String getDbCreatePwd()
          Returns the password used for database creation.
 String getDbCreateUser()
          Returns the database user that is used to connect to the database.
 String getDbDriver()
          Returns the database driver belonging to the database from the default configuration.
 String getDbProperty(String key)
          Returns the value for a given key from the database properties.
 String getDbTestQuery()
          Returns the validation query belonging to the database from the default configuration .
 String getDbWorkConStr()
          Returns a connection string.
 String getDbWorkPwd()
          Returns the password of the database from the properties .
 String getDbWorkUser()
          Returns the user of the database from the properties.
 String getDefaultContentEncoding()
          Returns the default content encoding.
 String getDefaultWebApplication()
          Returns the name of the default web application, configured in web.xml.
 String getDisplayForModule(Map module)
          Returns the display string for a given module.
 Vector getErrors()
          Returns the error messages.
 String getEthernetAddress()
          Returns the mac ethernet address.
protected  String getExtProperty(String key)
          Returns the value for a given key from the extended properties.
 String getHtmlHelpIcon(String id, String pathPrefix)
          Returns a help image icon tag to display a help text in the setup wizard.
 String getHtmlPart(String part)
          Returns the specified HTML part of the HTML property file to create the output.
 String getHtmlPart(String part, String replaceString)
          Returns the specified HTML part of the HTML property file to create the output.
 Map getModuleDependencies()
          Returns a map with lists of dependent module package names keyed by module package names.
 String getPool()
          Gets the default pool.
 ExtendedProperties getProperties()
          Returns the extended properties.
 Map getReplacer()
          Returns the replacer.
 String getServerName()
          Return the OpenCms server name.
 String getServletMapping()
          Returns the OpenCms servlet mapping, configured in web.xml.
 String getSetupLogName()
          Returns the name of the setup log file.
 List getSortedDatabases()
          Returns a sorted list with they keys (e.g.
 String getWebAppRfsPath()
          Returns the absolute path to the OpenCms home directory.
 boolean getWizardEnabled()
          Checks if the setup wizard is enabled.
 CmsSetupWorkplaceImportThread getWorkplaceImportThread()
          Returns the workplace import thread.
 String getWorkplaceSite()
          Return the OpenCms workplace site.
protected  void importModuleFromDefault(String importFile)
          Imports a module (zipfile) from the default module directory, creating a temporary project for this.
 void importModulesFromSetupBean()
          Installed all modules that have been set using setInstallModules(String).
 void init(PageContext pageContext)
          Creates a new instance of the setup Bean from a JSP page.
 void init(String webAppRfsPath, String servletMapping, String defaultWebApplication)
          Creates a new instance of the setup Bean.
 void initHtmlParts()
          This method reads the properties from the htmlmsg.property file and sets the HTML part properties with the matching values.
 void initShellCmsObject(CmsObject cms, CmsShell shell)
          Provides access to the shell CmsObject and the shell itself.
 String isChecked(String value1, String value2)
          Over simplistic helper to compare two strings to check radio buttons.
 boolean isInitialized()
          Returns true if this setup bean is correctly initialized.
 ExtendedProperties loadProperties(String file)
          Loads the default OpenCms properties.
 void lockWizard()
          Locks (i.e.
 void prepareStep10()
          Prepares step 10 of the setup wizard.
 boolean prepareStep8()
          Prepares step 8 of the setup wizard.
 void prepareStep8b()
          Prepares step 8b of the setup wizard.
 void prepareStep8bOutput(JspWriter out)
          Generates the output for step 8b of the setup wizard.
protected  void readDatabaseConfig()
          Stores the properties of all available database configurations in a map keyed by their database key names (e.g.
 void saveProperties(ExtendedProperties properties, String file, boolean backup)
          Saves properties to specified file.
 void setDatabase(String databaseKey)
          Sets the database drivers to the given value.
 void setDb(String db)
          Sets the database name.
 void setDbConStrParams(String value)
          Sets the JDBC connect URL parameters.
 void setDbCreateConStr(String dbCreateConStr)
          Sets the database create statement.
 void setDbCreatePwd(String dbCreatePwd)
          Sets the password used for the initial OpenCms database creation.
 void setDbCreateUser(String dbCreateUser)
          Set the database user that is used to connect to the database.
 void setDbDriver(String driver)
          Sets the database driver belonging to the database.
 boolean setDbParamaters(HttpServletRequest request, String provider)
          Sets the needed database parameters.
 void setDbProperty(String key, String value)
          This method sets the value for a given key in the database properties.
 void setDbWorkConStr(String dbWorkConStr)
          Sets the connection string to the database to the given value.
 void setDbWorkPwd(String dbWorkPwd)
          Sets the password of the database to the given value.
 void setDbWorkUser(String dbWorkUser)
          Sets the user of the database to the given value.
 void setEthernetAddress(String ethernetAddress)
          Set the mac ethernet address, required for UUID generation.
protected  void setExtProperty(String key, String value)
          This method sets the value for a given key in the extended properties.
 void setInstallModules(String value)
          Sets the list with the package names of the modules to be installed.
 void setReplacer(Map map)
          Sets the replacer.
 void setServerName(String name)
          Sets the OpenCms server name.
 void setWorkplaceSite(String newSite)
          Sets the OpenCms workplace site.
 void shellExit()
          May be called after shell exit, can e.g.
 void shellStart()
          May be called before shell startup, can e.g.
 List sortModules(Map modules)
          Sorts the modules for display.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GENERIC_PROVIDER

public static final String GENERIC_PROVIDER
DB provider constant.

See Also:
Constant Field Values

MYSQL_PROVIDER

public static final String MYSQL_PROVIDER
DB provider constant.

See Also:
Constant Field Values

ORACLE_PROVIDER

public static final String ORACLE_PROVIDER
DB provider constant.

See Also:
Constant Field Values

POSTGRESQL_PROVIDER

public static final String POSTGRESQL_PROVIDER
DB provider constant.

See Also:
Constant Field Values

HTML_MESSAGE_FILE

public static final String HTML_MESSAGE_FILE
Name of the property file containing HTML fragments for setup wizard and error dialog.

See Also:
Constant Field Values

REQUIRED_DB_SETUP_FILES

public static final String[] REQUIRED_DB_SETUP_FILES
Required files per database server setup.

Constructor Detail

CmsSetupBean

public CmsSetupBean()
Default constructor.

Method Detail

backupConfiguration

public void backupConfiguration(String filename,
                                String originalFilename)
Restores the opencms.xml either to or from a backup file, depending whether the setup wizard is executed the first time (the backup does not exist) or not (the backup exists).

Parameters:
filename - something like e.g. "opencms-xml.ori"
originalFilename - the configurations real file name, e.g. "opencms.xml"

checkEthernetAddress

public void checkEthernetAddress()
Checks the ethernet address value and generates a dummy address, if necessary.

*


copyFile

public void copyFile(String source,
                     String target)
Copies a given file.

Parameters:
source - the source file
target - the destination file

getAvailableModules

public Map getAvailableModules()
Returns a map with all available modules.

The map contains maps keyed by module package names. Each of these maps contains various information about the module such as the module name, version, description, and a list of it's dependencies. You should refer to the source code of this method to understand the data structure of the map returned by this method!

Returns:
a map with all available modules

getDisplayForModule

public String getDisplayForModule(Map module)
Returns the display string for a given module.

Parameters:
module - a module in the form of the result of getAvailableModules()
Returns:
the display string for the given module

sortModules

public List sortModules(Map modules)
Sorts the modules for display.

Parameters:
modules - the list of modules (the result of getAvailableModules())
Returns:
a list of sorted module names

getConfigRfsPath

public String getConfigRfsPath()
Returns the "config" path in the OpenCms web application.

Returns:
the config path

getDatabase

public String getDatabase()
Returns the key of the selected database server (e.g. "mysql", "generic" or "oracle").

Returns:
the key of the selected database server (e.g. "mysql", "generic" or "oracle")

getDatabaseConfigPage

public String getDatabaseConfigPage(String key)
Returns the URI of a database config page (in step 3) for a specified database key.

Parameters:
key - the database key (e.g. "mysql", "generic" or "oracle")
Returns:
the URI of a database config page

getDatabaseName

public String getDatabaseName(String databaseKey)
Returns the clear text name for a database server setup specified by a database key (e.g. "mysql", "generic" or "oracle").

Parameters:
databaseKey - a database key (e.g. "mysql", "generic" or "oracle")
Returns:
the clear text name for a database server setup

getDatabaseProperties

public Map getDatabaseProperties()
Returns a map with the database properties of *all* available database configurations keyed by their database keys (e.g. "mysql", "generic" or "oracle").

Returns:
a map with the database properties of *all* available database configurations

getDatabases

public List getDatabases()
Returns a list with they keys (e.g. "mysql", "generic" or "oracle") of all available database server setups found in "/setup/database/".

Returns:
a list with they keys (e.g. "mysql", "generic" or "oracle") of all available database server setups

getDb

public String getDb()
Returns the database name.

Returns:
the database name

getDbConStrParams

public String getDbConStrParams()
Returns the JDBC connect URL parameters.

Returns:
the JDBC connect URL parameters

getDbCreateConStr

public String getDbCreateConStr()
Returns the database create statement.

Returns:
the database create statement

getDbCreatePwd

public String getDbCreatePwd()
Returns the password used for database creation.

Returns:
the password used for database creation

getDbCreateUser

public String getDbCreateUser()
Returns the database user that is used to connect to the database.

Returns:
the database user

getDbDriver

public String getDbDriver()
Returns the database driver belonging to the database from the default configuration.

Returns:
name of the database driver

getDbProperty

public String getDbProperty(String key)
Returns the value for a given key from the database properties.

Parameters:
key - the property key
Returns:
the string value for a given key

getDbTestQuery

public String getDbTestQuery()
Returns the validation query belonging to the database from the default configuration .

Returns:
query used to validate connections

getDbWorkConStr

public String getDbWorkConStr()
Returns a connection string.

Returns:
the connection string used by the OpenCms core

getDbWorkPwd

public String getDbWorkPwd()
Returns the password of the database from the properties .

Returns:
the password for the OpenCms database user

getDbWorkUser

public String getDbWorkUser()
Returns the user of the database from the properties.

Returns:
the database user used by the opencms core

getDefaultContentEncoding

public String getDefaultContentEncoding()
Returns the default content encoding.

Returns:
String

getDefaultWebApplication

public String getDefaultWebApplication()
Returns the name of the default web application, configured in web.xml.

By default this is "ROOT".

Returns:
the name of the default web application, configured in web.xml

getErrors

public Vector getErrors()
Returns the error messages.

Returns:
a vector of error messages

getEthernetAddress

public String getEthernetAddress()
Returns the mac ethernet address.

Returns:
the mac ethernet addess

getHtmlHelpIcon

public String getHtmlHelpIcon(String id,
                              String pathPrefix)
Returns a help image icon tag to display a help text in the setup wizard.

Parameters:
id - the id of the desired help div
pathPrefix - the path prefix to the image
Returns:
the HTML part for the help icon or an empty String, if the part was not found

getHtmlPart

public String getHtmlPart(String part)
Returns the specified HTML part of the HTML property file to create the output.

Parameters:
part - the name of the desired part
Returns:
the HTML part or an empty String, if the part was not found

getHtmlPart

public String getHtmlPart(String part,
                          String replaceString)
Returns the specified HTML part of the HTML property file to create the output.

Parameters:
part - the name of the desired part
replaceString - String which is inserted in the found HTML part at the location of "$replace$"
Returns:
the HTML part or an empty String, if the part was not found

getModuleDependencies

public Map getModuleDependencies()
Returns a map with lists of dependent module package names keyed by module package names.

Returns:
a map with lists of dependent module package names keyed by module package names

getPool

public String getPool()
Gets the default pool.

Returns:
name of the default pool

getProperties

public ExtendedProperties getProperties()
Returns the extended properties.

Returns:
the extended properties

getReplacer

public Map getReplacer()
Returns the replacer.

Returns:
the replacer

getServerName

public String getServerName()
Return the OpenCms server name.

Returns:
the OpenCms server name

getServletMapping

public String getServletMapping()
Returns the OpenCms servlet mapping, configured in web.xml.

By default this is "/opencms/*".

Returns:
the OpenCms servlet mapping, configured in web.xml

getSetupLogName

public String getSetupLogName()
Returns the name of the setup log file.

Returns:
the name of the setup log file

getSortedDatabases

public List getSortedDatabases()
Returns a sorted list with they keys (e.g. "mysql", "generic" or "oracle") of all available database server setups found in "/setup/database/" sorted by their ranking property.

Returns:
a sorted list with they keys (e.g. "mysql", "generic" or "oracle") of all available database server setups

getWebAppRfsPath

public String getWebAppRfsPath()
Returns the absolute path to the OpenCms home directory.

Returns:
the path to the OpenCms home directory

getWizardEnabled

public boolean getWizardEnabled()
Checks if the setup wizard is enabled.

Returns:
true if the setup wizard is enables, false otherwise

getWorkplaceImportThread

public CmsSetupWorkplaceImportThread getWorkplaceImportThread()
Returns the workplace import thread.

Returns:
the workplace import thread

getWorkplaceSite

public String getWorkplaceSite()
Return the OpenCms workplace site.

Returns:
the OpenCms workplace site

importModulesFromSetupBean

public void importModulesFromSetupBean()
                                throws Exception
Installed all modules that have been set using setInstallModules(String).

This method is invoked as a shell command.

Throws:
Exception - if something goes wrong

init

public void init(PageContext pageContext)
Creates a new instance of the setup Bean from a JSP page.

Parameters:
pageContext - the JSP's page context

init

public void init(String webAppRfsPath,
                 String servletMapping,
                 String defaultWebApplication)
Creates a new instance of the setup Bean.

Parameters:
webAppRfsPath - path to the OpenCms web application
servletMapping - the OpenCms servlet mapping
defaultWebApplication - the name of the default web application

initHtmlParts

public void initHtmlParts()
This method reads the properties from the htmlmsg.property file and sets the HTML part properties with the matching values.


initShellCmsObject

public void initShellCmsObject(CmsObject cms,
                               CmsShell shell)
Description copied from interface: I_CmsShellCommands
Provides access to the shell CmsObject and the shell itself.

Specified by:
initShellCmsObject in interface I_CmsShellCommands
Parameters:
cms - the shell CmsObject
shell - the CmsShell
See Also:
I_CmsShellCommands.initShellCmsObject(org.opencms.file.CmsObject, org.opencms.main.CmsShell)

isChecked

public String isChecked(String value1,
                        String value2)
Over simplistic helper to compare two strings to check radio buttons.

Parameters:
value1 - the first value
value2 - the secound value
Returns:
"checked" if both values are equal, the empty String "" otherwise

isInitialized

public boolean isInitialized()
Returns true if this setup bean is correctly initialized.

Returns:
true if this setup bean is correctly initialized

loadProperties

public ExtendedProperties loadProperties(String file)
                                  throws IOException
Loads the default OpenCms properties.

Parameters:
file - the file tp read the properties from
Returns:
the initialized OpenCms properties
Throws:
IOException - in case of IO errors

lockWizard

public void lockWizard()
Locks (i.e. disables) the setup wizard.


prepareStep10

public void prepareStep10()
Prepares step 10 of the setup wizard.


prepareStep8

public boolean prepareStep8()
Prepares step 8 of the setup wizard.

Returns:
true if the workplace should be imported

prepareStep8b

public void prepareStep8b()
Prepares step 8b of the setup wizard.


prepareStep8bOutput

public void prepareStep8bOutput(JspWriter out)
                         throws IOException
Generates the output for step 8b of the setup wizard.

Parameters:
out - the JSP print stream
Throws:
IOException - in case errors occur while writing to "out"

saveProperties

public void saveProperties(ExtendedProperties properties,
                           String file,
                           boolean backup)
Saves properties to specified file.

Parameters:
properties - the properties to be saved
file - the file to save the properties to
backup - if true, create a backupfile

setDatabase

public void setDatabase(String databaseKey)
Sets the database drivers to the given value.

Parameters:
databaseKey - the key of the selected database server (e.g. "mysql", "generic" or "oracle")

setDb

public void setDb(String db)
Sets the database name.

Parameters:
db - the database name to set

setDbConStrParams

public void setDbConStrParams(String value)
Sets the JDBC connect URL parameters.

Parameters:
value - the JDBC connect URL parameters

setDbCreateConStr

public void setDbCreateConStr(String dbCreateConStr)
Sets the database create statement.

Parameters:
dbCreateConStr - the database create statement

setDbCreatePwd

public void setDbCreatePwd(String dbCreatePwd)
Sets the password used for the initial OpenCms database creation.

This password will not be stored permanently, but used only in the setup wizard.

Parameters:
dbCreatePwd - the password used for the initial OpenCms database creation

setDbCreateUser

public void setDbCreateUser(String dbCreateUser)
Set the database user that is used to connect to the database.

Parameters:
dbCreateUser - the user to set

setDbDriver

public void setDbDriver(String driver)
Sets the database driver belonging to the database.

Parameters:
driver - name of the opencms driver

setDbParamaters

public boolean setDbParamaters(HttpServletRequest request,
                               String provider)
Sets the needed database parameters.

Parameters:
request - the http request
provider - the db provider
Returns:
true if already submitted

setDbProperty

public void setDbProperty(String key,
                          String value)
This method sets the value for a given key in the database properties.

Parameters:
key - The key of the property
value - The value of the property

setDbWorkConStr

public void setDbWorkConStr(String dbWorkConStr)
Sets the connection string to the database to the given value.

Parameters:
dbWorkConStr - the connection string used by the OpenCms core

setDbWorkPwd

public void setDbWorkPwd(String dbWorkPwd)
Sets the password of the database to the given value.

Parameters:
dbWorkPwd - the password for the OpenCms database user

setDbWorkUser

public void setDbWorkUser(String dbWorkUser)
Sets the user of the database to the given value.

Parameters:
dbWorkUser - the database user used by the opencms core

setEthernetAddress

public void setEthernetAddress(String ethernetAddress)
Set the mac ethernet address, required for UUID generation.

Parameters:
ethernetAddress - the mac addess to set

setInstallModules

public void setInstallModules(String value)
Sets the list with the package names of the modules to be installed.

Parameters:
value - a string with the package names of the modules to be installed delimited by the pipe symbol "|"

setReplacer

public void setReplacer(Map map)
Sets the replacer.

Parameters:
map - the replacer to set

setServerName

public void setServerName(String name)
Sets the OpenCms server name.

Parameters:
name - the OpenCms server name

setWorkplaceSite

public void setWorkplaceSite(String newSite)
Sets the OpenCms workplace site.

Parameters:
newSite - the OpenCms workplace site

shellExit

public void shellExit()
Description copied from interface: I_CmsShellCommands
May be called after shell exit, can e.g. be used to ouput a goodbye message.

Please note: This method is not guaranteed to be called. For a shell that has more then one shell command object initialized, only the exit method of one of thouse will be called.

Specified by:
shellExit in interface I_CmsShellCommands
See Also:
I_CmsShellCommands.shellExit()

shellStart

public void shellStart()
Description copied from interface: I_CmsShellCommands
May be called before shell startup, can e.g. be used to ouput a welcome message.

Please note: This method is not guaranteed to be called. For a shell that has more then one shell command object initialized, only the start method of one of thouse will be called.

Specified by:
shellStart in interface I_CmsShellCommands
See Also:
I_CmsShellCommands.shellStart()

getExtProperty

protected String getExtProperty(String key)
Returns the value for a given key from the extended properties.

Parameters:
key - the property key
Returns:
the string value for a given key

importModuleFromDefault

protected void importModuleFromDefault(String importFile)
                                throws Exception
Imports a module (zipfile) from the default module directory, creating a temporary project for this.

Parameters:
importFile - the name of the import module located in the default module directory
Throws:
Exception - if something goes wrong
See Also:
CmsImportExportManager.importData(CmsObject, String, String, org.opencms.report.I_CmsReport)

readDatabaseConfig

protected void readDatabaseConfig()
Stores the properties of all available database configurations in a map keyed by their database key names (e.g. "mysql", "generic" or "oracle").


setExtProperty

protected void setExtProperty(String key,
                              String value)
This method sets the value for a given key in the extended properties.

Parameters:
key - The key of the property
value - The value of the property