Class PropertiesFile


  • public class PropertiesFile
    extends BasePropertiesFile

    In-memory representation of a TDI properties file. It may contain comments and empty lines as well as property definitions. It may also contain references to other properties files. The properties file could also be encrypted.

    A property in a TDI properties file can be protected or non-protected. Protected properties normally have their keys prefixed with PropertiesFile.PROTECT_PREFIX. Protected properties may have their values encrypted. If a property value is encrypted, it will be prefixed with PropertiesFile.PROTECT_VAL_PREFIX. If a property's value is encrypted, the property is considered protected no matter if it is actually marked as protected.

    Since:
    7.0
    See Also:
    BasePropertiesFile
    • Field Detail

      • INCLUDE_DIRECTIVE

        public static final java.lang.String INCLUDE_DIRECTIVE

        Include directive "!include <other-file/url>"

        Include one properties file into another properties file. Properties defined in the main properties file before the include directive can be potentially overridden by properties from the included file. Properties defined in the main properties file after the include directive can potentially override properties from the included file.

        See Also:
        Constant Field Values
      • MERGE_DIRECTIVE

        public static final java.lang.String MERGE_DIRECTIVE

        Merge directive - "!merge <other-file/url>".

        Merge the contents of one properties file into another properties file. Properties defined in the main properties file before the merge directive will not be overwritten by the properties from the merged file. Properties defined in the main properties file after the merge directive can potentially override properties from the merged file.

        See Also:
        Constant Field Values
    • Constructor Detail

      • PropertiesFile

        public PropertiesFile​(Crypto propertyCrypto)
        Create an empty object.
        Parameters:
        propertyCrypto - object used to encrypt/decrypt values of protected properties
      • PropertiesFile

        public PropertiesFile​(java.lang.String path,
                              boolean resolveReferences)
                       throws java.lang.Exception
        Load a properties file in memory. Uses a default Crypto.
        Parameters:
        path - properties file to load
        resolveReferences - whether to load the properties files that the specified file references
        Throws:
        java.lang.Exception - error while reading the properties file
      • PropertiesFile

        public PropertiesFile​(Crypto propertyCrypto,
                              java.lang.String path,
                              boolean resolveReferences)
                       throws java.lang.Exception
        Load a properties file in memory.
        Parameters:
        propertyCrypto - object used to encrypt/decrypt values of protected properties
        path - properties file to load
        resolveReferences - whether to load the properties files that the specified file references
        Throws:
        java.lang.Exception - error while reading the properties file
      • PropertiesFile

        public PropertiesFile​(Crypto propertyCrypto,
                              java.lang.String path,
                              boolean resolveReferences,
                              Crypto fileCrypto,
                              java.lang.String prefixToSkip)
                       throws java.lang.Exception
        Load a properties file in memory. If the specified file is encrypted as a whole, a cryptographic object to decrypt the file must be provided. If a file is encrypted as a whole, all the files it references are expected to be encrypted too. The specified crypto object will be used to decrypt them also.
        Parameters:
        propertyCrypto - object used to encrypt/decrypt values of protected properties
        path - properties file to load
        resolveReferences - whether to load the properties files that the specified file references
        fileCrypto - object used to decrypt the file; pass null if the properties file is not encrypted as a whole
        prefixToSkip - prefix that matches lines from the properties file, which will be skipped during processing; pass null to read all lines
        Throws:
        java.lang.Exception - error while reading the properties file, or error while decrypting it
    • Method Detail

      • store

        public void store​(java.lang.String path,
                          java.lang.String header,
                          Crypto fileCrypto)
                   throws java.lang.Exception
        Write the contents of this properties file to disk.
        Parameters:
        path - a file, whether the contents will be saved
        header - an optional header, that will be put as the first line in the properties file; must be a single comment line
        fileCrypto - object used to encrypt the file as a whole; if null the file will not be encrypted as a whole
        Throws:
        java.lang.Exception - error while writing the file or error while encrypting the file
      • store

        public void store​(java.lang.String path)
                   throws java.lang.Exception
        Write the contents of this properties file to disk. The file is not encrypted and no header is written.
        Specified by:
        store in class BasePropertiesFile
        Parameters:
        path - a file, whether the contents will be saved
        Throws:
        java.lang.Exception - error while writing the file