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

📄 cmsadministration.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param templateSelector template section that should be processed.
     */

    public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException {       
        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
        CmsXmlWpTemplateFile templateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
        CmsXmlLanguageFile lang = templateDocument.getLanguageFile();
        String navPos = (String)session.getValue(com.opencms.core.I_CmsConstants.C_SESSION_ADMIN_POS);
        templateDocument.setData("emptyPic", (String)resourcesUri(cms, "empty.gif", null, null));
        CmsXmlWpConfigFile confFile = new CmsXmlWpConfigFile(cms);
        String sentBy = (String)parameters.get("sender");      
        
        if(sentBy == null) {
            if(navPos == null) {
                sentBy = confFile.getWorkplaceAdministrationPath();
            }
            else {
                if(!navPos.endsWith("/")) {
                    navPos = navPos.substring(0, navPos.indexOf("/") + 1);
                }
                sentBy = navPos;
            }
        }
        
        if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
            CmsLog.getLog(this).debug("Getting content of element "
                    + ((elementName == null) ? "<root>" : elementName));
            CmsLog.getLog(this).debug("Template file is: " + templateFile);
            CmsLog.getLog(this).debug("Selected template section is: "
                    + ((templateSelector == null) ? "<default>" : templateSelector));
            CmsLog.getLog(this).debug("SentBy: " + sentBy );                    
        }          
        
        List iconVector = (List) new ArrayList();
        if(sentBy.endsWith("/administration/")) {

            // we must serch for administrationPoints in AdminPath and in system/modules/..
            sentBy = confFile.getWorkplaceAdministrationPath();
            iconVector = cms.getSubFolders(sentBy);
            List modules = (List) new ArrayList();

            modules = cms.getSubFolders(CmsWorkplace.VFS_PATH_MODULES);

            for(int i = 0;i < modules.size();i++) {
                List moduleAdminPoints = (List) new ArrayList();                
                String dummy = cms.getSitePath((CmsFolder)modules.get(i));
                dummy += "administration/";
                try {
                    moduleAdminPoints = cms.getSubFolders(dummy);
                } catch (CmsVfsResourceNotFoundException e) {
                    // folder does not exists
                    continue;
                } catch (CmsSecurityException e1) {
                    // no access to this adminstration point, skip it
                }
                for(int j = 0;j < moduleAdminPoints.size();j++) {
                    CmsFolder currentModuleAdminFolder = (CmsFolder) moduleAdminPoints.get(j);
                    iconVector.add(currentModuleAdminFolder);
                    //System.err.println( currentModuleAdminFolder.getResourceName() );
                }
            }
        }
        else {
            iconVector = cms.getSubFolders(sentBy);
        }
        session.putValue(com.opencms.core.I_CmsConstants.C_SESSION_ADMIN_POS, sentBy);
        List iconVector2 = cms.getFilesInFolder(sentBy);
        int numFolders = iconVector.size();
        if(numFolders > 0) {
            String iconNames[] = new String[numFolders];
            int index[] = new int[numFolders];
            String folderTitles[] = new String[numFolders];
            String folderLangKeys[] = new String[numFolders];
            String folderPos[] = new String[numFolders];
            String folderVisible[] = new String[numFolders];
            String folderActiv[] = new String[numFolders];
            String accessVisible[] = new String[numFolders];
            for(int i = 0;i < numFolders;i++) {
                CmsResource aktIcon = (CmsResource)iconVector.get(i);
                try {
                    Map propertyinfos = cms.readProperties(cms.getSitePath(aktIcon));
                    iconNames[i] = cms.getSitePath(aktIcon);
                    index[i] = i;
                    folderLangKeys[i] = getStringValue((String)propertyinfos.get(CmsPropertyDefinition.PROPERTY_NAVTEXT));
                    folderTitles[i] = getStringValue((String)propertyinfos.get(CmsPropertyDefinition.PROPERTY_TITLE));
                    folderPos[i] = getStringValue((String)propertyinfos.get(CmsPropertyDefinition.PROPERTY_NAVPOS));
                    if(folderPos[i].equals("")) {
                        folderPos[i] = "101";
                    }
                    folderVisible[i] = getStringValue((String)propertyinfos.get(org.opencms.file.CmsPropertyDefinition.PROPERTY_VISIBLE));
                    folderActiv[i] = getStringValue((String)propertyinfos.get(org.opencms.file.CmsPropertyDefinition.PROPERTY_ACTIV));
                    accessVisible[i] = new Boolean(checkVisible(cms, aktIcon)).toString();
                } catch(CmsSecurityException e) {
                    // ignore all "access denied" type exceptions
                } catch(CmsException e) {
                    throw e;
                } catch(Throwable t) {
                    throw new CmsLegacyException("[" + this.getClass().getName() + "] "
                            + t.getMessage(), CmsLegacyException.C_SQL_ERROR, t);
                }
            } // end of for
            sort(iconNames, index, folderPos, numFolders);
            String completeTable = "";
            int element = 0;
            int zeile = 0;
            while(element < numFolders) {
                String completeRow = "";
                //while((element < numFolders) && (element < (zeile + 1) * C_ELEMENT_PER_ROW)) {
                while((element < numFolders)) {
                    int pos = index[element];
                    if(iconNames[element] != null){
                        completeRow += generateIcon(cms, templateDocument, parameters, lang, folderTitles[pos],
                            iconNames[element], folderLangKeys[pos], folderActiv[pos], folderVisible[pos],
                            accessVisible[pos]);
                    }
                    element++;
                }
                templateDocument.setData("entrys", completeRow);
                completeTable += templateDocument.getProcessedDataValue("list_row");
                zeile++;
            } // of while
            templateDocument.setData("iconTable", completeTable);
        }
        else {

            // no Folders, just a real page
            try {
                CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(sentBy
                        + "index.html?initial=true");
            }
            catch(Exception e) {
                throw new CmsLegacyException("Redirect fails :" + cms.getSitePath((CmsFile)iconVector2.get(0)),
                    CmsLegacyException.C_UNKNOWN_EXCEPTION, e);
            }
            return null;
        }
        return startProcessing(cms, templateDocument, elementName, parameters, templateSelector);
    }

    /**
     * returns the String or "" if it is null.
     * Creation date: (29.10.00 16:05:38)
     * @return java.lang.String
     * @param param java.lang.String
     */

    private String getStringValue(String param) {
        if(param == null) {
            return "";
        }
        return param;
    }

    /**
     * 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;
    }

    /**
     * Sorts a set of arrays containing navigation information depending on
     * their navigation positions.
     * @param filenames Array of filenames
     * @param index Array of associate Strings
     * @param positions Array of navpostions
     */

    private void sort(String[] filenames, int[] index, String[] positions, int max) {

        // Sorting algorithm
        // This method uses an bubble sort, so replace this with something more
        // efficient
        try {
            for(int i = max - 1;i > 0;i--) {
                for(int j = 0;j < i;j++) {
                    float a = new Float(positions[j]).floatValue();
                    float b = new Float(positions[j + 1]).floatValue();
                    if(a > b) {
                        String tempfilename = filenames[j];
                        int tempindex = index[j];
                        String tempposition = positions[j];
                        filenames[j] = filenames[j + 1];
                        index[j] = index[j + 1];
                        positions[j] = positions[j + 1];
                        filenames[j + 1] = tempfilename;
                        index[j + 1] = tempindex;
                        positions[j + 1] = tempposition;
                    }
                }
            }
        }
        catch(Exception e) {
             if(CmsLog.getLog(this).isWarnEnabled()){
                 CmsLog.getLog(this).warn("Adminpoints unsorted cause I cant get a valid float value", e);
             }
        }
    } // of sort

    /**
     * Check if this resource should be displayed in the administrationview.
     * @param cms The CmsObject
     * @param resource The resource to be checked.
     * @return True or false.
     * @throws CmsException if something goes wrong.
     */

    private boolean checkVisible(CmsObject cms, CmsResource resource) throws CmsException {
    	return cms.hasPermissions(resource, CmsPermissionSet.ACCESS_VIEW);
    }
}

⌨️ 快捷键说明

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