📄 cmstree.java
字号:
if (resource != null) {
resource = CmsResource.getFolderPath(resource);
}
if ((lastknown != null) && (!lastknown.endsWith("/"))) {
lastknown += "/";
}
String rootFolder = getRootFolder();
if (rootFolder.equals(resource) && !rootFolder.equals(currentResource) && (lastknown == null) && !rootloaded) {
// direct load of a new tree with subtree (e.g. when returning from an editor)
lastknown = getRootFolder();
resource = CmsResource.getFolderPath(currentResource);
setNewTree(true);
} else if (rootFolder.equals(resource)) {
// load new tree if not already loaded
setNewTree(!rootloaded);
} else {
setNewTree(false);
}
if (getTreeType() != null) {
getSettings().setTreeResource(getTreeType(), resource);
if (treeSite != null) {
getSettings().setTreeSite(getTreeType(), treeSite);
}
}
setTargetFolder(resource);
setStartFolder(lastknown);
}
/**
* Determines if the site selector frame should be shown depending on the tree type or the value of a request parameter.<p>
*
* If only one site is available, the site selector is not displayed.<p>
*
* @param request the HttpServletRequest to check
*/
private void computeSiteSelector(HttpServletRequest request) {
boolean selectorForType = TYPE_SIBLING.equals(getTreeType())
|| TYPE_COPY.equals(getTreeType())
|| TYPE_PAGELINK.equals(getTreeType())
|| TYPE_PREFERENCES.equals(getTreeType());
boolean showFromRequest = Boolean.valueOf(request.getParameter(PARAM_SHOWSITESELECTOR)).booleanValue();
if (selectorForType || showFromRequest) {
// get all available sites
int siteCount = CmsSiteManager.getAvailableSites(getCms(), true).size();
setShowSiteSelector(siteCount > 1);
return;
}
setShowSiteSelector(false);
}
/**
* Creates the output for a tree node.<p>
*
* @param path the path of the resource represented by this tree node
* @param title the resource name
* @param type the resource type
* @param folder if the resource is a folder
* @param state the resource state
* @param grey if true, the node is displayed in grey
*
* @return the output for a tree node
*/
private String getNode(String path, String title, int type, boolean folder, int state, boolean grey) {
StringBuffer result = new StringBuffer(64);
String parent = CmsResource.getParentFolder(path);
result.append("parent.aC(\"");
// name
result.append(title);
result.append("\",");
// type
result.append(type);
result.append(",");
// folder
if (folder) {
result.append(1);
} else {
result.append(0);
}
result.append(",");
// hashcode of path
result.append(path.hashCode());
result.append(",");
// hashcode of parent path
result.append((parent != null) ? parent.hashCode() : 0);
result.append(",");
// resource state
result.append(state);
result.append(",");
// project status
if (grey) {
result.append(1);
} else {
result.append(0);
}
result.append(");\n");
return result.toString();
}
/**
* Creates a node entry for the root node of the current site.<p>
*
* @return a node entry for the root node of the current site
*/
private String getRootNode() {
CmsResource resource = null;
String title = null;
String folder = getRootFolder();
try {
resource = getCms().readFolder(folder, CmsResourceFilter.IGNORE_EXPIRATION);
// get the title information of the folder
CmsProperty titleProperty = getCms().readPropertyObject(folder, CmsPropertyDefinition.PROPERTY_TITLE, false);
if (titleProperty == null || titleProperty.isNullProperty()) {
getCms().getSitePath(resource);
title = resource.getRootPath();
} else {
title = titleProperty.getValue();
}
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
}
return getNode(resource.getRootPath(), title, resource.getTypeId(), true, resource.getState(), false);
}
/**
* Calculates the prefix that has to be added when selecting a resource in a popup tree window.<p>
*
* This is needed for the link dialog in editors
* as well as the copy, move and link popup dialogs for resources in the VFS.<p>
*
* @param prefix the current prefix of the resource
* @param storedSiteRoot the site root in which the workplace (not the tree!) is
* @return the prefix which is added to the resource name
*/
private String getSitePrefix(String prefix, String storedSiteRoot) {
if (TYPE_PAGELINK.equals(getTreeType())) {
// in editor link dialog, create a special prefix for internal links
if (!storedSiteRoot.equals(prefix)) {
// stored site is not selected site, create complete URL as prefix
CmsSite site = CmsSiteManager.getSite(prefix);
prefix = getCms().getRequestContext().removeSiteRoot(prefix);
prefix = site.getUrl() + OpenCms.getSystemInfo().getOpenCmsContext() + prefix;
} else {
// stored site is selected site, don't show prefix at all
prefix = "";
}
} else if (TYPE_COPY.equals(getTreeType())
|| TYPE_SIBLING.equals(getTreeType())
|| TYPE_VFSWIDGET.equals(getTreeType())) {
// in vfs copy|move|link or vfs widget mode, don't add the prefix for the current workplace site
if (storedSiteRoot.equals(prefix)) {
prefix = "";
}
} else if (TYPE_PREFERENCES.equals(getTreeType())) {
prefix = "";
}
return prefix;
}
/**
* Returns the name of the start folder (or "last known" folder) to be loaded.<p>
*
* @return the name of the start folder (or "last known" folder) to be loaded
*/
private String getStartFolder() {
return m_startFolder;
}
/**
* Returns the target folder name.<p>
*
* @return the target folder name
*/
private String getTargetFolder() {
return m_targetFolder;
}
/**
* Returns true if a complete new tree must be loaded, false if an existing
* tree is updated or extended.<p>
*
* @return true if a complete new tree must be loaded
*/
private boolean newTree() {
return m_newTree;
}
/**
* Creates error information output.<p>
*
* @param t an error that occured
* @return error information output
*/
private String printError(Throwable t) {
StringBuffer result = new StringBuffer(1024);
result.append("/*\n");
result.append(t.getMessage());
result.append("\n*/\n");
result.append("function init() {\n");
result.append("}\n");
return result.toString();
}
/**
* Sets the value to indicate if only folders or files and folders should be included in the tree.<p>
*
* @param includeFiles if true if files and folders should be included in the tree
*/
private void setIncludeFiles(boolean includeFiles) {
m_includeFiles = includeFiles;
}
/**
* Sets if a complete tree must be loaded.<p>
*
* @param newTree if true, a complete tree must be loaded
*/
private void setNewTree(boolean newTree) {
m_newTree = newTree;
}
/**
* Sets if the site selector should be shown depending on the tree type and the count of accessible sites.<p>
*
* @param showSiteSelector true if site selector should be shown, otherwise false
*/
private void setShowSiteSelector(boolean showSiteSelector) {
m_showSiteSelector = showSiteSelector;
}
/**
* Sets the name of the start folder (or "last known" folder) to be loaded.<p>
*
* @param startFolder the name of the start folder (or "last known" folder) to be loaded
*/
private void setStartFolder(String startFolder) {
m_startFolder = startFolder;
}
/**
* Sets the target folder name.<p>
*
* @param targetFolder the target folder name
*/
private void setTargetFolder(String targetFolder) {
m_targetFolder = targetFolder;
}
/**
* Sets the type of this tree.<p>
*
* @param type the type of this tree
*/
private void setTreeType(String type) {
m_treeType = type;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -