/** * Exits the shell.<p> */ public void exit() { m_shell.exit(); }
/** * Reads the given stream and executes the commands in this shell.<p> * * @param inputStream an input stream from which commands are read * @deprecated use {@link #execute(InputStream)} instead */ @Deprecated public void start(FileInputStream inputStream) { // in the old behavior 'interactive' was always true setInteractive(true); execute(inputStream); }
/** * Creates a new CmsShell.<p> * * @param cms the user context to run the shell from * @param prompt the prompt format to set * @param additionalShellCommands optional object for additional shell commands, or null * @param out stream to write the regular output messages to * @param err stream to write the error messages output to */ public CmsShell( CmsObject cms, String prompt, I_CmsShellCommands additionalShellCommands, PrintStream out, PrintStream err) { setPrompt(prompt); try { // has to be initialized already if this constructor is used m_opencms = null; Locale locale = getLocale(); m_messages = Messages.get().getBundle(locale); m_cms = cms; // initialize the shell initShell(additionalShellCommands, out, err); } catch (Throwable t) { t.printStackTrace(m_err); } }
/** * Checks whether the selected user and password are valid and the user has the ROOT_ADMIN role.<p> * * @return <code>true</code> if the selected user and password are valid and the user has the ROOT_ADMIN role */ public boolean isValidUser() { CmsShell shell = new CmsShell( getWebAppRfsPath() + "WEB-INF" + File.separator, getServletMapping(), getDefaultWebApplication(), "${user}@${project}>", null); boolean validUser = shell.validateUser(getAdminUser(), getAdminPwd(), CmsRole.ROOT_ADMIN); shell.exit(); return validUser; }
boolean interactive) { setPrompt(prompt); setInteractive(interactive); if (CmsStringUtil.isEmpty(servletMapping)) { servletMapping = "/opencms/*"; Locale locale = getLocale(); m_messages = Messages.get().getBundle(locale); initShell(additionalShellCommands, out, err); } catch (Throwable t) { t.printStackTrace(err);
I_CmsShellCommands additionalShellCommands) { setPrompt(prompt); if (CmsStringUtil.isEmpty(servletMapping)) { servletMapping = "/opencms/*"; Locale locale = getLocale(); m_messages = Messages.get().getBundle(locale); m_settings = initSettings();
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(fileInputStream)); while (!m_exitCalled) { printPrompt(); String line = lnr.readLine(); if (line == null) { executeCommand(command, parameters);
/** * Private internal helper for localization to the current user's locale * within OpenCms. <p> * * @return the current user's <code>Locale</code>. */ public Locale getLocale() { if (getSettings() == null) { return CmsLocaleManager.getDefaultLocale(); } return getSettings().getLocale(); }
/** * Log a user in to the the CmsSell.<p> * * @param username the name of the user to log in * @param password the password of the user */ public void login(String username, String password) { username = OpenCms.getImportExportManager().translateUser(username); try { m_cms.loginUser(username, password); // reset the settings, this will switch the startup site root etc. m_shell.initSettings(); m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_LOGIN_1, whoami().getName())); // output the login message if required CmsLoginMessage message = OpenCms.getLoginManager().getLoginMessage(); if ((message != null) && (message.isActive())) { m_shell.getOut().println(message.getMessage()); } } catch (Exception exc) { m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_LOGIN_FAILED_0)); } }
/** * Returns the localized messages object for the current user.<p> * * @return the localized messages object for the current user */ protected CmsMessages getMessages() { return m_shell.getMessages(); }
/** * Executes the commands from the given string in this shell.<p> * * <ul> * <li>Commands in the must be separated with a line break '\n'. * <li>Only one command per line is allowed. * <li>String parameters must be quoted like this: <code>'string value'</code>. * </ul> * * @param commands the string from which the commands are read */ public void execute(String commands) { execute(new StringReader(commands)); }
m_settings = initSettings();
System.out.println(Messages.get().getBundle(getLocale()).key( Messages.GUI_SHELL_EXEC_METHOD_1, new Object[] {foundMethod.getName()})); ite.getTargetException().printStackTrace(System.out); } catch (Throwable t) { System.out.println(Messages.get().getBundle(getLocale()).key( Messages.GUI_SHELL_EXEC_METHOD_1, new Object[] {foundMethod.getName()}));
if (m_interactive || m_echo) { printPrompt(); executeCommand(command, arguments);
/** * Private internal helper for localization to the current user's locale * within OpenCms. <p> * * @return the current user's <code>Locale</code>. */ public Locale getLocale() { if (getSettings() == null) { return CmsLocaleManager.getDefaultLocale(); } return getSettings().getLocale(); }
/** * Returns the localized messages object for the current user.<p> * * @return the localized messages object for the current user */ protected CmsMessages getMessages() { return m_shell.getMessages(); } }