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.form;
017
018import java.util.Collections;
019import java.util.HashMap;
020import java.util.Map;
021
022import org.ametys.plugins.repository.metadata.Resource;
023import org.ametys.plugins.repository.metadata.RichText;
024
025/**
026 * A rich text field for managing {@link RichText} metadata.
027 */
028public class RichTextField extends AbstractField
029{
030    private final String _content;
031    
032    private String _format;
033    
034    private Map<String, Resource> _additionalData;
035    
036    /**
037     * Creates a {@link RichTextField}.
038     * @param content the content.
039     */
040    public RichTextField(String content)
041    {
042        _content = content;
043    }
044    
045    /**
046     * Retrieves the content.
047     * @return the content.
048     */
049    public String getContent()
050    {
051        return _content;
052    }
053    
054    /**
055     * Retrieves the content format.
056     * @return the content format.
057     */
058    public String getFormat()
059    {
060        return _format;
061    }
062    
063    /**
064     * Set the content format.
065     * @param format the content format.
066     */
067    public void setFormat(String format)
068    {
069        _format = format;
070    }
071    
072    /**
073     * Get the additional data.
074     * @return the additional data.
075     */
076    public Map<String, Resource> getAdditionalData()
077    {
078        if (_additionalData == null)
079        {
080            return null;
081        }
082        else
083        {
084            return Collections.unmodifiableMap(_additionalData);
085        }
086    }
087    
088    /**
089     * Set the additional data.
090     * @param addData the additional data to set.
091     */
092    public void setAdditionalData(Map<String, Resource> addData)
093    {
094        _additionalData = new HashMap<>(addData);
095    }
096    
097    @Override
098    public String toString()
099    {
100        return "RICHTEXT: " + _content;
101    }
102}