📄 cmsshellcommands.java
字号:
I_CmsRegistry reg = m_cms.getRegistry();
Hashtable res = reg.getSystemValues(sysKey);
Enumeration keys = res.keys();
while(keys.hasMoreElements()) {
Object key = keys.nextElement();
System.out.println(key + "->" + res.get(key));
}
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Get a parameter value for a task.
*
* @param taskid the id of the task.
* @param parname the name of the parameter.
*/
public void getTaskPar(String taskid, String parname) {
try {
System.out.println(m_cms.getTaskPar(Integer.parseInt(taskid), parname));
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Get the template task id fo a given taskname.
*
* @param taskname the name of the task.
*/
public void getTaskType(String taskname) {
try {
System.out.println(m_cms.getTaskType(taskname));
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Returns all users of the cms.
*/
public void getUsers() {
try {
Vector users = m_cms.getUsers();
for(int i = 0;i < users.size();i++) {
System.out.println((CmsUser)users.elementAt(i));
}
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Returns all users of the given type in the Cms.
*
* @param type the type of the users.
*/
public void getUsers(String type) {
try {
Vector users = m_cms.getUsers(Integer.parseInt(type));
for(int i = 0;i < users.size();i++) {
System.out.println((CmsUser)users.elementAt(i));
}
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Returns all groups of a user.
*
* @param groupname The name of the group.
*/
public void getUsersOfGroup(String groupname) {
try {
Vector users = m_cms.getUsersOfGroup(groupname);
for(int i = 0;i < users.size();i++) {
System.out.println((CmsUser)users.elementAt(i));
}
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Returns all groups of a user.
*
* @param groupname The name of the group.
*/
public void getUsersByLastname(String Lastname, String userType,
String userStatus, String wasLoggedIn,
String nMax) {
int iUserType =0;
int iUserStatus =0;
int iWasLoggedIn =0;
int iNMax =0;
if(userType.equalsIgnoreCase("webuser")) {
iUserType = C_USER_TYPE_WEBUSER;
} else if(userType.equalsIgnoreCase("systemuser")) {
iUserType = C_USER_TYPE_SYSTEMUSER;
} else {
System.out.println("second parameter has to be a \"webuser\" or"
+ " \"systemuser\"!");
return;
}
if(userStatus.equalsIgnoreCase("enabled")) {
iUserStatus = C_FLAG_ENABLED;
} else if(userStatus.equalsIgnoreCase("disabled")) {
iUserStatus = C_FLAG_DISABLED;
} else {
System.out.println("third parameter has to be a \"enabled\" or"
+ " \"disabled\"!");
return;
}
if(wasLoggedIn.equalsIgnoreCase("never")) {
iWasLoggedIn = C_NEVER;
} else if(wasLoggedIn.equalsIgnoreCase("once")) {
iWasLoggedIn = C_AT_LEAST_ONCE;
} else if (wasLoggedIn.equalsIgnoreCase("whatever")) {
iWasLoggedIn = C_WHATEVER;
} else {
System.out.println("fourth parameter has to be a \"never\","
+ " \"once\" or \"whatever\"!");
return;
}
try {
iNMax = Integer.parseInt(nMax);
} catch (NumberFormatException e) {
System.out.println("last parameter has to be a number!");
return;
}
try {
Vector users = m_cms.getUsersByLastname(Lastname, iUserType,
iUserStatus, iWasLoggedIn, iNMax);
for(int i = 0;i < users.size();i++) {
System.out.println((CmsUser)users.elementAt(i));
}
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Imports a module into the cms.
*
* @param moduleZip The file-name of module to import.
*/
public void getViews() {
try {
I_CmsRegistry reg = m_cms.getRegistry();
java.util.Vector views = new java.util.Vector();
java.util.Vector urls = new java.util.Vector();
int max = reg.getViews(views, urls);
for(int i = 0;i < max;i++) {
System.out.println(views.elementAt(i) + " -> " + urls.elementAt(i));
}
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Prints all possible commands.
*/
public void help() {
Method meth[] = getClass().getMethods();
for(int z = 0;z < meth.length;z++) {
if((meth[z].getDeclaringClass() == getClass()) && (meth[z].getModifiers() == Modifier.PUBLIC)) {
CmsShell.printMethod(meth[z]);
}
}
}
/**
* Prints signature of all possible commands containing a certain string.<br>
* May also be used to print signature of a specific command by giving full command name.
*
* @param String The String to search for in the commands
*/
public void help(String searchString) {
if(searchString.equals("help")) {
printHelpText();
}
else {
Method meth[] = getClass().getMethods();
for(int z = 0;z < meth.length;z++) {
if((meth[z].getDeclaringClass() == getClass()) && (meth[z].getModifiers() == Modifier.PUBLIC)
&& (meth[z].getName().toLowerCase().indexOf(searchString.toLowerCase()) > -1)) {
CmsShell.printMethod(meth[z]);
}
}
}
}
/**
* Reads a given file from the local harddisk and uploads
* it to the OpenCms system.
* Used in the OpenCms console only.
*
* @author Alexander Lucas
* @param filename Local file to be uploaded.
* @return Byte array containing the file content.
* @throws CmsException
*/
private byte[] importFile(String filename) throws CmsException {
File file = null;
long len = 0;
FileInputStream importInput = null;
byte[] result;
// First try to load the file
try {
file = new File(filename);
}
catch(Exception e) {
file = null;
}
if(file == null) {
throw new CmsException("Could not load local file " + filename, CmsException.C_NOT_FOUND);
}
// File was loaded successfully.
// Now try to read the content.
try {
len = file.length();
result = new byte[(int)len];
importInput = new FileInputStream(file);
importInput.read(result);
importInput.close();
}
catch(Exception e) {
throw new CmsException(e.toString(), CmsException.C_UNKNOWN_EXCEPTION);
}
return result;
}
/**
* Imports a import-resource (folder or zipfile) to the cms.
*
* @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
*/
public void importFolder(String importFile, String importPath) {
// import the resources
try {
m_cms.importFolder(importFile, importPath);
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Checks for conflicting file names for a import.
*
* @param moduleZip The file-name of module to import.
*/
public void importGetConflictingFileNames(String moduleZip) {
try {
I_CmsRegistry reg = m_cms.getRegistry();
Vector conflicts = reg.importGetConflictingFileNames(moduleZip);
System.out.println("Conflicts: " + conflicts.size());
for(int i = 0;i < conflicts.size();i++) {
System.out.println(conflicts.elementAt(i));
}
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Checks for resources that should be copied to the import-project.
*
* @param moduleZip The file-name of module to import.
*/
public void importGetResourcesForProject(String moduleZip) {
try {
I_CmsRegistry reg = m_cms.getRegistry();
Vector resources = reg.importGetResourcesForProject(moduleZip);
System.out.println("Resources: " + resources.size());
for(int i = 0;i < resources.size();i++) {
System.out.println(resources.elementAt(i));
}
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Imports a module (zipfile) to the cms.
*
* @param importFile the name (complete Path) of the import module
*/
public void importModule(String importFile) {
// import the module
try {
I_CmsRegistry reg = m_cms.getRegistry();
reg.importModule(importFile, new Vector(), new CmsShellReport());
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Imports a module (zipfile) from the default module directory, creating a temporary project
* for this.
*
* @param importFile the name of the import module located in the default module directory
*/
public void importModuleFromDefault(String importFile) {
// build the complete filename
String fileName = com.opencms.boot.CmsBase.getAbsolutePath("export/")
+ I_CmsRegistry.C_MODULE_PATH
+ importFile;
System.out.println("Importing module: " + fileName);
// import the module
try {
// create a temporary project for the import
CmsProject project = m_cms.createProject("ModuleImport", "A temporary project to import the module " + importFile, C_GROUP_ADMIN, C_GROUP_ADMIN, C_PROJECT_TYPE_TEMPORARY);
int id = project.getId();
m_cms.getRequestContext().setCurrentProject(id);
m_cms.copyResourceToProject(C_ROOT);
// import the module
I_CmsRegistry reg = m_cms.getRegistry();
reg.importModule(fileName, new Vector(), new CmsShellReport());
// finally publish the project
m_cms.unlockProject(id);
m_cms.publishProject(id);
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Imports an import-resource (folder or zipfile) to the cms.
* Creation date: (09.08.00 16:28:48)
* @param importFile java.lang.String the name (absolute Path) of the import resource (zip or folder)
*/
public void importResources(String importFile) {
// import the resources
try {
m_cms.importResources(importFile, C_ROOT);
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Imports an import-resource (folder or zipfile) to the cms,
* and generates a special temp project for that import which is published right
* after the file has successfully been imported.
* @param importFile java.lang.String the name (absolute Path) of the import resource (zip or folder)
*/
public void importResourcesWithTempProject(String importFile) {
// import the resources
try {
CmsProject project = m_cms.createProject("SystemUpdate", "A temporary project for a system update", C_GROUP_ADMIN, C_GROUP_ADMIN, C_PROJECT_TYPE_TEMPORARY);
int id = project.getId();
m_cms.getRequestContext().setCurrentProject(id);
m_cms.copyResourceToProject(C_ROOT);
m_cms.importResources(importFile, C_ROOT);
m_cms.unlockProject(id);
m_cms.publishProject(id);
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Imports an import-resource (folder or zipfile) to the cms.
*
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -