cmsproject.java

来自「找了很久才找到到源代码」· Java 代码 · 共 583 行 · 第 1/2 页

JAVA
583
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/file/CmsProject.java,v $
 * Date   : $Date: 2007-08-13 16:29:58 $
 * Version: $Revision: 1.22 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.file;

import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.security.CmsOrganizationalUnit;
import org.opencms.util.A_CmsModeIntEnumeration;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;

import java.util.List;

/**
 * Describes an OpenCms project, 
 * which contains a set of VFS resources that are being worked on at the same time.<p>
 *
 * @author Alexander Kandzior 
 * @author Michael Emmerich 
 *
 * @version $Revision: 1.22 $
 * 
 * @since 6.0.0 
 */
public class CmsProject implements Cloneable, Comparable {

    /**
     *  Enumeration class for project types.<p>
     */
    public static final class CmsProjectType extends A_CmsModeIntEnumeration {

        /** Project type normal. */
        protected static final CmsProjectType MODE_PROJECT_NORMAL = new CmsProjectType(0);

        /** Project type temporary. */
        protected static final CmsProjectType MODE_PROJECT_TEMPORARY = new CmsProjectType(1);

        /** Serializable version id. */
        private static final long serialVersionUID = -8701314451776599534L;

        /**
         * Private constructor.<p>
         * 
         * @param mode the copy mode integer representation
         */
        private CmsProjectType(int mode) {

            super(mode);
        }

        /**
         * Returns the copy mode object from the old copy mode integer.<p>
         * 
         * @param mode the old copy mode integer
         * 
         * @return the copy mode object
         */
        public static CmsProjectType valueOf(int mode) {

            switch (mode) {
                case 0:
                    return CmsProjectType.MODE_PROJECT_NORMAL;
                case 1:
                    return CmsProjectType.MODE_PROJECT_TEMPORARY;
                default:
                    return CmsProjectType.MODE_PROJECT_NORMAL;
            }
        }
    }

    /** The name of the online project. */
    public static final String ONLINE_PROJECT_NAME = "Online";

    /** The id of the online project. */
    public static final CmsUUID ONLINE_PROJECT_ID = CmsUUID.getConstantUUID(ONLINE_PROJECT_NAME);

    /** Indicates that a project is invisible in the workplace. */
    public static final int PROJECT_FLAG_HIDDEN = 4;

    /** Indicates that a normal project. */
    public static final int PROJECT_FLAG_NONE = 0;

    /** Indicates a normal project. */
    public static final CmsProjectType PROJECT_TYPE_NORMAL = CmsProjectType.MODE_PROJECT_NORMAL;

    /** Indicates a temporary project that is deleted after it is published. */
    public static final CmsProjectType PROJECT_TYPE_TEMPORARY = CmsProjectType.MODE_PROJECT_TEMPORARY;

    /** The creation date of this project. */
    private long m_dateCreated;

    /** The description of this project. */
    private String m_description;

    /** The state of this project. */
    private int m_flags;

    /** The manager group id of this project. */
    private CmsUUID m_groupManagersId;

    /** The id of the user group of this project. */
    private CmsUUID m_groupUsersId;

    /** The id of this project. */
    private CmsUUID m_id;

    /** The name of this project. */
    private String m_name;

    /** The id of this projects owner. */
    private CmsUUID m_ownerId;

    /** The type of this project. */
    private CmsProjectType m_type;

    /**
     * Default constructor for gui usage.<p>
     */
    public CmsProject() {

        // empty
    }

    /**
     * Creates a new CmsProject.<p>
     *  
     * @param projectId the id to use for this project
     * @param projectFqn the name for this project
     * @param description the description for this project
     * @param ownerId the owner id for this project
     * @param groupId the group id for this project
     * @param managerGroupId the manager group id for this project
     * @param flags the flags for this project
     * @param dateCreated the creation date of this project
     * @param type the type of this project
     */
    public CmsProject(
        CmsUUID projectId,
        String projectFqn,
        String description,
        CmsUUID ownerId,
        CmsUUID groupId,
        CmsUUID managerGroupId,
        int flags,
        long dateCreated,
        CmsProjectType type) {

        m_id = projectId;
        m_name = projectFqn;
        m_description = description;
        m_ownerId = ownerId;
        m_groupUsersId = groupId;
        m_groupManagersId = managerGroupId;
        m_flags = flags;
        m_type = type;
        m_dateCreated = dateCreated;
    }

    /**
     * Throws a runtime exception if name is empty.<p>
     * 
     * @param name the project name to check
     */
    public static void checkProjectName(String name) {

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(name)) {
            throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_PROJECTNAME_VALIDATION_0));
        }
    }

    /**
     * Checks if the full resource name (including the site root) of a resource matches
     * any of the project resources of a project.<p>
     * 
     * @param projectResources a List of project resources as Strings
     * @param resource the resource to check
     * @return true, if the resource is "inside" the project resources
     */
    public static boolean isInsideProject(List projectResources, CmsResource resource) {

        String resourcename = resource.getRootPath();
        return isInsideProject(projectResources, resourcename);
    }

    /**
     * Checks if the full resource name (including the site root) of a resource matches
     * any of the project resources of a project.<p>
     * 
     * @param projectResources a List of project resources as Strings
     * @param resourcename the resource to check
     * @return true, if the resource is "inside" the project resources
     */
    public static boolean isInsideProject(List projectResources, String resourcename) {

        for (int i = (projectResources.size() - 1); i >= 0; i--) {
            String projectResource = (String)projectResources.get(i);
            if (CmsResource.isFolder(projectResource)) {
                if (resourcename.startsWith(projectResource)) {
                    // folder - check only the prefix
                    return true;
                }
            } else {
                if (resourcename.equals(projectResource)) {
                    // file - check the full path
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Returns true if the given project id is the online project id.<p>
     *  
     * @param projectId the project id to check
     * @return true if the given project id is the online project id
     */
    public static boolean isOnlineProject(CmsUUID projectId) {

        return projectId.equals(CmsProject.ONLINE_PROJECT_ID);
    }

    /**
     * @see java.lang.Object#clone()
     */
    public Object clone() {

        return new CmsProject(
            m_id,
            m_name,
            m_description,
            m_ownerId,
            m_groupUsersId,
            m_groupManagersId,
            m_flags,
            m_dateCreated,
            m_type);
    }

    /**
     * Compares this instance to another given object instance of this class .<p>
     * 
     * @param o the other given object instance to compare with
     * @return integer value for sorting the objects
     */
    public int compareTo(Object o) {

        if (o == this) {
            return 0;
        }

        if (o instanceof CmsProject) {
            try {
                // compare the names
                return m_name.compareTo(((CmsProject)o).getName());
            } catch (Exception e) {
                // ignore, return 0
            }
        }
        return 0;
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)

⌨️ 快捷键说明

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