📄 cmsshellcommands.java
字号:
/**
* Exits the shell.<p>
*/
public void exit() {
m_shell.exit();
}
/**
* Exports all resources from the current site root to a ZIP file.<p>
*
* @param exportFile the name (absolute path) of the ZIP file to export to
* @throws Exception if something goes wrong
*/
public void exportAllResources(String exportFile) throws Exception {
List exportPaths = new ArrayList(1);
exportPaths.add("/");
CmsVfsImportExportHandler vfsExportHandler = new CmsVfsImportExportHandler();
vfsExportHandler.setFileName(exportFile);
vfsExportHandler.setExportPaths(exportPaths);
vfsExportHandler.setIncludeSystem(true);
vfsExportHandler.setIncludeUnchanged(true);
vfsExportHandler.setExportUserdata(false);
OpenCms.getImportExportManager().exportData(
m_cms,
vfsExportHandler,
new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
/**
* Exports the module with the given name to the default location.<p>
*
* @param moduleName the name of the module to export
*
* @throws Exception if something goes wrong
*/
public void exportModule(String moduleName) throws Exception {
CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
if (module == null) {
throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_MODULE_1, moduleName));
}
String filename = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
OpenCms.getSystemInfo().getPackagesRfsPath()
+ CmsSystemInfo.FOLDER_MODULES
+ moduleName
+ "_"
+ OpenCms.getModuleManager().getModule(moduleName).getVersion().toString());
String[] resources = new String[module.getResources().size()];
System.arraycopy(module.getResources().toArray(), 0, resources, 0, resources.length);
// generate a module export handler
CmsModuleImportExportHandler moduleExportHandler = new CmsModuleImportExportHandler();
moduleExportHandler.setFileName(filename);
moduleExportHandler.setAdditionalResources(resources);
moduleExportHandler.setModuleName(module.getName().replace('\\', '/'));
moduleExportHandler.setDescription(getMessages().key(
Messages.GUI_SHELL_IMPORTEXPORT_MODULE_HANDLER_NAME_1,
new Object[] {moduleExportHandler.getModuleName()}));
// export the module
OpenCms.getImportExportManager().exportData(
m_cms,
moduleExportHandler,
new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
/**
* Exports a list of resources from the current site root to a ZIP file.<p>
*
* The resource names in the list must be separated with a ";".<p>
*
* @param exportFile the name (absolute path) of the ZIP file to export to
* @param pathList the list of resource to export, separated with a ";"
* @throws Exception if something goes wrong
*/
public void exportResources(String exportFile, String pathList) throws Exception {
StringTokenizer tok = new StringTokenizer(pathList, ";");
List exportPaths = new ArrayList();
while (tok.hasMoreTokens()) {
exportPaths.add(tok.nextToken());
}
boolean includeSystem = false;
if (pathList.startsWith(CmsWorkplace.VFS_PATH_SYSTEM)
|| (pathList.indexOf(";" + CmsWorkplace.VFS_PATH_SYSTEM) > -1)) {
includeSystem = true;
}
CmsVfsImportExportHandler vfsExportHandler = new CmsVfsImportExportHandler();
vfsExportHandler.setFileName(exportFile);
vfsExportHandler.setExportPaths(exportPaths);
vfsExportHandler.setIncludeSystem(includeSystem);
vfsExportHandler.setIncludeUnchanged(true);
vfsExportHandler.setExportUserdata(false);
OpenCms.getImportExportManager().exportData(
m_cms,
vfsExportHandler,
new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
/**
* Exports a list of resources from the current site root and the user data to a ZIP file.<p>
*
* The resource names in the list must be separated with a ";".<p>
*
* @param exportFile the name (absolute path) of the ZIP file to export to
* @param pathList the list of resource to export, separated with a ";"
* @throws Exception if something goes wrong
*/
public void exportResourcesAndUserdata(String exportFile, String pathList) throws Exception {
StringTokenizer tok = new StringTokenizer(pathList, ";");
List exportPaths = new ArrayList();
while (tok.hasMoreTokens()) {
exportPaths.add(tok.nextToken());
}
boolean includeSystem = false;
if (pathList.startsWith(CmsWorkplace.VFS_PATH_SYSTEM)
|| (pathList.indexOf(";" + CmsWorkplace.VFS_PATH_SYSTEM) > -1)) {
includeSystem = true;
}
CmsVfsImportExportHandler vfsExportHandler = new CmsVfsImportExportHandler();
vfsExportHandler.setFileName(exportFile);
vfsExportHandler.setExportPaths(exportPaths);
vfsExportHandler.setIncludeSystem(includeSystem);
vfsExportHandler.setIncludeUnchanged(true);
vfsExportHandler.setExportUserdata(true);
OpenCms.getImportExportManager().exportData(
m_cms,
vfsExportHandler,
new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
/**
* 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 principals = acList.getPrincipals().iterator();
while (principals.hasNext()) {
I_CmsPrincipal p = m_cms.lookupPrincipal((CmsUUID)principals.next());
System.out.println(p.getName() + ": " + acList.getPermissions(p).getPermissionString());
}
}
/**
* Returns the Locales available on the system ready to use on Method
* {@link #setLocale(String)} from the <code>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() {
System.out.println(getMessages().key(Messages.GUI_SHELL_LOCALES_AVAILABLE_0));
Locale[] locales = Locale.getAvailableLocales();
for (int i = locales.length - 1; i >= 0; i--) {
System.out.println(" \"" + locales[i].toString() + "\"");
}
}
/**
* Provides help information for the CmsShell.<p>
*/
public void help() {
System.out.println();
System.out.println(getMessages().key(Messages.GUI_SHELL_HELP1_0));
System.out.println(getMessages().key(Messages.GUI_SHELL_HELP2_0));
System.out.println(getMessages().key(Messages.GUI_SHELL_HELP3_0));
System.out.println(getMessages().key(Messages.GUI_SHELL_HELP4_0));
System.out.println();
}
/**
* Executes the given help command.<p>
*
* @param command the help command to execute
*/
public void help(String command) {
if ("*".equalsIgnoreCase(command)) {
m_shell.help(null);
} else if ("help".equalsIgnoreCase(command)) {
help();
} else {
m_shell.help(command);
}
}
/**
* Imports a module.<p>
*
* @param importFile the absolute path of the import module file
* @throws Exception if something goes wrong
* @see org.opencms.importexport.CmsImportExportManager#importData(CmsObject, String, String, org.opencms.report.I_CmsReport)
*/
public void importModule(String importFile) throws Exception {
OpenCms.getImportExportManager().importData(
m_cms,
importFile,
null,
new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
/**
* Imports a module (zipfile) from the default module directory,
* creating a temporary project for this.<p>
*
* @param importFile the name of the import module located in the default module directory
* @throws Exception if something goes wrong
* @see org.opencms.importexport.CmsImportExportManager#importData(CmsObject, String, String, org.opencms.report.I_CmsReport)
*/
public void importModuleFromDefault(String importFile) throws Exception {
String exportPath = OpenCms.getSystemInfo().getPackagesRfsPath();
String fileName = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
exportPath + CmsSystemInfo.FOLDER_MODULES + importFile);
OpenCms.getImportExportManager().importData(
m_cms,
fileName,
null,
new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
/**
* Exists so that the setup script can run without the wizard, does nothing.<p>
*/
public void importModulesFromSetupBean() {
// noop, exists so that the setup script can run without the wizard
}
/**
* Imports a resource into the Cms.<p>
*
* @param importFile the name (absolute Path) of the import resource (zip or folder)
* @param importPath the name (absolute Path) of folder in which should be imported
* @throws Exception if something goes wrong
*/
public void importResources(String importFile, String importPath) throws Exception {
OpenCms.getImportExportManager().importData(
m_cms,
OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(importFile),
importPath,
new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
/**
* Imports a folder or a ZIP file to the root folder of the
* current site, creating a temporary project for this.<p>
*
* @param importFile the absolute path of the import resource
* @throws Exception if something goes wrong
*/
public void importResourcesWithTempProject(String importFile) throws Exception {
CmsProject project = m_cms.createProject(
"SystemUpdate",
getMessages().key(Messages.GUI_SHELL_IMPORT_TEMP_PROJECT_NAME_0),
OpenCms.getDefaultUsers().getGroupAdministrators(),
OpenCms.getDefaultUsers().getGroupAdministrators(),
CmsProject.PROJECT_TYPE_TEMPORARY);
int id = project.getId();
m_cms.getRequestContext().setCurrentProject(project);
m_cms.copyResourceToProject("/");
OpenCms.getImportExportManager().importData(
m_cms,
importFile,
"/",
new CmsShellReport(m_cms.getRequestContext().getLocale()));
m_cms.unlockProject(id);
m_cms.publishProject();
}
/**
* @see org.opencms.main.I_CmsShellCommands#initShellCmsObject(org.opencms.file.CmsObject, org.opencms.main.CmsShell)
*/
public void initShellCmsObject(CmsObject cms, CmsShell shell) {
m_cms = cms;
m_shell = shell;
}
/**
* Displays a list of all currently installed modules.<p>
*
* @throws Exception if something goes wrong
*/
public void listModules() throws Exception {
Set modules = OpenCms.getModuleManager().getModuleNames();
System.out.println("\n" + getMessages().key(Messages.GUI_SHELL_LIST_MODULES_1, new Integer(modules.size())));
Iterator i = modules.iterator();
while (i.hasNext()) {
String moduleName = (String)i.next();
System.out.println(moduleName);
}
System.out.println();
}
/**
* 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();
System.out.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())) {
System.out.println(message.getMessage());
}
} catch (Exception exc) {
System.out.println(getMessages().key(Messages.GUI_SHELL_LOGIN_FAILED_0));
}
}
/**
* 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 resources = m_cms.getResourcesInFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION);
System.out.println("\n" + getMessages().key(Messages.GUI_SHELL_LS_2, folder, new Integer(resources.size())));
Iterator i = resources.iterator();
while (i.hasNext()) {
CmsResource r = (CmsResource)i.next();
System.out.println(m_cms.getSitePath(r));
}
System.out.println();
}
/**
* 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 acList = m_cms.getAccessControlEntries(resourceName);
for (int i = 0; i < acList.size(); i++) {
CmsAccessControlEntry ace = (CmsAccessControlEntry)acList.get(i);
I_CmsPrincipal acePrincipal = m_cms.lookupPrincipal(ace.getPrincipal());
if (true) {
String pName = (acePrincipal != null) ? acePrincipal.getName() : ace.getPrincipal().toString();
System.out.println(pName + ": " + ace.getPermissions().getPermissionString() + " " + ace);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -