1  /*
     2   * Copyright the original author or authors.
     3   * 
     4   * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   * 
     8   *      http://www.mozilla.org/MPL/MPL-1.1.html
     9   * 
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  import org.as2lib.data.type.Byte;
    18  import org.as2lib.io.file.SimpleTextFile;
    19  import org.as2lib.data.holder.Properties;
    20  import org.as2lib.data.holder.properties.PropertiesParser;
    21  
    22  /**
    23   * {@code PropertiesFile} represents a file of properties.
    24   * 
    25   * <p>A properties file contains simple key-value pairs. Multiple pairs are
    26   * separated by line terminators (\n or \r or \r\n). Keys are separated from
    27   * values with the characters '=', ':' or a white space character.
    28   * 
    29   * <p>Comments are also supported. Just add a '#' or '!' character at the
    30   * beginning of your comment-line.
    31   * 
    32   * <p>If you want to use any of the special characters in your key or value you
    33   * must escape it with a back-slash character '\'.
    34   * 
    35   * <p>The key contains all of the characters in a line starting from the first
    36   * non-white space character up to, but not including, the first unescaped
    37   * key-value-separator.
    38   * 
    39   * <p>The value contains all of the characters in a line starting from the first
    40   * non-white space character after the key-value-separator up to the end of the
    41   * line. You may of course also escape the line terminator and create a value
    42   * across multiple lines.
    43   * 
    44   * @author Martin Heidegger
    45   * @author Simon Wacker
    46   * @version 1.0
    47   * @see PropertiesParser
    48   */
    49  class org.as2lib.io.file.PropertiesFile extends SimpleTextFile {
    50  	
    51  	/** The data structure representation of this properties file. */
    52  	private var properties:Properties;
    53  	
    54  	/**
    55  	 * Constructs a new {@code PropertiesFile} instance.
    56  	 * 
    57  	 * <p>For information on how the source must look like take a look at this class's
    58  	 * class documentation.
    59  	 * 
    60  	 * @param source the content of the properties file
    61  	 * @param size the size in bytes of the properties file
    62  	 * @param uri the URI to the properties file
    63  	 */
    64  	public function PropertiesFile(source:String, size:Byte, uri:String) {
    65  		super(source, size, uri);
    66  	}
    67  	
    68  	/**
    69  	 * Returns the data structure representaton of this properties file.
    70  	 * 
    71  	 * @return this properties file data structure representation
    72  	 */
    73  	public function getProperties(Void):Properties {
    74  		if (!properties) {
    75  			properties = (new PropertiesParser()).parseProperties(source);
    76  		}
    77  		return properties;
    78  	}
    79  	
    80  }