org.opencms.main
Class CmsShell

java.lang.Object
  extended by org.opencms.main.CmsShell

public class CmsShell
extends java.lang.Object

A command line interface to access OpenCms functions which is used for the initial setup and also can be used to directly access the OpenCms repository without the Workplace.

The CmsShell has direct access to all methods in the "command objects". Currently the following classes are used as command objects: CmsShellCommands, CmsRequestContext and CmsObject.

Only public methods in the command objects that use supported data types as parameters can be called from the shell. Supported data types are: String, CmsUUID, boolean, int, long, double, float.

If a method name is ambiguous, i.e. the method name with the same number of parameter exist in more then one of the command objects, the method is only executed on the first matching method object.

Since:
6.0.0
Version:
$Revision: 1.58 $
Author:
Alexander Kandzior
See Also:
CmsShellCommands, CmsRequestContext, CmsObject

Field Summary
protected  CmsObject m_cms
          The OpenCms context object.
static java.lang.String SHELL_PARAM_BASE
          Prefix for "base" parameter.
static java.lang.String SHELL_PARAM_DEFAULT_WEB_APP
          Prefix for "servletMapping" parameter.
static java.lang.String SHELL_PARAM_SCRIPT
          Prefix for "script" parameter.
static java.lang.String SHELL_PARAM_SERVLET_MAPPING
          Prefix for "servletMapping" parameter.
 
Constructor Summary
CmsShell(java.lang.String webInfPath, java.lang.String servletMapping, java.lang.String defaultWebAppName, java.lang.String prompt, I_CmsShellCommands additionalShellCommands)
          Creates a new CmsShell.
 
Method Summary
 void exit()
          Exits this shell and destroys the OpenCms instance.
 java.util.Locale getLocale()
          Private internal helper for localization to the current user's locale within OpenCms.
 CmsMessages getMessages()
          Returns the localized messages object for the current user.
 CmsUserSettings getSettings()
          Obtain the additional settings related to the current user.
protected  void help(java.lang.String searchString)
          Shows the signature of all methods containing the given search String.
protected  CmsUserSettings initSettings()
          Initializes the internal CmsWorkplaceSettings that contain (amongst other information) important information additional information about the current user (an instance of CmsUserSettings).
static void main(java.lang.String[] args)
          Main program entry point when started via the command line.
 void printPrompt()
          Prints the shell prompt.
protected  void setEcho(boolean echo)
          Sets the echo status.
 void setLocale(java.util.Locale locale)
          Sets the locale of the current user.
protected  void setPrompt(java.lang.String prompt)
          Sets the current shell prompt.
 void start(java.io.FileInputStream fileInputStream)
          Starts this CmsShell.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHELL_PARAM_BASE

public static final java.lang.String SHELL_PARAM_BASE
Prefix for "base" parameter.

See Also:
Constant Field Values

SHELL_PARAM_DEFAULT_WEB_APP

public static final java.lang.String SHELL_PARAM_DEFAULT_WEB_APP
Prefix for "servletMapping" parameter.

See Also:
Constant Field Values

SHELL_PARAM_SCRIPT

public static final java.lang.String SHELL_PARAM_SCRIPT
Prefix for "script" parameter.

See Also:
Constant Field Values

SHELL_PARAM_SERVLET_MAPPING

public static final java.lang.String SHELL_PARAM_SERVLET_MAPPING
Prefix for "servletMapping" parameter.

See Also:
Constant Field Values

m_cms

protected CmsObject m_cms
The OpenCms context object.

Constructor Detail

CmsShell

public CmsShell(java.lang.String webInfPath,
                java.lang.String servletMapping,
                java.lang.String defaultWebAppName,
                java.lang.String prompt,
                I_CmsShellCommands additionalShellCommands)
Creates a new CmsShell.

Parameters:
webInfPath - the path to the 'WEB-INF' folder of the OpenCms installation
servletMapping - the mapping of the servlet (or null to use the default "/opencms/*")
defaultWebAppName - the name of the default web application (or null to use the default "ROOT")
prompt - the prompt format to set
additionalShellCommands - optional object for additional shell commands, or null
Method Detail

main

public static void main(java.lang.String[] args)
Main program entry point when started via the command line.

Parameters:
args - parameters passed to the application via the command line

exit

public void exit()
Exits this shell and destroys the OpenCms instance.


getLocale

public java.util.Locale getLocale()
Private internal helper for localization to the current user's locale within OpenCms.

Returns:
the current user's Locale.

getMessages

public CmsMessages getMessages()
Returns the localized messages object for the current user.

Returns:
the localized messages object for the current user

getSettings

public CmsUserSettings getSettings()
Obtain the additional settings related to the current user.

Returns:
the additional settings related to the current user.

printPrompt

public void printPrompt()
Prints the shell prompt.


setLocale

public void setLocale(java.util.Locale locale)
               throws CmsException
Sets the locale of the current user.

Parameters:
locale - the locale to set
Throws:
CmsException - in case the locale of the current user can not be stored

start

public void start(java.io.FileInputStream fileInputStream)
Starts this CmsShell.

Parameters:
fileInputStream - a (file) input stream from which commands are read

help

protected void help(java.lang.String searchString)
Shows the signature of all methods containing the given search String.

Parameters:
searchString - the String to search for in the methods, if null all methods are shown

initSettings

protected CmsUserSettings initSettings()
Initializes the internal CmsWorkplaceSettings that contain (amongst other information) important information additional information about the current user (an instance of CmsUserSettings).

This step is performed within the CmsShell constructor directly after switching to run-level 2 and obtaining the CmsObject for the guest user as well as when invoking the CmsShell command login.

Returns:
the user settings for the current user.

setEcho

protected void setEcho(boolean echo)
Sets the echo status.

Parameters:
echo - the echo status to set

setPrompt

protected void setPrompt(java.lang.String prompt)
Sets the current shell prompt.

To set the prompt, the following variables are available:

$u the current user name
$s the current site root
$p the current project name

Parameters:
prompt - the prompt to set