001/*
002 *  Copyright 2015 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 org.ametys.plugins.repository.metadata.BinaryMetadata;
019
020/**
021 * A field managing {@link BinaryMetadata}.
022 */
023public class BinaryField extends SimpleField<String>
024{
025    
026    private BinaryMetadata _binary;
027    
028    /**
029     * Creates a {@link BinaryField}.
030     * @param values the values.
031     */
032    public BinaryField(String[] values)
033    {
034        super(values);
035    }
036    
037    /**
038     * Get the binary content.
039     * @return the binary content.
040     */
041    public BinaryMetadata getBinaryValue()
042    {
043        return _binary;
044    }
045    
046    /**
047     * Set the source binary metadata.
048     * @param meta the source binary metadata.
049     */
050    public void setBinaryValue(BinaryMetadata meta)
051    {
052        _binary = meta;
053    }
054    
055    /**
056     * Test if a source binary metadata is present.
057     * @return true if a source binary metadata is present.
058     */
059    public boolean hasBinaryValue()
060    {
061        return _binary != null;
062    }
063    
064    @Override
065    public String toString()
066    {
067        StringBuilder s = new StringBuilder();
068        s.append("BINARY: ").append(getValues());
069        if (_binary.getFilename() != null)
070        {
071            s.append(" (").append(_binary.getFilename()).append(")");
072        }
073        return s.toString();
074//        String str = "BINARY: " + getValues();
075//        if (_binary.getFilename() != null)
076//        {
077//            str = str + " (" + _binary.
078//        }
079//        return "BINARY: " + getValues() + _binary.getFilename() != null ;
080    }
081    
082}