View Javadoc

1   /*
2    *   Copyright (C) Christian Schulte, 2005-206
3    *   All rights reserved.
4    *
5    *   Redistribution and use in source and binary forms, with or without
6    *   modification, are permitted provided that the following conditions
7    *   are met:
8    *
9    *     o Redistributions of source code must retain the above copyright
10   *       notice, this list of conditions and the following disclaimer.
11   *
12   *     o Redistributions in binary form must reproduce the above copyright
13   *       notice, this list of conditions and the following disclaimer in
14   *       the documentation and/or other materials provided with the
15   *       distribution.
16   *
17   *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18   *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19   *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20   *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
21   *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22   *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23   *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24   *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25   *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26   *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27   *
28   *   $JOMC: PropertiesResourceType.java 4613 2012-09-22 10:07:08Z schulte $
29   *
30   */
31  package org.jomc.mojo;
32  
33  import java.util.Arrays;
34  import java.util.Collections;
35  import java.util.List;
36  
37  /**
38   * Datatype describing a properties resource.
39   *
40   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
41   * @version $JOMC: PropertiesResourceType.java 4613 2012-09-22 10:07:08Z schulte $
42   * @since 1.2
43   */
44  public class PropertiesResourceType extends ResourceType
45  {
46  
47      /** Constant for the plain properties file format. */
48      public static final String PLAIN_FORMAT = "plain";
49  
50      /** Constant for the XML properties file format. */
51      public static final String XML_FORMAT = "xml";
52  
53      /** Supported properties file format values. */
54      private static final String[] FORMAT_VALUES =
55      {
56          PLAIN_FORMAT, XML_FORMAT
57      };
58  
59      /** The format of the properties resource. */
60      private String format;
61  
62      /** Creates a new {@code PropertiesResourceType} instance. */
63      public PropertiesResourceType()
64      {
65          super();
66      }
67  
68      /**
69       * Gets the value of the {@code format} property.
70       *
71       * @return The value of the {@code format} property.
72       */
73      public final String getFormat()
74      {
75          if ( this.format == null )
76          {
77              this.format = PLAIN_FORMAT;
78          }
79  
80          return this.format;
81      }
82  
83      /**
84       * Sets the value of the {@code format} property.
85       *
86       * @param value The new value of the {@code format} property or {@code null}.
87       */
88      public final void setFormat( final String value )
89      {
90          this.format = value;
91      }
92  
93      /**
94       * Gets a list holding supported format values.
95       *
96       * @return An unmodifiable list holding supported format values.
97       *
98       * @see #isFormatSupported(java.lang.String)
99       */
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 }