001package ball.util.ant.types;
002/*-
003 * ##########################################################################
004 * Utilities
005 * $Id: StringValueType.java 5285 2020-02-05 04:23:21Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/ball-util/trunk/src/main/java/ball/util/ant/types/StringValueType.java $
007 * %%
008 * Copyright (C) 2008 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import java.beans.ConstructorProperties;
024
025import static org.apache.commons.lang3.StringUtils.EMPTY;
026import static org.apache.commons.lang3.StringUtils.isEmpty;
027
028/**
029 * Class to provide a {@link String} value type for
030 * {@link.uri http://ant.apache.org/ Ant} {@link org.apache.tools.ant.Task}
031 * implementations.
032 *
033 * {@bean.info}
034 *
035 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
036 * @version $Revision: 5285 $
037 */
038public class StringValueType extends OptionalTextType {
039    private String value = null;
040
041    /**
042     * @param   value           The value.
043     */
044    @ConstructorProperties({ "value" })
045    public StringValueType(String value) {
046        this();
047
048        setValue(value);
049    }
050
051    /**
052     * No-argument constructor.
053     */
054    public StringValueType() { super(); }
055
056    public String getValue() { return value; }
057    public String setValue(String value) {
058        String previous = this.value;
059
060        this.value = value;
061
062        return previous;
063    }
064
065    @Override
066    public void addText(String text) {
067        setValue((isEmpty(getValue()) ? EMPTY : getValue()) + text);
068    }
069
070    @Override
071    public String toString() { return getValue(); }
072}