📄 cmsshellcommands.java
字号:
/**
* 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 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 (acePrincipal.equals(principal)) {
String pName = (acePrincipal != null) ? acePrincipal.getName() : ace.getPrincipal().toString();
System.out.println(pName + ": " + ace.getPermissions().getPermissionString() + " " + ace);
}
}
}
/**
* Does performance measurements of the OpenCms core.<p>
*
* @throws Exception if something goes wrong
*/
public void perf() throws Exception {
int maxTests = 50000;
m_cms.getRequestContext().saveSiteRoot();
m_cms.getRequestContext().setSiteRoot("/");
try {
Random random = new Random();
List testResources = m_cms.getResourcesInTimeRange("/", 0, System.currentTimeMillis());
int resourceCount = testResources.size();
System.out.println("#Resources:\t" + resourceCount);
long start, time;
long totalTime = 0;
long minTime = Long.MAX_VALUE;
long maxTime = Long.MIN_VALUE;
System.out.print("readFileHeader:\t");
for (int i = maxTests; i > 0; --i) {
int index = random.nextInt(resourceCount);
CmsResource resource = (CmsResource)testResources.get(index);
start = System.currentTimeMillis();
m_cms.readResource(m_cms.getSitePath(resource), CmsResourceFilter.ALL);
time = System.currentTimeMillis() - start;
totalTime += time;
if (time < minTime) {
minTime = time;
}
if (time > maxTime) {
maxTime = time;
}
if ((i % 100) == 0) {
System.out.print('.');
}
}
System.out.println("\nreadFileHeader:\t"
+ minTime
+ "\t"
+ maxTime
+ "\t"
+ (((float)totalTime) / maxTests)
+ " ms");
} finally {
m_cms.getRequestContext().restoreSiteRoot();
}
}
/**
* Sets the current shell prompt.<p>
*
* @param prompt the prompt to set
* @see CmsShell#setPrompt(String)
*/
public void prompt(String prompt) {
m_shell.setPrompt(prompt);
}
/**
* Purges the jsp repository.<p>
*
* @throws Exception if something goes wrong
*
* @see org.opencms.flex.CmsFlexCache#cmsEvent(org.opencms.main.CmsEvent)
*/
public void purgeJspRepository() throws Exception {
OpenCms.fireCmsEvent(new CmsEvent(
I_CmsEventListener.EVENT_FLEX_PURGE_JSP_REPOSITORY,
new HashMap(0)));
}
/**
* Returns the current folder set as URI in the request context.<p>
*
* @return the current folder
* @throws Exception if something goes wrong
* @see org.opencms.file.CmsRequestContext#getUri()
* @see CmsResource#getFolderPath(String)
*/
public String pwd() throws Exception {
return CmsResource.getFolderPath(m_cms.getRequestContext().getUri());
}
/**
* Exits the shell.<p>
*
* @see #exit()
*/
public void quit() {
exit();
}
/**
* Returns the selected files contentsls as a String.<p>
*
* @param filename the file to read the contents from
* @throws CmsException if something goes wrong
* @return the selected files contents
*/
public String readFileContent(String filename) throws CmsException {
filename = CmsLinkManager.getAbsoluteUri(
filename,
CmsResource.getFolderPath(m_cms.getRequestContext().getUri()));
CmsFile file = m_cms.readFile(filename, CmsResourceFilter.IGNORE_EXPIRATION);
return new String(file.getContents());
}
/**
* Returns the users group of a project.<p>
*
* @param project the id of the project to return the users group for
* @return the users group of the project
* @throws Exception if something goes wrong
*/
public CmsGroup readGroupOfProject(int project) throws Exception {
return m_cms.readGroup(m_cms.readProject(project));
}
/**
* Returns the manager group of a project.<p>
*
* @param project the id of the project to return the manager group for
* @return the manager group of the project
* @throws Exception if something goes wrong
*/
public CmsGroup readManagerGroup(int project) throws Exception {
return m_cms.readManagerGroup(m_cms.readProject(project));
}
/**
* Returns the owner of a project.<p>
*
* @param project the id of the project
* @return the owner of the project
* @throws Exception if something goes wrong
*/
public CmsUser readOwnerOfProject(int project) throws Exception {
return m_cms.readOwner(m_cms.readProject(project));
}
/**
* Rebuilds (if required creates) all configured search indexes.<p>
*
* @throws Exception if something goes wrong
*
* @see org.opencms.search.CmsSearchManager#rebuildAllIndexes(org.opencms.report.I_CmsReport)
*/
public void rebuildAllIndexes() throws Exception {
I_CmsReport report = new CmsShellReport(m_cms.getRequestContext().getLocale());
try {
OpenCms.getSearchManager().rebuildAllIndexes(report, true);
} catch (CmsException e) {
report.println(e);
}
}
/**
* Rebuilds (if required creates) the given search index.<p>
*
* @param index name of the index to update
* @throws Exception if something goes wrong
* @see org.opencms.search.CmsSearchManager#rebuildIndex(String, org.opencms.report.I_CmsReport)
*/
public void rebuildIndex(String index) throws Exception {
OpenCms.getSearchManager().rebuildIndex(index, new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
/**
* Replaces a module with another revision.<p>
*
* @param moduleName the name of the module
* @param importFile the name of the import file
*
* @throws Exception if something goes wrong
*/
public void replaceModule(String moduleName, String importFile) throws Exception {
if (OpenCms.getModuleManager().getModule(moduleName) != null) {
OpenCms.getModuleManager().deleteModule(
m_cms,
moduleName,
true,
new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
importModule(importFile);
}
/**
* Replaces a module with another revision.<p>
*
* @param moduleName the name of the module
* @param importFile the name of the import file
* @throws Exception if something goes wrong
*/
public void replaceModuleFromDefault(String moduleName, String importFile) throws Exception {
if (OpenCms.getModuleManager().getModule(moduleName) != null) {
OpenCms.getModuleManager().deleteModule(
m_cms,
moduleName,
true,
new CmsShellReport(m_cms.getRequestContext().getLocale()));
}
importModuleFromDefault(importFile);
}
/**
* Sets the current project to the provided project id.<p>
*
* @param id the project id to set
* @return the project set
* @throws Exception if something goes wrong
*/
public CmsProject setCurrentProject(int id) throws Exception {
return m_cms.getRequestContext().setCurrentProject(m_cms.readProject(id));
}
/**
* Sets the current project to the provided project name.<p>
*
* @param name the project name to set
* @return the project set
* @throws Exception if something goes wrong
*/
public CmsProject setCurrentProject(String name) throws Exception {
return m_cms.getRequestContext().setCurrentProject(m_cms.readProject(name));
}
/**
* 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);
System.out.println(getMessages().key(
Messages.GUI_SHELL_SETLOCALE_2,
locale,
m_cms.getRequestContext().currentUser().getName()));
m_shell.setLocale(locale);
System.out.println(getMessages().key(Messages.GUI_SHELL_SETLOCALE_POST_1, locale));
}
/**
* @see org.opencms.main.I_CmsShellCommands#shellExit()
*/
public void shellExit() {
System.out.println();
System.out.println(getMessages().key(Messages.GUI_SHELL_GOODBYE_0));
}
/**
* @see org.opencms.main.I_CmsShellCommands#shellStart()
*/
public void shellStart() {
System.out.println();
System.out.println(getMessages().key(Messages.GUI_SHELL_WELCOME_0));
System.out.println();
// print the version information
version();
// print the copyright message
copyright();
// print the help information
help();
}
/**
* Unlocks the current project, required before publishing.<p>
* @throws Exception if something goes wrong
*/
public void unlockCurrentProject() throws Exception {
m_cms.unlockProject(m_cms.getRequestContext().currentProject().getId());
}
/**
* Loads a file from the "real" file system to the VFS.<p>
*
* @param localfile the file upload
* @param folder the folder in the VFS to place the file into
* @param filename the name of the uploaded file in the VFS
* @param type the type of the new file in the VFS
* @return the createed file
* @throws Exception if something goes wrong
* @throws CmsIllegalArgumentException if the concatenation of String arguments
* <code>folder</code> and <code>localfile</code> is of length 0
*
*/
public CmsResource uploadFile(String localfile, String folder, String filename, String type)
throws Exception, CmsIllegalArgumentException {
int t = OpenCms.getResourceManager().getResourceType(type).getTypeId();
return m_cms.createResource(folder + filename, t, CmsFileUtil.readFile(localfile), null);
}
/**
* Returns the version information for this OpenCms instance.<p>
*/
public void version() {
System.out.println();
System.out.println(getMessages().key(Messages.GUI_SHELL_VERSION_1, OpenCms.getSystemInfo().getVersionName()));
}
/**
* Returns the current user.<p>
*
* @return the current user
*/
public CmsUser whoami() {
return m_cms.getRequestContext().currentUser();
}
/**
* 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();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -