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

📄 a_cmsbackoffice.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public byte[] getContentDirectPublish(CmsObject cms, CmsXmlWpTemplateFile template, String elementName,
                                          Hashtable parameters, String templateSelector) throws CmsException {
        //return var
        byte[] processResult = null;

        // session will be created or fetched
        I_CmsSession session = (CmsSession) cms.getRequestContext().getSession(true);
        //get the class of the content definition
        Class cdClass = getContentDefinitionClass();

        //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");

        //no button pressed, go to the default section!
        //publish dialog, displays the title of the entry to be published
        if (action == null || action.equals("")) {
            if (id != "") {
                //set template section
                templateSelector = "publish";
                //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("publishtitle", lang.getLanguageValue("messagebox.title.publishresource"));
                template.setData("publishdialog1", lang.getLanguageValue("messagebox.message1.publishresource"));
                template.setData("newsentry", id);
                template.setData("publishdialog2", lang.getLanguageValue("messagebox.message4.publishresource"));
                template.setData("setaction", "default");
            }
            // confirmation button pressed, process data!
        } else {
            //set template section
            templateSelector = "done";
            //remove marker
            session.removeValue("idsave");
            //publish the content definition instance
            Integer idInteger = null;
            try {
                idInteger = Integer.valueOf(id);
            } catch (Exception e) {
                //access content definition constructor by reflection
                Object o = null;
                o = getContentDefinition(cms, cdClass, id);
                //get publish method and publish content definition instance
                try {
                    ((I_CmsExtendedContentDefinition) o).publishResource(cms);
                } catch (Exception e1) {
                    if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                        A_OpenCms.log(C_OPENCMS_INFO, getClassName() + ": Backoffice: publish method throwed an exception!");
                    }
                    templateSelector = "publisherror";
                    template.setData("publisherror", e1.getMessage());
                }
                //finally start the processing
                processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
                return processResult;
            }

            //access content definition constructor by reflection
            Object o = null;
            o = getContentDefinition(cms, cdClass, idInteger);
            //get publish method and publish content definition instance
            try {
                ((I_CmsExtendedContentDefinition) o).publishResource(cms);
            }catch (Exception e) {
                templateSelector = "publisherror";
                template.setData("publisherror", e.getMessage());
            }
        }

        //finally start the processing
        processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
        return processResult;
    }

    /**
     * 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 history dialog
     *
     * @param cms A_CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @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.
     * @exception CmsException
     */
    public byte[] getContentHistory(CmsObject cms, CmsXmlWpTemplateFile template, String elementName,
                                          Hashtable parameters, String templateSelector) throws CmsException {
        //return var
        byte[] processResult = null;

        // session will be created or fetched
        I_CmsSession session = (CmsSession) cms.getRequestContext().getSession(true);
        //get the class of the content definition
        Class cdClass = getContentDefinitionClass();

        //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");
        //no button pressed, go to the default section!
        //history dialog, displays the versions of the cd in the history
        if (action == null || action.equals("")) {
            if (id != "") {
                //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 {
                //set template section
                templateSelector = "done";
                //remove marker
                session.removeValue("idhistory");
            }
            // confirmation button pressed, process data!
        } else if (action.equalsIgnoreCase("detail")){
            String versionId = (String)parameters.get("version");
            if(versionId != null && !"".equals(versionId)){
                templateSelector = "historydetail";
                //access content definition constructor by reflection
                Object o = null;
                o = getContentDefinition(cms, cdClass, new Integer(id));
                //get the version from history
                try {
                    I_CmsExtendedContentDefinition curVersion = (I_CmsExtendedContentDefinition)((I_CmsExtendedContentDefinition)o).getVersionFromHistory(cms, Integer.parseInt(versionId));
                    String projectName = "";
                    String projectDescription = "";
                    String userName = "";
                    try{
                        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", Integer.toString(curVersion.getId()));
                    template.setData("histtitle", curVersion.getTitle());
                    template.setData("histlastmodified", Utils.getNiceDate(curVersion.getDateLastModified()));
                    template.setData("histpublished", Utils.getNiceDate(curVersion.getDateCreated()));
                    template.setData("histmodifiedby", userName);
                    template.setData("histdescription", projectDescription);
                    int curUser = cms.getRequestContext().currentUser().getId();
                    int curProject = cms.getRequestContext().currentProject().getId();
                    if(((A_CmsContentDefinition) o).getLockstate() == 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 (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                        A_OpenCms.log(C_OPENCMS_INFO, getClassName() + ": Backoffice: history method throwed an exception! "+e.getMessage());
                    }
                    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 Integer(id));
                //get restore method and restore content definition instance
                try {
                    ((I_CmsExtendedContentDefinition)o).restore(cms, Integer.parseInt(versionId));
                }catch (Exception e) {
                    if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                        A_OpenCms.log(C_OPENCMS_INFO, getClassName() + ": Backoffice: restore method throwed an exception! "+e.getMessage());
                    }
                    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 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.
     * @exception CmsException
     */

    public Integer getHistory(CmsObject cms, CmsXmlLanguageFile lang, Vector names,
            Vector values, Hashtable parameters) throws CmsException {
        I_CmsSession session = cms.getRequestContext().getSession(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 Integer(id));
            //get history method and return the vector of the versions
            try {
                cdHistory = ((I_CmsExtendedContentDefinition) o).getHistory(cms);
            }catch (Exception e) {
                if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                    A_OpenCms.log(C_OPENCMS_INFO, getClassName() + ": Backoffice: history method throwed an exception!");
                }
            }
            // 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 = "";
                    try{
                        userName = cms.readUser(curCd.getLastModifiedBy()).getName();
                    } catch(CmsException exc){
                        userName = "";
                    }
                    long lastModified = curCd.getDateLastModified();
                    String output = Utils.getNiceDate(lastModified) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                                    + Utils.getNiceDate(updated) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                                    + userName;
                    names.addElement(output);
                    values.addElement(curCd.getVersionId()+"");
                } catch (Exception e){
                    if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                        A_OpenCms.log(C_OPENCMS_INFO, getClassName() + ": Backoffice: history method throwed an exception!");
                    }
                }
            }

⌨️ 快捷键说明

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