001/*
002 *   Copyright (C) Christian Schulte, 2005-206
003 *   All rights reserved.
004 *
005 *   Redistribution and use in source and binary forms, with or without
006 *   modification, are permitted provided that the following conditions
007 *   are met:
008 *
009 *     o Redistributions of source code must retain the above copyright
010 *       notice, this list of conditions and the following disclaimer.
011 *
012 *     o Redistributions in binary form must reproduce the above copyright
013 *       notice, this list of conditions and the following disclaimer in
014 *       the documentation and/or other materials provided with the
015 *       distribution.
016 *
017 *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
018 *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
019 *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
020 *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
021 *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
022 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
023 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
024 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
026 *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027 *
028 *   $JOMC: PropertiesResourceType.java 4613 2012-09-22 10:07:08Z schulte $
029 *
030 */
031package org.jomc.mojo;
032
033import java.util.Arrays;
034import java.util.Collections;
035import java.util.List;
036
037/**
038 * Datatype describing a properties resource.
039 *
040 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
041 * @version $JOMC: PropertiesResourceType.java 4613 2012-09-22 10:07:08Z schulte $
042 * @since 1.2
043 */
044public class PropertiesResourceType extends ResourceType
045{
046
047    /** Constant for the plain properties file format. */
048    public static final String PLAIN_FORMAT = "plain";
049
050    /** Constant for the XML properties file format. */
051    public static final String XML_FORMAT = "xml";
052
053    /** Supported properties file format values. */
054    private static final String[] FORMAT_VALUES =
055    {
056        PLAIN_FORMAT, XML_FORMAT
057    };
058
059    /** The format of the properties resource. */
060    private String format;
061
062    /** Creates a new {@code PropertiesResourceType} instance. */
063    public PropertiesResourceType()
064    {
065        super();
066    }
067
068    /**
069     * Gets the value of the {@code format} property.
070     *
071     * @return The value of the {@code format} property.
072     */
073    public final String getFormat()
074    {
075        if ( this.format == null )
076        {
077            this.format = PLAIN_FORMAT;
078        }
079
080        return this.format;
081    }
082
083    /**
084     * Sets the value of the {@code format} property.
085     *
086     * @param value The new value of the {@code format} property or {@code null}.
087     */
088    public final void setFormat( final String value )
089    {
090        this.format = value;
091    }
092
093    /**
094     * Gets a list holding supported format values.
095     *
096     * @return An unmodifiable list holding supported format values.
097     *
098     * @see #isFormatSupported(java.lang.String)
099     */
100    public static List<String> getSupportedFormats()
101    {
102        return Collections.unmodifiableList( Arrays.asList( FORMAT_VALUES ) );
103    }
104
105    /**
106     * Tests a given format value.
107     *
108     * @param value The format value to test.
109     *
110     * @return {@code true}, if the given format value is supported; {@code false}, if the given format value is not
111     * supported.
112     *
113     * @see #getSupportedFormats()
114     */
115    public static boolean isFormatSupported( final String value )
116    {
117        if ( value != null )
118        {
119            for ( int i = FORMAT_VALUES.length - 1; i >= 0; i-- )
120            {
121                if ( value.equalsIgnoreCase( FORMAT_VALUES[i] ) )
122                {
123                    return true;
124                }
125            }
126        }
127
128        return false;
129    }
130
131    /**
132     * Creates and returns a copy of this object.
133     *
134     * @return A copy of this object.
135     */
136    @Override
137    public PropertiesResourceType clone()
138    {
139        return (PropertiesResourceType) super.clone();
140    }
141
142}