001/*
002 *  Copyright 2010 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.cms.contenttype;
017
018import org.ametys.plugins.repository.data.type.ModelItemTypeConstants;
019import org.ametys.runtime.model.type.ElementType;
020import org.ametys.runtime.model.type.ModelItemType;
021
022/** 
023 * Metadata type
024 * @deprecated Use {@link ElementType} instead
025 */
026@Deprecated
027public enum MetadataType
028{
029    /** String type. */
030    STRING,
031    /** Multilingual string */
032    MULTILINGUAL_STRING
033    {
034        @Override
035        public String getId()
036        {
037            return super.getId().replaceAll("_", "-");
038        }
039    },
040    /** Date type. */
041    DATE,
042    /** Date time type. */
043    DATETIME,
044    /** Long type. */
045    LONG,
046    /** Geocode type. */
047    GEOCODE,
048    /** Double type. */
049    DOUBLE,
050    /** Boolean type. */
051    BOOLEAN,
052    /** Composite type. */
053    COMPOSITE,
054    /** Binary type. */
055    BINARY,
056    /** Rich text type. */
057    RICH_TEXT
058    {
059        @Override
060        public String getId()
061        {
062            return super.getId().replaceAll("_", "-");
063        }
064    },
065    /** User type. */
066    USER,
067    /** Reference type (Resources explorer / dn of a directory / ...). */
068    REFERENCE,
069    /** Reference to a content. */
070    CONTENT,
071    /** Sub-content. */
072    SUB_CONTENT,
073    /** File type, may be a binary or a reference (symbolic link). */
074    FILE;
075    
076    /**
077     * Retrieves the type identifier
078     * @return the type identifier
079     */
080    public String getId()
081    {
082        return name();
083    }
084    
085    /**
086     * Retrieves the {@link MetadataType} corresponding to the given {@link ModelItemType}
087     * @param type the {@link ModelItemType}
088     * @return the {@link MetadataType} corresponding to the given {@link ModelItemType}
089     */
090    public static MetadataType fromModelItemType(ModelItemType type)
091    {
092        return fromModelItemTypeId(type.getId());
093    }
094    
095    /**
096     * Retrieves the {@link MetadataType} corresponding to the given {@link ModelItemType} id
097     * @param typeId the {@link ModelItemType} id
098     * @return the {@link MetadataType} corresponding to the given {@link ModelItemType} id
099     */
100    public static MetadataType fromModelItemTypeId(String typeId)
101    {
102        if (ModelItemTypeConstants.REPEATER_TYPE_ID.equals(typeId))
103        {
104            return COMPOSITE;
105        }
106        return MetadataType.valueOf(typeId.toUpperCase().replaceAll("-", "_"));
107    }
108}