📄 cmsshellcommands.java
字号:
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.
*
* @author Jan Krag
* @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 java.lang.String 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());
}
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.
*
* @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 importResources(String importFile, String importPath) {
// import the resources
try {
m_cms.importResources(importFile, importPath);
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Determines, if the user is Admin.
*/
public void isAdmin() {
try {
System.out.println(m_cms.getRequestContext().isAdmin());
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Determines, if the user is Projectleader.
*/
public void isProjectManager() {
try {
System.out.println(m_cms.getRequestContext().isProjectManager());
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Returns the user, who has locked a given resource.
* <br>
* A user can lock a resource, so he is the only one who can write this
* resource. This methods checks, who has locked a resource.
*
* @param resource The complete path to the resource.
*
*/
public void lockedBy(String resource) {
try {
System.out.println(m_cms.lockedBy(resource));
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Locks a resource<BR/>
*
* A user can lock a resource, so he is the only one who can write this
* resource.
*
* @param resource The complete path to the resource to lock.
*/
public void lockResource(String resource) {
try {
m_cms.lockResource(resource);
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Locks a given resource.
* <br>
* A user can lock a resource, so he is the only one who can write this
* resource.
*
* @param resource the complete path to the resource to lock.
* @param force if force is <code>true</code>, a existing locking will be overwritten.
*/
public void lockResource(String resource, String force) {
try {
//m_cms.lockResource(resource, Boolean.getBoolean(force));
if(force.toLowerCase().equals("true")) {
m_cms.lockResource(resource, true);
}
else {
m_cms.lockResource(resource, false);
}
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Logs a user into the system.
*
* @param username The name of the user to log in.
* @param password The password.
*/
public void login(String username, String password) {
try {
m_cms.loginUser(username, password);
whoami();
}
catch(Exception exc) {
CmsShell.printException(exc);
System.out.println("Login failed!");
}
}
/**
* Logs a user into the system.
*
* @param username The name of the user to log in.
* @param password The password.
*/
public void loginUser(String username, String password) {
login(username, password);
}
/**
* Logs a web user into the Cms, if the password is correct.
*
* @param username the name of the user.
* @param password the password of the user.
*/
public void loginWebUser(String username, String password) {
try {
System.out.println(m_cms.loginWebUser(username, password));
}
catch(Exception exc) {
CmsShell.printException(exc);
}
}
/**
* Moves a file to the given destination.
*
* @param source the complete path of the sourcefile.
* @param destination the complete path of the dest
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -