/** * Prints the OpenCms copyright information.<p> */ public void copyright() { String[] copy = Messages.COPYRIGHT_BY_ALKACON; for (int i = 0; i < copy.length; i++) { m_shell.getOut().println(copy[i]); } }
/** * Returns the Locales available on the system ready to use on Method * {@link #setLocale(String)} from the <code>{@link CmsShell}</code>. <p> * * Note that the full name containing language, country and optional variant seperated * by underscores is returned always but the latter two parts may be left out. <p> */ public void getLocales() { m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_LOCALES_AVAILABLE_0)); Locale[] locales = Locale.getAvailableLocales(); for (int i = locales.length - 1; i >= 0; i--) { m_shell.getOut().println(" \"" + locales[i].toString() + "\""); } }
/** * Provides help information for the CmsShell.<p> */ public void help() { m_shell.getOut().println(); m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_HELP1_0)); m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_HELP2_0)); m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_HELP3_0)); m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_HELP4_0)); m_shell.getOut().println(); }
/** * Displays a list of all currently installed modules.<p> * * @throws Exception if something goes wrong */ public void listModules() throws Exception { Set<String> modules = OpenCms.getModuleManager().getModuleNames(); m_shell.getOut().println( "\n" + getMessages().key(Messages.GUI_SHELL_LIST_MODULES_1, new Integer(modules.size()))); Iterator<String> i = modules.iterator(); while (i.hasNext()) { String moduleName = i.next(); m_shell.getOut().println(moduleName); } m_shell.getOut().println(); }
/** * @see org.opencms.main.I_CmsShellCommands#shellStart() */ public void shellStart() { m_shell.getOut().println(); m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_WELCOME_0)); m_shell.getOut().println(); // print the version information version(); // print the copyright message copyright(); if (m_shell.isInteractive()) { // print the help information for interactive terminals help(); } }
/** * Displays a list of all resources in the current folder.<p> * * @throws Exception if something goes wrong * @see CmsObject#getResourcesInFolder(String, CmsResourceFilter) */ public void ls() throws Exception { String folder = CmsResource.getFolderPath(m_cms.getRequestContext().getUri()); List<CmsResource> resources = m_cms.getResourcesInFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION); m_shell.getOut().println( "\n" + getMessages().key(Messages.GUI_SHELL_LS_2, folder, new Integer(resources.size()))); Iterator<CmsResource> i = resources.iterator(); while (i.hasNext()) { CmsResource r = i.next(); m_shell.getOut().println(m_cms.getSitePath(r)); } m_shell.getOut().println(); }
/** * Turns the echo status for the shell on or off.<p> * * @param echo if "on", echo is turned on, otherwise echo is turned off */ public void echo(String echo) { if (echo == null) { return; } boolean b = "on".equalsIgnoreCase(echo.trim()); m_shell.setEcho(b); if (b) { m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_ECHO_ON_0)); } else { m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_ECHO_OFF_0)); } }
m_shell.getOut().println("#Resources:\t" + resourceCount); long start, time; long totalTime = 0; long minTime = Long.MAX_VALUE; long maxTime = Long.MIN_VALUE; m_shell.getOut().print("readFileHeader:\t"); for (int i = maxTests; i > 0; --i) { int index = random.nextInt(resourceCount); m_shell.getOut().print('.'); m_shell.getOut().println( "\nreadFileHeader:\t" + minTime + "\t" + maxTime + "\t" + (((float)totalTime) / maxTests) + " ms");
/** * Creates a new user.<p> * * @param name the name for the new user * @param password the password for the new user * @param description the description for the new user * * @throws Exception if something goes wrong * @see CmsObject#createUser(String, String, String, java.util.Map) * @return the created user */ public CmsUser createUser(String name, String password, String description) throws Exception { if (existsUser(name)) { m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_USER_ALREADY_EXISTS_1, name)); return null; } return m_cms.createUser(name, password, description, new Hashtable<String, Object>()); }
/** * Displays the access control list of a given resource.<p> * * @param resourceName the name of the resource * * @throws Exception if something goes wrong * * @see CmsObject#getAccessControlList(String) */ public void getAcl(String resourceName) throws Exception { CmsAccessControlList acList = m_cms.getAccessControlList(resourceName); Iterator<CmsUUID> principals = acList.getPrincipals().iterator(); while (principals.hasNext()) { I_CmsPrincipal p = m_cms.lookupPrincipal(principals.next()); m_shell.getOut().println(p.getName() + ": " + acList.getPermissions(p.getId()).getPermissionString()); } }
/** * Lists the access control entries of a given resource.<p> * * @param resourceName the name of the resource * @throws Exception if something goes wrong */ public void lsacc(String resourceName) throws Exception { List<CmsAccessControlEntry> acList = m_cms.getAccessControlEntries(resourceName); for (int i = 0; i < acList.size(); i++) { CmsAccessControlEntry ace = acList.get(i); I_CmsPrincipal acePrincipal = m_cms.lookupPrincipal(ace.getPrincipal()); String pName = (acePrincipal != null) ? acePrincipal.getName() : ace.getPrincipal().toString(); m_shell.getOut().println(pName + ": " + ace.getPermissions().getPermissionString() + " " + ace); } }
/** * Creates a new folder in the given target folder.<p> * * @param targetFolder the target folder * @param folderName the new folder to create in the target folder * @return the created folder * @throws Exception if somthing goes wrong */ public CmsResource createFolder(String targetFolder, String folderName) throws Exception { if (m_cms.existsResource(targetFolder + folderName)) { m_shell.getOut().println( getMessages().key(Messages.GUI_SHELL_FOLDER_ALREADY_EXISTS_1, targetFolder + folderName)); return null; } return m_cms.createResource(targetFolder + folderName, CmsResourceTypeFolder.getStaticTypeId()); }
/** * 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)); } }
/** * Set the locale of the current user logged in. <p> * * This method will always set a valid Locale for the current user! * If the provided locale name is not valid (i.e. leads to an Exception * when trying to create the Locale, then the configured default Locale is set.<p> * * The full name must consist of language code, * country code(optional), variant(optional) separated by "_".<p> * * @see Locale#getLanguage() * @see Locale#getCountry() * @see Locale#getVariant() * @param localeName the full locale name * * @throws CmsException if something goes wrong * */ public void setLocale(String localeName) throws CmsException { Locale locale = CmsLocaleManager.getLocale(localeName); m_shell.getOut().println( getMessages().key( Messages.GUI_SHELL_SETLOCALE_2, locale, m_cms.getRequestContext().getCurrentUser().getName())); m_shell.setLocale(locale); m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_SETLOCALE_POST_1, locale)); }
/** * Changes the current folder (i.e. the URI in the VFS).<p> * * @param target the new URI * @throws Exception if something goes wrong * @see org.opencms.file.CmsRequestContext#setUri(String) */ public void cd(String target) throws Exception { String folder = CmsResource.getFolderPath(m_cms.getRequestContext().getUri()); if (!target.endsWith("/")) { target += "/"; } String resolvedTarget = CmsLinkManager.getAbsoluteUri(target, folder); CmsResource res = m_cms.readResource(resolvedTarget); if (!res.isFolder()) { throw new CmsIllegalArgumentException( Messages.get().container(Messages.ERR_NOT_A_FOLDER_1, resolvedTarget)); } m_cms.getRequestContext().setUri(resolvedTarget); m_shell.getOut().println( '\n' + getMessages().key(Messages.GUI_SHELL_CURRENT_FOLDER_1, new Object[] {resolvedTarget})); m_shell.getOut().println(); }
/** * Lists the access control entries belonging to the given principal.<p> * * @param resourceName the name of the resource * @param principalName the name of the principal * @throws Exception if something goes wrong */ public void lsacc(String resourceName, String principalName) throws Exception { I_CmsPrincipal principal = m_cms.lookupPrincipal(principalName); List<CmsAccessControlEntry> acList = m_cms.getAccessControlEntries(resourceName); for (int i = 0; i < acList.size(); i++) { CmsAccessControlEntry ace = acList.get(i); I_CmsPrincipal acePrincipal = m_cms.lookupPrincipal(ace.getPrincipal()); if (principal.equals(acePrincipal)) { String pName = (acePrincipal != null) ? acePrincipal.getName() : ace.getPrincipal().toString(); m_shell.getOut().println(pName + ": " + ace.getPermissions().getPermissionString() + " " + ace); } } }
m_shell.getOut().println(getMessages().key(Messages.GUI_SHELL_USER_ALREADY_EXISTS_1, name)); return null;