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

📄 a_cmsbackoffice.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        CmsProject theProject = cms.readBackupProject(curVersion.getLockedInProject());
                        projectName = theProject.getName();
                        projectDescription = theProject.getDescription();
                    } catch (CmsException ex) {
                        projectName = "";
                    }
                    try {
                        CmsUser theUser = cms.readUser(curVersion.getLastModifiedBy());
                        userName = theUser.getName() + " " + theUser.getFirstname() + " " + theUser.getLastname();
                    } catch (CmsException ex) {
                        userName = curVersion.getLastModifiedByName();
                    }
                    template.setData("histproject", projectName);
                    template.setData("version", versionId);
                    template.setData("id", id);
                    template.setData("histid", curVersion.getId().toString());
                    template.setData("histtitle", curVersion.getTitle());
                    template.setData("histlastmodified", CmsDateUtil.getDateTimeShort(curVersion.getDateLastModified()));
                    template.setData("histpublished", CmsDateUtil.getDateTimeShort(curVersion.getDateCreated()));
                    template.setData("histmodifiedby", userName);
                    template.setData("histdescription", projectDescription);
                    CmsUUID curUser = cms.getRequestContext().currentUser().getId();
                    int curProject = cms.getRequestContext().currentProject().getId();
                    if (((A_CmsContentDefinition)o).getLockstate().equals(curUser) && ((I_CmsExtendedContentDefinition)o).getLockedInProject() == curProject) {
                        // enable restore button
                        template.setData("BUTTONRESTORE", template.getProcessedDataValue("ENABLERESTORE", this));
                        template.setData("setaction", "restore");
                    } else {
                        template.setData("BUTTONRESTORE", template.getProcessedDataValue("DISABLERESTORE", this));
                        template.setData("setaction", "");
                    }
                } catch (Exception e) {
                    if (CmsLog.getLog(this).isWarnEnabled()) {
                        CmsLog.getLog(this).warn("Backoffice: history method caused an exception", e);
                    }
                    templateSelector = "historyerror";
                    template.setData("historyerror", e.getMessage());
                    //remove marker
                    session.removeValue("idhistory");
                }
            } else {
                // no version selected
                //set template section
                templateSelector = "history";
                //create new language file object
                CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
                //get the dialog from the langauge file and set it in the template
                template.setData("historytitle", lang.getLanguageValue("messagebox.title.history"));
                // build the history list
                template.setData("id", id);
                template.setData("setaction", "detail");
            }
        } else if (action.equalsIgnoreCase("restore")) {
            String versionId = (String)parameters.get("version");
            //set template section
            templateSelector = "history";
            //create new language file object
            CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
            //get the dialog from the langauge file and set it in the template
            template.setData("historytitle", lang.getLanguageValue("messagebox.title.history"));
            // build the history list
            template.setData("id", id);
            template.setData("setaction", "detail");
            if (versionId != null && !"".equals(versionId)) {
                //access content definition constructor by reflection
                Object o = null;
                o = getContentDefinition(cms, cdClass, new CmsUUID(id));
                //get restore method and restore content definition instance
                try {
                    ((I_CmsExtendedContentDefinition)o).restore(cms, Integer.parseInt(versionId));
                } catch (Exception e) {
                    if (CmsLog.getLog(this).isWarnEnabled()) {
                        CmsLog.getLog(this).warn("Restore method caused an exception", e);
                    }
                    templateSelector = "historyerror";
                    template.setData("historyerror", e.getMessage());
                    //remove marker
                    session.removeValue("idhistory");
                }
            }
        }
        //finally start the processing
        processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
        return processResult;
    }

    /**
     * Gets all versions of the resource from the history.
     * <P>
     * The given vectors <code>names</code> and <code>values</code> will
     * be filled with the appropriate information to be used for building
     * a select box.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param lang the language file
     * @param names Vector to be filled with the appropriate values in this method.
     * @param values Vector to be filled with the appropriate values in this method.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return Index representing the current value in the vectors.
     * @throws CmsException if something goes wrong
     */

    public Integer getHistory(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Hashtable parameters) throws CmsException {
        CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
        String id = (String)parameters.get("id");
        if (id != null && !"".equals(id)) {
            Vector cdHistory = new Vector();
            //get the class of the content definition
            Class cdClass = getContentDefinitionClass();
            //access content definition constructor by reflection
            Object o = null;
            o = getContentDefinition(cms, cdClass, new CmsUUID(id));
            //get history method and return the vector of the versions
            try {
                cdHistory = ((I_CmsExtendedContentDefinition)o).getHistory(cms);
            } catch (Exception e) {
                if (CmsLog.getLog(this).isErrorEnabled()) {
                    CmsLog.getLog(this).error("History reading history for class " + cdClass.getName(), e);
                }
            }
            // fill the names and values
            for (int i = 0; i < cdHistory.size(); i++) {
                try {
                    I_CmsExtendedContentDefinition curCd = ((I_CmsExtendedContentDefinition)cdHistory.elementAt(i));
                    long updated = curCd.getDateCreated();
                    String userName = readSaveUserName(cms, curCd.getLastModifiedBy());
                    long lastModified = curCd.getDateLastModified();
                    String output = CmsDateUtil.getDateTimeShort(lastModified) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + CmsDateUtil.getDateTimeShort(updated) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + userName;
                    names.addElement(output);
                    values.addElement(curCd.getVersionId() + "");
                } catch (Exception e) {
                    if (CmsLog.getLog(this).isErrorEnabled()) {
                        CmsLog.getLog(this).error(e);
                    }
                }
            }
        }
        return new Integer(-1);
    }

    /**
     * Gets the content of a given template file.
     * <P>
     * While processing the template file the table entry
     * <code>entryTitle<code> will be displayed in the delete dialog
     *
     * @param cms A_CmsObject Object for accessing system resources
     * @param template the template
     * @param elementName not used here
     * @param parameters get the parameters action for the button activity
     * and id for the used content definition instance object
     * @param templateSelector template section that should be processed.
     * @return Processed content of the given template file.
     * @throws CmsException if something goes wrong
     */
    public byte[] getContentPermissions(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException {
        //return var
        byte[] processResult = null;
        Object o = null;
        // session will be created or fetched
        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
        //get the class of the content definition
        Class cdClass = getContentDefinitionClass();

        // get mode of permission changing
        String mode = (String)parameters.get("chmode");
        if (mode == null || "".equals(mode)) {
            mode = "";
        }
        //get (stored) id parameter
        String id = (String)parameters.get("id");
        if (id == null) {
            id = "";
        }
        // get value of hidden input field action
        String action = (String)parameters.get("action");
        // get values of input fields
        CmsUUID newOwner = CmsUUID.getNullUUID();
        CmsUUID newGroup = CmsUUID.getNullUUID();
        String newOwnerString = (String)parameters.get("owner");
        if (newOwnerString != null && !"".equals(newOwnerString)) {
            newOwner = new CmsUUID(newOwnerString);
        }
        String newGroupString = (String)parameters.get("groupId");
        if (newGroupString != null && !"".equals(newGroupString)) {
            newGroup = new CmsUUID(newGroupString);
        }
        int newAccessFlags = getAccessValue(parameters);
        //no button pressed, go to the default section!
        //change permissions dialog, displays owner, group and access flags of the entry to be changed
        if (action == null || action.equals("")) {
            if (id != "" && mode != "") {
                //access content definition constructor by reflection
                o = getContentDefinition(cms, cdClass, new CmsUUID(id));
                //set template section
                templateSelector = mode;
                CmsUUID curOwner = ((I_CmsExtendedContentDefinition)o).getOwner();
                CmsUUID curGroup = ((I_CmsExtendedContentDefinition)o).getGroupId();
                int curAccessFlags = ((I_CmsExtendedContentDefinition)o).getAccessFlags();
                // set the values in the dialog
                this.setOwnerSelectbox(cms, template, curOwner);
                this.setGroupSelectbox(cms, template, curGroup);
                this.setAccessValue(template, curAccessFlags);
                template.setData("id", id);
                template.setData("setaction", mode);
            }
            // confirmation button pressed, process data!
        } else {
            //set template section
            templateSelector = "done";
            //remove marker
            session.removeValue("idpermissions");
            //change the content definition instance
            CmsUUID contentId = new CmsUUID(id);
            o = getContentDefinition(cms, cdClass, contentId);
            //            try {
            //                contentId = Integer.valueOf(id);
            //                //access content definition constructor by reflection
            //                o = getContentDefinition(cms, cdClass, contentId);
            //            } catch (Exception e) {
            //                //access content definition constructor by reflection
            //                o = getContentDefinition(cms, cdClass, id);
            //            }

            //get change method and change content definition instance
            try {
                if ("chown".equalsIgnoreCase(action) && !newOwner.isNullUUID()) {
                    ((I_CmsExtendedContentDefinition)o).chown(cms, newOwner);
                } else if ("chgrp".equalsIgnoreCase(action) && !newGroup.isNullUUID()) {
                    ((I_CmsExtendedContentDefinition)o).chgrp(cms, newGroup);
                } else if ("chmod".equalsIgnoreCase(action)) {
                    ((I_CmsExtendedContentDefinition)o).chmod(cms, newAccessFlags);
                }
            } catch (Exception e) {
                if (CmsLog.getLog(this).isWarnEnabled()) {
                    CmsLog.getLog(this).warn("Changing permissions method caused an exception", e);
                }
                templateSelector = "permissionserror";
                template.setData("permissionserror", e.getMessage());
            }
        }
        //finally start the processing
        processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
        return processResult;
    }

    /**
    * Gets the content of a given template file.
    * <P>
    *
    * @param cms A_CmsObject Object for accessing system resources
    * @param template the template
    * @param elementName not used here
    * @param parameters get the parameters action for the button activity
    * and id for the used content definition instance object
    * and the author, title, text content for setting the new/changed data
    * @param templateSelector template section that should be processed.
    * @return Processed content of the given template file.
    * @throws CmsException if something goes wrong
    */

    private byte[] getContentHead(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException {

        //return var
        byte[] processResult = null;
        //get the class of the content definition

        //init vars

        //create new or fetch existing session
        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
        String uri = cms.getRequestContext().getUri();
        String sessionSelectBoxValue = uri + "selectBoxValue";
        //get filter method from session
        String selectBoxValue = (String)parameters.get("selectbox");
        if (selectBoxValue == null) {
            // set default value
            if ((String)session.getValue(sessionSelectBoxValue) != null) {
          

⌨️ 快捷键说明

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