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

📄 cmschannelcontent.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

    /**
     * write method
     * to write the current content of the content definition to the database.
     * @param cms the CmsObject to use.
     */
    public void write(CmsObject cms) throws Exception {
        CmsResource newChannel = null;
        CmsLock lock = null;
        // is this a new row or an existing row?
        cms.getRequestContext().saveSiteRoot();
        cms.getRequestContext().setSiteRoot(CmsResource.VFS_FOLDER_CHANNELS);
        try{
            if((CmsDbUtil.UNKNOWN_ID+"").equals(m_channelId)) {
                // this is a new row - call the create statement
                // first set the new channelId
                setNewChannelId();
                newChannel = cms.createResource(m_parentchannel + m_channelname, CmsResourceTypeFolder.RESOURCE_TYPE_ID, null, CmsProperty.toList(m_properties));
                cms.lockResource(cms.getSitePath(newChannel));
            } else {
                if (!"".equals(m_channel.getName())) {
                    newChannel = cms.readFolder(cms.getSitePath(m_channel));
                }
                
                if (newChannel!=null && !cms.getSitePath(newChannel).equals(m_parentchannel+m_channelname+"/")){
                    // the parent and/or the channelname has changed,
                    // so move or rename the channel
                    String parent = CmsResource.getParentFolder(cms.getSitePath(newChannel));
                    if(! parent.equals(m_parentchannel)){
                        // move the channel to the new parent channel
                        cms.moveResource(cms.getSitePath(newChannel), m_parentchannel+m_channelname);
                    } else if (!newChannel.getName().equals(m_channelname)){
                        // only rename the channel, the parent has not changed
                        cms.renameResource(cms.getSitePath(newChannel), m_channelname);
                    }
                }
                // read the changed channel
                newChannel =  cms.readFolder(m_parentchannel+m_channelname+"/");
                lock = cms.getLock(newChannel);
                // update the title of the channel
                String propTitle = cms.readProperty(cms.getSitePath(newChannel), CmsPropertyDefinition.PROPERTY_TITLE);
                if (propTitle == null){
                    propTitle = "";
                }
                if (!propTitle.equals(this.getTitle())){
                    cms.writeProperty(cms.getSitePath(newChannel), CmsPropertyDefinition.PROPERTY_TITLE, this.getTitle());
                }
                // check if the lockstate has changed
                if(!lock.getUserId().equals(this.getLockstate()) ||
                    lock.getProjectId() != cms.getRequestContext().currentProject().getId()){
                    if(this.getLockstate().isNullUUID()){
                        // unlock the channel
                        cms.unlockResource(cms.getSitePath(newChannel));
                    } else {
                        // lock the channel
                        cms.lockResource(cms.getSitePath(newChannel));
                    }
                }
            }
            // TODO: ACL's for COS
//            // check if the owner has changed
//            if(!newChannel.getOwnerId().equals(this.getOwner())){
//                cms.chown(cms.readAbsolutePath(newChannel), this.getOwnerName());
//            }
//            // check if the group has changed
//            if(!newChannel.getGroupId().equals(this.getGroupId())){
//                cms.chgrp(cms.readAbsolutePath(newChannel), this.getGroup());
//            }
//            // check if the accessflags has changed
//            if(newChannel.getAccessFlags() != this.getAccessFlags()){
//                cms.chmod(cms.readAbsolutePath(newChannel), this.getAccessFlags());
//            }
            m_channel = cms.readFolder(cms.getSitePath(newChannel));
        } catch (CmsException exc){
            throw exc;
            /*
            if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(C_OPENCMS_INFO, "[CmsChannelContent] Could not write channel "+cms.readPath(m_channel));
            }
            */
        } finally {
            cms.getRequestContext().restoreSiteRoot();
        }
    }

    /**
     * gets the unique Id of a content definition instance
     * @param cms the CmsObject to use.
     * @return a string with the Id
     */
    public String getUniqueId(CmsObject cms) {
        return m_channel.getStructureId().toString();
    }

    /**
     * gets the unique Id of a content definition instance
     *
     * @return int The unique id
     */
    public CmsUUID getId() {
        return m_channel.getStructureId();
    }

    /**
     * Gets the projectId where the CD belongs to.
     * This method is required for the use of the abstract backoffice.
     * @return int with the projectId.
     */
    public int getLockedInProject() {
        try {
            return m_cms.getLock(m_channel).getProjectId();
        } catch (CmsException e) {
            return CmsDbUtil.UNKNOWN_ID;
        }
    }

    /**
     * Gets the state of a CD.
     * This method is required for the use of the abstract backoffice.
     * @return int with the state.
     */
    public int getState() {
        return m_channel.getState();
    }

    /**
     * Gets the projectId of a CD.
     * This method is required for the use of the abstract backoffice.
     * @return int with the projectId.
     */
    public int getProjectId() {
        return m_channel.getProjectLastModified();
    }

    /**
     * gets the unique channel Id of a content definition instance
     * @return a string with the Id
     */
    public String getChannelId() {
        return m_channelId;
    }

    /**
     * sets the unique channel Id of a content definition instance
     */
    public void setChannelId(String id) {
        m_properties.put(CmsPropertyDefinition.PROPERTY_CHANNELID, id);
        m_channelId = id;
    }

    /**
     * Gets the title of the channel
     */
    public String getTitle(){
        String title = (String)m_properties.get(CmsPropertyDefinition.PROPERTY_TITLE);
        if (title == null){
            title = "";
        }
        return title;
    }

    /**
     * sets the title of a content definition instance
     */
    public void setTitle(String title) {
        m_properties.put(CmsPropertyDefinition.PROPERTY_TITLE, title);
    }

    /**
     * Gets the lockstate.
     * @return a int with the user who has locked the ressource.
     */
    public CmsUUID getLockstate() {
        try {
            return m_cms.getLock(m_channel).getUserId();
        } catch (CmsException e) {
            return CmsUUID.getNullUUID();
        }
    }

    /**
     * Sets the lockstates
     * @param the lockstate for the actual entry.
     */
    public void setLockstate(CmsUUID lockstate) {
        // m_channel.setLocked(lockstate);
    }

    /**
     * Gets the ownername of this contentdefinition.
     */
    public String getOwnerName() {
        String ownername = "";
        try{
            ownername = m_cms.readUser(getOwner()).getName();
        } catch (CmsException exc){
            //nothing to do, return empty string
        }
        return ownername;
    }

    /**
     * Gets the owner of this contentdefinition.
     */
    public CmsUUID getOwner() {
        return CmsUUID.getNullUUID();
        // return m_UserId;
    }

    /**
     * Sets the owner of this contentdefinition.
     */
    public void setOwner(CmsUUID id) {
        // m_UserId = id;
    }

    /**
     * Gets the groupname
     */
    public String getGroup() {
        String groupname = "*NOT USED*";
        // try{
        //     groupname = m_cms.readGroup(this.getGroupId()).getName();
        // } catch (CmsException exc){
            // nothing to do, return empty string
        // }
        return groupname;
    }

    /**
     * Gets the groupid
     */
    public CmsUUID getGroupId() {
        return CmsUUID.getNullUUID();
        // return m_GroupId;
    }

    /**
     * Sets the group.
     */
    public void setGroup(CmsUUID groupId) {
        // m_GroupId = groupId;
    }

    /**
     * Gets the channelname
     */
    public String getChannelPath() {
        return m_cms.getSitePath(m_channel);
    }

    /**
     * Gets the channelname
     */
    public String getChannelName() {
        return m_channelname;
    }

    /**
     * Sets the channelname.
     */
    public void setChannelName(String name) {
        m_channelname = name;
    }

    /**
     * Sets the parentname of the channel.
     */
    public void setParentName(String name) {
        m_parentchannel = name;
    }

    /**
     * Gets the name of the parent channel
     */
    public String getParentName() {
        return m_parentchannel;
    }

    /**
     * Sets the accessflags of the channel.
     */
    public void setAccessFlags(int flags) {
        m_accessflags = flags;
    }

    /**
     * Gets the accessflags of the channel
     */
    public int getAccessFlags() {
        return m_accessflags;
    }

    /**
     * Gets the date of the last modification of the channel
     */
    public long getDateLastModified(){
        return m_channel.getDateLastModified();
    }

    /**
     * Gets the date of the creation of the channel
     */
    public long getDateCreated(){
        return m_channel.getDateCreated();
    }

    /**
     * Gets the id of the user who has modified the channel
     */
    public CmsUUID getLastModifiedBy(){
        return m_channel.getUserLastModified();
    }

    /**
     * Gets the name of the user who has modified the channel
     */

⌨️ 快捷键说明

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