1 /* 2 * Copyright (C) Christian Schulte <cs@schulte.it>, 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 5043 2015-05-27 07:03:39Z 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 5043 2015-05-27 07:03:39Z schulte $ 42 * @since 1.2 43 */ 44 public class PropertiesResourceType extends ResourceType 45 { 46 47 /** 48 * Constant for the plain properties file format. 49 */ 50 public static final String PLAIN_FORMAT = "plain"; 51 52 /** 53 * Constant for the XML properties file format. 54 */ 55 public static final String XML_FORMAT = "xml"; 56 57 /** 58 * Supported properties file format values. 59 */ 60 private static final String[] FORMAT_VALUES = 61 { 62 PLAIN_FORMAT, XML_FORMAT 63 }; 64 65 /** 66 * The format of the properties resource. 67 */ 68 private String format; 69 70 /** 71 * Creates a new {@code PropertiesResourceType} instance. 72 */ 73 public PropertiesResourceType() 74 { 75 super(); 76 } 77 78 /** 79 * Gets the value of the {@code format} property. 80 * 81 * @return The value of the {@code format} property. 82 */ 83 public final String getFormat() 84 { 85 if ( this.format == null ) 86 { 87 this.format = PLAIN_FORMAT; 88 } 89 90 return this.format; 91 } 92 93 /** 94 * Sets the value of the {@code format} property. 95 * 96 * @param value The new value of the {@code format} property or {@code null}. 97 */ 98 public final void setFormat( final String value ) 99 { 100 this.format = value; 101 } 102 103 /** 104 * Gets a list holding supported format values. 105 * 106 * @return An unmodifiable list holding supported format values. 107 * 108 * @see #isFormatSupported(java.lang.String) 109 */ 110 public static List<String> getSupportedFormats() 111 { 112 return Collections.unmodifiableList( Arrays.asList( FORMAT_VALUES ) ); 113 } 114 115 /** 116 * Tests a given format value. 117 * 118 * @param value The format value to test. 119 * 120 * @return {@code true}, if the given format value is supported; {@code false}, if the given format value is not 121 * supported. 122 * 123 * @see #getSupportedFormats() 124 */ 125 public static boolean isFormatSupported( final String value ) 126 { 127 if ( value != null ) 128 { 129 for ( int i = FORMAT_VALUES.length - 1; i >= 0; i-- ) 130 { 131 if ( value.equalsIgnoreCase( FORMAT_VALUES[i] ) ) 132 { 133 return true; 134 } 135 } 136 } 137 138 return false; 139 } 140 141 /** 142 * Creates and returns a copy of this object. 143 * 144 * @return A copy of this object. 145 */ 146 @Override 147 public PropertiesResourceType clone() 148 { 149 return (PropertiesResourceType) super.clone(); 150 } 151 152 }