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

📄 a_cmsbackoffice.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        //finally return processed data
                        return returnProcess;
                    }
                }
            }
        }
    }

    /**
    * Gets the content definition class
    * @return class content definition class
    * Must be implemented in the extending backoffice class!
    */
    public abstract Class getContentDefinitionClass();

    /**
    * Gets the content definition class method constructor
    * 
    * @param cms the cms object
    * @param contentClass the content class
    * @param contentId the id of the content
    * @return content definition object
    */
    protected Object getContentDefinition(CmsObject cms, Class contentClass, CmsUUID contentId) {
        Object o = null;
        try {
            Constructor c = contentClass.getConstructor(new Class[] {CmsObject.class, CmsUUID.class});
            o = c.newInstance(new Object[] {cms, contentId});
        } catch (InvocationTargetException ite) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("Invocation target exception", ite);
            }
        } catch (NoSuchMethodException nsm) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("Requested method was not found", nsm);
            }
        } catch (InstantiationException ie) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("The reflected class is abstract", ie);
            }
        } catch (Exception e) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("Other exception", e);
            }
        }
        return o;
    }

    /**
     * Gets the content definition class method constructor.<p>
     * 
     * @param cms the cms object
     * @param cdClass the content definition class
     * @return content definition object
     */
    protected Object getContentDefinition(CmsObject cms, Class cdClass) {
        Object o = null;
        try {
            //Constructor c = cdClass.getConstructor(new Class[] {CmsObject.class, String.class});
            Constructor c = cdClass.getConstructor(new Class[] {CmsObject.class});
            o = c.newInstance(new Object[] {cms});
        } catch (InvocationTargetException ite) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("Invocation target exception", ite);
            }
        } catch (NoSuchMethodException nsm) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("Requested method was not found", nsm);
            }
        } catch (InstantiationException ie) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("The reflected class is abstract", ie);
            }
        } catch (Exception e) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("Other exception", e);
            }
        }
        return o;
    }

    /**
    * Gets the content definition class method constructor.<p>
    * 
    * @param cms the cms object
    * @param cdClass the content definition class
    * @param id the id of the content
    * @return content definition object
    */
    protected Object getContentDefinition(CmsObject cms, Class cdClass, String id) {
        Object o = null;
        try {
            Constructor c = cdClass.getConstructor(new Class[] {CmsObject.class, String.class});
            o = c.newInstance(new Object[] {cms, id});
        } catch (InvocationTargetException ite) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("Invocation target exception", ite);
            }
        } catch (NoSuchMethodException nsm) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("Requested method was not found", nsm);
            }
        } catch (InstantiationException ie) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("The reflected class is abstract", ie);
            }
        } catch (Exception e) {
            if (CmsLog.getLog(this).isWarnEnabled()) {
                CmsLog.getLog(this).warn("Other exception", e);
            }
        }
        return o;
    }

    /**
     * @param cms A CmsObject to read the user with
     * @param userId The id of the user to read
     * @return The name of the user, or the id (as a String) in case the user has been deleted
     */
    public String readSaveUserName(CmsObject cms, CmsUUID userId) {
        String userName = null;
        try {
            userName = cms.readUser(userId).getName();
        } catch (Exception e) {
            userName = "" + userId;
        }
        return userName;
    }

    /**
    * @param cms A CmsObject to read the group with
    * @param groupId The id of the group to read
    * @return The name of the group, or the id (as a String) in case the group has been deleted
    */
    public String readSaveGroupName(CmsObject cms, CmsUUID groupId) {
        String groupName = null;
        try {
            groupName = cms.readGroup(groupId).getName();
        } catch (Exception e) {
            groupName = "" + groupId;
        }
        return groupName;
    }

    /**
    * 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 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.
    * @throws CmsException if something goes wrong
    */

    public byte[] getContentDelete(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 = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), 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!
        //delete dialog, displays the title of the entry to be deleted
        if (action == null || action.equals("")) {
            if (id != "") {
                //set template section
                templateSelector = "delete";

                //create new language file object
                CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);

                //get the dialog from the language file and set it in the template
                template.setData("deletetitle", lang.getLanguageValue("title.delete"));
                template.setData("deletedialog", lang.getLanguageValue("messagebox.delete"));
                template.setData("newsentry", id);
                template.setData("setaction", "default");
            }
            // confirmation button pressed, process data!
        } else {
            //set template section
            templateSelector = "done";
            //remove marker
            session.removeValue("iddelete");
            //delete the content definition instance
            CmsUUID contentId = new CmsUUID(id);
            //        try {
            //            idInteger = Integer.valueOf(id);
            //        } catch (Exception e) {
            //            //access content definition constructor by reflection
            //            Object o = null;
            //            o = getContentDefinition(cms, cdClass, id);
            //            //get delete method and delete content definition instance
            //            try {
            //                ((A_CmsContentDefinition) o).delete(cms);
            //            } catch (Exception e1) {
            //                if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging()) {
            //                    A_OpenCms.log(this);
            //                }
            //                templateSelector = "deleteerror";
            //                template.setData("deleteerror", 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, contentId);
            //get delete method and delete content definition instance
            try {
                ((A_CmsContentDefinition)o).delete(cms);
            } catch (Exception e) {
                templateSelector = "deleteerror";
                template.setData("deleteerror", 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 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[] getContentUndelete(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 = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), 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 = "";
        }

        //set template section
        templateSelector = "done";
        //remove marker
        session.removeValue("idundelete");
        //undelete the content definition instance
        CmsUUID contentId = new CmsUUID(id);
        //        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);

⌨️ 快捷键说明

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