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

📄 cmsfilelist.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        // set the file type
                        String typename = type.getResourceTypeName();
                        typename = lang.getLanguageValue("fileicon." + typename);
                        template.fastSetXmlData(C_FILELIST_TYPE_VALUE, typename);
                    }
                    if((filelist & C_FILELIST_CHANGED) != 0) {

                        // get the file date
                        long time = file.getDateLastModified();
                        template.fastSetXmlData(C_FILELIST_CHANGED_VALUE, getNiceDate(time));
                    }
                    if((filelist & C_FILELIST_SIZE) != 0) {

                        // get the file size
                        template.fastSetXmlData(C_FILELIST_SIZE_VALUE, new Integer(file.getLength()).toString());
                    }
                    if((filelist & C_FILELIST_STATE) != 0) {

                        // get the file state
                        template.fastSetXmlData(C_FILELIST_STATE_VALUE, getState(cms, file, lang));
                    }
                    if((filelist & C_FILELIST_OWNER) != 0) {

                        // get the owner of the file
                        CmsUser owner = cms.readOwner(file);
                        template.fastSetXmlData(C_FILELIST_OWNER_VALUE, owner.getName());
                    }
                    if((filelist & C_FILELIST_GROUP) != 0) {

                        // get the group of the file
                        CmsGroup group = cms.readGroup(file);
                        template.fastSetXmlData(C_FILELIST_GROUP_VALUE, group.getName());
                    }
                    if((filelist & C_FILELIST_ACCESS) != 0) {

                        // get the access flags
                        int access = file.getAccessFlags();
                        template.fastSetXmlData(C_FILELIST_ACCESS_VALUE, getAccessFlags(access));
                    }
                    if((filelist & C_FILELIST_ACCESS) != 0) {

                        // get the locked by
                        int lockedby = file.isLockedBy();
                        if(lockedby == C_UNKNOWN_ID) {
                            template.fastSetXmlData(C_FILELIST_LOCKED_VALUE, "");
                        }
                        else {
                            template.fastSetXmlData(C_FILELIST_LOCKED_VALUE, cms.lockedBy(file).getName());
                        }
                    }

                    // Get all customized column values
                    callingObject.getCustomizedColumnValues(cms, template, res, lang);
                    template.fastSetXmlData(C_NAME_FILEFOLDER, template.getProcessedDataValue(getName(cms, file), this));
                }
                output.append(template.getProcessedDataValue(C_LIST_ENTRY, callingObject));
            }
        }
        return output.toString();
    }

    /**
     * Selects the icon that is displayed in the file list.<br>
     * This method includes cache to prevent to look up in the filesystem for each
     * icon to be displayed
     * @param cms The CmsObject.
     * @param type The resource type of the file entry.
     * @param config The configuration file.
     * @return String containing the complete name of the iconfile.
     * @throws Throws CmsException if something goes wrong.
     */
    private String getIcon(CmsObject cms, I_CmsResourceType type, CmsXmlWpConfigFile config) throws CmsException {
        // check if this icon is in the cache already
        String icon = (String)m_iconCache.get(type.getResourceTypeName());
        // no icon was found, so check if there is a icon file in the filesystem
        if(icon == null) {
            String filename = C_ICON_PREFIX + type.getResourceTypeName().toLowerCase() + C_ICON_EXTENSION;
            try {
                // read the icon file
                cms.readFileHeader(I_CmsWpConstants.C_VFS_PATH_SYSTEMPICS + filename);
                // add the icon to the cache
                icon = filename;
                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;
    }

    /**
     * Select which lock icon (if nescessary) is selected for a entry in the file list.
     * @param cms The CmsObject.
     * @param file The CmsResource displayed in the the file list.
     * @param template The file list template
     * @param lang The content definition language file.
     * @return HTML code for selecting a lock icon.
     */

    private String getLock(CmsObject cms, CmsResource file, CmsXmlWpTemplateFile template, CmsXmlLanguageFile lang) throws CmsException {
        StringBuffer output = new StringBuffer();

        // the file is locked
        if(file.isLocked()) {
            int locked = file.isLockedBy();

            // it is locked by the actuel user
            if(cms.getRequestContext().currentUser().getId() == locked) {
                template.fastSetXmlData(C_LOCKEDBY, lang.getLanguageValue("explorer.lockedby") + cms.getRequestContext().currentUser().getName());
                output.append(C_LOCKED_VALUE_OWN);
            }
            else {
                template.fastSetXmlData(C_LOCKEDBY, lang.getLanguageValue("explorer.lockedby") + cms.lockedBy(file.getAbsolutePath()).getName());
                output.append(C_LOCKED_VALUE_USER);
            }
        }
        else {
            output.append(C_LOCKED_VALUE_NOLOCK);
        }

        //  output.append(C_LOCKED_VALUE_NOLOCK);
        return output.toString();
    }

    /**
     * Gets the name (including link) for a entry in the file list.
     * @param cms The CmsObject.
     * @param file The CmsResource displayed in the the file list.
     * @return The name used for the actual entry.
     */

    private String getName(CmsObject cms, CmsResource file) {
        StringBuffer output = new StringBuffer();
        if(file.isFile()) {
            output.append(C_NAME_VALUE_FILE);
        }
        else {
            output.append(C_NAME_VALUE_FOLDER);
        }
        return output.toString();
    }

    /**
     * Gets a formated time string form a long time value.
     * @param time The time value as a long.
     * @return Formated time string.
     */

    private String getNiceDate(long time) {
        StringBuffer niceTime = new StringBuffer();
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(new Date(time));
        String day = "0" + new Integer(cal.get(Calendar.DAY_OF_MONTH)).intValue();
        String month = "0" + new Integer(cal.get(Calendar.MONTH) + 1).intValue();
        String year = new Integer(cal.get(Calendar.YEAR)).toString();
        String hour = "0" + new Integer(cal.get(Calendar.HOUR) + 12 * cal.get(Calendar.AM_PM)).intValue();
        String minute = "0" + new Integer(cal.get(Calendar.MINUTE));
        if(day.length() == 3) {
            day = day.substring(1, 3);
        }
        if(month.length() == 3) {
            month = month.substring(1, 3);
        }
        if(hour.length() == 3) {
            hour = hour.substring(1, 3);
        }
        if(minute.length() == 3) {
            minute = minute.substring(1, 3);
        }
        niceTime.append(day + ".");
        niceTime.append(month + ".");
        niceTime.append(year + " ");
        niceTime.append(hour + ":");
        niceTime.append(minute);
        return niceTime.toString();
    }

    /**
     * Gets a formated file state string for a entry in the file list.
     * @param cms The CmsObject.
     * @param file The CmsResource displayed in the the file list.
     * @param lang The content definition language file.
     * @return Formated state string.
     */

    private String getState(CmsObject cms, CmsResource file, CmsXmlLanguageFile lang) throws CmsException {
        StringBuffer output = new StringBuffer();
        if(file.inProject(cms.getRequestContext().currentProject())) {
            int state = file.getState();
            output.append(lang.getLanguageValue("explorer.state" + state));
        }
        else {
            output.append(lang.getLanguageValue("explorer.statenip"));
        }
        return output.toString();
    }

    /**
     * Gets the style for a entry in the file list.
     * @param cms The CmsObject.
     * @param file The CmsResource displayed in the the file list.
     * @return The style used for the actual entry.
     */

    private String getStyle(CmsObject cms, CmsResource file) throws CmsException {
        StringBuffer output = new StringBuffer();

        // check if the resource is in the actual project
        if(!file.inProject(cms.getRequestContext().currentProject())) {
            output.append(C_STYLE_NOTINPROJECT);
        }
        else {
            if(cms.getRequestContext().currentProject().isOnlineProject()) {

                // check if the actual project is the online project
                output.append(C_STYLE_UNCHANGED);
            }
            else {
                int style = file.getState();
                switch(style) {
                case 0:
                    output.append(C_STYLE_UNCHANGED);
                    break;

                case 1:
                    output.append(C_STYLE_CHANGED);
                    break;

                case 2:
                    output.append(C_STYLE_NEW);
                    break;

                case 3:
                    output.append(C_STYLE_DELETED);
                    break;

                default:
                    output.append(C_STYLE_UNCHANGED);
                }
            }
        }
        return output.toString();
    }

    /**
     * Handling of the special workplace <CODE>&lt;FILELIST&gt;</CODE> tags.
     * <P>
     * Reads the code of a file list from the file list definition file
     * and returns the processed code with the actual elements.
     *
     * @param cms CmsObject Object for accessing resources.
     * @param n XML element containing the <code>&lt;FILELIST&gt;</code> tag.
     * @param callingObject reference to the calling object.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @param lang CmsXmlLanguageFile conataining the currently valid language file.
     * @return Processed button.
     * @throws CmsException
     */

    public Object handleSpecialWorkplaceTag(CmsObject cms, Element n, A_CmsXmlContent doc,
            Object callingObject, Hashtable parameters, CmsXmlLanguageFile lang) throws CmsException {
        String template = n.getAttribute(C_FILELIST_TEMPLATE);
        String customizedTemplate = n.getAttribute(C_FILELIST_CUSTOMTEMPLATE);
        CmsXmlWpTemplateFile filelistTemplate = new CmsXmlWpTemplateFile(cms, template);
        filelistTemplate.setData(C_FILELIST_COLUMN_CUSTOMIZED, "");
        filelistTemplate.setData(C_FILELIST_COLUMN_CUSTOMIZED_VALUE, "");

        // Include the template file for the customized columns
        if(customizedTemplate != null && !"".equals(customizedTemplate)) {
            filelistTemplate.readIncludeFile(customizedTemplate);
        }

        // Check if the callingObject implements our interface
        if(!(callingObject instanceof I_CmsFileListUsers)) {
            throwException("Class " + callingObject.getClass().getName() + " is using a \"FILELIST\" tag in its "
                    + "template file " + doc.getAbsoluteFilename() + ", but does not implement I_CmsFileListUsers. ", CmsException.C_XML_WRONG_TEMPLATE_CLASS);
        }
        CmsXmlWpConfigFile configFile = this.getConfigFile(cms);
        I_CmsFileListUsers filelistUser = (I_CmsFileListUsers)callingObject;
        Vector filelist = filelistUser.getFiles(cms);
        return getFilelist(cms, filelist, filelistTemplate, lang, parameters, filelistUser, configFile);
    }
}

⌨️ 快捷键说明

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