Class ConfigHelper


  • public class ConfigHelper
    extends java.lang.Object
    The config helper provides convenience functions to load the configuration from the local application repo.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConfigHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean configExists​(java.io.File localDir)
      Returns true if the config.xml file exists, given a local directory.
      static java.io.File findLocalDirInPath​(java.io.File startingPath)
      Helper method to find the local sync directory, starting from a path equal or inside the local sync directory.
      static Config loadConfig​(java.io.File localDir)
      Loads a Config object from the given local directory.
      static ConfigTO loadConfigTO​(java.io.File localDir)
      Loads the config transfer object from the local directory or throws an exception if the file does not exist.
      static RepoTO loadRepoTO​(java.io.File localDir, ConfigTO configTO)
      Loads the repository transfer object from the local directory.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • loadConfig

        public static Config loadConfig​(java.io.File localDir)
                                 throws ConfigException
        Loads a Config object from the given local directory.

        If the config file (.syncany/config.xml) does not exist, null is returned. If it does, the method tries to do the following:

        • Load the .syncany/config.xml file and load the plugin given by the config file
        • Read .syncany/repo, decrypt it using the master key (if necessary) and load it
        • Instantiate a Config object with the transfer objects
        Returns:
        Returns an instantiated Config object, or null if the config file does not exist
        Throws:
        ConfigException - an exception if the config is invalid
      • configExists

        public static boolean configExists​(java.io.File localDir)
        Returns true if the config.xml file exists, given a local directory.
      • findLocalDirInPath

        public static java.io.File findLocalDirInPath​(java.io.File startingPath)
        Helper method to find the local sync directory, starting from a path equal or inside the local sync directory. If the starting path is not inside or equal to the local directory, null is returned.

        To find the local directory, the method looks for a file named "Config.DIR_APPLICATION/Config.FILE_CONFIG". If it is found, it stops. If not, it continues looking in the parent directory.

        Example: If /home/user/Syncany is the local sync directory and /home/user/NotSyncany is not a local directory, the method will return the following:

        • findLocalDirInPath(/home/user/Syncany) -> /home/user/Syncany
        • findLocalDirInPath(/home/user/Syncany/some/subfolder) -> /home/user/Syncany
        • findLocalDirInPath(/home/user/NotSyncany) ->null
        Parameters:
        startingPath - Path to start the search from
        Returns:
        Returns the local directory (if found), or null otherwise