⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmstree.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            }

            if (site.getSiteRoot().equals(preSelection)) {
                // this is the user's currently selected site
                selectedIndex = pos;
            }
            options.add(curOption);
            pos++;
        }

        return buildSelect(htmlAttributes, options, values, selectedIndex);
    }

    /**
     * Returns the html for the explorer tree.<p>
     *
     * @return the html for the explorer tree
     */
    public String getTree() {

        StringBuffer result = new StringBuffer(2048);
        String targetFolder = getTargetFolder();
        String startFolder = getStartFolder();
        List targetFolderList = new ArrayList();
        boolean grey;
        List resources = new ArrayList();
        CmsFolder folder = null;
        String oldSiteRoot = getCms().getRequestContext().getSiteRoot();
        boolean restoreSiteRoot = false;

        if (targetFolder != null) {
            // check if there is more than one folder to update (e.g. move operation)
            StringTokenizer T = new StringTokenizer(targetFolder, "|");
            while (T.hasMoreTokens()) {
                String currentFolder = T.nextToken().trim();
                targetFolderList.add(currentFolder);
            }
        } else {
            targetFolderList.add(null);
        }

        Iterator targets = targetFolderList.iterator();
        try {

            while (targets.hasNext()) {
                // iterate over all given target folders
                String currentTargetFolder = (String)targets.next();

                if ("channelselector".equals(getTreeType())) {
                    // change the site root for channel tree window
                    restoreSiteRoot = true;
                    getCms().getRequestContext().saveSiteRoot();
                    getCms().getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
                } else if (getSettings().getTreeSite(getTreeType()) != null) {
                    // change the site root for popup window with site selector
                    restoreSiteRoot = true;
                    getCms().getRequestContext().saveSiteRoot();
                    if (newTree() && currentTargetFolder == null) {
                        currentTargetFolder = "/";
                    }
                    getCms().getRequestContext().setSiteRoot(getSettings().getTreeSite(getTreeType()));
                    try {
                        // check presence of target folder
                        getCms().readFolder(currentTargetFolder, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
                    } catch (CmsException e) {
                        // target folder not found, set it to "/"
                        if (LOG.isInfoEnabled()) {
                            LOG.info(e);
                        }
                        currentTargetFolder = "/";
                    }
                }

                // read the selected folder

                try {
                    folder = getCms().readFolder(currentTargetFolder, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
                } catch (CmsException e) {
                    // return with error
                    return printError(e);
                }

                if ((startFolder == null) || (!currentTargetFolder.startsWith(startFolder))) {
                    // no (valid) start folder given, just load current folder        
                    try {
                        if (includeFiles()) {
                            resources.addAll(getCms().getResourcesInFolder(
                                currentTargetFolder,
                                CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
                        } else {
                            resources.addAll(getCms().getSubFolders(
                                currentTargetFolder,
                                CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
                        }
                    } catch (CmsException e) {
                        // return with error
                        return printError(e);
                    }
                } else {
                    // valid start folder given, load all folders between start and current folder
                    try {
                        if (includeFiles()) {
                            resources.addAll(getCms().getResourcesInFolder(
                                startFolder,
                                CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
                        } else {
                            resources.addAll(getCms().getSubFolders(
                                startFolder,
                                CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
                        }
                        StringTokenizer tok = new StringTokenizer(
                            currentTargetFolder.substring(startFolder.length()),
                            "/");
                        while (tok.hasMoreTokens()) {
                            startFolder += tok.nextToken() + "/";
                            if (includeFiles()) {
                                resources.addAll(getCms().getResourcesInFolder(
                                    startFolder,
                                    CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
                            } else {
                                resources.addAll(getCms().getSubFolders(
                                    startFolder,
                                    CmsResourceFilter.ONLY_VISIBLE_NO_DELETED));
                            }
                        }
                    } catch (CmsException e) {
                        // return with error 
                        return printError(e);
                    }
                }
            }

            result.append("function init() {\n");

            if (newTree()) {
                // new tree must be reloaded
                result.append("parent.initTree();\n");
                result.append(getRootNode());
            }

            // read the list of project resource to select which resource is "inside" or "outside" 
            List projectResources;
            try {
                projectResources = getCms().readProjectResources(getCms().getRequestContext().currentProject());
            } catch (CmsException e) {
                // use an empty list (all resources are "outside")
                if (LOG.isInfoEnabled()) {
                    LOG.info(e);
                }
                projectResources = new ArrayList();
            }

            // now output all the tree nodes
            Iterator i = resources.iterator();
            while (i.hasNext()) {
                CmsResource resource = (CmsResource)i.next();
                grey = !CmsProject.isInsideProject(projectResources, resource);
                if ((!grey) && (!getSettings().getResourceTypes().containsKey(new Integer(resource.getTypeId())))) {
                    grey = true;
                }

                result.append(getNode(
                    resource.getRootPath(),
                    resource.getName(),
                    resource.getTypeId(),
                    resource.isFolder(),
                    resource.getState(),
                    grey));
            }

            if (includeFiles()) {
                result.append("parent.setIncludeFiles(true);\n");
            }
            if (getTreeType() != null) {
                // this is a popup window tree
                result.append("parent.setTreeType(\"");
                result.append(getTreeType());
                result.append("\");\n");
                String curSite = getSettings().getTreeSite(getTreeType());
                if (curSite != null) {
                    // add the current site as prefix if present
                    result.append("parent.setSitePrefix(\"");
                    result.append(getSitePrefix(curSite, oldSiteRoot));
                    result.append("\");\n");
                }
            }
            // set the root folder in javascript
            result.append("parent.setRootFolder(\"");
            result.append(getRootFolder());
            result.append("\");\n");

            if (newTree()) {
                // new tree 
                result.append("parent.showTree(parent.tree_display.document, \"");
                result.append(folder.getRootPath().hashCode());
                result.append("\");\n");
            } else {
                // update the current tree with the childs of the selected node
                if (resources.size() == 0) {
                    // the node had no childs 
                    result.append("parent.setNoChilds(\"");
                    result.append(folder.getRootPath().hashCode());
                    result.append("\");\n");
                }
                result.append("parent.showLoadedNodes(parent.tree_display.document,\"");
                result.append(folder.getRootPath().hashCode());
                result.append("\");\n");
            }

            result.append("}\n");
        } finally {
            if (restoreSiteRoot) {
                getCms().getRequestContext().restoreSiteRoot();
            }
        }
        return result.toString();
    }

    /**
     * Returns the type of this tree (e.g. "copy", "project" etc.),
     * if null this is the default explorer version.<p>
     * 
     * @return the current type of the tree (e.g. "copy", "project" etc.)
     */
    public String getTreeType() {

        return m_treeType;
    }

    /**
     * Indicates if only folders or files and folders should be included in the tree.<p>
     * 
     * @return true if files and folders should be included in the tree
     */
    public boolean includeFiles() {

        return m_includeFiles;
    }

    /**
     * Returns the HTML for the tree initialization.<p>
     * 
     * @return the HTML for the tree initialization
     */
    public String initTree() {

        return initTree(getCms(), getEncoding(), getSkinUri());
    }

    /**
     * Indicates if the site selector should be shown depending on the tree type, initial settings and the count of accessible sites.<p>
     * 
     * @return true if site selector should be shown, otherwise false
     */
    public boolean showSiteSelector() {

        return m_showSiteSelector;
    }

    /**
     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
     */
    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {

        setIncludeFiles(Boolean.valueOf(request.getParameter(PARAM_INCLUDEFILES)).booleanValue());
        boolean rootloaded = Boolean.valueOf(request.getParameter(PARAM_ROOTLOADED)).booleanValue();
        String resource = request.getParameter(PARAM_RESOURCE);
        setTreeType(request.getParameter(PARAM_TYPE));
        String treeSite = request.getParameter(PARAM_TREESITE);
        computeSiteSelector(request);

        String currentResource;
        if (getTreeType() == null) {
            currentResource = getSettings().getExplorerResource();
        } else {
            // get the current tree resource from the settings for a special tree type
            currentResource = getSettings().getTreeResource(getTreeType());
        }

        String lastknown = request.getParameter(PARAM_LASTKNOWN);
        // both "resource" and "lastknown" must be folders

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -