cmsnewexplorerfilelist.java

来自「java 编写的程序」· Java 代码 · 共 657 行 · 第 1/2 页

JAVA
657
字号
                content.append( res.getLength() + ",");
            }
            // state
            content.append(res.getState() + ",");
            // project
            content.append(res.getProjectId() + ",");
            // owner
            if(showOwner){
                content.append("\"" + cms.readUser(res.getOwnerId()).getName() + "\",");
            }else{
                content.append("\"\",");
            }
            // group
            if(showGroup){
                content.append("\"" + cms.readGroup(res).getName() + "\",");
            }else{
                content.append("\"\",");
            }
            // accessFlags
            content.append(res.getAccessFlags() + ",");
            // locked by
            if(res.isLockedBy() == C_UNKNOWN_ID) {
                content.append("\"\",");
            }else {
                content.append("\"" + cms.lockedBy(res).getName() + "\",");
            }
            // locked in project
            int lockedInProject = res.getLockedInProject();
            String lockedInProjectName = "";
            try {
                lockedInProjectName = cms.readProject(lockedInProject).getName();
            } catch(CmsException exc) {
                // ignore the exception - this is an old project so ignore it
            }
            content.append("\"" + lockedInProjectName + "\"," + lockedInProject + ");\n");
        }

        //  now the tree, only if changed
        if(newTreePlease && (!listonly)) {
            content.append("\n top.rT();\n");
            Vector tree = cms.getFolderTree();
            int startAt = 1;
            int parentId;
            boolean grey = false;
            int onlineProjectId = cms.onlineProject().getId();
            if(onlineProjectId == cms.getRequestContext().currentProject().getId()) {

                // all easy: we are in the onlineProject
                CmsFolder rootFolder = (CmsFolder)tree.elementAt(0);
                content.append("top.aC(");
                content.append(rootFolder.getResourceId() + ", ");
                content.append("\"" + lang.getDataValue("title.rootfolder") + "\", ");
                content.append(rootFolder.getParentId() + ", false);\n");
                for(int i = startAt;i < tree.size();i++) {
                    CmsFolder folder = (CmsFolder)tree.elementAt(i);
                    content.append("top.aC(");
                    // id
                    content.append(folder.getResourceId() + ", ");
                    // name
                    content.append("\"" + folder.getName() + "\", ");
                    // parentId
                    content.append(folder.getParentId() + ", false);\n");
                }
            }else {
                // offline Project
                Hashtable idMixer = new Hashtable();
                CmsFolder rootFolder = (CmsFolder)tree.elementAt(0);
                String folderToIgnore = null;
                if(rootFolder.getProjectId() != onlineProjectId) {
                    startAt = 2;
                    grey = false;
                    idMixer.put(new Integer(((CmsFolder)tree.elementAt(1)).getResourceId()),
                            new Integer(rootFolder.getResourceId()));
                }else {
                    grey = true;
                }
                content.append("top.aC(");
                content.append(rootFolder.getResourceId() + ", ");
                content.append("\"" + lang.getDataValue("title.rootfolder") + "\", ");
                content.append(rootFolder.getParentId() + ", " + grey + ");\n");
                for(int i = startAt;i < tree.size();i++) {
                    CmsFolder folder = (CmsFolder)tree.elementAt(i);
                    if((folder.getState() == C_STATE_DELETED) || (folder.getAbsolutePath().equals(folderToIgnore))) {

                        // if the folder is deleted - ignore it and the following online res
                        folderToIgnore = folder.getAbsolutePath();
                    }else {
                        if(folder.getProjectId() != onlineProjectId) {
                            grey = false;
                            parentId = folder.getParentId();
                            try {
                                // the next res is the same res in the online-project: ignore it!
                                if(folder.getAbsolutePath().equals(((CmsFolder)tree.elementAt(i + 1)).getAbsolutePath())) {
                                    i++;
                                    idMixer.put(new Integer(((CmsFolder)tree.elementAt(i)).getResourceId()),
                                            new Integer(folder.getResourceId()));
                                }
                            }catch(IndexOutOfBoundsException exc) {
                            // ignore the exception, this was the last resource
                            }
                        }else {
                            grey = true;
                            parentId = folder.getParentId();
                            if(idMixer.containsKey(new Integer(parentId))) {
                                parentId = ((Integer)idMixer.get(new Integer(parentId))).intValue();
                            }
                        }
                        content.append("top.aC(");
                        // id
                        content.append(folder.getResourceId() + ", ");
                        // name
                        content.append("\"" + folder.getName() + "\", ");
                        // parentId
                        content.append(parentId + ", " + grey + ");\n");
                    }
                }
            }
        }
        if(listonly || projectView) {
            // only show the filelist
            content.append(" top.dUL(document); \n");
        } else {
            // update all frames
            content.append(" top.dU(document,"+numberOfPages+","+selectedPage+"); \n");
        }
        content.append("}\n");
        content.append("</script>\n</head> \n<BODY onLoad=\"initialize()\"></BODY> \n</html>\n");
        return (content.toString()).getBytes();
    }

    /**
     * Gets the content of a given template file.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName <em>not used here</em>.
     * @param parameters <em>not used here</em>.
     * @param templateSelector <em>not used here</em>.
     * @return Unprocessed content of the given template file.
     * @exception CmsException
     */

    public byte[] getContent(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) throws CmsException {

        // ignore the templateSelector since we only dump the template
        return getContent(cms, templateFile, elementName, parameters);
    }

    /**
     * Sets the default preferences for the current user if those values are not available.
     * @return Hashtable with default preferences.
     */

    private int getDefaultPreferences(CmsObject cms) {
        int filelist;
        String explorerSettings = (String)cms.getRequestContext().currentUser().getAdditionalInfo(C_ADDITIONAL_INFO_EXPLORERSETTINGS);
        if(explorerSettings != null) {
            filelist = new Integer(explorerSettings).intValue();
        }else {
            filelist = C_FILELIST_NAME + C_FILELIST_TITLE + C_FILELIST_TYPE + C_FILELIST_CHANGED;
        }
        return filelist;
    }

    /**
     * Gets the key that should be used to cache the results of
     * this template class.
     * <P>
     * Since this class is quite simple it's okay to return
     * just the name of the template file here.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return key that can be used for caching
     */

    public Object getKey(CmsObject cms, String templateFile, Hashtable parameter,
            String templateSelector) {

        //return templateFile.getAbsolutePath();
        //Vector v = new Vector();
        CmsRequestContext reqContext = cms.getRequestContext();

        //v.addElement(reqContext.currentProject().getName());
        //v.addElement(templateFile);
        //return v;
        return "" + reqContext.currentProject().getId() + ":" + templateFile;
    }

    /**
     * Template cache is not used here since we don't include
     * any subtemplates. So we can always return <code>true</code> here.
     * @return <code>true</code>
     */

    public boolean isCacheable(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) {
        return false;
    }
    public boolean isProxyPrivateCacheable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return false;
    }
    public boolean isProxyPublicCacheable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return false;
    }
    public boolean isExportable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return false;
    }
    public boolean isStreamable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return false;
    }
    public CmsCacheDirectives collectCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        CmsCacheDirectives myCd = new CmsCacheDirectives(false);
        return myCd;
    }

    /**
     * Any results of this class are cacheable since we don't include
     * any subtemplates. So we can always return <code>true</code> here.
     * @return <code>true</code>
     */

    public boolean isTemplateCacheSet() {
        return true;
    }

    /**
     * Template cache is not used here since we don't include
     * any subtemplates <em>(not implemented)</em>.
     */

    public void setTemplateCache(I_CmsTemplateCache c) {


    // do nothing.
    }

    /**
     * Template cache is not used here since we don't include
     * any subtemplates. So we can always return <code>false</code> here.
     * @return <code>false</code>
     */

    public boolean shouldReload(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) {
        return false;
    }

    public A_CmsElement createElement(CmsObject cms, String templateFile, Hashtable parameters) {
        return new CmsElementDump(getClass().getName(), templateFile, null, getCacheDirectives(cms, templateFile, null, parameters, null),
                                    cms.getRequestContext().getElementCache().getVariantCachesize());
    }

    /**
     * Get the resources in the folder stored in parameter param
     * or in the project shown in the projectview
     *
     * @param cms The CmsObject
     * @param param The name of the folder
     * @param parameters The parameters of the request
     * @return The vector with all ressources
     */
    private Vector getRessources(CmsObject cms, String param, Hashtable parameters) throws CmsException {
        String mode = (String)parameters.get("mode")!=null?(String)parameters.get("mode"):"";
        String submode = (String)parameters.get("submode")!=null?(String)parameters.get("submode"):"";
        if("projectview".equals(mode)) {
            I_CmsSession session = cms.getRequestContext().getSession(true);
            if("search".equals(submode)){
                Vector resources = new Vector();
                String currentFilter = (String)session.getValue("ocms_search.currentfilter");
                CmsSearchFormObject searchForm = null;
                if(currentFilter != null){
                    searchForm = (CmsSearchFormObject)((Hashtable)session.getValue("ocms_search.allfilter")).get(currentFilter);
                    if((currentFilter != null) && (searchForm != null)){
                        // flag for using lucene for search
                        I_CmsRegistry registry = cms.getRegistry();
                        boolean luceneEnabled = "on".equals(registry.getSystemValue("searchbylucene"));
                        if("property".equals(currentFilter)){
                            String definition = searchForm.getValue02();
                            String value = searchForm.getValue03();
                            int type = Integer.parseInt(searchForm.getValue01());
                            resources = cms.getResourcesWithProperty(definition, value, type);
                        } else if ("filename".equals(currentFilter)){
                            String filename = searchForm.getValue01();
                            // if lucene is enabled the use lucene for searching by filename
                            // else use the method that reads from the database
                            if(luceneEnabled){
                                // put here the lucene search for filenames
                            } else {
                                resources = cms.readResourcesLikeName(filename);
                            }
                        } else if ("content".equals(currentFilter)){
                            // this search is only available if lucene is enabled
                            String content = searchForm.getValue01();
                        }
                    }
                }
                // remove the channel resources
                for(int i=0; i<resources.size(); i++){
                    CmsResource curRes = (CmsResource)resources.elementAt(i);
                    if(curRes.getResourceName().startsWith(cms.getRequestContext().getSiteName()+cms.C_ROOTNAME_COS)){
                        resources.remove(i);
                    }
                }
                return resources;
            } else {
                String filter = new String();
                filter = (String) session.getValue("filter");
                String projectId = (String) session.getValue("projectid");
                int currentProjectId;
                if(projectId == null || "".equals(projectId)){
                    currentProjectId = cms.getRequestContext().currentProject().getId();
                } else {
                    currentProjectId = Integer.parseInt(projectId);
                }
                session.removeValue("filter");
                return cms.readProjectView(currentProjectId, filter);
            }
        } else {
            return cms.getResourcesInFolder(param);
        }
    }

}

⌨️ 快捷键说明

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