📄 cmsfoldertree.java
字号:
m_iconCache.put(type.getResourceTypeName(), icon);
}
catch(CmsException e) {
// no icon was found, so use the default
icon = C_ICON_DEFAULT;
m_iconCache.put(type.getResourceTypeName(), icon);
}
}
return icon;
}
/**
* Creates the folder tree i.
* @throws Throws CmsException if something goes wrong.
*/
public Object getTree(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) throws CmsException {
StringBuffer output = new StringBuffer();
I_CmsSession session = cms.getRequestContext().getSession(true);
CmsXmlWpConfigFile configFile = this.getConfigFile(cms);
String filelist = null;
String currentFolder;
String currentFilelist;
String rootFolder;
String files = null;
boolean displayFiles = false;
boolean enableOnlineFiles = false;
// if a foldername was included, overwrite the value in the session for later use.
currentFolder = cms.getRequestContext().getRequest().getParameter(C_PARA_FOLDERTREE);
if (currentFolder.trim().equalsIgnoreCase("/")) {
currentFolder = (String)session.getValue(C_PARA_FOLDERTREE);
if (currentFolder==null) {
currentFolder = "/";
session.putValue(C_PARA_FOLDERTREE, currentFolder);
}
}
else if (currentFolder!=null) {
session.putValue(C_PARA_FOLDERTREE, currentFolder);
}
// get the current folder to be displayed as maximum folder in the tree.
currentFilelist = (String)session.getValue(C_PARA_FILELIST);
if(currentFilelist == null) {
currentFilelist = cms.rootFolder().getAbsolutePath();
}
// check if the files must be displayed as well
files = (String)session.getValue(C_PARA_VIEWFILE);
if(files != null) {
displayFiles = true;
}
// check if the onlineresources are selectable
String offselect = (String)session.getValue("onlineselect_in_foldertree");
if(offselect != null){
enableOnlineFiles = true;
}
// get current and root folder
rootFolder = cms.rootFolder().getAbsolutePath();
//get the template
CmsXmlWpTemplateFile template = (CmsXmlWpTemplateFile)doc;
if(filelist != null) {
template.setData("PREVIOUS", filelist);
}
else {
template.setData("PREVIOUS", currentFilelist);
}
String tab = template.getProcessedDataValue(C_TREEIMG_EMPTY0, this);
showTree(cms, rootFolder, currentFolder, currentFilelist, template, output, tab,
displayFiles, enableOnlineFiles, configFile);
return output.toString();
}
/**
* Indicates if the results of this class are cacheable.
*
* @param cms CmsObject Object for accessing system resources
* @param templateFile Filename of the template file
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
* @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
*/
public boolean isCacheable(CmsObject cms, String templateFile, String elementName,
Hashtable parameters, String templateSelector) {
return false;
}
/**
* Generates a subtree of the folder tree.
* @param cms The CmsObject.
* @param curFolder The rootfolder of ther subtree to display
* @param endfolder The last folder to be displayed.
* @param filelist The folder that is displayed in the file list
* @param template The foldertree template file.
* @param output The output buffer where all data is written to.
* @param tab The prefix-HTML code fo this subtree.
* @param displayFiles Flag to signal if to display the files as well.
*/
private void showTree(CmsObject cms, String curfolder, String endfolder, String filelist,
CmsXmlWpTemplateFile template, StringBuffer output, String tab,
boolean displayFiles, boolean offselect, CmsXmlWpConfigFile configFile) throws CmsException {
String newtab = new String();
String folderimg = new String();
String treeswitch = new String();
CmsResource lastFolder = null;
Vector subfolders = new Vector();
Vector list = new Vector();
Vector untestedSubfolders = new Vector();
Vector untestedSubfiles = new Vector();
Vector untestedlist = cms.getSubFolders(curfolder);
// remove invisible folders
for(int i = 0;i < untestedlist.size();i++) {
CmsFolder subfolder = (CmsFolder)untestedlist.elementAt(i);
if(checkAccess(cms, subfolder)) {
list.addElement(subfolder);
}
}
// load the files as well if nescessary
if(displayFiles) {
Vector untestedfileslist = cms.getFilesInFolder(curfolder);
for(int i = 0;i < untestedfileslist.size();i++) {
CmsFile file = (CmsFile)untestedfileslist.elementAt(i);
if(checkAccess(cms, file)) {
list.addElement(file);
}
}
}
Enumeration enum = list.elements();
if(list.size() > 0) {
lastFolder = (CmsResource)list.lastElement();
}
else {
lastFolder = null;
}
//CmsFolder folder=null;
while(enum.hasMoreElements()) {
CmsResource res = (CmsResource)enum.nextElement();
//CmsFolder folder=(CmsFolder)enum.nextElement();
// check if this folder is visible
if(checkAccess(cms, (CmsResource)res)) {
subfolders = new Vector();
if(res.isFolder()) {
untestedSubfolders = cms.getSubFolders(res.getAbsolutePath());
// now filter all invisible subfolders
for(int i = 0;i < untestedSubfolders.size();i++) {
CmsFolder subfolder = (CmsFolder)untestedSubfolders.elementAt(i);
if(checkAccess(cms, subfolder)) {
subfolders.addElement(subfolder);
}
}
// load the files as well if nescessary
if(displayFiles) {
untestedSubfiles = cms.getFilesInFolder(res.getAbsolutePath());
for(int i = 0;i < untestedSubfiles.size();i++) {
CmsFile subfile = (CmsFile)untestedSubfiles.elementAt(i);
if(checkAccess(cms, subfile)) {
subfolders.addElement(subfile);
}
}
}
}
// check if this folder must diplayes open
if(res.isFolder()) {
if(res.getAbsolutePath().equals(filelist)) {
folderimg = template.getProcessedDataValue(C_TREEIMG_FOLDEROPEN, this);
}
else {
folderimg = template.getProcessedDataValue(C_TREEIMG_FOLDERCLOSE, this);
}
}
else {
I_CmsResourceType type = cms.getResourceType(res.getType());
String icon = getIcon(cms, type, configFile);
template.setData("icon", configFile.getWpPicturePath() + icon);
folderimg = template.getProcessedDataValue("TREEIMG_FILE", this);
}
// now check if a treeswitch has to displayed
// is this the last element of the current folder, so display the end image
if(res.getAbsolutePath().equals(lastFolder.getAbsolutePath())) {
// if there are any subfolders extisintg, use the + or - box
if(subfolders.size() > 0) {
// test if the + or minus must be displayed
if(endfolder.startsWith(res.getAbsolutePath())) {
template.setData(C_TREELINK, C_WP_FOLDER_TREE + "?" + C_PARA_FOLDERTREE
+ "=" + Encoder.escape(curfolder,
cms.getRequestContext().getEncoding()));
treeswitch = template.getProcessedDataValue(C_TREEIMG_MEND, this);
}
else {
template.setData(C_TREELINK, C_WP_FOLDER_TREE + "?" + C_PARA_FOLDERTREE
+ "=" + Encoder.escape(res.getAbsolutePath(),
cms.getRequestContext().getEncoding()));
treeswitch = template.getProcessedDataValue(C_TREEIMG_PEND, this);
}
}
else {
treeswitch = template.getProcessedDataValue(C_TREEIMG_END, this);
}
}
else {
// use the cross image
// if there are any subfolders extisintg, use the + or - box
if(subfolders.size() > 0) {
// test if the + or minus must be displayed
if(endfolder.startsWith(res.getAbsolutePath())) {
template.setData(C_TREELINK, C_WP_FOLDER_TREE + "?" + C_PARA_FOLDERTREE
+ "=" + Encoder.escape(curfolder,
cms.getRequestContext().getEncoding()));
treeswitch = template.getProcessedDataValue(C_TREEIMG_MCROSS, this);
}
else {
template.setData(C_TREELINK, C_WP_FOLDER_TREE + "?" + C_PARA_FOLDERTREE
+ "=" + Encoder.escape(res.getAbsolutePath(),
cms.getRequestContext().getEncoding()));
treeswitch = template.getProcessedDataValue(C_TREEIMG_PCROSS, this);
}
}
else {
treeswitch = template.getProcessedDataValue(C_TREEIMG_CROSS, this);
}
}
if(res.getAbsolutePath().equals(lastFolder.getAbsolutePath())) {
newtab = tab + template.getProcessedDataValue(C_TREEIMG_EMPTY, this);
}
else {
newtab = tab + template.getProcessedDataValue(C_TREEIMG_VERT, this);
}
// test if the folder is in the current project
if(res.inProject(cms.getRequestContext().currentProject())) {
template.setData(C_TREESTYLE, C_FILE_INPROJECT);
}
else {
template.setData(C_TREESTYLE, C_FILE_NOTINPROJECT);
}
// set all data for the treeline tag
template.setData(C_FILELIST, C_WP_EXPLORER_FILELIST + "?" + C_PARA_FILELIST
+ "=" + res.getAbsolutePath());
template.setData(C_TREELIST, C_WP_EXPLORER_TREE + "?" + C_PARA_FILELIST
+ "=" + res.getAbsolutePath());
template.setData(C_TREEENTRY, res.getName());
template.setData(C_TREEVAR, res.getAbsolutePath());
template.setData(C_TREETAB, tab);
template.setData(C_TREEFOLDER, folderimg);
template.setData(C_TREESWITCH, treeswitch);
// test if the folder is in the current project and if the user has
// write access to this folder.
// CHECK: The logic in CmsFolderTree was changed
// if((res.inProject(cms.getRequestContext().currentProject()) && checkWriteable(cms,
// (CmsResource)res)) || offselect) {
if(checkWriteable(cms, (CmsResource)res) || offselect) {
template.setData(C_TREESTYLE, C_FILE_INPROJECT);
output.append(template.getProcessedDataValue(C_TREELINE, this));
} else {
template.setData(C_TREESTYLE, C_FILE_NOTINPROJECT);
output.append(template.getProcessedDataValue(C_TREELINEDISABLED, this));
}
//finally process all subfolders if nescessary
if((endfolder.startsWith(res.getAbsolutePath())) && (endfolder.endsWith("/"))) {
showTree(cms, res.getAbsolutePath(), endfolder, filelist, template,
output, newtab, displayFiles, offselect, configFile);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -