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

📄 cmsmastercontent.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * Gets the lockstate.
     * @return a int with the user who has locked the ressource.
     */
    public CmsUUID getLockstate() {  
        /*
        CmsUUID lockedByUserId = CmsUUID.getNullUUID();

        try {
            if (hasWriteAccess(m_cms)) {
                lockedByUserId = m_dataSet.m_lockedBy;
            }
        } catch (CmsException exc) {
            // NOOP
        }

        return lockedByUserId;
        */
        
        return m_dataSet.m_lockedBy;
    }

    /**
     * Sets the lockstates
     * @param the lockstate for the actual entry.
     */
    public void setLockstate(CmsUUID lockstate) {
        m_lockstateWasChanged = true;
        m_dataSet.m_lockedBy = lockstate;
    }

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

    /**
     * Gets the ownername
     */
    public String getOwnerName() {

        String retValue = m_dataSet.m_userId + "";
        if ((m_dataSet.m_userName == null || "".equals(m_dataSet.m_userName.trim()))
            && !CmsUUID.getNullUUID().equals(m_dataSet.m_userId)) {
            try { // to read the real name of this user
                retValue = m_cms.readUser(m_dataSet.m_userId).getName();
            } catch (CmsException exc) {
                // ignore the exception - it was not possible to read the group
                // instead return the groupid
            }
        } else {
            // this is a history value - return it
            retValue = m_dataSet.m_userName;
        }
        return retValue;
    }

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

    /**
     * Gets the groupname
     */
    public String getGroup() {

        String retValue = "";

        if (m_dataSet.m_groupId != null) {
            retValue = m_dataSet.m_groupId + "";
        }

        if ((m_dataSet.m_groupName == null || "".equals(m_dataSet.m_groupName.trim()))
            && (m_dataSet.m_groupId != null && !CmsUUID.getNullUUID().equals(m_dataSet.m_groupId))) {
            try {
                retValue = m_cms.readGroup(m_dataSet.m_groupId).getName();
            } catch (CmsException exc) {
                // ignore the exception - it was not possible to read the group
                // instead return the groupid
            }
        } else {
            // this is historical data - return it
            retValue = m_dataSet.m_groupName;
        }

        return retValue;
    }

    /**
     * Gets the groupid
     */
    public CmsUUID getGroupId() {
        return m_dataSet.m_groupId;
    }

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

    /**
     * Returns the projectId of the content definition.
     * If the cd belongs to the current project the value
     * is the id of the current project otherwise its
     * the id of the online project
     *
     * @return int The project id
     */
    public int getProjectId() {
        return m_dataSet.m_projectId;
    }

    /**
     * Returns the state of the content definition:
     * unchanged, new, changed or deleted
     *
     * @return int The state of the cd
     */
    public int getState() {
        return m_dataSet.m_state;
    }

    /**
     * Returns the projectId of the content definition
     * that is stored in the cd table after the cd
     * was locked
     *
     * @return int The id of the cd
     */
    public int getLockedInProject() {
        return m_dataSet.m_lockedInProject;
    }

    /**
     * Returns the sub-id of this contentdefinition. You have to implement this
     * method so it returns a unique sunb-id that describes the type of the
     * contentdefinition. (E.g. article: sub-id=1; table: sub-id=2).
     */
    abstract public int getSubId();

    /**
     * Returns a String representation of this instance.
     * This can be used for debugging purposes.
     */
    public String toString() {
        StringBuffer returnValue = new StringBuffer();
        returnValue.append(this.getClass().getName() + "{");
        returnValue.append("UniqueId=" + getUniqueId(m_cms) + ";");
        returnValue.append("Lockstate=" + getLockstate() + ";");
        returnValue.append("AccessFlags=" + getAccessFlagsAsString() + ";");
        returnValue.append(m_dataSet.toString() + "}");
        return returnValue.toString();
    }

    /**
     * set the accessFlag for the CD
     * @param the accessFlag
     */
    public void setAccessFlags(int accessFlags) {
        m_dataSet.m_accessFlags = accessFlags;
    }

    /**
     * get the accessFlag for the CD
     * @return the accessFlag
     */
    public int getAccessFlags() {
        return m_dataSet.m_accessFlags;
    }

    /**
     * Convenience method to get the access-Flags as String representation.
     * @return String of access rights
     */
    public String getAccessFlagsAsString() {

        int accessFlags = getAccessFlags();
        StringBuffer buf = new StringBuffer();

        buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_READ) > 0 ? "r" : "-"));
        buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_WRITE) > 0 ? "w" : "-"));
        buf.append(((accessFlags & I_CmsExtendedContentDefinition.C_PERMISSION_VIEW) > 0 ? "v" : "-"));
        buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_READ) > 0 ? "r" : "-"));
        buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_WRITE) > 0 ? "w" : "-"));
        buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_VISIBLE) > 0 ? "v" : "-"));
        buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_READ) > 0 ? "r" : "-"));
        buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_WRITE) > 0 ? "w" : "-"));
        buf.append(((accessFlags & com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_VISIBLE) > 0 ? "v" : "-"));
        buf.append(((accessFlags & CmsResource.FLAG_INTERNAL) > 0 ? "i" : "-"));

        return buf.toString();
    }

    /**
     * has the current user the right to view the CD
     * @return true if this cd is visible
     */
    public boolean isVisible() {
        CmsUser currentUser = m_cms.getRequestContext().currentUser();
        try {
            if(m_cms.isAdmin()) {
                return true;
            } else {
                if ( !accessOther(com.opencms.core.I_CmsConstants.C_ACCESS_PUBLIC_VISIBLE)
                    && !accessOwner(m_cms, currentUser, CmsPermissionSet.PERMISSION_VIEW)
                    && !accessGroup(m_cms, currentUser, com.opencms.core.I_CmsConstants.C_ACCESS_GROUP_VISIBLE)) {
                    return false;
                } else {
                    return true;
                }
            }
        } catch(CmsException exc) {
            // no access to cms -> not visible
            return false;
        }
    }

    /**
     * returns true if the CD is readable for the current user
     * @return true if the cd is readable
     */
    public boolean isReadable() {
        try {
            if(m_cms.isAdmin()) {
                return true;
            } else {
                return hasReadAccess(m_cms);
            }
        } catch(CmsException exc) {
            // there was a cms-exception - no read-access!
            return false;
        }
    }

    /**
     * returns true if the CD is writeable for the current user
     * @return true if the cd is writeable
     */
    public boolean isWriteable() {
        try {
            if(m_cms.isAdmin()) {
                return true;
            } else {
                return this.hasWriteAccess(m_cms);
            }
        } catch(CmsException exc) {
            // there was a cms-exception - no write-access!
            return false;
        }
    }

    /**
     * Publishes the content definition directly
     *
     * @param cms The CmsObject
     */
    public void publishResource(CmsObject cms) throws Exception {
        Vector changedResources = new Vector();
        Vector changedModuleData = new Vector();
        int versionId = 0;
        long publishDate = System.currentTimeMillis();
        boolean historyEnabled = OpenCms.getSystemInfo().isVersionHistoryEnabled();
        CmsUUID publishHistoryId = new CmsUUID();

        try {
            if (historyEnabled) {
                // Get the next version id
                versionId = cms.getBackupTagId();
                // backup the current project
                cms.backupProject(versionId, publishDate);
            }
            
            // now publish the content definition
            getDbAccessObject(getSubId()).publishResource(cms, publishHistoryId, m_dataSet, getSubId(), this.getClass().getName(), historyEnabled, versionId, publishDate, changedResources, changedModuleData);
            
            // update the cache
            if (CmsXmlTemplateLoader.isElementCacheEnabled()) {
                CmsXmlTemplateLoader.getOnlineElementCache().cleanupCache(changedResources, changedModuleData);
            }
        } finally {
            
            // a "directly" published COS resource can be handled totally equal to a published project
            Map eventData = new HashMap();
            eventData.put(I_CmsEventListener.KEY_PUBLISHID, publishHistoryId.toString());  
            eventData.put(I_CmsEventListener.KEY_PROJECTID, new Integer(cms.getRequestContext().currentProject().getId()));
            eventData.put(I_CmsEventListener.KEY_DBCONTEXT, new CmsDbContext(cms.getRequestContext()));
            OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_PUBLISH_PROJECT, eventData));
        }
    }
    
    /**
     * Writes an entry to the publish history for a published COS resource.<p>
     * 
     * @param project the current project
     * @param publishedBoResource the CmsPublishedResource onject representing the published COS resource
     * @param publishId unique int ID to identify each publish task in the publish history
     * @param tagId the backup tag revision
     * 
     * @throws CmsException if something goes wrong
     */
    public void writePublishHistory(CmsProject project, CmsPublishedResource publishedBoResource, CmsUUID publishId, int tagId) throws CmsException {

        getDbAccessObject(getSubId()).writePublishHistory(
            project,
            publishId,
            tagId,
            // content definition name
            publishedBoResource.getRootPath(),
            // master id
            publishedBoResource.getResourceId(),
            // sub ID
            publishedBoResource.getType(), // state
            publishedBoResource.getState());
        
    }    

    /**
     * Undelete method
     * for undelete instance of content definition
     *
     * @param cms The CmsObject
     */
    public void undelete(CmsObject cms) throws Exception {
        getDbAccessObject(getSubId()).undelete(m_cms, this, m_dataSet);
    }
    
    /**
     * Overwrite this method in your subclasses to execute any tasks before the resources are published.
     */
    public static boolean beforePublish( CmsObject cms, Boolean enableHistory,
        Integer projectId, Integer versionId, Long publishingDate,
        Vector changedRessources, Vector changedModuleData, CmsMasterDataSet dataset ) {
        
        if (false && ((cms == null) && (enableHistory == null) && (projectId == null) &&
            (versionId == null) && (publishingDate == null) && (changedRessources == null) &&
            (changedModuleData == null) && (dataset == null))) {
            // silly test so that eclipse does not complain about unused method parameters
        }
        
        return true;
    }

    /**
     * Publishes all modified content definitions for this project.<p>
     * 
     * @param cms The CmsObject
     * @param publishHistoryId the ID of the current publish task
     * @param enableHistory set to true if backup tables should be filled.
     * @param projectId the Project that should be published.
     * @param versionId the versionId to save in the backup tables.
     * @param publishingDate the date and time of this publishing process.
     * @param subId the subId to publish cd's for.
     * @param contentDefinitionClassName the name of cd-class.
     * @param changedRessources a Vector of Ressources that were changed by this
     * publishing process.
     * @param changedModuleData a Vector of Ressource that were changed by this
     * publishing process. New published data will be add to this Vector to
     * return it.
     */
    protected static void publishProject(CmsObject cms, CmsUUID publishHistoryId,
        boolean enableHistory, int projectId, int versionId, long publishingDate,
        int subId, String contentDefinitionClassName,
        Vector changedRessources, Vector changedModuleData) throws CmsException {

         // now publish the project
         getDbAccessObject(subId).publishProject(cms, publishHistoryId, enableHistory,
             projectId, versionId, publishingDate, subId,
             contentDefinitionClassName, changedRessources, changedModuleData );
    }

    /**
     * Returns a Vector with the datasets of the contentdefinitions in the given channel.
     * @param subId the id-type of the contentdefinition.
     * @param channelId the id of the channel.
     * @return Vector the vector that includes the datasets
     */

⌨️ 快捷键说明

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